|
1 | 1 | // Copyright Kani Contributors |
2 | 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 | 3 |
|
6 | 4 | //! This is a regression test for size_and_align_of_dst computing the |
7 | 5 | //! size and alignment of a dynamically-sized type like |
8 | 6 | //! Arc<Mutex<dyn Subscriber>>. |
9 | | -//! We added a simplified version of the original harness from: |
10 | 7 | //! <https://github.com/model-checking/kani/issues/426> |
11 | | -//! This currently fails due to |
12 | | -//! <https://github.com/model-checking/kani/issues/1781> |
13 | 8 |
|
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 | + } |
26 | 21 |
|
27 | | -impl DummySubscriber { |
28 | | - fn new() -> Self { |
29 | | - DummySubscriber { val: 0 } |
| 22 | + struct DummySubscriber { |
| 23 | + val: u32, |
30 | 24 | } |
31 | | -} |
32 | 25 |
|
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 | + } |
37 | 30 | } |
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 | + } |
40 | 40 | } |
41 | | -} |
42 | 41 |
|
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 | + } |
50 | 49 |
|
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 | + } |
58 | 58 | } |
0 commit comments