File tree Expand file tree Collapse file tree 3 files changed +81
-4
lines changed Expand file tree Collapse file tree 3 files changed +81
-4
lines changed Original file line number Diff line number Diff line change 1
1
// Copyright Kani Contributors
2
2
// SPDX-License-Identifier: Apache-2.0 OR MIT
3
- // This test takes too long with all the std symbols. Use --legacy-linker for now .
4
- // kani-flags: --legacy-linker
3
+ // The original harness takes too long so we introduced a simplified version to run in CI .
4
+ // kani-flags: --harness simplified
5
5
6
6
//! This is a regression test for size_and_align_of_dst computing the
7
7
//! size and alignment of a dynamically-sized type like
8
8
//! Arc<Mutex<dyn Subscriber>>.
9
- //! https://github.com/model-checking/kani/issues/426
9
+ //! We added a simplified version of the original harness from:
10
+ //! <https://github.com/model-checking/kani/issues/426>
10
11
11
12
use std:: sync:: Arc ;
12
13
use std:: sync:: Mutex ;
@@ -37,9 +38,17 @@ impl Subscriber for DummySubscriber {
37
38
}
38
39
}
39
40
41
+ #[ kani:: proof]
42
+ #[ kani:: unwind( 2 ) ]
43
+ fn simplified ( ) {
44
+ let s: Arc < Mutex < dyn Subscriber > > = Arc :: new ( Mutex :: new ( DummySubscriber :: new ( ) ) ) ;
45
+ let data = s. lock ( ) . unwrap ( ) ;
46
+ assert ! ( data. get( ) == 0 ) ;
47
+ }
48
+
40
49
#[ kani:: proof]
41
50
#[ kani:: unwind( 1 ) ]
42
- fn main ( ) {
51
+ fn original ( ) {
43
52
let s: Arc < Mutex < dyn Subscriber > > = Arc :: new ( Mutex :: new ( DummySubscriber :: new ( ) ) ) ;
44
53
let mut data = s. lock ( ) . unwrap ( ) ;
45
54
data. increment ( ) ;
Original file line number Diff line number Diff line change
1
+ // Copyright Kani Contributors
2
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
3
+
4
+ //! This test was created to cover panic hook handling by Kani.
5
+ //! Tracking issue: <https://github.com/model-checking/kani/issues/208>
6
+ use std:: panic;
7
+
8
+ #[ kani:: proof]
9
+ #[ kani:: unwind( 2 ) ]
10
+ fn custom_hook ( ) {
11
+ panic:: set_hook ( Box :: new ( |_| {
12
+ assert ! ( false ) ;
13
+ } ) ) ;
14
+
15
+ let _ = panic:: take_hook ( ) ;
16
+
17
+ panic ! ( "Normal panic" ) ;
18
+ }
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
2
+ //
3
+ // Modifications Copyright Kani Contributors
4
+ // See GitHub history for details.
5
+
6
+ //! This test is to check how Kani handle some std functions. The original issue was:
7
+ //! <https://github.com/model-checking/kani/issues/564>
8
+ //! This code was extracted from Rust by Example book.
9
+ trait UsernameWidget {
10
+ // Get the selected username out of this widget
11
+ fn get ( & self ) -> String ;
12
+ }
13
+
14
+ trait AgeWidget {
15
+ // Get the selected age out of this widget
16
+ fn get ( & self ) -> u8 ;
17
+ }
18
+
19
+ // A form with both a UsernameWidget and an AgeWidget
20
+ struct Form {
21
+ username : String ,
22
+ age : u8 ,
23
+ }
24
+
25
+ impl UsernameWidget for Form {
26
+ fn get ( & self ) -> String {
27
+ self . username . clone ( )
28
+ }
29
+ }
30
+
31
+ impl AgeWidget for Form {
32
+ fn get ( & self ) -> u8 {
33
+ self . age
34
+ }
35
+ }
36
+
37
+ #[ kani:: proof]
38
+ pub fn main ( ) {
39
+ let form = Form { username : "rustacean" . to_owned ( ) , age : 28 } ;
40
+
41
+ // If you uncomment this line, you'll get an error saying
42
+ // "multiple `get` found". Because, after all, there are multiple methods
43
+ // named `get`.
44
+ // println!("{}", form.get());
45
+
46
+ let username = <Form as UsernameWidget >:: get ( & form) ;
47
+ assert_eq ! ( "rustacean" . to_owned( ) , username) ;
48
+ let age = <Form as AgeWidget >:: get ( & form) ;
49
+ assert_eq ! ( 28 , age) ;
50
+ }
You can’t perform that action at this time.
0 commit comments