loader.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Université de Bordeaux 1
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <sys/wait.h>
  17. #include <sys/resource.h>
  18. #include <unistd.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <signal.h>
  22. #include <string.h>
  23. #include <common/config.h>
  24. #define DEFAULT_TIMEOUT 600
  25. #define AUTOTEST_SKIPPED_TEST 77
  26. static pid_t child_pid = 0;
  27. static int timeout;
  28. static void test_cleaner(int sig)
  29. {
  30. pid_t child_gid;
  31. // send signal to all loader family members
  32. fprintf(stderr, "[error] test is blocked since %d seconds. Mark it as failed\n", timeout);
  33. child_gid = getpgid(child_pid);
  34. kill(-child_gid, SIGKILL);
  35. exit(EXIT_FAILURE);
  36. }
  37. int main(int argc, char *argv[])
  38. {
  39. int child_exit_status;
  40. char *test_name;
  41. char *test_args;
  42. int status;
  43. struct sigaction sa;
  44. test_args = NULL;
  45. timeout = 0;
  46. test_name = argv[1];
  47. if (!test_name)
  48. {
  49. fprintf(stderr, "[error] Need name of program to start\n");
  50. exit(EXIT_FAILURE);
  51. }
  52. if (strstr(test_name, "spmv/dw_block_spmv")) {
  53. test_args = (char *) malloc(150*sizeof(char));
  54. sprintf(test_args, "%s/examples/spmv/matrix_market/examples/fidapm05.mtx", STARPU_SRC_DIR);
  55. }
  56. /* get user-defined iter_max value */
  57. if (getenv("STARPU_TIMEOUT_ENV"))
  58. timeout = strtol(getenv("STARPU_TIMEOUT_ENV"), NULL, 10);
  59. if (timeout <= 0)
  60. timeout = DEFAULT_TIMEOUT;
  61. /* set SIGALARM handler */
  62. sa.sa_flags = 0;
  63. sigemptyset(&sa.sa_mask);
  64. sa.sa_handler = test_cleaner;
  65. if (-1 == sigaction(SIGALRM, &sa, NULL))
  66. perror("sigaction");
  67. child_pid = fork();
  68. if (child_pid == 0)
  69. {
  70. // get a new pgid
  71. if (setpgid(0, 0) == -1)
  72. {
  73. perror("setpgid");
  74. fprintf(stderr, "[error] setpgid. Mark test as failed\n");
  75. exit(EXIT_FAILURE);
  76. }
  77. execl(test_name, test_name, test_args, NULL);
  78. fprintf(stderr, "[error] execl. Mark test as failed\n");
  79. exit(EXIT_FAILURE);
  80. }
  81. if (child_pid == -1) {
  82. fprintf(stderr, "[error] fork. Mark test as failed\n");
  83. exit(EXIT_FAILURE);
  84. }
  85. alarm(timeout);
  86. if (child_pid == waitpid(child_pid, &child_exit_status, 0))
  87. {
  88. if (WIFEXITED(child_exit_status))
  89. {
  90. status = WEXITSTATUS(child_exit_status);
  91. if (status == EXIT_SUCCESS)
  92. {
  93. alarm(0);
  94. }
  95. else
  96. {
  97. if (status != AUTOTEST_SKIPPED_TEST)
  98. fprintf(stdout, "Exited with return code %d\n", status);
  99. return status;
  100. }
  101. }
  102. else
  103. {
  104. fprintf(stderr, "[error] child process did not terminate normally. Mark test as failed\n");
  105. return EXIT_FAILURE;
  106. }
  107. }
  108. return EXIT_SUCCESS;
  109. }