Skip to content

Commit

Permalink
iox-#5 Add RuDiEnvironment for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Jun 20, 2022
1 parent d0813f9 commit e8078f5
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
7 changes: 7 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn make_and_install(source_dir: &str, build_dir: &str, install_dir: &str) -> std
.args(&[
"-DCMAKE_BUILD_TYPE=Release",
"-DBUILD_SHARED_LIBS=OFF",
"-DROUDI_ENVIRONMENT=ON",
&cmake_prefix_path,
&cmake_install_prefix,
&component_source_dir,
Expand Down Expand Up @@ -136,14 +137,20 @@ fn main() -> std::io::Result<()> {

println!("cargo:rustc-link-search={}", iceoryx_lib_dir);

println!("cargo:rustc-link-lib=iceoryx_posh_testing");

println!("cargo:rustc-link-lib=iceoryx_posh_roudi");
println!("cargo:rustc-link-lib=iceoryx_posh");
println!("cargo:rustc-link-lib=iceoryx_hoofs");
println!("cargo:rustc-link-lib=iceoryx_platform");

println!("cargo:rustc-link-lib=acl");

#[cfg(not(any(target_os = "windows", target_os = "macos")))]
println!("cargo:rustc-link-lib=stdc++");
#[cfg(any(target_os = "macos"))]
println!("cargo:rustc-link-lib=c++");


Ok(())
}
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ pub mod sb;
// re-export structs
pub use error::IceOryxError;
pub use runtime::Runtime;

mod testing;
#[cfg(test)]
mod tests;
8 changes: 8 additions & 0 deletions src/testing/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project
// SPDX-FileContributor: Mathias Kraus

mod roudi_environment_ffi;

// re-exports
pub (crate) use roudi_environment_ffi::RouDiEnvironment;
25 changes: 25 additions & 0 deletions src/testing/roudi_environment_ffi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project
// SPDX-FileContributor: Mathias Kraus

cpp! {{
#include "iceoryx_posh/testing/roudi_environment/roudi_environment.hpp"

using iox::roudi::RouDiEnvironment;
}}

cpp_class!(pub unsafe struct RouDiEnvironment as "RouDiEnvironment");

impl RouDiEnvironment {
pub(crate) fn new(
) -> Box<Self> {
unsafe {
let raw = cpp!([] -> *mut RouDiEnvironment as "RouDiEnvironment*"
{
return new RouDiEnvironment();
});

Box::from_raw(raw)
}
}
}
45 changes: 45 additions & 0 deletions src/tests/basic_pub_sub.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project
// SPDX-FileContributor: Mathias Kraus

use crate::pb::{self, POD};
use crate::sb;
use crate::Runtime;
use crate::testing::RouDiEnvironment;

#[repr(C)]
struct CounterTopic {
counter: u32,
}

unsafe impl POD for CounterTopic {}

#[test]
fn basic_pub_sub() {
let _roudi = RouDiEnvironment::new();

Runtime::init("publisher_simple");

let topic = sb::TopicBuilder::<CounterTopic>::new("Radar", "FrontLeft", "Counter")
.queue_capacity(5)
.build();

let (subscriber, sample_receive_token) = topic.subscribe();

let topic = pb::TopicBuilder::<CounterTopic>::new("Radar", "FrontLeft", "Counter").build().expect("Topic");//?;

let publisher = topic.offer();
let mut sample = publisher.allocate_sample().expect("Samle");//?;
sample.counter = 42;
publisher.publish(sample);

println!("Sending: {}", 42);

let sample_receiver = subscriber.get_sample_receiver(sample_receive_token);

if sample_receiver.has_samples() {
while let Some(sample) = sample_receiver.get_sample() {
println!("Receiving: {}", sample.counter);
}
}
}
6 changes: 6 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project
// SPDX-FileContributor: Mathias Kraus

// minimal setup with one publisher and one subscriber exchanging data
mod basic_pub_sub;

0 comments on commit e8078f5

Please sign in to comment.