test/integration/harness.rad 23.0 KiB raw
1
//! Shared state of the integration driver: the string arena, the work
2
//! directory, file helpers, checks, and child runs. A failed check prints what
3
//! was expected and what happened on standard error, prints the log it
4
//! concerns, and counts a failure.
5
6
use std::fmt;
7
use std::fs;
8
use std::io;
9
use std::mem;
10
use std::process;
11
use std::sys;
12
use std::lang::alloc;
13
use std::lang::ast;
14
use std::lang::manifest;
15
use std::lang::parser;
16
use std::lang::strings;
17
use std::mem::heap;
18
19
/// Capacity of the string arena, in bytes (128 MB). It holds every path,
20
/// argument list and file the command reads, and is never reset.
21
export constant ARENA_CAPACITY: u32 = 134217728;
22
/// Most children the host runs at once, which bounds `-jobs`.
23
export constant MAX_JOBS: u32 = 64;
24
/// Parent of the work directories of the commands.
25
constant WORK_ROOT: *[u8] = "bin/test";
26
27
/// Instruction budget of a compiler, image tool or formatter run. The slowest,
28
/// the image tool over the kernel, takes 4.5 billion instructions.
29
export constant COMPILE_STEPS: u64 = 50000000000;
30
/// Instruction budget of a hosted program or tool run. The slowest, the IL
31
/// verifier over all fixtures, takes 379 million instructions.
32
export constant RUN_STEPS: u64 = 4000000000;
33
/// Tick budget of a machine run. The slowest, the cycles fixture on eight
34
/// harts, takes 6.5 billion ticks.
35
export constant MACHINE_STEPS: u64 = 70000000000;
36
37
/// Output destination that shares the parent's streams.
38
export constant INHERIT: process::Output = process::Output::Inherit;
39
/// Hosted target that takes the host default sizes.
40
export constant HOSTED: process::Target =
41
    process::Target::Hosted(process::Memory { memory: 0, data: 0, stack: 0 });
