Skip to content

Commit 09d7c2f

Browse files
committed
[#301] Remove 'timespec' from 'Duration'
1 parent f063f7a commit 09d7c2f

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
@@ -507,11 +494,6 @@ constexpr auto Duration::from_days(const T value) noexcept -> Duration {
507494
return Duration { static_cast<Duration::SecondsT>(clamped_value * SECS_PER_DAY), 0U };
508495
}
509496

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

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

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::SecondsT>::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
@@ -800,69 +744,6 @@ TEST(Duration_test, ConvertNanoecondsFromMaxDurationResultsInSaturation) {
800744
EXPECT_THAT(sut.to_nanoseconds(), Eq(std::numeric_limits<uint64_t>::max()));
801745
}
802746

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

868749
// BEGIN SUBSECONDS ACCESS TESTS

0 commit comments

Comments
 (0)