test/integration/linking.rad 1.7 KiB raw
1
//! Deterministic exact package identities and implementation updates.
2
3
use std::fs;
4
use std::io;
5
use std::lang::il::binary;
6
use std::lang::il::binary::program;
7
use std::sys;
8
use super::harness;
9
use super::harness::Harness;
10
11
/// Compile repeated and body-changed package images.
12
export fn check(h: &mut Harness) throws (sys::Error) {
13
    try h.begin("linking");
14
    let mut packages: *mut [binary::Package] = &mut [];
15
    for name, i in &["first", "body", "repeat"] {
16
        let directory = h.path(&[name]);
17
        try harness::makeDirs(directory);
18
        let source = h.join(&[directory, "/support.rad"]);
19
        let body = "1" if i == 1 else "0";
20
        try fs::writeFileParts(
21
            source,
22
            &[
23
                "/// Public nominal value.\nexport record Value: Copy {\n",
24
                "    /// Payload.\n    value: u32,\n}\n",
25
                "/// Read the payload.\nexport fn read(input: &Value) -> u32 {\n",
26
                "    return input.value + ", body, ";\n}\n",
27
            ]
28
        );
29
        h.add(&["-pkg", "support", "-mod", source, "-ril", directory]);
30
        if not h.compile(h.join(&["compile package ", name]), h.out(&[name, ".log"])) {
31
            return;
32
        }
33
        let wire = try h.load(h.join(&[directory, "/support/support.ril.bin"]));
34
        let decoded = try! program::decode(wire, h.arena, binary::Limits {
35
            registers: 1024, blocks: 1024
36
        });
37
        try! packages.append(decoded, h.arena);
38
    }
39
    assert packages[0].links.image <> packages[1].links.image;
40
    assert packages[0].links.image == packages[2].links.image;
41
    h.pass();
42
    io::printLn(
43
        "package identities: deterministic images and body updates passed"
44
    );
45
}