Skip to content

Commit

Permalink
Run integration tests on both ST and MT executors
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarral committed Nov 8, 2024
1 parent 35e7e17 commit abbfb64
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on:
pull_request:
push:
branches: [main, dev]
branches: [ main ]

env:
RUSTFLAGS: -Dwarnings
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable

- name: Dry-run cargo test (Loom)
run: cargo test --no-run --tests --all-features
run: cargo test --no-run --lib --all-features
env:
RUSTFLAGS: --cfg asynchronix_loom

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/loom.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Loom

on:
workflow_dispatch:
pull_request:
push:
branches: [ main ]
Expand Down Expand Up @@ -30,6 +31,6 @@ jobs:
uses: dtolnay/rust-toolchain@stable

- name: Run cargo test (Loom)
run: cargo test --tests --release
run: cargo test --lib --release
env:
RUSTFLAGS: --cfg asynchronix_loom
7 changes: 1 addition & 6 deletions asynchronix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ A high performance asychronous compute framework for system simulation.
"""
categories = ["simulation", "aerospace", "science"]
keywords = ["simulation", "discrete-event", "systems", "cyberphysical", "real-time"]
autotests = false

[features]
# gRPC service.
Expand Down Expand Up @@ -65,7 +64,7 @@ futures-executor = "0.3"
tracing-subscriber = { version= "0.3.18", features=["env-filter"] }

[target.'cfg(asynchronix_loom)'.dev-dependencies]
loom = "0.5"
loom = "0.7"
waker-fn = "1.1"

[target.'cfg(asynchronix_grpc_codegen)'.build-dependencies]
Expand All @@ -79,7 +78,3 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(asynchronix_loom)', 'cfg(a
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[[test]]
name = "integration"
path = "tests/tests.rs"
2 changes: 1 addition & 1 deletion asynchronix/src/util/cached_rw_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ mod tests {

#[test]
fn loom_cached_rw_lock_write() {
const DEFAULT_PREEMPTION_BOUND: usize = 4;
const DEFAULT_PREEMPTION_BOUND: usize = 3;
const ITERATIONS_NUMBER: usize = 5;

let mut builder = Builder::new();
Expand Down
92 changes: 77 additions & 15 deletions asynchronix/tests/model_scheduling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use asynchronix::ports::{EventBuffer, Output};
use asynchronix::simulation::{ActionKey, Mailbox, SimInit};
use asynchronix::time::MonotonicTime;

#[test]
fn model_schedule_event() {
const MT_NUM_THREADS: usize = 4;

fn model_schedule_event(num_threads: usize) {
#[derive(Default)]
struct TestModel {
output: Output<()>,
Expand Down Expand Up @@ -38,7 +39,10 @@ fn model_schedule_event() {
let addr = mbox.address();

let t0 = MonotonicTime::EPOCH;
let mut simu = SimInit::new().add_model(model, mbox, "").init(t0).unwrap();
let mut simu = SimInit::with_num_threads(num_threads)
.add_model(model, mbox, "")
.init(t0)
.unwrap();

simu.process_event(TestModel::trigger, (), addr).unwrap();
simu.step().unwrap();
Expand All @@ -48,8 +52,7 @@ fn model_schedule_event() {
assert!(output.next().is_none());
}

#[test]
fn model_cancel_future_keyed_event() {
fn model_cancel_future_keyed_event(num_threads: usize) {
#[derive(Default)]
struct TestModel {
output: Output<i32>,
Expand Down Expand Up @@ -93,7 +96,10 @@ fn model_cancel_future_keyed_event() {
let addr = mbox.address();

let t0 = MonotonicTime::EPOCH;
let mut simu = SimInit::new().add_model(model, mbox, "").init(t0).unwrap();
let mut simu = SimInit::with_num_threads(num_threads)
.add_model(model, mbox, "")
.init(t0)
.unwrap();

simu.process_event(TestModel::trigger, (), addr).unwrap();
simu.step().unwrap();
Expand All @@ -104,8 +110,7 @@ fn model_cancel_future_keyed_event() {
assert!(output.next().is_none());
}

#[test]
fn model_cancel_same_time_keyed_event() {
fn model_cancel_same_time_keyed_event(num_threads: usize) {
#[derive(Default)]
struct TestModel {
output: Output<i32>,
Expand Down Expand Up @@ -149,7 +154,10 @@ fn model_cancel_same_time_keyed_event() {
let addr = mbox.address();

let t0 = MonotonicTime::EPOCH;
let mut simu = SimInit::new().add_model(model, mbox, "").init(t0).unwrap();
let mut simu = SimInit::with_num_threads(num_threads)
.add_model(model, mbox, "")
.init(t0)
.unwrap();

simu.process_event(TestModel::trigger, (), addr).unwrap();
simu.step().unwrap();
Expand All @@ -160,8 +168,7 @@ fn model_cancel_same_time_keyed_event() {
assert!(output.next().is_none());
}

#[test]
fn model_schedule_periodic_event() {
fn model_schedule_periodic_event(num_threads: usize) {
#[derive(Default)]
struct TestModel {
output: Output<i32>,
Expand Down Expand Up @@ -192,7 +199,10 @@ fn model_schedule_periodic_event() {
let addr = mbox.address();

let t0 = MonotonicTime::EPOCH;
let mut simu = SimInit::new().add_model(model, mbox, "").init(t0).unwrap();
let mut simu = SimInit::with_num_threads(num_threads)
.add_model(model, mbox, "")
.init(t0)
.unwrap();

simu.process_event(TestModel::trigger, (), addr).unwrap();

Expand All @@ -208,8 +218,7 @@ fn model_schedule_periodic_event() {
}
}

#[test]
fn model_cancel_periodic_event() {
fn model_cancel_periodic_event(num_threads: usize) {
#[derive(Default)]
struct TestModel {
output: Output<()>,
Expand Down Expand Up @@ -243,7 +252,10 @@ fn model_cancel_periodic_event() {
let addr = mbox.address();

let t0 = MonotonicTime::EPOCH;
let mut simu = SimInit::new().add_model(model, mbox, "").init(t0).unwrap();
let mut simu = SimInit::with_num_threads(num_threads)
.add_model(model, mbox, "")
.init(t0)
.unwrap();

simu.process_event(TestModel::trigger, (), addr).unwrap();

Expand All @@ -256,3 +268,53 @@ fn model_cancel_periodic_event() {
assert_eq!(simu.time(), t0 + Duration::from_secs(2));
assert!(output.next().is_none());
}

#[test]
fn model_schedule_event_st() {
model_schedule_event(1);
}

#[test]
fn model_schedule_event_mt() {
model_schedule_event(MT_NUM_THREADS);
}

#[test]
fn model_cancel_future_keyed_event_st() {
model_cancel_future_keyed_event(1);
}

#[test]
fn model_cancel_future_keyed_event_mt() {
model_cancel_future_keyed_event(MT_NUM_THREADS);
}

#[test]
fn model_cancel_same_time_keyed_event_st() {
model_cancel_same_time_keyed_event(1);
}

#[test]
fn model_cancel_same_time_keyed_event_mt() {
model_cancel_same_time_keyed_event(MT_NUM_THREADS);
}

#[test]
fn model_schedule_periodic_event_st() {
model_schedule_periodic_event(1);
}

#[test]
fn model_schedule_periodic_event_mt() {
model_schedule_periodic_event(MT_NUM_THREADS);
}

#[test]
fn model_cancel_periodic_event_st() {
model_cancel_periodic_event(1);
}

#[test]
fn model_cancel_periodic_event_mt() {
model_cancel_periodic_event(MT_NUM_THREADS);
}
62 changes: 50 additions & 12 deletions asynchronix/tests/simulation_deadlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use asynchronix::ports::{Output, Requestor};
use asynchronix::simulation::{DeadlockInfo, ExecutionError, Mailbox, SimInit};
use asynchronix::time::MonotonicTime;

const MT_NUM_THREADS: usize = 4;

#[derive(Default)]
struct TestModel {
output: Output<()>,
Expand All @@ -22,8 +24,7 @@ impl Model for TestModel {}

/// Overflows a mailbox by sending 2 messages in loopback for each incoming
/// message.
#[test]
fn deadlock_on_mailbox_overflow() {
fn deadlock_on_mailbox_overflow(num_threads: usize) {
const MODEL_NAME: &str = "testmodel";
const MAILBOX_SIZE: usize = 5;

Expand All @@ -41,7 +42,7 @@ fn deadlock_on_mailbox_overflow() {
.connect(TestModel::activate_output, addr.clone());

let t0 = MonotonicTime::EPOCH;
let mut simu = SimInit::new()
let mut simu = SimInit::with_num_threads(num_threads)
.add_model(model, mbox, MODEL_NAME)
.init(t0)
.unwrap();
Expand All @@ -64,8 +65,7 @@ fn deadlock_on_mailbox_overflow() {
}

/// Generates a deadlock with a query loopback.
#[test]
fn deadlock_on_query_loopback() {
fn deadlock_on_query_loopback(num_threads: usize) {
const MODEL_NAME: &str = "testmodel";

let mut model = TestModel::default();
Expand All @@ -77,7 +77,7 @@ fn deadlock_on_query_loopback() {
.connect(TestModel::activate_requestor, addr.clone());

let t0 = MonotonicTime::EPOCH;
let mut simu = SimInit::new()
let mut simu = SimInit::with_num_threads(num_threads)
.add_model(model, mbox, MODEL_NAME)
.init(t0)
.unwrap();
Expand All @@ -100,8 +100,7 @@ fn deadlock_on_query_loopback() {
}

/// Generates a deadlock with a query loopback involving several models.
#[test]
fn deadlock_on_transitive_query_loopback() {
fn deadlock_on_transitive_query_loopback(num_threads: usize) {
const MODEL1_NAME: &str = "testmodel1";
const MODEL2_NAME: &str = "testmodel2";

Expand All @@ -121,7 +120,7 @@ fn deadlock_on_transitive_query_loopback() {
.connect(TestModel::activate_requestor, addr1.clone());

let t0 = MonotonicTime::EPOCH;
let mut simu = SimInit::new()
let mut simu = SimInit::with_num_threads(num_threads)
.add_model(model1, mbox1, MODEL1_NAME)
.add_model(model2, mbox2, MODEL2_NAME)
.init(t0)
Expand All @@ -145,8 +144,7 @@ fn deadlock_on_transitive_query_loopback() {
}

/// Generates deadlocks with query loopbacks on several models at the same time.
#[test]
fn deadlock_on_multiple_query_loopback() {
fn deadlock_on_multiple_query_loopback(num_threads: usize) {
const MODEL0_NAME: &str = "testmodel0";
const MODEL1_NAME: &str = "testmodel1";
const MODEL2_NAME: &str = "testmodel2";
Expand Down Expand Up @@ -178,7 +176,7 @@ fn deadlock_on_multiple_query_loopback() {
.connect(TestModel::activate_requestor, addr2);

let t0 = MonotonicTime::EPOCH;
let mut simu = SimInit::new()
let mut simu = SimInit::with_num_threads(num_threads)
.add_model(model0, mbox0, MODEL0_NAME)
.add_model(model1, mbox1, MODEL1_NAME)
.add_model(model2, mbox2, MODEL2_NAME)
Expand Down Expand Up @@ -209,3 +207,43 @@ fn deadlock_on_multiple_query_loopback() {
_ => panic!("deadlock not detected"),
}
}

#[test]
fn deadlock_on_mailbox_overflow_st() {
deadlock_on_mailbox_overflow(1);
}

#[test]
fn deadlock_on_mailbox_overflow_mt() {
deadlock_on_mailbox_overflow(MT_NUM_THREADS);
}

#[test]
fn deadlock_on_query_loopback_st() {
deadlock_on_query_loopback(1);
}

#[test]
fn deadlock_on_query_loopback_mt() {
deadlock_on_query_loopback(MT_NUM_THREADS);
}

#[test]
fn deadlock_on_transitive_query_loopback_st() {
deadlock_on_transitive_query_loopback(1);
}

#[test]
fn deadlock_on_transitive_query_loopback_mt() {
deadlock_on_transitive_query_loopback(MT_NUM_THREADS);
}

#[test]
fn deadlock_on_multiple_query_loopback_st() {
deadlock_on_multiple_query_loopback(1);
}

#[test]
fn deadlock_on_multiple_query_loopback_mt() {
deadlock_on_multiple_query_loopback(MT_NUM_THREADS);
}
Loading

0 comments on commit abbfb64

Please sign in to comment.