-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
411 simple integration test using old simple rust programs (#413)
This PR adds a set of simple rust programs (from prior art) for a simple parser test: * salvages [old test programs from `run-rs` in the `textual-mir` branch](https://github.com/runtimeverification/mir-semantics/tree/textual-mir/kmir/src/tests/integration/test-data/run-rs) * [sets up `smir_pretty`](https://github.com/runtimeverification/smir_pretty) as a submodule for integration tests * adds `make` targets to manage the submodule build (including a bootstrap of `rustc`, which [should be set up as a recursive submodule](runtimeverification/stable-mir-json#8) in the future) * adds a `make` target for a simple integration test: convert each `run-rs` program to Stable-MIR and parse the result. Remarks: * The tests are currently only proving that the parser succeeds. We can add better checks later when the format is stable enough to not cause noise in golden tests. * In order to run `smir_pretty`, information about the rust target architecture is needed. To circumvent this, the related script (within `smir_pretty` repo) is patched (but only the copy in the docker file system). This is a workaround and could be addressed properly by - crafting a github action to set up K and removing the dockerised K, - or preparing `smir_pretty` to run within `nix` and using a nix shell. - or (not recommended) placing the custom `rust` build and `smir_pretty` within the docker image or container. --------- Co-authored-by: devops <[email protected]>
- Loading branch information
Showing
44 changed files
with
473 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "deps/smir_pretty"] | ||
path = deps/smir_pretty | ||
url = https://github.com/runtimeverification/smir_pretty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule smir_pretty
added at
dcc656
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" | |
|
||
[tool.poetry] | ||
name = "kmir" | ||
version = "0.3.41" | ||
version = "0.3.42" | ||
description = "" | ||
authors = [ | ||
"Runtime Verification, Inc. <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from typing import Final | ||
|
||
VERSION: Final = '0.3.41' | ||
VERSION: Final = '0.3.42' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn main() { | ||
let a = [1, 2, 3, 4]; | ||
|
||
assert!(a == [1, 2, 3, 4]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fn main() { | ||
let a = 42; | ||
let b = 3 + 39; | ||
|
||
assert_eq!(b, a); | ||
} |
5 changes: 5 additions & 0 deletions
5
kmir/src/tests/integration/data/run-rs/closures/closure-args.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn main() { | ||
let sum = |x, y| -> i32 { x + y }; | ||
|
||
assert!(sum(20, 22) == 42); | ||
} |
5 changes: 5 additions & 0 deletions
5
kmir/src/tests/integration/data/run-rs/closures/closure-no-args.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn main() { | ||
let sum = || -> u32 { 42 }; | ||
|
||
assert!(sum() == 42); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![allow(unused)] | ||
#![allow(dead_code)] | ||
enum Letter { | ||
A, | ||
B, | ||
} | ||
|
||
fn main() { | ||
let a = Letter::A; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fn main() { | ||
let a:f32 = 3.5; | ||
let b:f32 = 1.2; | ||
|
||
assert!(a + b == 4.7); | ||
|
||
let c:f64 = 3.5; | ||
let d:f64 = 1.2; | ||
|
||
assert!(c + d == 4.7); | ||
} |
23 changes: 23 additions & 0 deletions
23
kmir/src/tests/integration/data/run-rs/functions/sum-to-n.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
fn sum_to_n(n:usize) -> usize { | ||
let mut sum = 0; | ||
let mut counter = n; | ||
|
||
while counter > 0 { | ||
sum += counter; | ||
counter = counter - 1; | ||
} | ||
return sum; | ||
} | ||
|
||
fn test_sum_to_n() -> () { | ||
let n = 10; | ||
let golden = 55; | ||
let sucess = sum_to_n(n) == golden; | ||
assert!(sucess); | ||
} | ||
|
||
|
||
fn main() { | ||
test_sum_to_n(); | ||
return (); | ||
} |
14 changes: 14 additions & 0 deletions
14
kmir/src/tests/integration/data/run-rs/generics/generic.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
fn index_slice<T>(slice:&[T], index: usize) -> &T { | ||
&(slice[index]) | ||
} | ||
|
||
fn main() { | ||
let numbers = [1, 2, 3, 4, 5]; | ||
let letters = ['a', 'b', 'c', 'd', 'e']; | ||
|
||
let middle_number:&i32 = index_slice(&numbers[..], 2); | ||
let middle_letter:&char = index_slice(&letters[..], 2); | ||
|
||
assert!(*middle_number == 3); | ||
assert!(*middle_letter == 'c'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
fn test_binop(x:i32, y:i32) -> () { | ||
// Arithmetic | ||
// Addition | ||
assert!(x + y == 52); | ||
assert!(52 == x + y); | ||
assert!(x + y == y + x); | ||
|
||
// Subtraction | ||
assert!(x - y == 32); | ||
assert!(y - x == -32); | ||
assert!(y - x != x - y); | ||
|
||
// Multiplication | ||
assert!(x * y == 420); | ||
assert!(x * -y == -420); | ||
assert!(-x * y == -420); | ||
assert!(-x * -y == 420); | ||
|
||
// Division | ||
// assert!(420 / 10 == 42); // FAILING SEE div.rs and div.mir | ||
|
||
// Modulo | ||
// assert!(x % 10 == 2); // FAILING SEE modulo.rs and modulo.mir | ||
|
||
// Bitwise | ||
// Xor | ||
assert!(1 ^ 2 == 3); | ||
assert!(1 ^ 3 == 2); | ||
|
||
// Or | ||
assert!(1 | 2 == 3); | ||
assert!(1 | 3 == 3); | ||
|
||
// And | ||
assert!(1 & 2 == 0); | ||
assert!(1 & 3 == 1); | ||
|
||
// // Shl | ||
assert!(2 << 1 == 4); | ||
// assert!(-128_i8 << 1 == 0); FAILS SEE shl_min.rs and shl_min.mir | ||
// assert!(-32768_i16 << 1 == 0); FAILS SEE shl_min.rs and shl_min.mir | ||
// assert!(-2147483648_i32 << 1 == 0); FAILS SEE shl_min.rs and shl_min.mir | ||
// assert!(-9223372036854775808_i64 << 1 == 0); FAILS SEE shl_min.rs and shl_min.mir | ||
// assert!(-17014118346046923173168730371588410572_i128 << 1 == 0); FAILS SEE shl_min.rs and shl_min.mir | ||
|
||
|
||
// // Shr | ||
assert!(2 >> 1 == 1); | ||
assert!(3 >> 1 == 1); | ||
assert!(1 >> 1 == 0); | ||
|
||
// Comparisions | ||
// Less Then | ||
assert!(x < x + y); | ||
|
||
// Less Then or Equal | ||
assert!(x <= x + y); | ||
assert!(x <= x + y - y); | ||
|
||
// Greater Then | ||
assert!(x + y > x); | ||
|
||
// Greater Then or Equal | ||
assert!(x + y >= x); | ||
assert!(x + y - y >= x); | ||
} | ||
|
||
|
||
fn main() { | ||
let x = 42; | ||
let y = 10; | ||
test_binop(x, y); | ||
return (); | ||
} |
12 changes: 12 additions & 0 deletions
12
kmir/src/tests/integration/data/run-rs/integers/const-arithm-simple.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
fn test(x: usize, y:usize) -> bool { | ||
return x > y; | ||
} | ||
|
||
|
||
fn main() { | ||
let x:usize = 42; | ||
let y:usize = 0; | ||
let z:bool = test(x, y); | ||
assert!(z); | ||
return (); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
assert!(420 / 10 ==42); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
assert!(42 % 10 == 2); | ||
} |
5 changes: 5 additions & 0 deletions
5
kmir/src/tests/integration/data/run-rs/integers/primitive-type-bounds.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn main () { | ||
let a:u32 = 4294967295; | ||
let b:u32 = 4294967294 + 1; | ||
assert!(a == b) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fn main() { | ||
assert!(-128_i8 << 1 == 0); | ||
assert!(-32768_i16 << 1 == 0); | ||
assert!(-2147483648_i32 << 1 == 0); | ||
assert!(-9223372036854775808_i64 << 1 == 0); | ||
assert!(-170141183460469231731687303715884105728_i128 << 1 == 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fn main() { | ||
let a = Box::new(5); | ||
let b = Box::new(5); | ||
|
||
assert!(a == b); | ||
assert!(*a == *b); | ||
assert!(*a == 5); | ||
// assert!(a == 5); // Not possible to equate Box::(Type) with Type | ||
} |
6 changes: 6 additions & 0 deletions
6
kmir/src/tests/integration/data/run-rs/option/option-construction.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![allow(unused)] | ||
fn main() { | ||
let a:Option<u32> = Some(42); | ||
let b:Option<u32> = None; | ||
let c:u32 = a.unwrap(); | ||
} |
Oops, something went wrong.