loader.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. {
  54. test_args = (char *) malloc(150*sizeof(char));
  55. sprintf(test_args, "%s/examples/spmv/matrix_market/examples/fidapm05.mtx", STARPU_SRC_DIR);
  56. }
  57. /* get user-defined iter_max value */
  58. if (getenv("STARPU_TIMEOUT_ENV"))
  59. timeout = strtol(getenv("STARPU_TIMEOUT_ENV"), NULL, 10);
  60. if (timeout <= 0)
  61. timeout = DEFAULT_TIMEOUT;
  62. /* set SIGALARM handler */
  63. sa.sa_flags = 0;
  64. sigemptyset(&sa.sa_mask);
  65. sa.sa_handler = test_cleaner;
  66. if (-1 == sigaction(SIGALRM, &sa, NULL))
  67. perror("sigaction");
  68. child_pid = fork();
  69. if (child_pid == 0)
  70. {
  71. // get a new pgid
  72. if (setpgid(0, 0) == -1)
  73. {
  74. perror("setpgid");
  75. fprintf(stderr, "[error] setpgid. Mark test as failed\n");
  76. exit(EXIT_FAILURE);
  77. }
  78. execl(test_name, test_name, test_args, NULL);
  79. fprintf(stderr, "[error] execl. Mark test as failed\n");
  80. exit(EXIT_FAILURE);
  81. }
  82. if (child_pid == -1)
  83. {
  84. fprintf(stderr, "[error] fork. Mark test as failed\n");
  85. exit(EXIT_FAILURE);
  86. }
  87. alarm(timeout);
  88. if (child_pid == waitpid(child_pid, &child_exit_status, 0))
  89. {
  90. if (WIFEXITED(child_exit_status))
  91. {
  92. status = WEXITSTATUS(child_exit_status);
  93. if (status == EXIT_SUCCESS)
  94. {
  95. alarm(0);
  96. }
  97. else
  98. {
  99. if (status != AUTOTEST_SKIPPED_TEST)
  100. fprintf(stdout, "Exited with return code %d\n", status);
  101. return status;
  102. }
  103. }
  104. else
  105. {
  106. fprintf(stderr, "[error] child process did not terminate normally. Mark test as failed\n");
  107. return EXIT_FAILURE;
  108. }
  109. }
  110. return EXIT_SUCCESS;
  111. }