-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_verify_ownership.rs
More file actions
129 lines (115 loc) · 4.55 KB
/
Copy pathcli_verify_ownership.rs
File metadata and controls
129 lines (115 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// SPDX-License-Identifier: PMPL-1.0-or-later
//
// End-to-end test for `ephapax compile --verify-ownership` (C7).
//
// Spawns the built `ephapax` binary, asks it to compile a small
// program, and asserts the verifier runs and reports clean output.
// The negative path (verifier catching codegen bugs) is unit-tested
// in `typed-wasm-verify`; this test exists to prove the CLI plumbing
// works — flag parsing → post-compile verification call → exit code
// → user-facing output.
//
// The two positive-assertion tests are gated by the
// `typed-wasm-verify` feature: with the feature OFF, the CLI prints a
// warning and skips verification, so the "verification: clean" line
// the tests look for is absent (by design). The third test —
// `compile_without_verify_flag_does_not_run_verifier` — works
// regardless because it asserts an *absence* of verifier output.
use std::process::Command;
fn ephapax_bin() -> String {
env!("CARGO_BIN_EXE_ephapax").to_string()
}
#[cfg(feature = "typed-wasm-verify")]
#[test]
fn verify_ownership_clean_module() {
let src = tempfile::NamedTempFile::with_suffix(".eph").expect("tempfile");
std::fs::write(src.path(), "fn add(a: I32, b: I32): I32 = a + b\n")
.expect("write source");
let out = tempfile::NamedTempFile::new().expect("output tempfile");
let result = Command::new(ephapax_bin())
.arg("compile")
.arg(src.path())
.arg("-o")
.arg(out.path())
.arg("--verify-ownership")
.arg("--verbose")
.output()
.expect("ephapax must run");
assert!(
result.status.success(),
"expected exit 0, got status: {:?}\nstdout: {}\nstderr: {}",
result.status,
String::from_utf8_lossy(&result.stdout),
String::from_utf8_lossy(&result.stderr)
);
let stdout = String::from_utf8_lossy(&result.stdout);
assert!(
stdout.contains("typed-wasm L7+L10 verification: clean"),
"expected verifier-clean line in stdout:\n{}",
stdout
);
}
#[cfg(feature = "typed-wasm-verify")]
#[test]
fn verify_ownership_linear_program() {
// A program that takes a linear String param and consumes it
// exactly once should verify clean. This exercises the
// ownership-section-emission path from C6 plus the verifier
// wiring from C7.
let src = tempfile::NamedTempFile::with_suffix(".eph").expect("tempfile");
// `s` is Linear (String); returning it consumes it exactly once,
// satisfying the source-level linear typechecker. The emitted wasm
// therefore has param_kinds = [Linear] in the ownership section
// and a body that uses local 0 exactly once.
std::fs::write(src.path(), "fn echo(s: String): String = s\n")
.expect("write source");
let out = tempfile::NamedTempFile::new().expect("output tempfile");
let result = Command::new(ephapax_bin())
.arg("compile")
.arg(src.path())
.arg("-o")
.arg(out.path())
.arg("--verify-ownership")
.arg("--verbose")
.output()
.expect("ephapax must run");
assert!(
result.status.success(),
"expected exit 0, got status: {:?}\nstdout: {}\nstderr: {}",
result.status,
String::from_utf8_lossy(&result.stdout),
String::from_utf8_lossy(&result.stderr)
);
let stdout = String::from_utf8_lossy(&result.stdout);
assert!(
stdout.contains("typed-wasm L7+L10 verification: clean"),
"expected verifier-clean line in stdout for linear program:\n{}",
stdout
);
}
#[test]
fn compile_without_verify_flag_does_not_run_verifier() {
// Without --verify-ownership, the verifier line should not appear
// in verbose output (and the build should not fail even if the
// emitted module would hypothetically have issues — the verifier
// isn't invoked).
let src = tempfile::NamedTempFile::with_suffix(".eph").expect("tempfile");
std::fs::write(src.path(), "fn add(a: I32, b: I32): I32 = a + b\n")
.expect("write source");
let out = tempfile::NamedTempFile::new().expect("output tempfile");
let result = Command::new(ephapax_bin())
.arg("compile")
.arg(src.path())
.arg("-o")
.arg(out.path())
.arg("--verbose")
.output()
.expect("ephapax must run");
assert!(result.status.success(), "expected exit 0");
let stdout = String::from_utf8_lossy(&result.stdout);
assert!(
!stdout.contains("typed-wasm L7+L10 verification"),
"verifier should not run without --verify-ownership flag; stdout: {}",
stdout
);
}