Skip to content

Commit c1026ce

Browse files
committed
[#301] Remove 'timespec' from 'Duration'
1 parent 5315ea5 commit c1026ce

File tree

2 files changed

+1
-153
lines changed

2 files changed

+1
-153
lines changed

iceoryx2-bb/cxx/include/iox2/bb/duration.hpp

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "iox2/legacy/type_traits.hpp"
2121

2222
#include <cmath>
23-
#include <ctime>
2423

2524
namespace iox2 {
2625
namespace bb {
@@ -143,15 +142,6 @@ class Duration {
143142
static constexpr auto zero() noexcept -> Duration;
144143
// END CREATION FROM STATIC FUNCTIONS
145144

146-
// BEGIN CONSTRUCTORS AND ASSIGNMENT
147-
148-
/// @brief Construct a Duration object from timespec
149-
/// @param[in] value as timespec
150-
// AXIVION Next Line AutosarC++19_03-A8.4.7 : Argument is larger than two words
151-
constexpr explicit Duration(const struct timespec& value) noexcept;
152-
153-
// END CONSTRUCTORS AND ASSIGNMENT
154-
155145
// BEGIN COMPARISON
156146
// AXIVION DISABLE STYLE AutosarC++19_03-A8.4.7 : Each argument is larger than two words
157147
friend constexpr auto operator==(const Duration& lhs, const Duration& rhs) noexcept -> bool;
@@ -263,9 +253,6 @@ class Duration {
263253
/// @note The remaining microseconds are truncated, similar to the casting behavior of a float to an int.
264254
constexpr auto subsec_millis() const noexcept -> uint32_t;
265255

266-
/// @brief converts duration in a timespec c struct
267-
constexpr auto timespec() const noexcept -> struct timespec;
268-
269256
// END CONVERSION
270257

271258
// AXIVION DISABLE STYLE AutosarC++19_03-A3.9.1 : Use of unsigned long long int in user-defined literals is enforced by the standard
@@ -508,11 +495,6 @@ constexpr auto Duration::from_days(const T value) noexcept -> Duration {
508495
return Duration { static_cast<Duration::SecondsType>(clamped_value * SECS_PER_DAY), 0U };
509496
}
510497

511-
// AXIVION Next Construct AutosarC++19_03-A8.4.7 : Argument is larger than two words
512-
constexpr Duration::Duration(const struct timespec& value) noexcept
513-
: Duration(static_cast<SecondsType>(value.tv_sec), static_cast<NanosecondsType>(value.tv_nsec)) {
514-
}
515-
516498
constexpr auto Duration::to_nanoseconds() const noexcept -> uint64_t {
517499
constexpr SecondsType MAX_SECONDS_BEFORE_OVERFLOW { std::numeric_limits<uint64_t>::max()
518500
/ static_cast<uint64_t>(NANOSECS_PER_SEC) };
@@ -604,23 +586,8 @@ constexpr auto Duration::operator+(const Duration& rhs) const noexcept -> Durati
604586
return sum;
605587
}
606588

607-
constexpr auto Duration::timespec() const noexcept -> struct timespec {
608-
using SecType = decltype(std::declval<struct timespec>().tv_sec);
609-
using NsecType = decltype(std::declval<struct timespec>().tv_nsec);
610-
611-
static_assert(sizeof(uint64_t) >= sizeof(SecType), "casting might alter result");
612-
if (this->m_seconds > static_cast<uint64_t>(std::numeric_limits<SecType>::max())) {
613-
return { std::numeric_limits<SecType>::max(), NANOSECS_PER_SEC - 1U };
614-
}
615-
616-
const auto tv_sec = static_cast<SecType>(this->m_seconds);
617-
const auto tv_nsec = static_cast<NsecType>(this->m_nanoseconds);
618-
return { tv_sec, tv_nsec };
619-
}
620-
621589
// AXIVION Next Construct AutosarC++19_03-A8.4.7 : Argument is larger than two words
622-
constexpr auto
623-
Duration::operator+=(const Duration& rhs) noexcept -> Duration& {
590+
constexpr auto Duration::operator+=(const Duration& rhs) noexcept -> Duration& {
624591
*this = *this + rhs;
625592
return *this;
626593
}

iceoryx2-bb/cxx/tests/src/duration_tests.cpp

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <gmock/gmock.h>
1919
#include <gtest/gtest.h>
2020

21-
#include <ctime>
2221
#include <iostream>
2322
#include <limits>
2423
#include <ostream>
@@ -159,61 +158,6 @@ TEST(Duration_test, ConstructDurationWithOneNanosecondResultsNotInZeroNanosecond
159158
EXPECT_THAT(sut.to_nanoseconds(), Eq(EXPECTED_DURATION_IN_NANOSECONDS));
160159
}
161160

162-
TEST(Duration_test, ConstructFromTimespecWithZeroValue) {
163-
::testing::Test::RecordProperty("TEST_ID", "0360ae1d-b7e7-4b07-b515-fdc82703d16f");
164-
constexpr uint64_t SECONDS { 0U };
165-
constexpr uint64_t NANOSECONDS { 0U };
166-
constexpr Duration EXPECTED_DURATION = create_duration(SECONDS, NANOSECONDS);
167-
168-
timespec ts = {}; // NOLINT
169-
ts.tv_sec = SECONDS;
170-
ts.tv_nsec = NANOSECONDS;
171-
172-
Duration sut { ts };
173-
EXPECT_THAT(sut, Eq(EXPECTED_DURATION));
174-
}
175-
176-
TEST(Duration_test, ConstructFromTimespecWithValueLessThanOneSecond) {
177-
::testing::Test::RecordProperty("TEST_ID", "3cc49b4b-2bdf-491a-9015-9e8d769ba113");
178-
constexpr uint64_t SECONDS { 0U };
179-
constexpr uint64_t NANOSECONDS { 456U };
180-
constexpr Duration EXPECTED_DURATION = create_duration(SECONDS, NANOSECONDS);
181-
182-
timespec value = {};
183-
value.tv_sec = SECONDS;
184-
value.tv_nsec = NANOSECONDS;
185-
186-
Duration sut { value };
187-
EXPECT_THAT(sut, Eq(EXPECTED_DURATION));
188-
}
189-
190-
TEST(Duration_test, ConstructFromTimespecWithValueMoreThanOneSecond) {
191-
::testing::Test::RecordProperty("TEST_ID", "d8a165e4-3117-4897-bd16-3c5a0333c1b5");
192-
constexpr uint64_t SECONDS { 73U };
193-
constexpr uint64_t NANOSECONDS { 456U };
194-
constexpr Duration EXPECTED_DURATION = create_duration(SECONDS, NANOSECONDS);
195-
196-
timespec value = {};
197-
value.tv_sec = SECONDS;
198-
value.tv_nsec = NANOSECONDS;
199-
200-
Duration sut { value };
201-
EXPECT_THAT(sut, Eq(EXPECTED_DURATION));
202-
}
203-
204-
TEST(Duration_test, ConstructFromTimespecWithMaxValue) {
205-
::testing::Test::RecordProperty("TEST_ID", "d160d324-914f-4a66-ac96-17828442d4bd");
206-
constexpr uint64_t SECONDS { std::numeric_limits<DurationAccessor::SecondsType>::max() };
207-
constexpr uint64_t NANOSECONDS { NANOSECS_PER_SECOND - 1U };
208-
209-
timespec ts = {}; // NOLINT
210-
ts.tv_sec = static_cast<time_t>(SECONDS);
211-
ts.tv_nsec = static_cast<long>(NANOSECONDS);
212-
213-
Duration sut { ts };
214-
EXPECT_THAT(sut, Eq(DurationAccessor::max()));
215-
}
216-
217161
// END CONSTRUCTOR TESTS
218162

219163
// BEGIN CREATION FROM LITERAL TESTS
@@ -801,69 +745,6 @@ TEST(Duration_test, ConvertNanoecondsFromMaxDurationResultsInSaturation) {
801745
EXPECT_THAT(sut.to_nanoseconds(), Eq(std::numeric_limits<uint64_t>::max()));
802746
}
803747

804-
TEST(Duration_test, ConvertTimespecFromZeroDuration) {
805-
::testing::Test::RecordProperty("TEST_ID", "6a049ba6-885e-48c0-a9e8-3de6fa9a79f2");
806-
constexpr int64_t SECONDS { 0 };
807-
constexpr int64_t NANOSECONDS { 0 };
808-
809-
auto duration = create_duration(SECONDS, NANOSECONDS);
810-
811-
const timespec sut = duration.timespec();
812-
813-
EXPECT_THAT(sut.tv_sec, Eq(SECONDS));
814-
EXPECT_THAT(sut.tv_nsec, Eq(NANOSECONDS));
815-
}
816-
817-
TEST(Duration_test, ConvertTimespecFromDurationLessThanOneSecond) {
818-
::testing::Test::RecordProperty("TEST_ID", "d20435da-4585-44d9-9be7-24eb22c3ca85");
819-
constexpr int64_t SECONDS { 0 };
820-
constexpr int64_t NANOSECONDS { 55 };
821-
822-
auto duration = create_duration(SECONDS, NANOSECONDS);
823-
824-
const timespec sut = duration.timespec();
825-
826-
EXPECT_THAT(sut.tv_sec, Eq(SECONDS));
827-
EXPECT_THAT(sut.tv_nsec, Eq(NANOSECONDS));
828-
}
829-
830-
TEST(Duration_test, ConvertTimespecFromDurationMoreThanOneSecond) {
831-
::testing::Test::RecordProperty("TEST_ID", "1b298bc3-3a0b-48a2-8d9c-1ee03dea925c");
832-
constexpr int64_t SECONDS { 44 };
833-
constexpr int64_t NANOSECONDS { 55 };
834-
835-
auto duration = create_duration(SECONDS, NANOSECONDS);
836-
837-
const timespec sut = duration.timespec();
838-
839-
EXPECT_THAT(sut.tv_sec, Eq(SECONDS));
840-
EXPECT_THAT(sut.tv_nsec, Eq(NANOSECONDS));
841-
}
842-
843-
TEST(Duration_test, ConvertTimespecFromDurationResultsNotYetInSaturation) {
844-
::testing::Test::RecordProperty("TEST_ID", "70f11b99-78ec-442a-aefe-4dd9152b7903");
845-
constexpr int64_t SECONDS { std::numeric_limits<decltype(timespec::tv_sec)>::max() };
846-
constexpr int64_t NANOSECONDS { NANOSECS_PER_SECOND - 1U };
847-
848-
auto duration = create_duration(SECONDS, NANOSECONDS);
849-
850-
const timespec sut = duration.timespec();
851-
852-
EXPECT_THAT(sut.tv_sec, Eq(SECONDS));
853-
EXPECT_THAT(sut.tv_nsec, Eq(NANOSECONDS));
854-
}
855-
856-
TEST(Duration_test, ConvertTimespecFromMaxDurationResultsInSaturation) {
857-
::testing::Test::RecordProperty("TEST_ID", "3bf4bb34-46f3-4889-84f5-9220b32fff73");
858-
constexpr int64_t SECONDS { std::numeric_limits<decltype(timespec::tv_sec)>::max() };
859-
constexpr int64_t NANOSECONDS { NANOSECS_PER_SECOND - 1U };
860-
861-
const timespec sut = DurationAccessor::max().timespec();
862-
863-
EXPECT_THAT(sut.tv_sec, Eq(SECONDS));
864-
EXPECT_THAT(sut.tv_nsec, Eq(NANOSECONDS));
865-
}
866-
867748
// END CONVERSION FUNCTION TESTS
868749

869750
// BEGIN SUBSECONDS ACCESS TESTS

0 commit comments

Comments
 (0)