18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * sync fence wait tests 38c2ecf20Sopenharmony_ci * Copyright 2015-2016 Collabora Ltd. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Based on the implementation from the Android Open Source Project, 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright 2012 Google, Inc 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 108c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 118c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 128c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 138c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 148c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 178c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 208c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 218c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 228c2ecf20Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 238c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 248c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 258c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 268c2ecf20Sopenharmony_ci */ 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#include "sync.h" 298c2ecf20Sopenharmony_ci#include "sw_sync.h" 308c2ecf20Sopenharmony_ci#include "synctest.h" 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ciint test_fence_multi_timeline_wait(void) 338c2ecf20Sopenharmony_ci{ 348c2ecf20Sopenharmony_ci int timelineA, timelineB, timelineC; 358c2ecf20Sopenharmony_ci int fenceA, fenceB, fenceC, merged; 368c2ecf20Sopenharmony_ci int valid, active, signaled, ret; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci timelineA = sw_sync_timeline_create(); 398c2ecf20Sopenharmony_ci timelineB = sw_sync_timeline_create(); 408c2ecf20Sopenharmony_ci timelineC = sw_sync_timeline_create(); 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci fenceA = sw_sync_fence_create(timelineA, "fenceA", 5); 438c2ecf20Sopenharmony_ci fenceB = sw_sync_fence_create(timelineB, "fenceB", 5); 448c2ecf20Sopenharmony_ci fenceC = sw_sync_fence_create(timelineC, "fenceC", 5); 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci merged = sync_merge("mergeFence", fenceB, fenceA); 478c2ecf20Sopenharmony_ci merged = sync_merge("mergeFence", fenceC, merged); 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci valid = sw_sync_fence_is_valid(merged); 508c2ecf20Sopenharmony_ci ASSERT(valid, "Failure merging fence from various timelines\n"); 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci /* Confirm fence isn't signaled */ 538c2ecf20Sopenharmony_ci active = sync_fence_count_with_status(merged, FENCE_STATUS_ACTIVE); 548c2ecf20Sopenharmony_ci ASSERT(active == 3, "Fence signaled too early!\n"); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci ret = sync_wait(merged, 0); 578c2ecf20Sopenharmony_ci ASSERT(ret == 0, 588c2ecf20Sopenharmony_ci "Failure waiting on fence until timeout\n"); 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci ret = sw_sync_timeline_inc(timelineA, 5); 618c2ecf20Sopenharmony_ci active = sync_fence_count_with_status(merged, FENCE_STATUS_ACTIVE); 628c2ecf20Sopenharmony_ci signaled = sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED); 638c2ecf20Sopenharmony_ci ASSERT(active == 2 && signaled == 1, 648c2ecf20Sopenharmony_ci "Fence did not signal properly!\n"); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci ret = sw_sync_timeline_inc(timelineB, 5); 678c2ecf20Sopenharmony_ci active = sync_fence_count_with_status(merged, FENCE_STATUS_ACTIVE); 688c2ecf20Sopenharmony_ci signaled = sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED); 698c2ecf20Sopenharmony_ci ASSERT(active == 1 && signaled == 2, 708c2ecf20Sopenharmony_ci "Fence did not signal properly!\n"); 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci ret = sw_sync_timeline_inc(timelineC, 5); 738c2ecf20Sopenharmony_ci active = sync_fence_count_with_status(merged, FENCE_STATUS_ACTIVE); 748c2ecf20Sopenharmony_ci signaled = sync_fence_count_with_status(merged, FENCE_STATUS_SIGNALED); 758c2ecf20Sopenharmony_ci ASSERT(active == 0 && signaled == 3, 768c2ecf20Sopenharmony_ci "Fence did not signal properly!\n"); 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci /* confirm you can successfully wait */ 798c2ecf20Sopenharmony_ci ret = sync_wait(merged, 100); 808c2ecf20Sopenharmony_ci ASSERT(ret > 0, "Failure waiting on signaled fence\n"); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci sw_sync_fence_destroy(merged); 838c2ecf20Sopenharmony_ci sw_sync_fence_destroy(fenceC); 848c2ecf20Sopenharmony_ci sw_sync_fence_destroy(fenceB); 858c2ecf20Sopenharmony_ci sw_sync_fence_destroy(fenceA); 868c2ecf20Sopenharmony_ci sw_sync_timeline_destroy(timelineC); 878c2ecf20Sopenharmony_ci sw_sync_timeline_destroy(timelineB); 888c2ecf20Sopenharmony_ci sw_sync_timeline_destroy(timelineA); 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci return 0; 918c2ecf20Sopenharmony_ci} 92