42
/// Outcome of a child that exited with status zero.
43
export constant OK: process::Outcome = process::Outcome::Exited(0);
44
45
/// Memory of the driver. The compiler-generated entry supplies one zero-filled
46
/// region of this type.
47
export record Storage {
48
    /// Backing storage of the string arena.
49
    arena: [u8; ARENA_CAPACITY],
50
}
51
52
/// State of one command run.
53
export record Harness {
54
    /// Arena of all strings and lists the command builds.
55
    arena: *heap::Heap,
56
    /// Path of the compiler image that compile steps run.
57
    compiler: *[u8],
58
    /// Most children the worker pool runs at once.
59
    jobs: u32,
60
    /// Work directory of the command. Empty before [`Harness::begin`].
61
    work: *[u8],
62
    /// Checks that passed.
63
    passed: u32,
64
    /// Checks that failed.
65
    failed: u32,
66
    /// Compiler arguments collected by [`Harness::add`].
67
    args: *mut [*[u8]],
68
    /// Number of collected arguments that [`Harness::take`] returned.
69
    taken: u32,
70
}
71
72
/// What a check requires of a text file. Line checks look at the lines of the
73
/// file, split at line breaks.
74
export union Expect: Copy {
75
    /// Some line equals the text.
76
    Line(*[u8]),
77
    /// Exactly `count` lines equal the text.
78
    Lines {
79
        /// Text of the lines.
80
        text: *[u8],
81
        /// Required number of lines.
82
        count: u32,
83
    },
84
    /// Some line contains the text.
85
    Contains(*[u8]),
86
    /// Exactly `count` lines contain the text.
87
    Matching {
88
        /// Text the lines contain.
89
        text: *[u8],
90
        /// Required number of lines.
91
        count: u32,
92
    },
93
    /// Some line starts with the text.
94
    Prefix(*[u8]),
95
    /// The file has exactly these bytes.
96
    Exact(*[u8]),
97
    /// The file has the same bytes as the file at the path.
98
    Same(*[u8]),
99
    /// The file exists.
100
    Present,
101
    /// Nothing exists at the path.
102
    Absent,
103
}
104
105
/// Create the state of a command run over `storage`. `jobs` must be in
106
/// `1..=MAX_JOBS`.
107
export fn new(storage: *mut Storage, compiler: *[u8], jobs: u32) -> Harness {
108
    assert jobs >= 1 and jobs <= MAX_JOBS;
109
    return Harness {
110
        arena: heap::over(&mut storage.arena[..]),
111
        compiler,
112
        jobs,
113
        work: "",
114
        passed: 0,
115
        failed: 0,
116
        args: &mut [],
117
        taken: 0,
118
    };
119
}
120
121
/// Name of a host error, for messages.
122
export fn errorName(error: sys::Error) -> *[u8] {
123
    match error {
124
        case sys::Error::NotFound => return "not found",
125
        case sys::Error::Exists   => return "already exists",
126
        case sys::Error::Denied   => return "denied",
127
        case sys::Error::NotEmpty => return "directory not empty",
128
        case sys::Error::Invalid  => return "invalid",
129
        case sys::Error::TooLarge => return "too large",
130
        case sys::Error::Limit    => return "limit reached",
131
        case sys::Error::Io       => return "i/o error",
132
    }
133
}
134
135
/// Copy the parts, in order, into one string allocated from the arena. Panics
136
/// when the arena is exhausted, because the driver sizes it for every command.
137
export fn (h: &mut Harness) join(parts: &[*[u8]]) -> *[u8] {
138
    let joined = try alloc::concatBytes(h.arena, parts) catch {
139
        panic "join: string arena exhausted";
140
    };
141
    return &joined[..];
142
}
143
144
/// Format a number in decimal into a string allocated from the arena.
145
export fn (h: &mut Harness) num(value: u32) -> *[u8] {
146
    let mut digits: [u8; fmt::U32_STR_LEN] = [0; fmt::U32_STR_LEN];
147
    let mut text: *mut [u8] = &mut [];
148
    try! text.extend(fmt::formatU32(value, &mut digits[..]), h.arena);
149
    return &text[..];
150
}
151
152
/// Return the path in the work directory of the file whose name is the
153
/// concatenation of `parts`.
154
export fn (h: &mut Harness) path(parts: &[*[u8]]) -> *[u8] {
155
    return h.join(&[h.work, "/", h.join(parts)]);
156
}
157
158
/// Copy an argument list into the arena, as the host call takes it.
159
export fn (h: &mut Harness) copy(args: &[*[u8]]) -> *[*[u8]] {
160
    let mut list: *mut [*[u8]] = &mut [];
161
    for arg in args {
162
        try! list.append(arg, h.arena);
163
    }
164
    return &list[..];
165
}
166
167
/// Count a passed check. Returns true.
168
export fn (h: &mut Harness) pass() -> bool {
169
    set h.passed += 1;
170
    return true;
171
}
172
173
/// Count a failed check and report it on standard error. Returns false.
174
export fn (h: &mut Harness) fail(what: *[u8], detail: *[u8]) -> bool {
175
    io::printError(h.join(&["FAILED: ", what, ": ", detail, "\n"]));
176
    set h.failed += 1;
177
    return false;
178
}
179
180
/// Print `line` when no check failed since `mark`, a value of `h.failed`
181
/// taken at the start of a group of checks.
182
export fn (h: &mut Harness) done(mark: u32, line: *[u8]) {
183
    if h.failed == mark {
184
        io::printLn(line);
185
    }
186
}
187
188
/// Exit status of the run: zero when no check failed.
189
export fn (h: &Harness) status() -> i32 {
190
    return 0 if h.failed == 0 else 1;
191
}
192
193
/// Read the file at `path` into the arena and return its contents. Throws
194
/// `TooLarge` when the file is larger than `4194304`.
195
export fn (h: &mut Harness) load(path: *[u8]) -> *[u8] throws (sys::Error) {
196
    let info = try fs::stat(path) else {
197
        throw sys::Error::NotFound;
198
    };
199
    if info.size > 4194304 as u64 {
200
        throw sys::Error::TooLarge;
201
    }
202
    let mut buf: *mut [u8] = &mut [];
203
    try! buf.resize(info.size as u32, 0, h.arena);
204
    let n = try fs::readFile(path, &mut buf[..]);
205
    return &buf[.. n];
206
}
207
208
/// Return the contents of the file at `path`, or a note that it cannot be
209
/// read, for messages.
210
export fn (h: &mut Harness) text(path: *[u8]) -> *[u8] {
211
    let content = try h.load(path) catch err {
212
        return h.join(&["(cannot read ", path, ": ", errorName(err), ")\n"]);
213
    };
214
    return content;
215
}
216
217
/// Return the number of the first line, counting from one, at which the files
218
/// differ, or `nil` when they have the same bytes. A file that ends early
219
/// differs at the line after its last line break.
220
export fn (h: &mut Harness) compare(left: *[u8], right: *[u8]) -> ?u32 throws (sys::Error) {
221
    let a = try h.load(left);
222
    let b = try h.load(right);
223
    let mut line: u32 = 1;
224
    for i in 0 .. (a.len if a.len < b.len else b.len) {
225
        if a[i] <> b[i] {
226
            return line;
227
        }
228
        if a[i] == '\n' {
229
            set line += 1;
230
        }
231
    }
232
    if a.len <> b.len {
233
        return line;
234
    }
235
    return nil;
236
}
237
238
/// Read the lines of the manifest at `path`, skipping empty lines.
239
export fn (h: &mut Harness) manifest(path: *[u8]) -> *[*[u8]] throws (sys::Error) {
240
    let mut entries: *mut [*[u8]] = &mut [];
241
    let mut lines = mem::split(try h.load(path), '\n');
242
    while let line = lines.next() {
243
        if line.len > 0 {
244
            try! entries.append(line, h.arena);
245
        }
246
    }
247
    return &entries[..];
248
}
249
250
/// List the entries of the directory `dir` as paths below it, in host order.
251
export fn (h: &mut Harness) children(dir: *[u8]) -> *[*[u8]] throws (sys::Error) {
252
    let mut size: u32 = 4096;
253
    let mut found: *mut [*[u8]] = &mut [];
254
    while true {
255
        let mut buf: *mut [u8] = &mut [];
256
        try! buf.resize(size, 0, h.arena);
257
        let listing = try fs::listDir(dir, buf) catch err {
258
            if err == sys::Error::TooLarge and size < 524288 {
259
                set size *= 2;
260
                continue;
261
            }
262
            throw err;
263
        };
264
        let mut names = mem::split(listing, 0);
265
        while let name = names.next() {
266
            try! found.append(h.join(&[dir, "/", name]), h.arena);
267
        }
268
        break;
269
    }
270
    return &found[..];
271
}
272
273
/// Sort byte strings in ascending byte order. The sort is stable and takes
274
/// time proportional to the square of the count, which suits directory
275
/// listings of a few thousand names.
276
export fn sort(names: &mut [*[u8]]) {
277
    for i in 1 .. names.len {
278
        let item = names[i];
279
        let mut j = i;
280
        while j > 0 and mem::cmp(names[j - 1], item) > 0 {
281
            set names[j] = names[j - 1];
282
            set j -= 1;
283
        }
284
        set names[j] = item;
285
    }
286
}
287
288
/// List the entries of the directory `dir` whose names end with `suffix`, as
289
/// paths in ascending order.
290
export fn (h: &mut Harness) listFiles(dir: *[u8], suffix: *[u8]) -> *[*[u8]] throws (sys::Error) {
291
    let mut found: *mut [*[u8]] = &mut [];
292
    for path in try h.children(dir) {
293
        if mem::endsWith(path, suffix) {
294
            try! found.append(path, h.arena);
295
        }
296
    }
297
    sort(&mut found[..]);
298
    return &found[..];
299
}
300
301
/// Return the directory part of `path`, or `.` when it has none.
302
export fn directory(path: *[u8]) -> *[u8] {
303
    let slash = mem::rfind(path, "/") else return ".";
304
    return &path[.. slash];
305
}
306
307
/// Return the path without its last extension, or the path itself when it has
308
/// none.
309
export fn stripExt(path: *[u8]) -> *[u8] {
310
    let mut end = path.len;
311
    while end > 0 and path[end - 1] <> '.' {
312
        set end -= 1;
313
    }
314
    return &path[.. end - 1] if end > 0 else path;
315
}
316
317
/// Return the rest of the first line of `content` that starts with `prefix`,
318
/// without the spaces that follow it, or `nil` when no line does.
319
export fn marker(content: *[u8], prefix: *[u8]) -> ?*[u8] {
320
    let mut lines = mem::split(content, '\n');
321
    while let line = lines.next() {
322
        if mem::startsWith(line, prefix) {
323
            let rest = &line[prefix.len ..];
324
            let mut start: u32 = 0;
325
            while start < rest.len and rest[start] == ' ' {
326
                set start += 1;
327
            }
328
            return &rest[start ..];
329
        }
330
    }
331
    return nil;
332
}
333
334
/// Parse a decimal number that fits in a `u32`. Throws `Invalid` otherwise.
335
export fn number(text: *[u8]) -> u32 throws (sys::Error) {
336
    let literal = try fmt::parseInt(text) catch {
337
        throw sys::Error::Invalid;
338
    };
339
    if literal.magnitude > mem::U32_MAX as u64 {
340
        throw sys::Error::Invalid;
341
    }
342
    return literal.magnitude as u32;
343
}
344
345
/// Return true when something exists at `path`.
346
export fn exists(path: *[u8]) -> bool throws (sys::Error) {
347
    return try fs::stat(path) <> nil;
348
}
349
350
/// Write the concatenation of the files `inputs`, in order, to `output`.
351
export fn (h: &mut Harness) concat(output: *[u8], inputs: &[*[u8]]) throws (sys::Error) {
352
    let mut out = try fs::create(output);
353
    for input in inputs {
354
        out.write(
355
            try h.load(input) catch err {
356
                try out.close() catch {};
357
                throw err;
358
            }
359
        );
360
    }
361
    try out.close();
362
}
363
364
/// Create the directory `path` and any missing parents.
365
export fn makeDirs(path: *[u8]) throws (sys::Error) {
366
    for end in 1 .. path.len + 1 {
367
        if end == path.len or path[end] == '/' {
368
            try fs::makeDir(&path[.. end]) catch err {
369
                if err <> sys::Error::Exists {
370
                    throw err;
371
                }
372
            };
373
        }
374
    }
375
}
376
377
/// Remove the file or directory tree at `path`, if it exists.
378
fn removeTree(h: &mut Harness, path: *[u8]) throws (sys::Error) {
379
    let info = try fs::stat(path) else {
380
        return;
381
    };
382
    if info.kind == fs::Kind::Directory {
383
        for child in try h.children(path) {
384
            try removeTree(h, child);
385
        }
386
    }
387
    try fs::remove(path);
388
}
389
390
/// Start a command: remove the work directory `bin/test/<command>` with
391
/// everything in it and create it empty. It stays in place afterwards so a
392
/// failure can be inspected.
393
export fn (h: &mut Harness) begin(command: *[u8]) throws (sys::Error) {
394
    try makeDirs(WORK_ROOT);
395
    set h.work = h.join(&[WORK_ROOT, "/", command]);
396
    let work = h.work;
397
    try removeTree(h, work);
398
    try fs::makeDir(work);
399
}
400
401
/// Return true when the line meets a line expectation.
402
fn hit(want: Expect, line: *[u8]) -> bool {
403
    match want {
404
        case Expect::Line(text)            => return mem::eq(line, text),
405
        case Expect::Lines { text, .. }    => return mem::eq(line, text),
406
        case Expect::Prefix(text)          => return mem::stripPrefix(text, line) <> nil,
407
        case Expect::Contains(text)        => return mem::find(line, text) <> nil,
408
        case Expect::Matching { text, .. } => return mem::find(line, text) <> nil,
409
        else                               => return false,
410
    }
411
}
412
413
/// Return whether the file at `path` meets the expectation. Throws when the
414
/// file cannot be examined.
415
fn satisfied(h: &mut Harness, path: *[u8], want: Expect) -> bool throws (sys::Error) {
416
    let mut count: ?u32 = nil;
417
    match want {
418
        case Expect::Present                   => return try exists(path),
419
        case Expect::Absent                    => return not try exists(path),
420
        case Expect::Same(right)               => return try h.compare(path, right) == nil,
421
        case Expect::Exact(text)               => return mem::eq(try h.load(path), text),
422
        case Expect::Lines { count: n, .. }    => set count = n,
423
        case Expect::Matching { count: n, .. } => set count = n,
424
        else                                   => {}
425
    }
426
    let mut hits: u32 = 0;
427
    let mut lines = mem::split(try h.load(path), '\n');
428
    while let line = lines.next() {
429
        if hit(want, line) {
430
            set hits += 1;
431
        }
432
    }
433
    if let n = count {
434
        return hits == n;
435
    }
436
    return hits > 0;
437
}
438
439
/// Check the file at `path` against the expectation `want`. A failure is
440
/// labeled `what` and shows the file. Returns whether the check passed.
441
export fn (h: &mut Harness) expect(what: *[u8], path: *[u8], want: Expect) -> bool {
442
    let ok = try satisfied(h, path, want) catch err {
443
        return h.fail(what, h.join(&["cannot check ", path, ": ", errorName(err)]));
444
    };
445
    if ok {
446
        return h.pass();
447
    }
448
    io::printError(h.text(path));
449
    return h.fail(what, h.join(&["unmet expectation on ", path]));
450
}
451
452
/// Describe how a child ended, for messages.
453
export fn (h: &mut Harness) describe(outcome: process::Outcome) -> *[u8] {
454
    match outcome {
455
        case process::Outcome::Exited(status) => {
456
            let sign = "-" if status < 0 else "";
457
            return h.join(&[
458
                "exit status ", sign, h.num((status if status >= 0 else 0 - status) as u32)
459
            ]);
460
        }
461
        case process::Outcome::StepLimit => return "step limit reached",
462
        case process::Outcome::Fault     => return "fault",
463
    }
464
}
465
466
/// Check that a child ended with the `want` outcome. The file `report`, if any,
467
/// is shown on failure.
468
export fn (h: &mut Harness) outcome(
469
    what: *[u8],
470
    actual: process::Outcome,
471
    want: process::Outcome,
472
    report: ?*[u8]
473
) -> bool {
474
    if actual == want {
475
        return h.pass();
476
    }
477
    if let path = report {
478
        io::printError(h.text(path));
479
    }
480
    return h.fail(what, h.join(&["expected ", h.describe(want), ", got ", h.describe(actual)]));
481
}
482
483
/// Build a command that runs `image` with the arguments. Standard output and
484
/// standard error both go to `output`.
485
export fn (h: &mut Harness) cmd(
486
    image: *[u8],
487
    args: &[*[u8]],
488
    target: process::Target,
489
    steps: u64,
490
    output: process::Output
491
) -> process::Command {
492
    return process::Command {
493
        image, args: h.copy(args), stdout: output, stderr: output, target, maxSteps: steps
494
    };
495
}
496
497
/// Build a command that runs the machine image on `harts` harts with the
498
/// memory of the kernel fixtures. Its output goes to `output`.
499
export fn (h: &mut Harness) machine(
500
    image: *[u8], harts: u32, output: process::Output
501
) -> process::Command {
502
    let target = process::Target::Machine(process::Machine {
503
        harts, memory: 262144, irq: nil
504
    });
505
    return h.cmd(image, &[], target, MACHINE_STEPS, output);
506
}
507
508
/// Return the output destination that creates the file in the work directory
509
/// whose name is the concatenation of `parts`.
510
export fn (h: &mut Harness) out(parts: &[*[u8]]) -> process::Output {
511
    return process::Output::File(h.path(parts));
512
}
513
514
/// Run every command of the batch, with up to `h.jobs` children at once, and
515
/// return the outcome of each command in the order of the batch. A child that
516
/// cannot start counts a failure and ends as a fault.
517
export fn (h: &mut Harness) runAll(commands: *[process::Command]) -> *[process::Outcome] {
518
    let mut outcomes: *mut [process::Outcome] = &mut [];
519
    try! outcomes.resize(commands.len, process::Outcome::Fault, h.arena);
520
    let mut handles: [u32; MAX_JOBS] = [0; MAX_JOBS];
521
    let mut indices: [u32; MAX_JOBS] = [0; MAX_JOBS];
522
    let mut live: u32 = 0;
523
    let mut next: u32 = 0;
524
    while next < commands.len or live > 0 {
525
        while next < commands.len and live < h.jobs {
526
            let child = try process::spawn(&commands[next]) catch err {
527
                h.fail(commands[next].image, h.join(&["cannot start: ", errorName(err)]));
528
                set next += 1;
529
                continue;
530
            };
531
            set handles[live] = child.handle;
532
            set indices[live] = next;
533
            set live += 1;
534
            set next += 1;
535
        }
536
        if live == 0 {
537
            break;
538
        }
539
        let done = try! process::waitAny();
540
        let mut slot: u32 = 0;
541
        while slot < live and handles[slot] <> done.child.handle {
542
            set slot += 1;
543
        }
544
        assert slot < live;
545
        set outcomes[indices[slot]] = done.outcome;
546
        set live -= 1;
547
        set handles[slot] = handles[live];
548
        set indices[slot] = indices[live];
549
    }
550
    return &outcomes[..];
551
}
552
553
/// Run the command and check that it ends with the outcome `want` and that the
554
/// file it writes its output to meets the expectations, which require standard
555
/// output to go to a file. A child that cannot start counts a failure. Returns
556
/// true when no check failed.
557
export fn (h: &mut Harness) run(
558
    what: *[u8],
559
    command: process::Command,
560
    want: process::Outcome,
561
    expects: &[Expect]
562
) -> bool {
563
    let mark = h.failed;
564
    let mut report: ?*[u8] = nil;
565
    if let case process::Output::File(path) = command.stdout {
566
        set report = path;
567
    }
568
    assert expects.len == 0 or report <> nil;
569
    let actual = try process::run(&command) catch err {
570
        h.fail(command.image, h.join(&["cannot start: ", errorName(err)]));
571
        return false;
572
    };
573
    h.outcome(what, actual, want, report);
574
    if let path = report {
575
        for expectation in expects {
576
            h.expect(what, path, expectation);
577
        }
578
    }
579
    return h.failed == mark;
580
}
581
582
/// Run a hosted tool with the arguments and its output inherited, and check
583
/// that it exits with status zero.
584
export fn (h: &mut Harness) tool(what: *[u8], image: *[u8], args: &[*[u8]]) -> bool {
585
    let command = h.cmd(image, args, HOSTED, RUN_STEPS, INHERIT);
586
    return h.run(what, command, OK, &[]);
587
}
588
589
/// Run the machine image on `harts` harts with its output inherited, and check
590
/// that it exits with status zero.
591
export fn (h: &mut Harness) boot(what: *[u8], image: *[u8], harts: u32) -> bool {
592
    let command = h.machine(image, harts, INHERIT);
593
    return h.run(what, command, OK, &[]);
594
}
595
596
/// Add arguments for the next compiler run.
597
export fn (h: &mut Harness) add(parts: &[*[u8]]) {
598
    for part in parts {
599
        try! h.args.append(part, h.arena);
600
    }
601
}
602
603
/// Add the module at `path` to the current package under the logical name
604
/// `name`, which may contain `/` to place it in a child module.
605
export fn (h: &mut Harness) named(name: *[u8], path: *[u8]) {
606
    h.add(&["-mod", h.join(&[name, "=", path])]);
607
}
608
609
/// Directory of the standard library package.
610
constant STD_DIR: *[u8] = "lib/std";
611
/// Root module of the standard library package.
612
constant STD_ROOT: *[u8] = "lib/std/std.rad";
613
614
/// Add standard library inputs with `extension`, or all inputs when it is empty.
615
export fn (h: &mut Harness) addStd(extension: *[u8]) throws (sys::Error) {
616
    h.add(&["-pkg", "std", "-manifest", "seed/dependencies/none"]);
617
    for path in try h.manifest("std.lib") {
618
        if mem::endsWith(path, extension) {
619
            h.addStdModule(path);
620
        }
621
    }
622
}
623
624
/// Add the standard library input `path`. Modules after the root are in the
625
/// package directory, so each is mapped to its logical path.
626
export fn (h: &mut Harness) addStdModule(path: *[u8]) {
627
    if mem::eq(path, STD_ROOT) or not mem::endsWith(path, ".rad") {
628
        h.add(&["-mod", path]);
629
    } else {
630
        h.named(&path[STD_DIR.len + 1 .. path.len - ".rad".len], path);
631
    }
632
}
633
634
/// Read the standard library package for builds that take explicit module flags.
635
export fn (h: &mut Harness) stdPackage() -> manifest::Package throws (sys::Error) {
636
    let path = "lib/std/std.manifest";
637
    let text = try h.load(path);
638
    let mut table: *mut [*[u8]] = &mut [];
639
    try table.resize(strings::TABLE_SIZE, "", h.arena) catch {
640
        throw sys::Error::TooLarge;
641
    };
642
    let nodes = ast::NodeArena { heap: h.arena, nextId: 0 };
643
    let mut syntax = parser::newParser(nodes, strings::freshPool(table));
644
645
    return try manifest::read(&mut syntax, path, text, h.arena) catch {
646
        throw sys::Error::Invalid;
647
    };
648
}
649
650
/// Return a copy of the compiler arguments collected since the last call.
651
export fn (h: &mut Harness) take() -> *[*[u8]] {
652
    let mut list: *mut [*[u8]] = &mut [];
653
    for arg in &h.args[h.taken ..] {
654
        try! list.append(arg, h.arena);
655
    }
656
    set h.taken = h.args.len;
657
    return &list[..];
658
}
659
660
/// Build a command that runs the compiler on `args` with the parent's memory
661
/// sizes. Standard output and standard error both go to `output`.
662
export fn (h: &mut Harness) cc(args: &[*[u8]], output: process::Output) -> process::Command {
663
    let compiler = h.compiler;
664
    return h.cmd(compiler, args, process::Target::Inherit, COMPILE_STEPS, output);
665
}
666
667
/// Run the compiler on the collected arguments and check that it exits with
668
/// status zero. Its output goes to `output`.
669
export fn (h: &mut Harness) compile(what: *[u8], output: process::Output) -> bool {
670
    let command = h.cc(h.take(), output);
671
    return h.run(what, command, OK, &[]);
672
}