sched_ctx_list.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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 <starpu.h>
  17. #include "../helper.h"
  18. #include "../../src/core/sched_ctx_list.h"
  19. int main(void)
  20. {
  21. struct _starpu_sched_ctx_list *ctx_list = NULL, *found_list;
  22. struct _starpu_sched_ctx_elt *elt;
  23. struct _starpu_sched_ctx_list_iterator it;
  24. int ret=1, global=1;
  25. /* Check prio list addition */
  26. ret &= (_starpu_sched_ctx_list_add_prio(&ctx_list, 50, 0) != NULL);
  27. ret &= (ctx_list->priority == 50);
  28. ret &= (_starpu_sched_ctx_list_add_prio(&ctx_list, 999, 2) != NULL);
  29. ret &= (ctx_list->priority == 999);
  30. ret &= (ctx_list->next->priority == 50);
  31. ret &= !_starpu_sched_ctx_list_add(&ctx_list, 1);
  32. ret &= (ctx_list->next->next->priority == 0);
  33. /* Check elements added */
  34. ret &= (ctx_list->head->sched_ctx == 2);
  35. ret &= (ctx_list->next->head->sched_ctx == 0);
  36. ret &= (ctx_list->next->next->head->sched_ctx == 1);
  37. /* Check singleton status */
  38. ret &= (ctx_list->next->head->prev->sched_ctx == 0);
  39. ret &= (ctx_list->next->head->next->sched_ctx == 0);
  40. global &= ret;
  41. STARPU_CHECK_RETURN_VALUE_IS(ret, 1, "_starpu_sched_ctx_list_add");
  42. /* Check addition to existing list */
  43. ret = 1;
  44. _starpu_sched_ctx_elt_add(ctx_list->next, 3);
  45. ret &= (ctx_list->next->head->next->sched_ctx == 3);
  46. ret &= (ctx_list->next->head->prev->sched_ctx == 3);
  47. global &= ret;
  48. STARPU_CHECK_RETURN_VALUE_IS(ret, 1, "_starpu_sched_ctx_elt_add");
  49. /* Find element */
  50. ret = 1;
  51. elt = _starpu_sched_ctx_elt_find(ctx_list, 3);
  52. ret &= (elt != NULL && elt->sched_ctx == 3);
  53. elt = _starpu_sched_ctx_elt_find(ctx_list, 5);
  54. ret &= (elt == NULL);
  55. global &= ret;
  56. STARPU_CHECK_RETURN_VALUE_IS(ret, 1, "_starpu_sched_ctx_elt_find");
  57. /* Find list */
  58. ret = 1;
  59. found_list = _starpu_sched_ctx_list_find(ctx_list, 0);
  60. ret &= (found_list->priority == 0);
  61. ret &= (found_list->prev->priority == 50);
  62. found_list = _starpu_sched_ctx_list_find(ctx_list, 999);
  63. ret &= (found_list->priority==999);
  64. found_list = _starpu_sched_ctx_list_find(ctx_list, 42);
  65. ret &= (found_list == NULL);
  66. global &= ret;
  67. STARPU_CHECK_RETURN_VALUE_IS(ret, 1, "_starpu_sched_ctx_list_find");
  68. /* List exists */
  69. ret = 1;
  70. ret &= _starpu_sched_ctx_list_exists(ctx_list, 999);
  71. ret &= _starpu_sched_ctx_list_exists(ctx_list, 50);
  72. ret &= _starpu_sched_ctx_list_exists(ctx_list, 0);
  73. ret &= !_starpu_sched_ctx_list_exists(ctx_list, 42);
  74. global &= ret;
  75. STARPU_CHECK_RETURN_VALUE_IS(ret, 1, "_starpu_sched_ctx_list_exists");
  76. /* Iterator */
  77. ret = 1;
  78. ret &= !_starpu_sched_ctx_list_iterator_init(ctx_list, &it);
  79. ret &= _starpu_sched_ctx_list_iterator_has_next(&it);
  80. elt = _starpu_sched_ctx_list_iterator_get_next(&it);
  81. ret &= (elt->sched_ctx == 2);
  82. ret &= _starpu_sched_ctx_list_iterator_has_next(&it);
  83. elt = _starpu_sched_ctx_list_iterator_get_next(&it);
  84. ret &= (elt->sched_ctx == 0);
  85. ret &= _starpu_sched_ctx_list_iterator_has_next(&it);
  86. elt = _starpu_sched_ctx_list_iterator_get_next(&it);
  87. ret &= (elt->sched_ctx == 3);
  88. ret &= _starpu_sched_ctx_list_iterator_has_next(&it);
  89. elt = _starpu_sched_ctx_list_iterator_get_next(&it);
  90. ret &= (elt->sched_ctx == 1);
  91. ret &= !_starpu_sched_ctx_list_iterator_has_next(&it);
  92. global &= ret;
  93. STARPU_CHECK_RETURN_VALUE_IS(ret, 1, "_starpu_sched_ctx_list_iterator");
  94. /* Add element before head */
  95. ret = 1;
  96. _starpu_sched_ctx_elt_add_before(ctx_list->next, 4);
  97. ret &= (ctx_list->next->head->prev->sched_ctx == 4);
  98. ret &= (ctx_list->next->head->next->next->sched_ctx == 4);
  99. global &= ret;
  100. STARPU_CHECK_RETURN_VALUE_IS(ret, 1, "_starpu_sched_ctx_elt_add_before");
  101. /* Let's move it */
  102. ret = 1;
  103. ret &= !_starpu_sched_ctx_list_move(&ctx_list, 4, 1002);
  104. ret &= (ctx_list->priority == 1002);
  105. ret &= (ctx_list->head->sched_ctx == 4);
  106. ret &= (ctx_list->head->next->sched_ctx == 4);
  107. ret &= (ctx_list->next->next->head->prev->sched_ctx != 4);
  108. STARPU_CHECK_RETURN_VALUE_IS(ret, 1, "_starpu_sched_ctx_list_move");
  109. /* Let's remove it */
  110. ret = 1;
  111. elt = _starpu_sched_ctx_elt_find(ctx_list, 4);
  112. _starpu_sched_ctx_list_remove_elt(&ctx_list, elt);
  113. //ret &= (elt == NULL);
  114. ret &= (_starpu_sched_ctx_elt_find(ctx_list, 4) == NULL);
  115. ret &= (ctx_list->next->head->next->sched_ctx == 3);
  116. ret &= (ctx_list->next->head->prev->sched_ctx == 3);
  117. global &= ret;
  118. STARPU_CHECK_RETURN_VALUE_IS(ret, 1, "_starpu_sched_ctx_elt_remove");
  119. /* Let's remove head of that same ctx */
  120. ret = 1;
  121. ret &= !_starpu_sched_ctx_list_remove(&ctx_list, 0);
  122. ret &= (_starpu_sched_ctx_elt_find(ctx_list, 0) == NULL);
  123. ret &= (ctx_list->next->head->sched_ctx == 3);
  124. ret &= (ctx_list->next->head->next->sched_ctx == 3);
  125. ret &= (ctx_list->next->head->prev->sched_ctx == 3);
  126. global &= ret;
  127. STARPU_CHECK_RETURN_VALUE_IS(ret, 1, "_starpu_sched_ctx_list_remove");
  128. /* Remove the last one of this list, we get an empty ctx */
  129. ret = 1;
  130. ret &= !_starpu_sched_ctx_list_remove(&ctx_list, 3);
  131. ret &= (_starpu_sched_ctx_elt_find(ctx_list, 3) == NULL);
  132. found_list = _starpu_sched_ctx_list_find(ctx_list, 50);
  133. ret &= (found_list == NULL && ctx_list->priority != 50);
  134. ret &= (ctx_list->next->priority == 0);
  135. global &= ret;
  136. STARPU_CHECK_RETURN_VALUE_IS(ret, 1, "_starpu_sched_ctx_list_remove");
  137. /* Add an element to a new prio then remove it to ensure prio list is cleaned correctly */
  138. ret = 1;
  139. ret &= (_starpu_sched_ctx_list_add_prio(&ctx_list, 100000, 75) != NULL);
  140. ret &= (ctx_list->priority == 100000);
  141. ret &= (_starpu_sched_ctx_elt_find(ctx_list, 75) != NULL);
  142. ret &= (ctx_list->head->sched_ctx == 75);
  143. ret &= !_starpu_sched_ctx_list_remove(&ctx_list, 75);
  144. ret &= (_starpu_sched_ctx_elt_find(ctx_list, 75) == NULL);
  145. found_list = _starpu_sched_ctx_list_find(ctx_list, 100000);
  146. ret &= (found_list == NULL && ctx_list->priority != 100000);
  147. ret &= (ctx_list->priority == 999);
  148. global &= ret;
  149. STARPU_CHECK_RETURN_VALUE_IS(ret, 1, "_starpu_sched_ctx_list_remove");
  150. /* Delete this list, the function is internal only so we need to modify the list pointers too */
  151. ret = 1;
  152. found_list = ctx_list->next;
  153. found_list->prev = ctx_list->prev;
  154. _starpu_sched_ctx_list_remove_all(ctx_list);
  155. ctx_list = found_list;
  156. found_list = _starpu_sched_ctx_list_find(ctx_list, 999);
  157. ret &= (found_list == NULL && ctx_list->priority != 999);
  158. ret &= (_starpu_sched_ctx_elt_find(ctx_list, 2) == NULL);
  159. ret &= (ctx_list->priority == 0);
  160. ret &= (ctx_list->head->sched_ctx == 1); //as before
  161. ret &= (ctx_list->head->next->sched_ctx == 1);
  162. ret &= (ctx_list->head->prev->sched_ctx == 1);
  163. global &= ret;
  164. STARPU_CHECK_RETURN_VALUE_IS(ret, 1, "_starpu_sched_ctx_list_remove_all");
  165. /* Let's add some things again then clean everything */
  166. ret = 1;
  167. ret &= (_starpu_sched_ctx_list_add_prio(&ctx_list, 1000, 42) != NULL);
  168. ret &= (_starpu_sched_ctx_list_add_prio(&ctx_list, 1000, 43) != NULL);
  169. _starpu_sched_ctx_list_delete(&ctx_list);
  170. ret &= (ctx_list == NULL);
  171. global &= ret;
  172. STARPU_CHECK_RETURN_VALUE_IS(ret, 1, "_starpu_sched_ctx_list_delete");
  173. STARPU_CHECK_RETURN_VALUE_IS(global, 1, "_starpu_sched_ctx_(list|elt) global status");
  174. return 0;
  175. }