Repository navigation
Expand file tree
/
Copy pathMain.lean
More file actions
93 lines (84 loc) · 3.1 KB
/
Copy pathMain.lean
File metadata and controls
93 lines (84 loc) · 3.1 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
-- SPDX-FileCopyrightText: 2026 Christopher Lang
--
-- SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause
import Cli
import ArchSem.LitmusTest.Parse
import ArchSem.LitmusTest.Run
import ArchSem.LitmusTest.Basic
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 configFname : System.FilePath ← match p.flag? "config" |>.bind (Cli.Parsed.Flag.as? · String) with
| .some str => pure str
| .none =>
IO.eprintln "Config unspecified."
return 1
let config : LitmusTestConfig ← Config.readConfigFile configFname
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 => fuel
| .none => config.defaultFuel
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 testRepr ← Parse.readTestFile fname
let finalStates ← match Run.runLitmusTest model testRepr with
| .ok states => pure states
| .error msg =>
let msg := s!"[{testRepr.name}] Error: Failed to run test {msg}"
IO.eprintln msg
return .some msg
let results ← match prepareTestResults config testRepr finalStates with
| .ok results => pure results
| .error msg =>
let msg := s!"[{testRepr.name}] Error: Failed to prepare test results {msg}"
IO.eprintln msg
return .some msg
let mcompare : String ← match MCompare.testOutput testRepr results with
| .ok mcompare => pure mcompare
| .error msg =>
let msg := s!"[{testRepr.name}] Error: Failed to prepare mcompare {msg}"
IO.eprintln msg
return .some msg
IO.print mcompare
return Option.none
)
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."
config : String; "Config file to use."
ARGS:
...tests : String; "Tests to run of the `.archsem.toml` format."
]
def main (args : List String) : IO UInt32 :=
litmusTestCmd.validate args