Skip to content

Commit 004429b

Browse files
committed
Split test into two depending on the platform
The same test currently succeeds for Linux but fails for MacOS, thus, we split it into a regular test and a fixme test.
1 parent 2d71dad commit 004429b

File tree

2 files changed

+113
-42
lines changed

2 files changed

+113
-42
lines changed
Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
11
// Copyright Kani Contributors
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
3-
// The original harness takes too long so we introduced a simplified version to run in CI.
4-
// kani-flags: --harness simplified
53

64
//! This is a regression test for size_and_align_of_dst computing the
75
//! size and alignment of a dynamically-sized type like
86
//! Arc<Mutex<dyn Subscriber>>.
9-
//! We added a simplified version of the original harness from:
107
//! <https://github.com/model-checking/kani/issues/426>
11-
//! This currently fails due to
12-
//! <https://github.com/model-checking/kani/issues/1781>
138
14-
use std::sync::Arc;
15-
use std::sync::Mutex;
16-
17-
pub trait Subscriber {
18-
fn process(&self);
19-
fn increment(&mut self);
20-
fn get(&self) -> u32;
21-
}
22-
23-
struct DummySubscriber {
24-
val: u32,
25-
}
9+
/// This test fails on macos but not in other platforms.
10+
/// Thus only enable it for platforms where this shall succeed.
11+
#[cfg(not(target_os = "macos"))]
12+
mod not_macos {
13+
use std::sync::Arc;
14+
use std::sync::Mutex;
15+
16+
pub trait Subscriber {
17+
fn process(&self);
18+
fn increment(&mut self);
19+
fn get(&self) -> u32;
20+
}
2621

27-
impl DummySubscriber {
28-
fn new() -> Self {
29-
DummySubscriber { val: 0 }
22+
struct DummySubscriber {
23+
val: u32,
3024
}
31-
}
3225

33-
impl Subscriber for DummySubscriber {
34-
fn process(&self) {}
35-
fn increment(&mut self) {
36-
self.val = self.val + 1;
26+
impl DummySubscriber {
27+
fn new() -> Self {
28+
DummySubscriber { val: 0 }
29+
}
3730
}
38-
fn get(&self) -> u32 {
39-
self.val
31+
32+
impl Subscriber for DummySubscriber {
33+
fn process(&self) {}
34+
fn increment(&mut self) {
35+
self.val = self.val + 1;
36+
}
37+
fn get(&self) -> u32 {
38+
self.val
39+
}
4040
}
41-
}
4241

43-
#[kani::proof]
44-
#[kani::unwind(2)]
45-
fn simplified() {
46-
let s: Arc<Mutex<dyn Subscriber>> = Arc::new(Mutex::new(DummySubscriber::new()));
47-
let data = s.lock().unwrap();
48-
assert!(data.get() == 0);
49-
}
42+
#[kani::proof]
43+
#[kani::unwind(2)]
44+
fn simplified() {
45+
let s: Arc<Mutex<dyn Subscriber>> = Arc::new(Mutex::new(DummySubscriber::new()));
46+
let data = s.lock().unwrap();
47+
assert!(data.get() == 0);
48+
}
5049

51-
#[kani::proof]
52-
#[kani::unwind(1)]
53-
fn original() {
54-
let s: Arc<Mutex<dyn Subscriber>> = Arc::new(Mutex::new(DummySubscriber::new()));
55-
let mut data = s.lock().unwrap();
56-
data.increment();
57-
assert!(data.get() == 1);
50+
#[kani::proof]
51+
#[kani::unwind(1)]
52+
fn original() {
53+
let s: Arc<Mutex<dyn Subscriber>> = Arc::new(Mutex::new(DummySubscriber::new()));
54+
let mut data = s.lock().unwrap();
55+
data.increment();
56+
assert!(data.get() == 1);
57+
}
5858
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
// The original harness takes too long so we introduced a simplified version to run in CI.
4+
// kani-flags: --harness simplified
5+
6+
//! This is a regression test for size_and_align_of_dst computing the
7+
//! size and alignment of a dynamically-sized type like
8+
//! Arc<Mutex<dyn Subscriber>>.
9+
//! We added a simplified version of the original harness from:
10+
//! <https://github.com/model-checking/kani/issues/426>
11+
//! This currently fails on MacOS instances due to unsupported foreign function:
12+
//! `pthread_mutexattr_init`.
13+
14+
#[cfg(target_os = "macos")]
15+
mod macos {
16+
use std::sync::Arc;
17+
use std::sync::Mutex;
18+
19+
pub trait Subscriber {
20+
fn process(&self);
21+
fn increment(&mut self);
22+
fn get(&self) -> u32;
23+
}
24+
25+
struct DummySubscriber {
26+
val: u32,
27+
}
28+
29+
impl DummySubscriber {
30+
fn new() -> Self {
31+
DummySubscriber { val: 0 }
32+
}
33+
}
34+
35+
impl Subscriber for DummySubscriber {
36+
fn process(&self) {}
37+
fn increment(&mut self) {
38+
self.val = self.val + 1;
39+
}
40+
fn get(&self) -> u32 {
41+
self.val
42+
}
43+
}
44+
45+
#[kani::proof]
46+
#[kani::unwind(2)]
47+
fn simplified() {
48+
let s: Arc<Mutex<dyn Subscriber>> = Arc::new(Mutex::new(DummySubscriber::new()));
49+
let data = s.lock().unwrap();
50+
assert!(data.get() == 0);
51+
}
52+
53+
#[kani::proof]
54+
#[kani::unwind(1)]
55+
fn original() {
56+
let s: Arc<Mutex<dyn Subscriber>> = Arc::new(Mutex::new(DummySubscriber::new()));
57+
let mut data = s.lock().unwrap();
58+
data.increment();
59+
assert!(data.get() == 1);
60+
}
61+
}
62+
63+
#[cfg(not(target_os = "macos"))]
64+
mod not_macos {
65+
/// Since this is a fixme test, it must also fail in other platforms.
66+
/// Remove this once we fix the issue above.
67+
#[kani::proof]
68+
fn fail() {
69+
assert!(false);
70+
}
71+
}

0 commit comments

Comments
 (0)