staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / sync / sync_stress_merge.c
blob99e83ef45fbf45e8f3c777e57c73ad5f933f5fe1
1 /*
2 * sync stress test: merging
3 * Copyright 2015-2016 Collabora Ltd.
5 * Based on the implementation from the Android Open Source Project,
7 * Copyright 2012 Google, Inc
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:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
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.
28 #include <stdlib.h>
29 #include <string.h>
30 #include <time.h>
32 #include "sync.h"
33 #include "sw_sync.h"
34 #include "synctest.h"
36 int test_merge_stress_random_merge(void)
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;
46 srand(time(NULL));
48 for (i = 0; i < timeline_count; i++)
49 timelines[i] = sw_sync_timeline_create();
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");
55 memset(fence_map, -1, sizeof(fence_map));
56 fence_map[0] = 0;
59 * Randomly create sync_points out of a fixed set of timelines,
60 * and merge them together
62 for (i = 0; i < merge_count; i++) {
63 /* Generate sync_point. */
64 timeline_offset = rand() % timeline_count;
65 timeline = timelines[timeline_offset];
66 sync_point = rand();
68 /* Keep track of the latest sync_point in each timeline. */
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;
74 /* Merge */
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;
81 valid = sw_sync_fence_is_valid(merged);
82 ASSERT(valid, "Failure creating fence i\n");
85 size = 0;
86 for (i = 0; i < timeline_count; i++)
87 if (fence_map[i] != -1)
88 size++;
90 /* Confirm our map matches the fence. */
91 ASSERT(sync_fence_size(fence) == size,
92 "Quantity of elements not matching\n");
94 /* Trigger the merged fence */
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 /* Increment the timeline to the last sync_point */
101 sw_sync_timeline_inc(timelines[i], fence_map[i]);
105 /* Check that the fence is triggered. */
106 ret = sync_wait(fence, 0);
107 ASSERT(ret > 0, "Failure triggering fence\n");
109 sw_sync_fence_destroy(fence);
111 for (i = 0; i < timeline_count; i++)
112 sw_sync_timeline_destroy(timelines[i]);
114 return 0;