1 /* 2 Copyright (c) 2005-2021 Intel Corporation 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 #if __INTEL_COMPILER && _MSC_VER 18 #pragma warning(disable : 2586) // decorated name length exceeded, name was truncated 19 #endif 20 21 #include "conformance_mutex.h" 22 23 #include "oneapi/tbb/spin_mutex.h" 24 #include "oneapi/tbb/mutex.h" 25 #include "oneapi/tbb/spin_rw_mutex.h" 26 #include "oneapi/tbb/rw_mutex.h" 27 #include "oneapi/tbb/queuing_mutex.h" 28 #include "oneapi/tbb/queuing_rw_mutex.h" 29 #include "oneapi/tbb/null_mutex.h" 30 #include "oneapi/tbb/null_rw_mutex.h" 31 32 //! \file conformance_mutex.cpp 33 //! \brief Test for [mutex.spin_mutex mutex.spin_rw_mutex mutex.queuing_mutex mutex.queuing_rw_mutex mutex.speculative_spin_mutex mutex.speculative_spin_rw_mutex mutex.null_mutex mutex.null_rw_mutex] specifications 34 35 //! Testing Mutex requirements 36 //! \brief \ref interface \ref requirement 37 TEST_CASE("Basic Locable requirement test") { 38 // BasicLockable 39 GeneralTest<oneapi::tbb::spin_mutex>("Spin Mutex"); 40 GeneralTest<oneapi::tbb::spin_rw_mutex>("Spin RW Mutex"); 41 GeneralTest<oneapi::tbb::queuing_mutex>("Queuing Mutex"); 42 GeneralTest<oneapi::tbb::queuing_rw_mutex>("Queuing RW Mutex"); 43 // TODO: Consider adding Thread Sanitizer (note that accesses inside the transaction 44 // considered as races by Thread Sanitizer) 45 #if !__TBB_USE_THREAD_SANITIZER 46 GeneralTest<oneapi::tbb::speculative_spin_mutex>("Speculative Spin Mutex"); 47 GeneralTest<oneapi::tbb::speculative_spin_rw_mutex>("Speculative Spin RW Mutex"); 48 #endif 49 // NullMutexes 50 GeneralTest<oneapi::tbb::null_mutex, utils::AtomicCounter<oneapi::tbb::null_mutex>>("Null Mutex", false); 51 GeneralTest<oneapi::tbb::null_rw_mutex, utils::AtomicCounter<oneapi::tbb::null_rw_mutex>>("Null RW Mutex", false); 52 TestNullMutex<oneapi::tbb::null_mutex>("Null Mutex"); 53 TestNullMutex<oneapi::tbb::null_rw_mutex>("Null RW Mutex"); 54 } 55 56 //! \brief \ref interface \ref requirement 57 TEST_CASE("Lockable requirement test") { 58 // Lockable - single threaded try_acquire operations 59 TestTryAcquire<oneapi::tbb::spin_mutex>("Spin Mutex"); 60 TestTryAcquire<oneapi::tbb::spin_rw_mutex>("Spin RW Mutex"); 61 TestTryAcquire<oneapi::tbb::queuing_mutex>("Queuing Mutex"); 62 TestTryAcquire<oneapi::tbb::queuing_rw_mutex>("Queuing RW Mutex"); 63 #if !__TBB_USE_THREAD_SANITIZER 64 TestTryAcquire<oneapi::tbb::speculative_spin_mutex>("Speculative Spin Mutex"); 65 TestTryAcquire<oneapi::tbb::speculative_spin_rw_mutex>("Speculative Spin RW Mutex"); 66 #endif 67 TestTryAcquire<oneapi::tbb::null_mutex>("Null Mutex"); 68 } 69 70 //! Testing ReaderWriterMutex requirements 71 //! \brief \ref interface \ref requirement 72 TEST_CASE("Shared mutexes (reader/writer) test") { 73 // General reader writer capabilities + upgrade/downgrade 74 TestReaderWriterLock<oneapi::tbb::spin_rw_mutex>("Spin RW Mutex"); 75 TestReaderWriterLock<oneapi::tbb::queuing_rw_mutex>("Queuing RW Mutex"); 76 TestNullRWMutex<oneapi::tbb::null_rw_mutex>("Null RW Mutex"); 77 // Single threaded read/write try_acquire operations 78 TestTryAcquireReader<oneapi::tbb::spin_rw_mutex>("Spin RW Mutex"); 79 TestTryAcquireReader<oneapi::tbb::queuing_rw_mutex>("Queuing RW Mutex"); 80 TestRWStateMultipleChange<oneapi::tbb::spin_rw_mutex>("Spin RW Mutex"); 81 TestRWStateMultipleChange<oneapi::tbb::queuing_rw_mutex>("Queuing RW Mutex"); 82 TestTryAcquireReader<oneapi::tbb::null_rw_mutex>("Null RW Mutex"); 83 #if !__TBB_USE_THREAD_SANITIZER 84 TestReaderWriterLock<oneapi::tbb::speculative_spin_rw_mutex>("Speculative Spin RW Mutex"); 85 TestTryAcquireReader<oneapi::tbb::speculative_spin_rw_mutex>("Speculative Spin RW Mutex"); 86 TestRWStateMultipleChange<oneapi::tbb::speculative_spin_rw_mutex>("Speculative Spin RW Mutex"); 87 #endif 88 } 89 90 //! Testing ISO C++ Mutex and Shared Mutex requirements. 91 //! Compatibility with the standard 92 //! \brief \ref interface \ref requirement 93 TEST_CASE("ISO interface test") { 94 GeneralTest<TBB_MutexFromISO_Mutex<oneapi::tbb::spin_mutex> >("ISO Spin Mutex"); 95 GeneralTest<TBB_MutexFromISO_Mutex<oneapi::tbb::spin_rw_mutex> >("ISO Spin RW Mutex"); 96 TestTryAcquire<TBB_MutexFromISO_Mutex<oneapi::tbb::spin_mutex> >("ISO Spin Mutex"); 97 TestTryAcquire<TBB_MutexFromISO_Mutex<oneapi::tbb::spin_rw_mutex> >("ISO Spin RW Mutex"); 98 TestTryAcquireReader<TBB_MutexFromISO_Mutex<oneapi::tbb::spin_rw_mutex> >("ISO Spin RW Mutex"); 99 TestReaderWriterLock<TBB_MutexFromISO_Mutex<oneapi::tbb::spin_rw_mutex> >("ISO Spin RW Mutex"); 100 } 101