invalid_blocking_calls.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010, 2013, 2015 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. #ifdef STARPU_NO_ASSERT
  21. int main(int argc, char **argv)
  22. {
  23. return STARPU_TEST_SKIPPED;
  24. }
  25. #else
  26. #define TAG 0x42
  27. static starpu_data_handle_t handle;
  28. static unsigned *data;
  29. void wrong_func(void *descr[], void *arg)
  30. {
  31. /* The function is expected to fail. This is indicated in tests/Makefile.am */
  32. /* try to fetch data in the RAM while we are in a codelet, such a
  33. * blocking call is forbidden */
  34. starpu_data_acquire(handle, STARPU_RW);
  35. starpu_tag_wait(TAG);
  36. }
  37. static struct starpu_codelet wrong_codelet =
  38. {
  39. .modes = { STARPU_RW },
  40. .cpu_funcs = {wrong_func},
  41. .cuda_funcs = {wrong_func},
  42. .opencl_funcs = {wrong_func},
  43. .model = NULL,
  44. .nbuffers = 0
  45. };
  46. static void wrong_callback(void *arg)
  47. {
  48. /* The function is expected to fail. This is indicated in tests/Makefile.am */
  49. starpu_data_acquire(handle, STARPU_RW);
  50. starpu_tag_wait(TAG);
  51. }
  52. int main(int argc, char **argv)
  53. {
  54. int ret;
  55. if (RUNNING_ON_VALGRIND)
  56. return STARPU_TEST_SKIPPED;
  57. ret = starpu_initialize(NULL, &argc, &argv);
  58. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  59. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  60. starpu_malloc((void**)&data, sizeof(*data));
  61. *data = 42;
  62. /* register a piece of data */
  63. starpu_vector_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)data,
  64. 1, sizeof(unsigned));
  65. struct starpu_task *task = starpu_task_create();
  66. task->cl = &wrong_codelet;
  67. task->handles[0] = handle;
  68. task->use_tag = 1;
  69. task->tag_id = TAG;
  70. task->callback_func = wrong_callback;
  71. task->detach = 0;
  72. ret = starpu_task_submit(task);
  73. if (ret == -ENODEV) goto enodev;
  74. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  75. ret = starpu_tag_wait(TAG);
  76. STARPU_CHECK_RETURN_VALUE(ret, "starpu_tag_wait");
  77. /* This call is valid as it is done by the application outside a
  78. * callback */
  79. ret = starpu_data_acquire(handle, STARPU_RW);
  80. STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_acquire");
  81. starpu_data_release(handle);
  82. ret = starpu_task_wait(task);
  83. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait");
  84. starpu_data_unregister(handle);
  85. starpu_free(data);
  86. starpu_shutdown();
  87. return EXIT_SUCCESS;
  88. enodev:
  89. fprintf(stderr, "WARNING: No one can execute this task\n");
  90. /* yes, we do not perform the computation but we did detect that no one
  91. * could perform the kernel, so this is not an error from StarPU */
  92. starpu_shutdown();
  93. return STARPU_TEST_SKIPPED;
  94. }
  95. #endif