invalid_blocking_calls.c 3.2 KB

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