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