sched_ctx_list.c 7.4 KB

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