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