1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include <stdlib.h>
29#include <string.h>
30#include <time.h>
31
32#include "sync.h"
33#include "sw_sync.h"
34#include "synctest.h"
35
36int test_merge_stress_random_merge(void)
37{
38 int i, size, ret;
39 int timeline_count = 32;
40 int merge_count = 1024 * 32;
41 int timelines[timeline_count];
42 int fence_map[timeline_count];
43 int fence, tmpfence, merged, valid;
44 int timeline, timeline_offset, sync_point;
45
46 srand(time(NULL));
47
48 for (i = 0; i < timeline_count; i++)
49 timelines[i] = sw_sync_timeline_create();
50
51 fence = sw_sync_fence_create(timelines[0], "fence", 0);
52 valid = sw_sync_fence_is_valid(fence);
53 ASSERT(valid, "Failure creating fence\n");
54
55 memset(fence_map, -1, sizeof(fence_map));
56 fence_map[0] = 0;
57
58
59
60
61
62 for (i = 0; i < merge_count; i++) {
63
64 timeline_offset = rand() % timeline_count;
65 timeline = timelines[timeline_offset];
66 sync_point = rand();
67
68
69 if (fence_map[timeline_offset] == -1)
70 fence_map[timeline_offset] = sync_point;
71 else if (fence_map[timeline_offset] < sync_point)
72 fence_map[timeline_offset] = sync_point;
73
74
75 tmpfence = sw_sync_fence_create(timeline, "fence", sync_point);
76 merged = sync_merge("merge", tmpfence, fence);
77 sw_sync_fence_destroy(tmpfence);
78 sw_sync_fence_destroy(fence);
79 fence = merged;
80
81 valid = sw_sync_fence_is_valid(merged);
82 ASSERT(valid, "Failure creating fence i\n");
83 }
84
85 size = 0;
86 for (i = 0; i < timeline_count; i++)
87 if (fence_map[i] != -1)
88 size++;
89
90
91 ASSERT(sync_fence_size(fence) == size,
92 "Quantity of elements not matching\n");
93
94
95 for (i = 0; i < timeline_count; i++) {
96 if (fence_map[i] != -1) {
97 ret = sync_wait(fence, 0);
98 ASSERT(ret == 0,
99 "Failure waiting on fence until timeout\n");
100
101 sw_sync_timeline_inc(timelines[i], fence_map[i]);
102 }
103 }
104
105
106 ret = sync_wait(fence, 0);
107 ASSERT(ret > 0, "Failure triggering fence\n");
108
109 sw_sync_fence_destroy(fence);
110
111 for (i = 0; i < timeline_count; i++)
112 sw_sync_timeline_destroy(timelines[i]);
113
114 return 0;
115}
116