invalid_blocking_calls.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013,2017 Inria
  4. * Copyright (C) 2009-2011,2013-2016 Université de Bordeaux
  5. * Copyright (C) 2010-2013,2015,2017 CNRS
  6. * Copyright (C) 2013 Thibaut Lambert
  7. *
  8. * StarPU is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation; either version 2.1 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * StarPU is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  18. */
  19. #include <starpu.h>
  20. #include "../helper.h"
  21. /*
  22. * Check that we catch calling tag_wait, i.e. a blocking call, from the
  23. * codelet function, which is invalid. This test is thus expected to fail.
  24. */
  25. /* mpirun may not exit if it fails, skip the test for master-slave */
  26. #if defined(STARPU_NO_ASSERT) || defined(STARPU_USE_MPI_MASTER_SLAVE)
  27. int main(void)
  28. {
  29. return STARPU_TEST_SKIPPED;
  30. }
  31. #else
  32. #define TAG 0x42
  33. static starpu_data_handle_t handle;
  34. static unsigned *data;
  35. void wrong_func(void *descr[], void *arg)
  36. {
  37. (void)descr;
  38. (void)arg;
  39. /* The function is expected to fail. This is indicated in tests/Makefile.am */
  40. /* try to fetch data in the RAM while we are in a codelet, such a
  41. * blocking call is forbidden */
  42. starpu_data_acquire(handle, STARPU_RW);
  43. starpu_tag_wait(TAG);
  44. }
  45. static struct starpu_codelet wrong_codelet =
  46. {
  47. .modes = { STARPU_RW },
  48. .cpu_funcs = {wrong_func},
  49. .cuda_funcs = {wrong_func},
  50. .opencl_funcs = {wrong_func},
  51. .model = NULL,
  52. .nbuffers = 0
  53. };
  54. static void wrong_callback(void *arg)
  55. {
  56. (void)arg;
  57. /* The function is expected to fail. This is indicated in tests/Makefile.am */
  58. starpu_data_acquire(handle, STARPU_RW);
  59. starpu_tag_wait(TAG);
  60. }
  61. int main(int argc, char **argv)
  62. {
  63. int ret;
  64. if (RUNNING_ON_VALGRIND)
  65. return STARPU_TEST_SKIPPED;
  66. ret = starpu_initialize(NULL, &argc, &argv);
  67. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  68. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  69. starpu_malloc((void**)&data, sizeof(*data));
  70. *data = 42;
  71. /* register a piece of data */
  72. starpu_vector_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)data,
  73. 1, sizeof(unsigned));
  74. struct starpu_task *task = starpu_task_create();
  75. task->cl = &wrong_codelet;
  76. task->handles[0] = handle;
  77. task->use_tag = 1;
  78. task->tag_id = TAG;
  79. task->callback_func = wrong_callback;
  80. task->detach = 0;
  81. ret = starpu_task_submit(task);
  82. if (ret == -ENODEV) goto enodev;
  83. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  84. ret = starpu_tag_wait(TAG);
  85. STARPU_CHECK_RETURN_VALUE(ret, "starpu_tag_wait");
  86. /* This call is valid as it is done by the application outside a
  87. * callback */
  88. ret = starpu_data_acquire(handle, STARPU_RW);
  89. STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_acquire");
  90. starpu_data_release(handle);
  91. ret = starpu_task_wait(task);
  92. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait");
  93. starpu_data_unregister(handle);
  94. starpu_free(data);
  95. starpu_shutdown();
  96. return EXIT_SUCCESS;
  97. enodev:
  98. fprintf(stderr, "WARNING: No one can execute this task\n");
  99. /* yes, we do not perform the computation but we did detect that no one
  100. * could perform the kernel, so this is not an error from StarPU */
  101. starpu_shutdown();
  102. return STARPU_TEST_SKIPPED;
  103. }
  104. #endif