// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2020 - 2021 by Apex.AI Inc. All rights reserved. // // 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. // // SPDX-License-Identifier: Apache-2.0 #include "test.hpp" #include "iceoryx_hoofs/concurrent/lockfree_queue.hpp" #include "iceoryx_hoofs/concurrent/resizeable_lockfree_queue.hpp" // We test the common functionality of LockFreeQueue and ResizableLockFreeQueue here // in typed tests to reduce code duplication. namespace { using namespace ::testing; // use a non-POD type for testing (just a boxed version of int). // We use implicit conversions of int to Integer to be able use the same test structure // for Integer and int (primarily for tryPush). // This allows testing PODs and Custom Types with the same test structure. struct Integer { Integer(int value = 0) : value(value) { } int value{0}; // so that it behaves like an int for comparison purposes operator int() const { return value; } }; template class LockFreeQueueTest : public ::testing::Test { protected: LockFreeQueueTest() { } ~LockFreeQueueTest() { } void SetUp() { // reduce capacity before running the tests if required by config setCapacity(); } void TearDown() { } void fillQueue(int start = 0) { int data{start}; for (uint64_t i = 0; i < queue.capacity(); ++i) { queue.tryPush(data); data++; } } // only set Capacity if DynamicCapacity is smaller // since some queue types may not even provide the option to call setCapacity // this must be done at compile time // (the additional template indirection via Config_ is required for SFINAE) template typename std::enable_if::type setCapacity() { queue.setCapacity(Config::DynamicCapacity); } template typename std::enable_if::type setCapacity() { } using Queue = typename Config::QueueType; Queue queue; }; template using IntegerQueue = iox::concurrent::LockFreeQueue; // define the test configurations with varying types, capacities and dynamically reduced capacities template