xref: /linux/tools/testing/selftests/sync/sync_merge.c (revision 9095bf25ea08135a5b74875dd0e3eeaddc4218a0)
1*1c5839c6SEmilio López /*
2*1c5839c6SEmilio López  *  sync fence merge tests
3*1c5839c6SEmilio López  *  Copyright 2015-2016 Collabora Ltd.
4*1c5839c6SEmilio López  *
5*1c5839c6SEmilio López  *  Based on the implementation from the Android Open Source Project,
6*1c5839c6SEmilio López  *
7*1c5839c6SEmilio López  *  Copyright 2012 Google, Inc
8*1c5839c6SEmilio López  *
9*1c5839c6SEmilio López  *  Permission is hereby granted, free of charge, to any person obtaining a
10*1c5839c6SEmilio López  *  copy of this software and associated documentation files (the "Software"),
11*1c5839c6SEmilio López  *  to deal in the Software without restriction, including without limitation
12*1c5839c6SEmilio López  *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
13*1c5839c6SEmilio López  *  and/or sell copies of the Software, and to permit persons to whom the
14*1c5839c6SEmilio López  *  Software is furnished to do so, subject to the following conditions:
15*1c5839c6SEmilio López  *
16*1c5839c6SEmilio López  *  The above copyright notice and this permission notice shall be included in
17*1c5839c6SEmilio López  *  all copies or substantial portions of the Software.
18*1c5839c6SEmilio López  *
19*1c5839c6SEmilio López  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20*1c5839c6SEmilio López  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21*1c5839c6SEmilio López  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22*1c5839c6SEmilio López  *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23*1c5839c6SEmilio López  *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24*1c5839c6SEmilio López  *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25*1c5839c6SEmilio López  *  OTHER DEALINGS IN THE SOFTWARE.
26*1c5839c6SEmilio López  */
27*1c5839c6SEmilio López 
28*1c5839c6SEmilio López #include "sync.h"
29*1c5839c6SEmilio López #include "sw_sync.h"
30*1c5839c6SEmilio López #include "synctest.h"
31*1c5839c6SEmilio López 
test_fence_merge_same_fence(void)32*1c5839c6SEmilio López int test_fence_merge_same_fence(void)
33*1c5839c6SEmilio López {
34*1c5839c6SEmilio López 	int fence, valid, merged;
35*1c5839c6SEmilio López 	int timeline = sw_sync_timeline_create();
36*1c5839c6SEmilio López 
37*1c5839c6SEmilio López 	valid = sw_sync_timeline_is_valid(timeline);
38*1c5839c6SEmilio López 	ASSERT(valid, "Failure allocating timeline\n");
39*1c5839c6SEmilio López 
40*1c5839c6SEmilio López 	fence = sw_sync_fence_create(timeline, "allocFence", 5);
41*1c5839c6SEmilio López 	valid = sw_sync_fence_is_valid(fence);
42*1c5839c6SEmilio López 	ASSERT(valid, "Failure allocating fence\n");
43*1c5839c6SEmilio López 
44*1c5839c6SEmilio López 	merged = sync_merge("mergeFence", fence, fence);
45*1c5839c6SEmilio López 	valid = sw_sync_fence_is_valid(fence);
46*1c5839c6SEmilio López 	ASSERT(valid, "Failure merging fence\n");
47*1c5839c6SEmilio López 
48*1c5839c6SEmilio López 	ASSERT(sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED) == 0,
49*1c5839c6SEmilio López 	       "fence signaled too early!\n");
50*1c5839c6SEmilio López 
51*1c5839c6SEmilio López 	sw_sync_timeline_inc(timeline, 5);
52*1c5839c6SEmilio López 	ASSERT(sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED) == 1,
53*1c5839c6SEmilio López 	       "fence did not signal!\n");
54*1c5839c6SEmilio López 
55*1c5839c6SEmilio López 	sw_sync_fence_destroy(merged);
56*1c5839c6SEmilio López 	sw_sync_fence_destroy(fence);
57*1c5839c6SEmilio López 	sw_sync_timeline_destroy(timeline);
58*1c5839c6SEmilio López 
59*1c5839c6SEmilio López 	return 0;
60*1c5839c6SEmilio López }
61