-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.lean
More file actions
75 lines (67 loc) · 2.29 KB
/
Main.lean
File metadata and controls
75 lines (67 loc) · 2.29 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
import Cli
import ArchSem.LitmusTest.Parse
import ArchSem.LitmusTest.Run
import ArchSem.TerminatingModel
import ArchSemTinyArm.Promising
open ArchSem.LitmusTest
open ArchSem.TerminatingModel (ComputationalTerminatingModel)
def modelFromStr (fuel : Nat) : String → Option ComputationalTerminatingModel
| "tinyarm-promisefirst" =>
ArchSemTinyArm.Promising.createPromiseFirstModel
ArchSemTinyArm.sailTinyArmIsem fuel |> some
| "tinyarm-promisenaive" =>
ArchSemTinyArm.Promising.createNaiveModel
ArchSemTinyArm.sailTinyArmIsem fuel |> some
| _ => none
def runTests (p : Cli.Parsed) : IO UInt32 := do
let testFnames : List System.FilePath := p.variableArgsAs! String |>.toList
let fuel : Nat ← match p.flag? "fuel" |>.bind (Cli.Parsed.Flag.as? · Nat) with
| .some fuel => pure fuel
| .none =>
IO.eprintln "Please specify fuel as a natural number."
return 1
let modelStr : String ← match p.flag? "model" |>.bind (Cli.Parsed.Flag.as? · String) with
| .some str => pure str
| .none =>
IO.eprintln "Model unspecified."
return 1
let model ← match modelFromStr fuel modelStr with
| .some m => pure m
| .none => do
IO.eprintln s!"Model does not exist: '{modelStr}'"
return 1
if testFnames.length == 0 then
IO.eprintln s!"No tests specified."
return 1
let errors : List String ← testFnames.filterMapM (fun fname => do
(← IO.getStdout).flush
(← IO.getStderr).flush
let test ← Parse.readTestFile fname
let result : Except String LitmusTestResult := Run.runLitmusTest model test
match result with
| .ok .allowed =>
IO.print s!"{test.name}\tOk\n"
return Option.none
| .ok (.forbidden _) =>
IO.print s!"{test.name}\tNo\n"
return Option.none
| .error msg =>
IO.eprintln s!"[{test.name}] Error: {msg}"
return Option.some msg
)
if errors == [] then
pure 0
else
IO.eprintln "At least one test failed."
pure 1
def litmusTestCmd : Cli.Cmd := `[Cli|
archsem VIA runTests;
"Run litmus tests from `.archsem.toml` format."
FLAGS:
model : String; "Name of model to use."
fuel : Nat; ""
ARGS:
...tests : String; "Tests to run of the `.archsem.toml` format."
]
def main (args : List String) : IO UInt32 :=
litmusTestCmd.validate args