/* Copyright (c) 2005-2021 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #if __INTEL_COMPILER && _MSC_VER #pragma warning(disable : 2586) // decorated name length exceeded, name was truncated #endif #include "conformance_mutex.h" #include "oneapi/tbb/spin_mutex.h" #include "oneapi/tbb/mutex.h" #include "oneapi/tbb/spin_rw_mutex.h" #include "oneapi/tbb/rw_mutex.h" #include "oneapi/tbb/queuing_mutex.h" #include "oneapi/tbb/queuing_rw_mutex.h" #include "oneapi/tbb/null_mutex.h" #include "oneapi/tbb/null_rw_mutex.h" //! \file conformance_mutex.cpp //! \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 //! Testing Mutex requirements //! \brief \ref interface \ref requirement TEST_CASE("Basic Locable requirement test") { // BasicLockable GeneralTest("Spin Mutex"); GeneralTest("Spin RW Mutex"); GeneralTest("Queuing Mutex"); GeneralTest("Queuing RW Mutex"); // TODO: Consider adding Thread Sanitizer (note that accesses inside the transaction // considered as races by Thread Sanitizer) #if !__TBB_USE_THREAD_SANITIZER GeneralTest("Speculative Spin Mutex"); GeneralTest("Speculative Spin RW Mutex"); #endif // NullMutexes GeneralTest>("Null Mutex", false); GeneralTest>("Null RW Mutex", false); TestNullMutex("Null Mutex"); TestNullMutex("Null RW Mutex"); } //! \brief \ref interface \ref requirement TEST_CASE("Lockable requirement test") { // Lockable - single threaded try_acquire operations TestTryAcquire("Spin Mutex"); TestTryAcquire("Spin RW Mutex"); TestTryAcquire("Queuing Mutex"); TestTryAcquire("Queuing RW Mutex"); #if !__TBB_USE_THREAD_SANITIZER TestTryAcquire("Speculative Spin Mutex"); TestTryAcquire("Speculative Spin RW Mutex"); #endif TestTryAcquire("Null Mutex"); } //! Testing ReaderWriterMutex requirements //! \brief \ref interface \ref requirement TEST_CASE("Shared mutexes (reader/writer) test") { // General reader writer capabilities + upgrade/downgrade TestReaderWriterLock("Spin RW Mutex"); TestReaderWriterLock("Queuing RW Mutex"); TestNullRWMutex("Null RW Mutex"); // Single threaded read/write try_acquire operations TestTryAcquireReader("Spin RW Mutex"); TestTryAcquireReader("Queuing RW Mutex"); TestRWStateMultipleChange("Spin RW Mutex"); TestRWStateMultipleChange("Queuing RW Mutex"); TestTryAcquireReader("Null RW Mutex"); #if !__TBB_USE_THREAD_SANITIZER TestReaderWriterLock("Speculative Spin RW Mutex"); TestTryAcquireReader("Speculative Spin RW Mutex"); TestRWStateMultipleChange("Speculative Spin RW Mutex"); #endif } //! Testing ISO C++ Mutex and Shared Mutex requirements. //! Compatibility with the standard //! \brief \ref interface \ref requirement TEST_CASE("ISO interface test") { GeneralTest >("ISO Spin Mutex"); GeneralTest >("ISO Spin RW Mutex"); TestTryAcquire >("ISO Spin Mutex"); TestTryAcquire >("ISO Spin RW Mutex"); TestTryAcquireReader >("ISO Spin RW Mutex"); TestReaderWriterLock >("ISO Spin RW Mutex"); }