test/integration/integration.rad 5.5 KiB raw
1
//! Integration test driver. It runs the checks that need other programs: the
2
//! compiler, the test tools and the emulator. Make starts it as
3
//!
4
//!     integration <command> [-compiler <path>] [-jobs <n>] [arguments...]
5
//!
6
//! and its exit status is zero when every check passed. Each command works in
7
//! `bin/test/<command>`, which it empties first and leaves in place afterwards.
8
//!
9
//! Commands:
10
//!
11
//!     host                      Check std::process against the emulator.
12
//!     compile <source> <out>    Compile a compiler test fixture.
13
//!     bin [tests...]            Check IL snapshots and run test binaries.
14
//!     seed                      Check the format of the checked-in seed.
15
//!     sync                      Run the synchronization fixture on 1, 2 and 8 harts.
16
//!     trap                      Run the trap fixtures.
17
//!     shared                    Run the shared package fixtures.
18
//!     slots                     Check that reservation misuse is rejected.
19
//!     dispatch-build <fixture> <image>
20
//!                               Build a dispatch fixture image.
21
//!     cycles-build <image>      Build the cycles fixture image.
22
//!     boot                      Boot the kernel and check traps.
23
//!     bootstrap                 Check root construction from a boot package.
24
//!     loader                    Check the runtime loader and hostile packages.
25
//!     runtime                   Check scheduled loading and cancellation.
26
//!     scheduling [harts...]     Check root handoff and user-space yields.
27
//!     fmt <sources...>          Check that the formatter round-trips sources.
28
//!     format <sources...>       Format sources in place.
29
//!     verify [checker]          Check the IL verifier on the fixtures.
30
31
mod harness;
32
mod fixtures;
33
mod format;
34
mod host;
35
mod kernel;
36
mod machine;
37
mod linking;
38
mod boot;
39
mod verify;
40
mod packages;
41
42
use std::io;
43
use std::mem;
44
use std::sys;
45
46
/// Compiler used when `-compiler` is not given.
47
constant DEFAULT_COMPILER: *[u8] = "bin/radiance.rv64.dev";
48
/// Exit status of a command line that cannot be run.
49
constant USAGE_STATUS: i32 = 2;
50
/// Usage message.
51
constant USAGE: *[u8] =
52
    "usage: integration <command> [-compiler <path>] [-jobs <n>] [arguments...]\nSee test/integration/integration.rad for the commands.\n";
53
54
/// A command, how many arguments it takes, and its handler.
55
record Entry: Copy {
56
    /// Name given on the command line.
57
    name: *[u8],
58
    /// Fewest arguments.
59
    min: u32,
60
    /// Most arguments.
61
    max: u32,
62
    /// The handler.
63
    run: fn(&mut harness::Harness, *[*[u8]]) throws (sys::Error),
64
}
65
66
/// Print the usage message and return the exit status of a bad command line.
67
fn usage() -> i32 {
68
    io::printError(USAGE);
69
    return USAGE_STATUS;
70
}
71
72
/// Run the command named by the first argument. The options `-compiler` and
73
/// `-jobs` follow it, and the remaining arguments belong to the command.
74
@default fn main(env: *sys::Env, storage: *mut harness::Storage) -> i32 {
75
    let args = env.args;
76
    let mut compiler = DEFAULT_COMPILER;
77
    let mut jobs: u32 = 1;
78
    let mut first: u32 = 1;
79
    while first + 1 < args.len {
80
        if mem::eq(args[first], "-compiler") {
81
            set compiler = args[first + 1];
82
        } else if mem::eq(args[first], "-jobs") {
83
            set jobs = try harness::number(args[first + 1]) catch {
84
                return usage();
85
            };
86
        } else {
87
            break;
88
        }
89
        set first += 2;
90
    }
91
    if args.len == 0 or jobs < 1 or jobs > harness::MAX_JOBS {
92
        return usage();
93
    }
94
    // The commands.
95
    let commands: [Entry; 19] = [
96
        Entry { name: "host",           min: 0, max: 0, run: host::check },
97
        Entry { name: "compile",        min: 2, max: 2, run: fixtures::compile },
98
        Entry { name: "bin",            min: 0, max: mem::MAX_SIZE, run: fixtures::bin },
99
        Entry { name: "seed",           min: 0, max: 0, run: machine::seed },
100
        Entry { name: "sync",           min: 0, max: 0, run: machine::sync },
101
        Entry { name: "trap",           min: 0, max: 0, run: machine::trap },
102
        Entry { name: "shared",         min: 0, max: 0, run: machine::shared },
103
        Entry { name: "slots",          min: 0, max: 0, run: machine::slots },
104
        Entry { name: "dispatch-build", min: 2, max: 2, run: machine::dispatchBuild },
105
        Entry { name: "cycles-build",   min: 1, max: 1, run: machine::cyclesBuild },
106
        Entry { name: "boot",           min: 0, max: 0, run: boot::boot },
107
        Entry { name: "bootstrap",      min: 0, max: 0, run: boot::bootstrap },
108
        Entry { name: "loader",         min: 0, max: 0, run: boot::loader },
109
        Entry { name: "runtime",        min: 0, max: 0, run: boot::runtime },
110
        Entry { name: "scheduling",     min: 0, max: mem::MAX_SIZE, run: boot::scheduling },
111
        Entry { name: "fmt",            min: 0, max: mem::MAX_SIZE, run: format::check },
112
        Entry { name: "format",         min: 1, max: mem::MAX_SIZE, run: format::rewrite },
113
        Entry { name: "packages",       min: 0, max: 0, run: packages::check },
114
        Entry { name: "verify",         min: 0, max: 1, run: verify::check },
115
    ];
116
    for entry in &commands[..] {
117
        let rest = &args[first ..];
118
        if mem::eq(entry.name, args[0]) and rest.len >= entry.min and rest.len <= entry.max {
119
            let mut h = harness::new(storage, compiler, jobs);
120
            try entry.run(&mut h, rest) catch err {
121
                io::printError(h.join(&[args[0], ": ", harness::errorName(err), "\n"]));
122
                return 1;
123
            };
124
            return h.status();
125
        }
126
    }
127
    return usage();
128
}