sync_fence.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * sync fence tests with one timeline
  3. * Copyright 2015-2016 Collabora Ltd.
  4. *
  5. * Based on the implementation from the Android Open Source Project,
  6. *
  7. * Copyright 2012 Google, Inc
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a
  10. * copy of this software and associated documentation files (the "Software"),
  11. * to deal in the Software without restriction, including without limitation
  12. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13. * and/or sell copies of the Software, and to permit persons to whom the
  14. * Software is furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  23. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  24. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25. * OTHER DEALINGS IN THE SOFTWARE.
  26. */
  27. #include "sync.h"
  28. #include "sw_sync.h"
  29. #include "synctest.h"
  30. int test_fence_one_timeline_wait(void)
  31. {
  32. int fence, valid, ret;
  33. int timeline = sw_sync_timeline_create();
  34. valid = sw_sync_timeline_is_valid(timeline);
  35. ASSERT(valid, "Failure allocating timeline\n");
  36. fence = sw_sync_fence_create(timeline, "allocFence", 5);
  37. valid = sw_sync_fence_is_valid(fence);
  38. ASSERT(valid, "Failure allocating fence\n");
  39. /* Wait on fence until timeout */
  40. ret = sync_wait(fence, 0);
  41. ASSERT(ret == 0, "Failure waiting on fence until timeout\n");
  42. /* Advance timeline from 0 -> 1 */
  43. ret = sw_sync_timeline_inc(timeline, 1);
  44. ASSERT(ret == 0, "Failure advancing timeline\n");
  45. /* Wait on fence until timeout */
  46. ret = sync_wait(fence, 0);
  47. ASSERT(ret == 0, "Failure waiting on fence until timeout\n");
  48. /* Signal the fence */
  49. ret = sw_sync_timeline_inc(timeline, 4);
  50. ASSERT(ret == 0, "Failure signaling the fence\n");
  51. /* Wait successfully */
  52. ret = sync_wait(fence, 0);
  53. ASSERT(ret > 0, "Failure waiting on fence\n");
  54. /* Go even further, and confirm wait still succeeds */
  55. ret = sw_sync_timeline_inc(timeline, 10);
  56. ASSERT(ret == 0, "Failure going further\n");
  57. ret = sync_wait(fence, 0);
  58. ASSERT(ret > 0, "Failure waiting ahead\n");
  59. sw_sync_fence_destroy(fence);
  60. sw_sync_timeline_destroy(timeline);
  61. return 0;
  62. }
  63. int test_fence_one_timeline_merge(void)
  64. {
  65. int a, b, c, d, valid;
  66. int timeline = sw_sync_timeline_create();
  67. /* create fence a,b,c and then merge them all into fence d */
  68. a = sw_sync_fence_create(timeline, "allocFence", 1);
  69. b = sw_sync_fence_create(timeline, "allocFence", 2);
  70. c = sw_sync_fence_create(timeline, "allocFence", 3);
  71. valid = sw_sync_fence_is_valid(a) &&
  72. sw_sync_fence_is_valid(b) &&
  73. sw_sync_fence_is_valid(c);
  74. ASSERT(valid, "Failure allocating fences\n");
  75. d = sync_merge("mergeFence", b, a);
  76. d = sync_merge("mergeFence", c, d);
  77. valid = sw_sync_fence_is_valid(d);
  78. ASSERT(valid, "Failure merging fences\n");
  79. /* confirm all fences have one active point (even d) */
  80. ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
  81. "a has too many active fences!\n");
  82. ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
  83. "b has too many active fences!\n");
  84. ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
  85. "c has too many active fences!\n");
  86. ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
  87. "d has too many active fences!\n");
  88. /* confirm that d is not signaled until the max of a,b,c */
  89. sw_sync_timeline_inc(timeline, 1);
  90. ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_SIGNALED) == 1,
  91. "a did not signal!\n");
  92. ASSERT(sync_fence_count_with_status(d, FENCE_STATUS_ACTIVE) == 1,
  93. "d signaled too early!\n");
  94. sw_sync_timeline_inc(timeline, 1);
  95. ASSERT(sync_fence_count_with_status(b, FENCE_STATUS_SIGNALED) == 1,
  96. "b did not signal!\n");
  97. ASSERT(sync_fence_count_with_status(d, FENCE_STATUS_ACTIVE) == 1,
  98. "d signaled too early!\n");
  99. sw_sync_timeline_inc(timeline, 1);
  100. ASSERT(sync_fence_count_with_status(c, FENCE_STATUS_SIGNALED) == 1,
  101. "c did not signal!\n");
  102. ASSERT(sync_fence_count_with_status(d, FENCE_STATUS_ACTIVE) == 0 &&
  103. sync_fence_count_with_status(d, FENCE_STATUS_SIGNALED) == 1,
  104. "d did not signal!\n");
  105. sw_sync_fence_destroy(d);
  106. sw_sync_fence_destroy(c);
  107. sw_sync_fence_destroy(b);
  108. sw_sync_fence_destroy(a);
  109. sw_sync_timeline_destroy(timeline);
  110. return 0;
  111. }