Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  *  sync fence wait tests
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_multi_timeline_wait(void)
0033 {
0034     int timelineA, timelineB, timelineC;
0035     int fenceA, fenceB, fenceC, merged;
0036     int valid, active, signaled, ret;
0037 
0038     timelineA = sw_sync_timeline_create();
0039     timelineB = sw_sync_timeline_create();
0040     timelineC = sw_sync_timeline_create();
0041 
0042     fenceA = sw_sync_fence_create(timelineA, "fenceA", 5);
0043     fenceB = sw_sync_fence_create(timelineB, "fenceB", 5);
0044     fenceC = sw_sync_fence_create(timelineC, "fenceC", 5);
0045 
0046     merged = sync_merge("mergeFence", fenceB, fenceA);
0047     merged = sync_merge("mergeFence", fenceC, merged);
0048 
0049     valid = sw_sync_fence_is_valid(merged);
0050     ASSERT(valid, "Failure merging fence from various timelines\n");
0051 
0052     /* Confirm fence isn't signaled */
0053     active = sync_fence_count_with_status(merged, FENCE_STATUS_ACTIVE);
0054     ASSERT(active == 3, "Fence signaled too early!\n");
0055 
0056     ret = sync_wait(merged, 0);
0057     ASSERT(ret == 0,
0058            "Failure waiting on fence until timeout\n");
0059 
0060     ret = sw_sync_timeline_inc(timelineA, 5);
0061     active = sync_fence_count_with_status(merged, FENCE_STATUS_ACTIVE);
0062     signaled = sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED);
0063     ASSERT(active == 2 && signaled == 1,
0064            "Fence did not signal properly!\n");
0065 
0066     ret = sw_sync_timeline_inc(timelineB, 5);
0067     active = sync_fence_count_with_status(merged, FENCE_STATUS_ACTIVE);
0068     signaled = sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED);
0069     ASSERT(active == 1 && signaled == 2,
0070            "Fence did not signal properly!\n");
0071 
0072     ret = sw_sync_timeline_inc(timelineC, 5);
0073     active = sync_fence_count_with_status(merged, FENCE_STATUS_ACTIVE);
0074     signaled = sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED);
0075     ASSERT(active == 0 && signaled == 3,
0076            "Fence did not signal properly!\n");
0077 
0078     /* confirm you can successfully wait */
0079     ret = sync_wait(merged, 100);
0080     ASSERT(ret > 0, "Failure waiting on signaled fence\n");
0081 
0082     sw_sync_fence_destroy(merged);
0083     sw_sync_fence_destroy(fenceC);
0084     sw_sync_fence_destroy(fenceB);
0085     sw_sync_fence_destroy(fenceA);
0086     sw_sync_timeline_destroy(timelineC);
0087     sw_sync_timeline_destroy(timelineB);
0088     sw_sync_timeline_destroy(timelineA);
0089 
0090     return 0;
0091 }