dependency_on_destroyed_task.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <signal.h>
  2. #include <stdlib.h>
  3. #include "../helper.h"
  4. /*
  5. * It is possible to depend on a task that is over, but not on a task that has
  6. * already been destroyed. In this test, we make sure things go wrong if taskB
  7. * depends upon the destroyed taskA. It should trigger STARPU_ASSERT or
  8. * STARPU_ABORT somewhere in StarPU, so we can try and cath SIGABRT. Note that
  9. * the error might be weirder, leading this test to fail. In this case, it is
  10. * probably OK to disable it for a while :-) Maybe we could also detect
  11. * destroyed tasks in starpu_task_declare_deps_array.
  12. */
  13. static void abort_catcher(int sig)
  14. {
  15. (void) sig;
  16. starpu_shutdown();
  17. /* Here, failure is success. */
  18. exit(EXIT_SUCCESS);
  19. }
  20. int
  21. main(void)
  22. {
  23. int ret;
  24. struct starpu_task *taskA, *taskB;
  25. ret = starpu_init(NULL);
  26. if (ret == -ENODEV)
  27. {
  28. return STARPU_TEST_SKIPPED;
  29. }
  30. taskA = starpu_task_create();
  31. taskA->cl = NULL;
  32. taskA->detach = 0;
  33. taskB = starpu_task_create();
  34. taskB->cl = NULL;
  35. ret = starpu_task_submit(taskA);
  36. if (ret == -ENODEV)
  37. {
  38. starpu_shutdown();
  39. return STARPU_TEST_SKIPPED;
  40. }
  41. ret = starpu_task_wait(taskA);
  42. if (ret != 0)
  43. {
  44. starpu_shutdown();
  45. return EXIT_FAILURE;
  46. }
  47. /* taskA should have been destroyed by now. */
  48. struct sigaction sa;
  49. sa.sa_handler = abort_catcher;
  50. sigaction(SIGABRT, &sa, NULL);
  51. sigaction(SIGSEGV, &sa, NULL);
  52. starpu_task_declare_deps_array(taskB, 1, &taskA);
  53. ret = starpu_task_submit(taskB);
  54. if (ret == -ENODEV)
  55. {
  56. starpu_shutdown();
  57. return EXIT_FAILURE;
  58. }
  59. starpu_task_wait_for_all();
  60. starpu_shutdown();
  61. return EXIT_FAILURE;
  62. }