< prev index next >

test/native/runtime/test_semaphore.cpp

Print this page
rev 13183 : imported patch trywait-test

*** 1,7 **** /* ! * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 60,69 **** --- 60,81 ---- for (uint i = 0; i < total; i++) { sem.wait(); } } + static void test_semaphore_trywait(uint value, uint max) { + Semaphore sem(value); + + for (uint i = 0; i < max; ++i) { + if (i < value) { + ASSERT_EQ(sem.trywait(), true); + } else { + ASSERT_EQ(sem.trywait(), false); + } + } + } + TEST(Semaphore, single_separate) { for (uint i = 1; i < 10; i++) { test_semaphore_single_separate(i); } }
*** 81,85 **** --- 93,105 ---- test_semaphore_many(value, max, inc); } } } } + + TEST(Semaphore, trywait) { + for (uint max = 0; max < 10; max++) { + for (uint value = 0; value < max; value++) { + test_semaphore_trywait(value, max); + } + } + }
< prev index next >