Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  *  sync fence tests with one timeline
0003  *  Copyright 2015-2016 Collabora Ltd.
0004  *
0005  *  Based on the implementation from the Android Open Source Project,
0006  *
0007  *  Copyright 2012 Google, Inc
0008  *
0009  *  Permission is hereby granted, free of charge, to any person obtaining a
0010  *  copy of this software and associated documentation files (the "Software"),
0011  *  to deal in the Software without restriction, including without limitation
0012  *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
0013  *  and/or sell copies of the Software, and to permit persons to whom the
0014  *  Software is furnished to do so, subject to the following conditions:
0015  *
0016  *  The above copyright notice and this permission notice shall be included in
0017  *  all copies or substantial portions of the Software.
0018  *
0019  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0020  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0021  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
0022  *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
0023  *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0024  *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0025  *  OTHER DEALINGS IN THE SOFTWARE.
0026  */
0027 
0028 #include "sync.h"
0029 #include "sw_sync.h"
0030 #include "synctest.h"
0031 
0032 int test_fence_one_timeline_wait(void)
0033 {
0034     int fence, valid, ret;
0035     int timeline = sw_sync_timeline_create();
0036 
0037     valid = sw_sync_timeline_is_valid(timeline);
0038     ASSERT(valid, "Failure allocating timeline\n");
0039 
0040     fence = sw_sync_fence_create(timeline, "allocFence", 5);
0041     valid = sw_sync_fence_is_valid(fence);
0042     ASSERT(valid, "Failure allocating fence\n");
0043 
0044     /* Wait on fence until timeout */
0045     ret = sync_wait(fence, 0);
0046     ASSERT(ret == 0, "Failure waiting on fence until timeout\n");
0047 
0048     /* Advance timeline from 0 -> 1 */
0049     ret = sw_sync_timeline_inc(timeline, 1);
0050     ASSERT(ret == 0, "Failure advancing timeline\n");
0051 
0052     /* Wait on fence until timeout */
0053     ret = sync_wait(fence, 0);
0054     ASSERT(ret == 0, "Failure waiting on fence until timeout\n");
0055 
0056     /* Signal the fence */
0057     ret = sw_sync_timeline_inc(timeline, 4);
0058     ASSERT(ret == 0, "Failure signaling the fence\n");
0059 
0060     /* Wait successfully */
0061     ret = sync_wait(fence, 0);
0062     ASSERT(ret > 0, "Failure waiting on fence\n");
0063 
0064     /* Go even further, and confirm wait still succeeds */
0065     ret = sw_sync_timeline_inc(timeline, 10);
0066     ASSERT(ret == 0, "Failure going further\n");
0067     ret = sync_wait(fence, 0);
0068     ASSERT(ret > 0, "Failure waiting ahead\n");
0069 
0070     sw_sync_fence_destroy(fence);
0071     sw_sync_timeline_destroy(timeline);
0072 
0073     return 0;
0074 }
0075 
0076 int test_fence_one_timeline_merge(void)
0077 {
0078     int a, b, c, d, valid;
0079     int timeline = sw_sync_timeline_create();
0080 
0081     /* create fence a,b,c and then merge them all into fence d */
0082     a = sw_sync_fence_create(timeline, "allocFence", 1);
0083     b = sw_sync_fence_create(timeline, "allocFence", 2);
0084     c = sw_sync_fence_create(timeline, "allocFence", 3);
0085 
0086     valid = sw_sync_fence_is_valid(a) &&
0087         sw_sync_fence_is_valid(b) &&
0088         sw_sync_fence_is_valid(c);
0089     ASSERT(valid, "Failure allocating fences\n");
0090 
0091     d = sync_merge("mergeFence", b, a);
0092     d = sync_merge("mergeFence", c, d);
0093     valid = sw_sync_fence_is_valid(d);
0094     ASSERT(valid, "Failure merging fences\n");
0095 
0096     /* confirm all fences have one active point (even d) */
0097     ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
0098            "a has too many active fences!\n");
0099     ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
0100            "b has too many active fences!\n");
0101     ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
0102            "c has too many active fences!\n");
0103     ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_ACTIVE) == 1,
0104            "d has too many active fences!\n");
0105 
0106     /* confirm that d is not signaled until the max of a,b,c */
0107     sw_sync_timeline_inc(timeline, 1);
0108     ASSERT(sync_fence_count_with_status(a, FENCE_STATUS_SIGNALED) == 1,
0109            "a did not signal!\n");
0110     ASSERT(sync_fence_count_with_status(d, FENCE_STATUS_ACTIVE) == 1,
0111            "d signaled too early!\n");
0112 
0113     sw_sync_timeline_inc(timeline, 1);
0114     ASSERT(sync_fence_count_with_status(b, FENCE_STATUS_SIGNALED) == 1,
0115            "b did not signal!\n");
0116     ASSERT(sync_fence_count_with_status(d, FENCE_STATUS_ACTIVE) == 1,
0117            "d signaled too early!\n");
0118 
0119     sw_sync_timeline_inc(timeline, 1);
0120     ASSERT(sync_fence_count_with_status(c, FENCE_STATUS_SIGNALED) == 1,
0121            "c did not signal!\n");
0122     ASSERT(sync_fence_count_with_status(d, FENCE_STATUS_ACTIVE) == 0 &&
0123            sync_fence_count_with_status(d, FENCE_STATUS_SIGNALED) == 1,
0124            "d did not signal!\n");
0125 
0126     sw_sync_fence_destroy(d);
0127     sw_sync_fence_destroy(c);
0128     sw_sync_fence_destroy(b);
0129     sw_sync_fence_destroy(a);
0130     sw_sync_timeline_destroy(timeline);
0131     return 0;
0132 }