11c5839c6SEmilio López /*
21c5839c6SEmilio López  *  sync fence merge tests
31c5839c6SEmilio López  *  Copyright 2015-2016 Collabora Ltd.
41c5839c6SEmilio López  *
51c5839c6SEmilio López  *  Based on the implementation from the Android Open Source Project,
61c5839c6SEmilio López  *
71c5839c6SEmilio López  *  Copyright 2012 Google, Inc
81c5839c6SEmilio López  *
91c5839c6SEmilio López  *  Permission is hereby granted, free of charge, to any person obtaining a
101c5839c6SEmilio López  *  copy of this software and associated documentation files (the "Software"),
111c5839c6SEmilio López  *  to deal in the Software without restriction, including without limitation
121c5839c6SEmilio López  *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
131c5839c6SEmilio López  *  and/or sell copies of the Software, and to permit persons to whom the
141c5839c6SEmilio López  *  Software is furnished to do so, subject to the following conditions:
151c5839c6SEmilio López  *
161c5839c6SEmilio López  *  The above copyright notice and this permission notice shall be included in
171c5839c6SEmilio López  *  all copies or substantial portions of the Software.
181c5839c6SEmilio López  *
191c5839c6SEmilio López  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
201c5839c6SEmilio López  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
211c5839c6SEmilio López  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
221c5839c6SEmilio López  *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
231c5839c6SEmilio López  *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
241c5839c6SEmilio López  *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
251c5839c6SEmilio López  *  OTHER DEALINGS IN THE SOFTWARE.
261c5839c6SEmilio López  */
271c5839c6SEmilio López 
281c5839c6SEmilio López #include "sync.h"
291c5839c6SEmilio López #include "sw_sync.h"
301c5839c6SEmilio López #include "synctest.h"
311c5839c6SEmilio López 
test_fence_merge_same_fence(void)321c5839c6SEmilio López int test_fence_merge_same_fence(void)
331c5839c6SEmilio López {
341c5839c6SEmilio López 	int fence, valid, merged;
351c5839c6SEmilio López 	int timeline = sw_sync_timeline_create();
361c5839c6SEmilio López 
371c5839c6SEmilio López 	valid = sw_sync_timeline_is_valid(timeline);
381c5839c6SEmilio López 	ASSERT(valid, "Failure allocating timeline\n");
391c5839c6SEmilio López 
401c5839c6SEmilio López 	fence = sw_sync_fence_create(timeline, "allocFence", 5);
411c5839c6SEmilio López 	valid = sw_sync_fence_is_valid(fence);
421c5839c6SEmilio López 	ASSERT(valid, "Failure allocating fence\n");
431c5839c6SEmilio López 
441c5839c6SEmilio López 	merged = sync_merge("mergeFence", fence, fence);
451c5839c6SEmilio López 	valid = sw_sync_fence_is_valid(fence);
461c5839c6SEmilio López 	ASSERT(valid, "Failure merging fence\n");
471c5839c6SEmilio López 
481c5839c6SEmilio López 	ASSERT(sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED) == 0,
491c5839c6SEmilio López 	       "fence signaled too early!\n");
501c5839c6SEmilio López 
511c5839c6SEmilio López 	sw_sync_timeline_inc(timeline, 5);
521c5839c6SEmilio López 	ASSERT(sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED) == 1,
531c5839c6SEmilio López 	       "fence did not signal!\n");
541c5839c6SEmilio López 
551c5839c6SEmilio López 	sw_sync_fence_destroy(merged);
561c5839c6SEmilio López 	sw_sync_fence_destroy(fence);
571c5839c6SEmilio López 	sw_sync_timeline_destroy(timeline);
581c5839c6SEmilio López 
591c5839c6SEmilio López 	return 0;
601c5839c6SEmilio López }
61