sched_ctx_list.c 7.6 KB

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