Skip to content

Commit a657228

Browse files
authored
Merge pull request #472 from elfenpiff/iox2-349-bazel-compatible-tests
[#349] Add service name generator to be able to run tests concurrently
2 parents a85eda8 + b3dfa90 commit a657228

File tree

8 files changed

+98
-103
lines changed

8 files changed

+98
-103
lines changed

doc/how-to-create-an-iceoryx2-release.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ number is `Xold.Yold.Zold`.
7979
10. Adjust the `<version>` to `X.Y.Z` in `$GIT_ROOT$/package.xml`.
8080
11. Call `rg "Xold\.Yold\.Zold"` and adjust all findings.
8181
* C and C++ examples, `BUILD.bazel` & `CMakeLists.txt`
82-
12. **Merge all changes to `main`.**
83-
13. Set tag on GitHub and add the release document as notes to the tag
82+
12. Adjust the major, minor and patch version number in `iceoryx2_bb_elementary::PackageVersion`
83+
13. **Merge all changes to `main`.**
84+
14. Set tag on GitHub and add the release document as notes to the tag
8485
description. Add also a link to the file.
85-
14. Check the order of all dependencies in
86+
15. Check the order of all dependencies in
8687
`$GIT_ROOT$/./internal/scripts/crates_io_publish_script.sh`.
8788
When calling `cargo publish -p $PACKAGE$` all dependencies, also dev-dependencies,
8889
must be already published to `crates.io` via `cargo publish -p`. Verify the
@@ -92,7 +93,7 @@ number is `Xold.Yold.Zold`.
9293
* If the publish script was started and a crate requires a dependency which
9394
is not available on `crates.io` the release has to be redone and the patch
9495
version has to increase by one for the whole workspace.
95-
15. Call `$GIT_ROOT$/./internal/scripts/crates_io_publish_script.sh` and publish
96+
16. Call `$GIT_ROOT$/./internal/scripts/crates_io_publish_script.sh` and publish
9697
all crates on `crates.io` and `docs.rs`.
97-
16. Verify that the release looks fine on `docs.rs` (click through the
98+
17. Verify that the release looks fine on `docs.rs` (click through the
9899
documentation to check if everything was generated correctly)

iceoryx2-bb/elementary/src/package_version.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
//
1111
// SPDX-License-Identifier: Apache-2.0 OR MIT
1212

13-
use iceoryx2_pal_concurrency_sync::iox_atomic::IoxAtomicU64;
14-
use std::{fmt::Display, sync::atomic::Ordering};
13+
use std::fmt::Display;
1514

1615
/// Represents the crates version acquired through the internal environment variables set by cargo,
1716
/// ("CARGO_PKG_VERSION_{MAJOR|MINOR|PATCH}").
@@ -63,26 +62,11 @@ impl PackageVersion {
6362

6463
/// Returns the current [`PackageVersion`]
6564
pub fn get() -> PackageVersion {
66-
static PACKAGE_VERSION: IoxAtomicU64 = IoxAtomicU64::new(0);
65+
const MAJOR: u16 = 0;
66+
const MINOR: u16 = 4;
67+
const PATCH: u16 = 1;
6768

68-
if PACKAGE_VERSION.load(Ordering::Relaxed) == 0 {
69-
let major = option_env!("CARGO_PKG_VERSION_MAJOR")
70-
.and_then(|s| s.parse::<u16>().ok())
71-
.unwrap_or(u16::MAX);
72-
let minor = option_env!("CARGO_PKG_VERSION_MINOR")
73-
.and_then(|s| s.parse::<u16>().ok())
74-
.unwrap_or(u16::MAX);
75-
let patch = option_env!("CARGO_PKG_VERSION_PATCH")
76-
.and_then(|s| s.parse::<u16>().ok())
77-
.unwrap_or(u16::MAX);
78-
79-
PACKAGE_VERSION.store(
80-
PackageVersion::from_version(major, minor, patch).0,
81-
Ordering::Relaxed,
82-
);
83-
}
84-
85-
PackageVersion::from_u64(PACKAGE_VERSION.load(Ordering::Relaxed))
69+
PackageVersion::from_version(MAJOR, MINOR, PATCH)
8670
}
8771
}
8872

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2024 Contributors to the Eclipse Foundation
2+
//
3+
// See the NOTICE file(s) distributed with this work for additional
4+
// information regarding copyright ownership.
5+
//
6+
// This program and the accompanying materials are made available under the
7+
// terms of the Apache Software License 2.0 which is available at
8+
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
9+
// which is available at https://opensource.org/licenses/MIT.
10+
//
11+
// SPDX-License-Identifier: Apache-2.0 OR MIT
12+
13+
use iceoryx2_bb_elementary::package_version::PackageVersion;
14+
use iceoryx2_bb_testing::assert_that;
15+
16+
#[test]
17+
fn package_version_works() {
18+
let major = option_env!("CARGO_PKG_VERSION_MAJOR")
19+
.and_then(|s| s.parse::<u16>().ok())
20+
.expect("Contains a valid major version number.");
21+
let minor = option_env!("CARGO_PKG_VERSION_MINOR")
22+
.and_then(|s| s.parse::<u16>().ok())
23+
.expect("Contains a valid minor version number.");
24+
let patch = option_env!("CARGO_PKG_VERSION_PATCH")
25+
.and_then(|s| s.parse::<u16>().ok())
26+
.expect("Contains a valid patch version number.");
27+
28+
let sut = PackageVersion::get();
29+
30+
assert_that!(sut.major(), eq major);
31+
assert_that!(sut.minor(), eq minor);
32+
assert_that!(sut.patch(), eq patch);
33+
34+
assert_that!(major == 0 && minor == 0 && patch == 0, eq false);
35+
}

iceoryx2-cal/src/dynamic_storage/posix_shared_memory.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,18 @@ impl<'builder, T: Send + Sync + Debug> Builder<'builder, T> {
215215

216216
let init_state = shm.base_address().as_ptr() as *const Data<T>;
217217

218-
// The mem-sync is actually not required since an uninitialized dynamic storage has
219-
// only write permissions and can be therefore not consumed.
220-
// This is only for the case that this strategy fails on an obscure POSIX platform.
221-
//
222-
//////////////////////////////////////////
223-
// SYNC POINT: read Data<T>::data
224-
//////////////////////////////////////////
225-
let package_version = unsafe { &(*init_state) }
226-
.version
227-
.load(std::sync::atomic::Ordering::SeqCst);
228-
229218
loop {
219+
// The mem-sync is actually not required since an uninitialized dynamic storage has
220+
// only write permissions and can be therefore not consumed.
221+
// This is only for the case that this strategy fails on an obscure POSIX platform.
222+
//
223+
//////////////////////////////////////////
224+
// SYNC POINT: read Data<T>::data
225+
//////////////////////////////////////////
226+
let package_version = unsafe { &(*init_state) }
227+
.version
228+
.load(std::sync::atomic::Ordering::SeqCst);
229+
230230
let package_version = PackageVersion::from_u64(package_version);
231231
if package_version.to_u64() == 0 {
232232
if elapsed_time >= self.timeout {

iceoryx2-ffi/cxx/tests/src/service_event_tests.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//
1111
// SPDX-License-Identifier: Apache-2.0 OR MIT
1212

13+
#include <cstdlib>
14+
1315
#include "iox2/node.hpp"
1416
#include "iox2/node_name.hpp"
1517
#include "iox2/service.hpp"
@@ -24,8 +26,7 @@ constexpr iox::units::Duration TIMEOUT = iox::units::Duration::fromMilliseconds(
2426
template <typename T>
2527
struct ServiceEventTest : public ::testing::Test {
2628
ServiceEventTest()
27-
: service_name_value { "We all love the hypnotoad!" }
28-
, service_name { ServiceName::create(service_name_value).expect("") }
29+
: service_name { iox2_testing::generate_service_name() }
2930
, node { NodeBuilder().create<T::TYPE>().expect("") }
3031
, service { node.service_builder(service_name).event().create().expect("") }
3132
, notifier { service.notifier_builder().create().expect("") }
@@ -37,7 +38,6 @@ struct ServiceEventTest : public ::testing::Test {
3738
static std::atomic<size_t> event_id_counter;
3839
static constexpr ServiceType TYPE = T::TYPE;
3940
//NOLINTBEGIN(misc-non-private-member-variables-in-classes), required for tests
40-
const char* service_name_value { nullptr };
4141
ServiceName service_name;
4242
Node<T::TYPE> node;
4343
PortFactoryEvent<T::TYPE> service;
@@ -56,8 +56,7 @@ TYPED_TEST_SUITE(ServiceEventTest, iox2_testing::ServiceTypes);
5656
TYPED_TEST(ServiceEventTest, created_service_does_exist) {
5757
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
5858

59-
const auto* name_value = "First time we met, I saw the ocean, it was wet!";
60-
const auto service_name = ServiceName::create(name_value).expect("");
59+
const auto service_name = iox2_testing::generate_service_name();
6160

6261
ASSERT_FALSE(
6362
Service<SERVICE_TYPE>::does_exist(service_name, Config::global_config(), MessagingPattern::Event).expect(""));
@@ -78,8 +77,7 @@ TYPED_TEST(ServiceEventTest, created_service_does_exist) {
7877
TYPED_TEST(ServiceEventTest, creating_existing_service_fails) {
7978
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
8079

81-
const auto* name_value = "First time we met, I saw the ocean, it was wet!";
82-
const auto service_name = ServiceName::create(name_value).expect("");
80+
const auto service_name = iox2_testing::generate_service_name();
8381

8482
auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
8583
auto sut = node.service_builder(service_name).event().create().expect("");
@@ -94,8 +92,7 @@ TYPED_TEST(ServiceEventTest, service_settings_are_applied) {
9492
constexpr uint64_t NUMBER_OF_NOTIFIERS = 5;
9593
constexpr uint64_t NUMBER_OF_LISTENERS = 7;
9694

97-
const auto* name_value = "First time we met, I saw the ocean, it was wet!";
98-
const auto service_name = ServiceName::create(name_value).expect("");
95+
const auto service_name = iox2_testing::generate_service_name();
9996

10097
auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
10198
auto sut = node.service_builder(service_name)
@@ -115,8 +112,7 @@ TYPED_TEST(ServiceEventTest, open_fails_with_incompatible_max_notifiers_requirem
115112
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
116113
constexpr uint64_t NUMBER_OF_NOTIFIERS = 5;
117114

118-
const auto* name_value = "First time we met, I saw the ocean, it was wet!";
119-
const auto service_name = ServiceName::create(name_value).expect("");
115+
const auto service_name = iox2_testing::generate_service_name();
120116

121117
auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
122118
auto sut = node.service_builder(service_name).event().max_notifiers(NUMBER_OF_NOTIFIERS).create().expect("");
@@ -130,8 +126,7 @@ TYPED_TEST(ServiceEventTest, open_fails_with_incompatible_max_listeners_requirem
130126
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
131127
constexpr uint64_t NUMBER_OF_LISTENERS = 7;
132128

133-
const auto* name_value = "First time we met, I saw the ocean, it was wet!";
134-
const auto service_name = ServiceName::create(name_value).expect("");
129+
const auto service_name = iox2_testing::generate_service_name();
135130

136131
auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
137132
auto sut = node.service_builder(service_name).event().max_listeners(NUMBER_OF_LISTENERS).create().expect("");
@@ -144,8 +139,7 @@ TYPED_TEST(ServiceEventTest, open_fails_with_incompatible_max_listeners_requirem
144139
TYPED_TEST(ServiceEventTest, open_or_create_service_does_exist) {
145140
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
146141

147-
const auto* name_value = "First time we met, I saw the ocean, it was wet!";
148-
const auto service_name = ServiceName::create(name_value).expect("");
142+
const auto service_name = iox2_testing::generate_service_name();
149143

150144
ASSERT_FALSE(
151145
Service<SERVICE_TYPE>::does_exist(service_name, Config::global_config(), MessagingPattern::Event).expect(""));
@@ -180,8 +174,7 @@ TYPED_TEST(ServiceEventTest, open_or_create_service_does_exist) {
180174
TYPED_TEST(ServiceEventTest, opening_non_existing_service_fails) {
181175
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
182176

183-
const auto* name_value = "First time we met, I saw the ocean, it was wet!";
184-
const auto service_name = ServiceName::create(name_value).expect("");
177+
const auto service_name = iox2_testing::generate_service_name();
185178

186179
auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
187180
auto sut = node.service_builder(service_name).event().open();
@@ -192,8 +185,7 @@ TYPED_TEST(ServiceEventTest, opening_non_existing_service_fails) {
192185
TYPED_TEST(ServiceEventTest, opening_existing_service_works) {
193186
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
194187

195-
const auto* name_value = "First time we met, I saw the ocean, it was wet!";
196-
const auto service_name = ServiceName::create(name_value).expect("");
188+
const auto service_name = iox2_testing::generate_service_name();
197189

198190
auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
199191
auto sut_create = node.service_builder(service_name).event().create();
@@ -204,8 +196,7 @@ TYPED_TEST(ServiceEventTest, opening_existing_service_works) {
204196
TYPED_TEST(ServiceEventTest, service_name_is_set) {
205197
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
206198

207-
const auto* name_value = "Another one bites the toad.";
208-
const auto service_name = ServiceName::create(name_value).expect("");
199+
const auto service_name = iox2_testing::generate_service_name();
209200

210201
auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
211202
auto sut = node.service_builder(service_name).event().create().expect("");

0 commit comments

Comments
 (0)