0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #include "sync.h"
0029 #include "sw_sync.h"
0030 #include "synctest.h"
0031
0032 int test_fence_one_timeline_wait(void)
0033 {
0034 int fence, valid, ret;
0035 int timeline = sw_sync_timeline_create();
0036
0037 valid = sw_sync_timeline_is_valid(timeline);
0038 ASSERT(valid, "Failure allocating timeline\n");
0039
0040 fence = sw_sync_fence_create(timeline, "allocFence", 5);
0041 valid = sw_sync_fence_is_valid(fence);
0042 ASSERT(valid, "Failure allocating fence\n");
0043
0044
0045 ret = sync_wait(fence, 0);
0046 ASSERT(ret == 0, "Failure waiting on fence until timeout\n");
0047
0048
0049 ret = sw_sync_timeline_inc(timeline, 1);
0050 ASSERT(ret == 0, "Failure advancing timeline\n");
0051
0052
0053 ret = sync_wait(fence, 0);
0054 ASSERT(ret == 0, "Failure waiting on fence until timeout\n");
0055
0056
0057 ret = sw_sync_timeline_inc(timeline, 4);
0058 ASSERT(ret == 0, "Failure signaling the fence\n");
0059
0060
0061 ret = sync_wait(fence, 0);
0062 ASSERT(ret > 0, "Failure waiting on fence\n");
0063
0064
0065 ret = sw_sync_timeline_inc(timeline, 10);
0066 ASSERT(ret == 0, "Failure going further\n");
0067 ret = sync_wait(fence, 0);
0068 ASSERT(ret > 0, "Failure waiting ahead\n");
0069
0070 sw_sync_fence_destroy(fence);
0071 sw_sync_timeline_destroy(timeline);
0072
0073 return 0;
0074 }
0075
0076 int test_fence_one_timeline_merge(void)
0077 {
0078 int a, b, c, d, valid;
0079 int timeline = sw_sync_timeline_create();
0080
0081
0082 a = sw_sync_fence_create(timeline, "allocFence", 1);
0083 b = sw_sync_fence_create(timeline, "allocFence", 2);
0084 c = sw_sync_fence_create(timeline, "allocFence", 3);
0085
0086 valid = sw_sync_fence_is_valid(a) &&
0087 sw_sync_fence_is_valid(b) &&
0088 sw_sync_fence_is_valid(c);
0089 ASSERT(valid, "Failure allocating fences\n");
0090
0091 d = sync_merge("mergeFence", b, a);
0092 d = sync_merge("mergeFence", c, d);
0093 valid = sw_sync_fence_is_valid(d);
0094 ASSERT(valid, "Failure merging fences\n");
0095
0096
0097 ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
0098 "a has too many active fences!\n");
0099 ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
0100 "b has too many active fences!\n");
0101 ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
0102 "c has too many active fences!\n");
0103 ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
0104 "d has too many active fences!\n");
0105
0106
0107 sw_sync_timeline_inc(timeline, 1);
0108 ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_SIGNALED) == 1,
0109 "a did not signal!\n");
0110 ASSERT(sync_fence_count_with_status(d, FENCE_STATUS_ACTIVE) == 1,
0111 "d signaled too early!\n");
0112
0113 sw_sync_timeline_inc(timeline, 1);
0114 ASSERT(sync_fence_count_with_status(b, FENCE_STATUS_SIGNALED) == 1,
0115 "b did not signal!\n");
0116 ASSERT(sync_fence_count_with_status(d, FENCE_STATUS_ACTIVE) == 1,
0117 "d signaled too early!\n");
0118
0119 sw_sync_timeline_inc(timeline, 1);
0120 ASSERT(sync_fence_count_with_status(c, FENCE_STATUS_SIGNALED) == 1,
0121 "c did not signal!\n");
0122 ASSERT(sync_fence_count_with_status(d, FENCE_STATUS_ACTIVE) == 0 &&
0123 sync_fence_count_with_status(d, FENCE_STATUS_SIGNALED) == 1,
0124 "d did not signal!\n");
0125
0126 sw_sync_fence_destroy(d);
0127 sw_sync_fence_destroy(c);
0128 sw_sync_fence_destroy(b);
0129 sw_sync_fence_destroy(a);
0130 sw_sync_timeline_destroy(timeline);
0131 return 0;
0132 }