test/integration/packages.rad 45.3 KiB raw
1
//! Source-free package inputs and content-keyed compilation cache checks.
2
3
use std::fs;
4
use std::lang::il::binary;
5
use std::lang::il::binary::program;
6
use std::lang::il::binary::reader;
7
use std::lang::il::verify;
8
use std::lang::il::verify::linking;
9
use std::mem;
10
use std::mem::heap;
11
use std::process;
12
use std::sys;
13
use super::harness;
14
use super::harness::Harness;
15
16
/// Temporary verifier tables for the package fixture.
17
static VERIFY: [u8; 1048576] = [0; 1048576];
18
/// Export classifications retained across the two fixture verifications.
19
static KEEP: [u8; 65536] = [0; 65536];
20
21
/// Verify the provider and then the client's exact typed imports through the kernel API.
22
unsafe fn verified(h: &mut Harness, root: *[u8]) throws (sys::Error) {
23
    let limits = binary::Limits { registers: 4096, blocks: 4096 };
24
    let config = verify::Config {
25
        registers: 4096,
26
        blocks: 4096,
27
        layoutSize: 1048576,
28
        layoutDepth: 32,
29
        params: 16,
30
        envSize: 4096,
31
    };
32
    let dep = try h.load(h.join(&[root, "/dep/dep.ril.bin"]));
33
    let app = try h.load(h.join(&[root, "/app/app.ril.bin"]));
34
    let mut provider = try! program::decode(dep, h.arena, limits);
35
    let mut client = try! program::decode(app, h.arena, limits);
36
    let scratch = heap::over(&mut VERIFY[..]);
37
    let keep = heap::over(&mut KEEP[..]);
38
    try verify::verifyPackage(&mut provider, config, scratch, keep) catch error {
39
        h.fail("verify interface provider", verify::ruleName(error.rule));
40
        return;
41
    };
42
    heap::reset(scratch);
43
    let image = provider.links.image else panic "verified: missing image identity";
44
    let providers = [linking::Provider { image, contract: provider }];
45
    try verify::verifyLinkedPackage(
46
        &mut client, &providers[..], config, scratch, keep
47
    ) catch error {
48
        h.fail("verify interface client imports", verify::ruleName(error.rule));
49
        return;
50
    };
51
    h.pass();
52
}
53
54
/// Add the same source graph and a selected output mode.
55
fn source(h: &mut Harness, output: *[u8], flag: *[u8]) {
56
    h.add(
57
        &[
58
            "-cache", h.path(&["cache"]), "-pkg", "dep", "-mod", h.path(&["dep.rad"]),
59
            "-pkg", "app", "-mod", h.path(&["app.rad"]), "-entry", "app", flag, output,
60
        ]
61
    );
62
}
63
64
/// Run one hosted fixture and require successful assertions.
65
fn execute(h: &mut Harness, image: *[u8]) {
66
    let command = h.cmd(image, &[], harness::HOSTED, harness::RUN_STEPS, harness::INHERIT);
67
    h.run("execute package client", command, harness::OK, &[]);
68
}
69
70
/// Assembly inputs require native output and link with source or artifact packages.
71
fn nativeInputs(h: &mut Harness) throws (sys::Error) {
72
    let root = h.path(&["native-inputs"]);
73
    try harness::makeDirs(root);
74
    let source = h.join(&[root, "/entry.rad"]);
75
    let assembly = h.join(&[root, "/entry.ras"]);
76
    let exported = h.join(&[root, "/packages"]);
77
    let image = h.join(&[root, "/entry.rv64"]);
78
    try fs::writeFile(source, try h.load("test/packages/native-inputs/entry.rad"));
79
    let mut previous: ?*[u8] = nil;
80
    for increment in 1 .. 3 {
81
        try fs::writeFileParts(
82
            assembly,
83
            &[
84
                ".text; .export @entry::native; @entry::native addi %a0 %a0 ",
85
                h.num(increment), "; ret;\n",
86
            ]
87
        );
88
        h.add(
89
            &[
90
                "-cache", h.join(&[root, "/cache"]), "-pkg", "entry", "-mod", source,
91
                "-mod", assembly, "-o", image,
92
            ]
93
        );
94
        if not h.compile("link assembly with native output", h.out(&["native-link.log"])) {
95
            return;
96
        }
97
        execute(h, image);
98
        let bytes = try h.load(image);
99
        if let earlier = previous {
100
            assert not mem::eq(earlier, bytes);
101
        }
102
        set previous = bytes;
103
        if increment == 2 {
104
            h.expect(
105
                "assembly edits reuse package RIL",
106
                h.path(&["native-link.log"]),
107
                harness::Expect::Contains("cache hit entry")
108
            );
109
        }
110
    }
111
    for flag in &["", "-ril", "-dump"] {
112
        h.add(&["-pkg", "entry", "-mod", source, "-mod", assembly]);
113
        if flag.len > 0 {
114
            h.add(&[flag, exported if mem::eq(flag, "-ril") else "il"]);
115
        }
116
        let command = h.cc(h.take(), h.out(&["native-rejected.log"]));
117
        h.run("reject assembly without native output", command, process::Outcome::Exited(1), &[
118
            harness::Expect::Contains("assembly inputs require native output with `-o`")
119
        ]);
120
    }
121
    h.add(&["-pkg", "entry", "-mod", source, "-start", assembly, "-ril", exported]);
122
    let command = h.cc(h.take(), h.out(&["startup-rejected.log"]));
123
    h.run("reject startup assembly without native output", command, process::Outcome::Exited(1), &[
124
        harness::Expect::Contains("assembly inputs require native output with `-o`")
125
    ]);
126
    h.add(&["-pkg", "entry", "-mod", source, "-ril", exported]);
127
    if not h.compile("export Radiance declarations and code", h.out(&["native-export.log"])) {
128
        return;
129
    }
130
    h.add(&["-pkg", "entry", "-artifact", exported, "-mod", assembly, "-o", image]);
131
    if h.compile("link assembly with an artifact package", h.out(&["native-artifact.log"])) {
132
        execute(h, image);
133
    }
134
}
135
136
/// Compile a large std test artifact, then use its complete interfaces in a test client.
137
fn large(h: &mut Harness) throws (sys::Error) {
138
    let root = h.path(&["large"]);
139
    h.add(&["-no-cache", "-test"]);
140
    try h.addStd(".rad");
141
    for path in try h.manifest("std.lib.test") {
142
        h.addStdModule(path);
143
    }
144
    let standard = try h.stdPackage();
145
    for path in standard.embed {
146
        h.add(&["-embed", h.join(&["lib/std/", path])]);
147
    }
148
    let provider = h.path(&["large-provider.rad"]);
149
    let client = h.path(&["large-client.rad"]);
150
    try fs::writeFile(provider, "export fn value() -> u32 { return 42; }\n");
151
    try fs::writeFile(
152
        client, "use provider; export fn value() -> u32 { return provider::value(); }\n"
153
    );
154
    try fs::writeFile(h.path(&["provider.manifest"]), "std\n");
155
    try fs::writeFile(h.path(&["client.manifest"]), "provider\n");
156
    h.add(&["-pkg", "provider", "-mod", provider, "-pkg", "client", "-mod", client]);
157
    h.add(&["-entry", "std", "-ril", root]);
158
    if not h.compile("export the std test artifact", h.out(&["large-export.log"])) {
159
        return;
160
    }
161
    let source = h.path(&["checks.rad"]);
162
    try fs::writeFile(
163
        source,
164
        "use std::testing; @test unsafe fn check() throws (testing::TestError) { assert true; }\n"
165
    );
166
    try fs::writeFile(h.path(&["checks.manifest"]), "std\n");
167
    h.add(&["-no-cache", "-test", "-pkg", "std", "-artifact", root]);
168
    for path in try h.manifest("std.lib") {
169
        if mem::endsWith(path, ".ras") {
170
            h.add(&["-mod", path]);
171
        }
172
    }
173
    h.add(&[
174
        "-pkg", "checks", "-mod", source, "-entry", "checks", "-o", h.path(&["large.rv64"])
175
    ]);
176
    if h.compile("use the large std artifact without source", h.out(&["large-client.log"])) {
177
        execute(h, h.path(&["large.rv64"]));
178
    }
179
}
180
181
/// Embed declared package files, and read them through generated interfaces.
182
fn embeds(h: &mut Harness) throws (sys::Error) {
183
    let root = h.path(&["embeds"]);
184
    try harness::makeDirs(h.join(&[root, "/data"]));
185
    let provider = h.join(&[root, "/text.rad"]);
186
    let data = h.join(&[root, "/data/hello.txt"]);
187
    let app = h.join(&[root, "/app.rad"]);
188
    let exported = h.join(&[root, "/exported"]);
189
    let image = h.join(&[root, "/app.rv64"]);
190
    let code = try h.load("test/packages/embeds/text.rad");
191
    try fs::writeFile(provider, code);
192
    try fs::writeFile(data, "hello\n");
193
    try fs::writeFile(app, try h.load("test/packages/embeds/app.rad"));
194
    try fs::writeFile(h.join(&[root, "/app.manifest"]), "text\n");
195
    let cache = h.join(&[root, "/cache"]);
196
    for i in 0 .. 2 {
197
        if i == 1 {
198
            try fs::writeFile(data, "hullo\n");
199
        }
200
        h.add(
201
            &[
202
                "-cache", cache, "-pkg", "text", "-mod", provider, "-embed", data,
203
                "-pkg", "app", "-mod", app, "-entry", "app", "-o", image,
204
            ]
205
        );
206
        if h.compile("compile embedded package files", h.out(&["embed.log"])) {
207
            execute(h, image);
208
        }
209
    }
210
    h.expect(
211
        "embedded file edits invalidate clients",
212
        h.path(&["embed.log"]),
213
        harness::Expect::Matching {
214
            text: "cache hit", count: 0
215
        }
216
    );
217
    h.add(
218
        &[
219
            "-no-cache", "-pkg", "text", "-mod", provider, "-embed", data,
220
            "-pkg", "app", "-mod", app, "-entry", "app", "-ril", exported,
221
        ]
222
    );
223
    if not h.compile("export embedded package files", h.out(&["embed-export.log"])) {
224
        return;
225
    }
226
    h.expect(
227
        "interfaces keep embed calls",
228
        h.join(&[exported, "/text/interface/text.rid"]),
229
        harness::Expect::Contains("@embed(\"data/hello.txt\")")
230
    );
231
    h.expect(
232
        "interface trees hold embedded files",
233
        h.join(&[exported, "/text/interface/data/hello.txt"]),
234
        harness::Expect::Contains("hullo")
235
    );
236
    try fs::remove(provider);
237
    try fs::remove(data);
238
    h.add(
239
        &[
240
            "-no-cache", "-pkg", "text", "-artifact", exported,
241
            "-pkg", "app", "-mod", app, "-entry", "app", "-o", image,
242
        ]
243
    );
244
    if h.compile("embed through an interface without source", h.out(&["embed-client.log"])) {
245
        execute(h, image);
246
    }
247
    try fs::writeFile(provider, code);
248
    try fs::writeFile(data, "hello\n");
249
    let rejected = h.join(&[root, "/rejected"]);
250
    h.add(
251
        &[
252
            "-no-cache", "-pkg", "text", "-mod", provider, "-embed", data, "-embed", data,
253
            "-ril", rejected,
254
        ]
255
    );
256
    let twice = h.cc(h.take(), h.out(&["embed-twice.log"]));
257
    h.run("reject embedded files declared twice", twice, process::Outcome::Exited(1), &[
258
        harness::Expect::Contains("embedded file is declared twice")
259
    ]);
260
    // An embedded file shares the interface tree with the generated module interfaces.
261
    let interface = h.join(&[root, "/text.rid"]);
262
    try fs::writeFile(interface, "");
263
    try fs::writeFileParts(provider, &[
264
        code, "export constant INTERFACE: *[u8] = @embed(\"text.rid\");\n"
265
    ]);
266
    h.add(
267
        &[
268
            "-no-cache", "-pkg", "text", "-mod", provider, "-embed", data, "-embed", interface,
269
            "-ril", rejected,
270
        ]
271
    );
272
    let clash = h.cc(h.take(), h.out(&["embed-clash.log"]));
273
    h.run("reject embedded files at interface paths", clash, process::Outcome::Exited(1), &[
274
        harness::Expect::Contains("artifact path conflicts with another stored path: text.rid")
275
    ]);
276
    try fs::writeFile(provider, code);
277
    let outside = h.path(&["outside.txt"]);
278
    try fs::writeFile(outside, "");
279
    h.add(&["-no-cache", "-pkg", "text", "-mod", provider, "-embed", outside, "-ril", rejected]);
280
    let escaped = h.cc(h.take(), h.out(&["embed-outside.log"]));
281
    h.run("reject embedded files outside the package", escaped, process::Outcome::Exited(1), &[
282
        harness::Expect::Contains("not a clean path under the package root")
283
    ]);
284
}
285
286
/// Private embedded inputs rebuild their provider and preserve its client contract.
287
fn privateEmbeds(h: &mut Harness) throws (sys::Error) {
288
    let root = h.path(&["private-embeds"]);
289
    try harness::makeDirs(h.join(&[root, "/data"]));
290
    try harness::makeDirs(h.join(&[root, "/text"]));
291
    let provider = h.join(&[root, "/text.rad"]);
292
    let child = h.join(&[root, "/text/labels.rad"]);
293
    let private = h.join(&[root, "/data/private.txt"]);
294
    let unused = h.join(&[root, "/data/unused.txt"]);
295
    let public = h.join(&[root, "/data/public.txt"]);
296
    let client = h.join(&[root, "/app.rad"]);
297
    let first = h.join(&[root, "/0"]);
298
    let mut original: ?binary::Id = nil;
299
    try fs::writeFile(provider, try h.load("test/packages/private-embeds/text.rad"));
300
    try fs::writeFile(
301
        child,
302
        "constant TEXT: *[u8] = @embed(\"data/public.txt\");\nexport constant VALUE: *[u8] = TEXT;\n"
303
    );
304
    try fs::writeFile(private, "p");
305
    try fs::writeFile(unused, "u");
306
    try fs::writeFile(public, "hello\n");
307
    try fs::writeFile(client, try h.load("test/packages/private-embeds/app.rad"));
308
    try fs::writeFile(h.join(&[root, "/app.manifest"]), "text\n");
309
    for version in 0 .. 3 {
310
        if version == 1 {
311
            try fs::writeFile(private, "q");
312
        } else if version == 2 {
313
            try fs::writeFile(unused, "v");
314
        }
315
        let output = h.join(&[root, "/", h.num(version)]);
316
        let report = h.join(&[root, "/", h.num(version), ".log"]);
317
        h.add(
318
            &[
319
                "-cache", h.join(&[root, "/cache"]),
320
                "-pkg", "text", "-mod", provider, "-mod", child,
321
                "-embed", private, "-embed", unused, "-embed", public,
322
                "-pkg", "app", "-mod", client, "-entry", "app", "-ril", output,
323
            ]
324
        );
325
        if not h.compile("compile private embedded inputs", process::Output::File(report)) {
326
            return;
327
        }
328
        let wire = try h.load(h.join(&[output, "/text/text.ril.bin"]));
329
        let mut input = reader::new(wire);
330
        let header = try! program::header(&mut input, h.arena);
331
        if let expected = original {
332
            assert header.links.metadata == expected;
333
            h.expect("private embed edits retain clients", report, harness::Expect::Contains(
334
                "cache hit app"
335
            ));
336
            h.expect("private embeds remain build inputs", report, harness::Expect::Matching {
337
                text: "cache hit text", count: 0
338
            });
339
            h.expect(
340
                "private embed edits preserve client images",
341
                h.join(&[output, "/app/app.ril.bin"]),
342
                harness::Expect::Same(h.join(&[first, "/app/app.ril.bin"]))
343
            );
344
        } else {
345
            set original = header.links.metadata;
346
        }
347
        if version == 1 {
348
            assert not mem::eq(wire, try h.load(h.join(&[first, "/text/text.ril.bin"])));
349
        }
350
        h.expect(
351
            "retain embeds reached through private interface declarations",
352
            h.join(&[output, "/text/interface/data/public.txt"]),
353
            harness::Expect::Present
354
        );
355
        for name in &["private.txt", "unused.txt"] {
356
            h.expect(
357
                "store only interface embeds",
358
                h.join(&[output, "/text/interface/data/", name]),
359
                harness::Expect::Absent
360
            );
361
        }
362
    }
363
    for path in &[provider, child, private, unused, public] {
364
        try fs::remove(path);
365
    }
366
    let image = h.join(&[root, "/app.rv64"]);
367
    h.add(
368
        &[
369
            "-no-cache", "-pkg", "app", "-artifact", h.join(&[root, "/2"]),
370
            "-entry", "app", "-o", image,
371
        ]
372
    );
373
    if h.compile("link private embeds without source files", h.out(&["private-embed-link.log"])) {
374
        execute(h, image);
375
    }
376
}
377
378
/// Clean package cache entries and retain files outside the cache.
379
fn cleanCache(h: &mut Harness) throws (sys::Error) {
380
    let root = h.path(&["clean-cache"]);
381
    let cache = h.join(&[root, "/cache"]);
382
    let exported = h.join(&[root, "/exported"]);
383
    let code = h.join(&[root, "/cleancheck.rad"]);
384
    try harness::makeDirs(root);
385
    try fs::writeFile(code, "@default fn main() -> u32 { return 0; }\n");
386
    h.add(
387
        &[
388
            "-cache", cache, "-pkg", "cleancheck", "-mod", code,
389
            "-entry", "cleancheck", "-ril", exported,
390
        ]
391
    );
392
    if not h.compile("populate the cache to clean", h.out(&["clean-populate.log"])) {
393
        return;
394
    }
395
    let entries = try h.children(cache);
396
    assert entries.len == 1;
397
    let partial = h.join(&[
398
        cache, "/0000000000000000000000000000000000000000000000000000000000000000.tmp.0"
399
    ]);
400
    try harness::makeDirs(partial);
401
    try fs::writeFile(h.join(&[partial, "/partial"]), "partial cache entry");
402
    let unrelated = h.join(&[cache, "/keep.txt"]);
403
    try fs::writeFile(unrelated, "unrelated file");
404
    let prefix = h.join(&[
405
        cache, "/0000000000000000000000000000000000000000000000000000000000000000"
406
    ]);
407
    let suffixes = [".tar", ".tmp.", ".tmp.00", ".tmp.4096"];
408
    for suffix in &suffixes[..] {
409
        try fs::writeFile(h.join(&[prefix, suffix]), "keep");
410
    }
411
    h.add(&["clean", "-cache", cache]);
412
    if not h.compile("clean the selected package cache", h.out(&["clean.log"])) {
413
        return;
414
    }
415
    for suffix in &suffixes[..] {
416
        h.expect(
417
            "retain files outside the publication names",
418
            h.join(&[prefix, suffix]),
419
            harness::Expect::Present
420
        );
421
    }
422
    h.expect("remove completed cache entries", entries[0], harness::Expect::Absent);
423
    h.expect("remove interrupted cache entries", partial, harness::Expect::Absent);
424
    h.expect("retain unrelated cache-root files", unrelated, harness::Expect::Present);
425
    h.expect(
426
        "retain exported packages",
427
        h.join(&[exported, "/cleancheck/cleancheck.ril.bin"]),
428
        harness::Expect::Present
429
    );
430
    h.add(&["clean", "-cache", cache]);
431
    h.compile("clean an empty cache", h.out(&["clean-empty.log"]));
432
    h.add(&["clean", "-cache", h.join(&[root, "/missing"])]);
433
    h.compile("clean a missing cache", h.out(&["clean-missing.log"]));
434
    h.add(&["clean", "-cache"]);
435
    let invalid = h.cc(h.take(), h.out(&["clean-invalid.log"]));
436
    h.run("reject a missing cache path", invalid, process::Outcome::Exited(1), &[]);
437
}
438
439
/// Relocated and renamed source files share cache entries and portable debug information.
440
fn relocation(h: &mut Harness) throws (sys::Error) {
441
    let root = h.path(&["relocation"]);
442
    let first = h.join(&[root, "/0/exported"]);
443
    let second = h.join(&[root, "/1/exported"]);
444
445
    let entry = try h.load("test/packages/relocation/entry.rad");
446
447
    for i in 0 .. 3 {
448
        let checkout = h.join(&[root, "/", h.num(i)]);
449
        try harness::makeDirs(checkout);
450
        let source = h.join(&[checkout, "/entry.rad" if i == 0 else "/renamed.rad"]);
451
        let child = h.join(&[checkout, "/implementation.rad"]);
452
        let data = h.join(&[checkout, "/asset.bin"]);
453
        try fs::writeFile(source, entry);
454
        try fs::writeFile(child, "export fn answer() -> u32 { return 42; }\n");
455
        try fs::writeFile(data, "x");
456
        let output = h.join(&[checkout, "/exported"]);
457
        let report = h.join(&[checkout, "/build.log"]);
458
        h.add(
459
            &[
460
                "-cache", h.join(&[root, "/cache"]), "-debug",
461
                "-pkg", "portable", "-mod", source,
462
                "-mod", h.join(&["detail=", child]), "-embed", data,
463
                "-entry", "portable", "-ril", output,
464
            ]
465
        );
466
        if not h.compile("compile a relocated package", process::Output::File(report)) {
467
            return;
468
        }
469
        let native = h.join(&[checkout, "/portable.rv64"]);
470
        let nativeLog = h.out(&["relocated-native.log"]);
471
        h.add(
472
            &[
473
                "-cache", h.join(&[root, "/cache"]), "-debug",
474
                "-pkg", "portable", "-mod", source, "-mod", h.join(&["detail=", child]),
475
                "-embed", data, "-entry", "portable", "-o", native,
476
            ]
477
        );
478
        if not h.compile("link from the relocated cache", nativeLog) {
479
            return;
480
        }
481
        h.expect(
482
            "link reuses the source cache",
483
            h.path(&["relocated-native.log"]),
484
            harness::Expect::Contains("cache hit portable")
485
        );
486
        for path in &[source, child] {
487
            h.expect(
488
                "debug locations use current source paths",
489
                h.join(&[native, ".debug"]),
490
                harness::Expect::Contains(path)
491
            );
492
        }
493
        h.expect(
494
            "artifacts omit checkout paths",
495
            h.join(&[output, "/portable/portable.ril.debug"]),
496
            harness::Expect::Matching { text: root, count: 0 }
497
        );
498
        if i > 0 {
499
            // Renamed source files keep their logical module paths.
500
            h.expect("relocation reuses compiled packages", report, harness::Expect::Contains(
501
                "cache hit portable"
502
            ));
503
            for path in &[
504
                "portable/portable.ril.bin", "portable/portable.ril.debug",
505
                "portable/interface/asset.bin",
506
            ] {
507
                h.expect(
508
                    "relocation preserves package artifacts",
509
                    h.join(&[output, "/", path]),
510
                    harness::Expect::Same(h.join(&[first, "/", path]))
511
                );
512
            }
513
        }
514
    }
515
    let image = h.join(&[root, "/portable.rv64"]);
516
    h.add(&["-no-cache", "-debug", "-pkg", "portable", "-artifact", second, "-o", image]);
517
    if h.compile("link a relocated artifact", h.out(&["relocation-link.log"])) {
518
        execute(h, image);
519
    }
520
    let single = h.join(&[root, "/single.rad"]);
521
    try fs::writeFile(single, "@default fn main() -> u32 { return 0; }");
522
    h.add(&["-no-cache", "-pkg", "sibling", "-mod", single, "-ril", second]);
523
    if not h.compile("export a sibling package", h.out(&["sibling.log"])) {
524
        return;
525
    }
526
    h.add(&["-no-cache", "-pkg", "portable", "-mod", single, "-ril", second]);
527
    if not h.compile("replace the exported package", h.out(&["replace.log"])) {
528
        return;
529
    }
530
    for path in &[
531
        "portable/interface/portable/detail.rid", "portable/interface/asset.bin",
532
        "portable/portable.ril.debug",
533
    ] {
534
        h.expect(
535
            "remove obsolete package inputs", h.join(&[second, "/", path]), harness::Expect::Absent
536
        );
537
    }
538
    h.expect(
539
        "preserve the sibling export",
540
        h.join(&[second, "/sibling/sibling.ril.bin"]),
541
        harness::Expect::Present
542
    );
543
    h.add(&["-no-cache", "-pkg", "portable", "-artifact", second, "-o", image]);
544
    if h.compile("read the replacement package", h.out(&["read-replacement.log"])) {
545
        execute(h, image);
546
    }
547
}
548
549
/// Reject the compilation of the package in `directory` with `flags`, and
550
/// require `message` in the compiler output.
551
fn rejectPackage(
552
    h: &mut Harness, what: *[u8], flags: &[*[u8]], directory: *[u8], message: *[u8]
553
) {
554
    h.add(&["-no-cache"]);
555
    h.add(flags);
556
    h.add(&[directory]);
557
    let command = h.cc(h.take(), h.out(&["manifest-rejected.log"]));
558
    h.run(what, command, process::Outcome::Exited(1), &[harness::Expect::Contains(message)]);
559
}
560
561
/// Package directories of the manifest checks.
562
constant MANIFESTS: *[u8] = "test/manifests";
563
564
/// Build the packages in [`MANIFESTS`]: listed modules, dependencies found by
565
/// name and version in the library directory of a parent, in `-lib`
566
/// directories and with `-dep`, compiled libraries, single modules, and
567
/// rejected graphs.
568
fn manifests(h: &mut Harness) throws (sys::Error) {
569
    let lib = h.join(&[MANIFESTS, "/lib"]);
570
    let app = h.join(&[MANIFESTS, "/app"]);
571
    let image = h.path(&["manifest-app.rv64"]);
572
    h.add(&["-no-cache", app, "-o", image]);
573
    if not h.compile("find a library in the lib directory of a parent", h.out(&["manifest.log"])) {
574
        return;
575
    }
576
    execute(h, image);
577
    let exported = h.path(&["manifest-exported"]);
578
    h.add(&["-no-cache", app, "-ril", exported]);
579
    if not h.compile("export a package graph", h.out(&["manifest-export.log"])) {
580
        return;
581
    }
582
    let linked = h.path(&["manifest-linked.rv64"]);
583
    h.add(&["-no-cache", "-lib", exported, app, "-o", linked]);
584
    if not h.compile("find a compiled library with -lib first", h.out(&["manifest-lib.log"])) {
585
        return;
586
    }
587
    h.expect(
588
        "compiled library is not parsed",
589
        h.path(&["manifest-lib.log"]),
590
        harness::Expect::Matching {
591
            text: "util: parsing", count: 0
592
        }
593
    );
594
    execute(h, linked);
595
    let facade = h.join(&[lib, "/facade"]);
596
    let bridge = h.join(&[MANIFESTS, "/bridge"]);
597
    let separate = h.path(&["manifest-separate"]);
598
    h.add(&["-no-cache", facade, "-ril", separate]);
599
    if not h.compile("export a package with a dependency", h.out(&["manifest-facade.log"])) {
600
        return;
601
    }
602
    let moved = h.join(&[separate, "/renamed"]);
603
    try fs::rename(h.join(&[separate, "/util"]), moved);
604
    h.add(&["-no-cache", "-lib", separate, "-lib", exported, bridge, "-o", linked]);
605
    let transitiveLib = h.out(&["manifest-transitive-lib.log"]);
606
    if h.compile("find a compiled package's provider in the next -lib", transitiveLib) {
607
        h.expect(
608
            "use the compiled provider from -lib",
609
            h.path(&["manifest-transitive-lib.log"]),
610
            harness::Expect::Matching { text: "util: parsing", count: 0 }
611
        );
612
        execute(h, linked);
613
    }
614
    h.add(&[
615
        "-no-cache", "-lib", separate, "-dep", h.join(&["util=", moved]), bridge, "-o", linked
616
    ]);
617
    let transitiveDep = h.out(&["manifest-transitive-dep.log"]);
618
    if h.compile("override a compiled package's provider with -dep", transitiveDep) {
619
        h.expect(
620
            "use the renamed compiled provider from -dep",
621
            h.path(&["manifest-transitive-dep.log"]),
622
            harness::Expect::Matching { text: "util: parsing", count: 0 }
623
        );
624
        execute(h, linked);
625
    }
626
    h.add(&["-no-cache", app, "-dump", "il"]);
627
    if h.compile("dump IL for a manifest dependency graph", h.out(&["manifest-il.log"])) {
628
        h.expect(
629
            "dump includes dependency IL",
630
            h.path(&["manifest-il.log"]),
631
            harness::Expect::Contains("util::answer")
632
        );
633
    }
634
    h.add(&["-no-cache", app, "-dump", "asm"]);
635
    if h.compile("dump assembly for a manifest dependency graph", h.out(&["manifest-asm.log"])) {
636
        h.expect(
637
            "dump includes dependency assembly",
638
            h.path(&["manifest-asm.log"]),
639
            harness::Expect::Contains("util::answer")
640
        );
641
    }
642
    h.add(&["-no-cache", "test/tests/asm.link", "-dump", "asm"]);
643
    if h.compile("dump linked assembly", h.out(&["manifest-native.log"])) {
644
        h.expect(
645
            "dump includes the assembly symbol",
646
            h.path(&["manifest-native.log"]),
647
            harness::Expect::Contains("test::asmAddOne")
648
        );
649
    }
650
    rejectPackage(
651
        h,
652
        "reject an incompatible compiled package",
653
        &["-lib", exported],
654
        h.join(&[MANIFESTS, "/newer"]),
655
        "requires util version 1.3.0"
656
    );
657
    let unversioned = h.path(&["unversioned"]);
658
    h.add(&["-no-cache", "-name", "util", h.join(&[lib, "/util/text.rad"]), "-ril", unversioned]);
659
    if not h.compile("export a single module", h.out(&["unversioned.log"])) {
660
        return;
661
    }
662
    rejectPackage(
663
        h,
664
        "reject a provider without the required version",
665
        &["-lib", unversioned],
666
        app,
667
        "has no version"
668
    );
669
    let wrongUtil = h.join(&["util=", unversioned, "/util"]);
670
    rejectPackage(
671
        h,
672
        "verify compiled dependency pins with an override",
673
        &["-lib", separate, "-lib", exported, "-dep", wrongUtil],
674
        bridge,
675
        "package dependency artifact mismatch util"
676
    );
677
    let pinned = h.path(&["manifest-pinned.rv64"]);
678
    h.add(&["-no-cache", "-dep", h.join(&["util=", exported, "/util"]), app, "-o", pinned]);
679
    if not h.compile("select a compiled library with -dep", h.out(&["manifest-dep.log"])) {
680
        return;
681
    }
682
    h.expect(
683
        "selected library is not parsed",
684
        h.path(&["manifest-dep.log"]),
685
        harness::Expect::Matching {
686
            text: "util: parsing", count: 0
687
        }
688
    );
689
    execute(h, pinned);
690
    let single = h.path(&["manifest-single.rv64"]);
691
    h.add(&["-no-cache", h.join(&[app, "/other.rad"]), "-o", single]);
692
    if not h.compile("compile one module that imports a library", h.out(&["manifest-single.log"])) {
693
        return;
694
    }
695
    execute(h, single);
696
    let client = h.join(&[MANIFESTS, "/client"]);
697
    rejectPackage(h, "reject a package that is not found", &[], client, "package other not found");
698
    rejectPackage(
699
        h,
700
        "reject an incompatible version",
701
        &[],
702
        h.join(&[MANIFESTS, "/newer"]),
703
        "requires util version 1.3.0"
704
    );
705
    rejectPackage(
706
        h,
707
        "reject an undeclared listed module",
708
        &[],
709
        h.join(&[MANIFESTS, "/loose"]),
710
        "is not declared by its parent"
711
    );
712
    let wrong: [*[u8]; 2] = ["-lib", h.join(&[MANIFESTS, "/wrong"])];
713
    rejectPackage(
714
        h, "reject a manifest named after another package", &wrong[..], client, "must be named"
715
    );
716
    rejectPackage(h, "reject a dependency cycle", &[], h.join(&[lib, "/cycle"]), "cyclic");
717
    let unused: [*[u8]; 2] = ["-dep", h.join(&["other=", MANIFESTS, "/wrong/other"])];
718
    rejectPackage(h, "reject -dep for no dependency", &unused[..], app, "names no dependency");
719
    rejectPackage(
720
        h, "reject a package directory with -pkg", &["-pkg", "x"], app, "cannot be combined"
721
    );
722
    let native = h.join(&[exported, "/util/native/"]);
723
    try fs::writeFile(h.join(&[native, "extra.ras"]), "");
724
    rejectPackage(
725
        h,
726
        "reject an unexpected native file",
727
        &["-lib", exported, "-o", pinned],
728
        app,
729
        "invalid native assembly filename extra.ras"
730
    );
731
    try fs::remove(h.join(&[native, "extra.ras"]));
732
    try fs::rename(h.join(&[native, "0.ras"]), h.join(&[native, "1.ras"]));
733
    rejectPackage(
734
        h,
735
        "reject a missing assembly index",
736
        &["-lib", exported, "-o", pinned],
737
        app,
738
        "native assembly indices must be consecutive from zero"
739
    );
740
}
741
742
/// Read native manifest inputs only for the requested output.
743
fn manifestNativeModes(h: &mut Harness) throws (sys::Error) {
744
    let root = h.path(&["manifest-native-modes"]);
745
    let app = h.join(&[root, "/app"]);
746
    let dependency = h.join(&[root, "/lib/util"]);
747
    try harness::makeDirs(app);
748
    try harness::makeDirs(dependency);
749
    let manifest = h.join(&[app, "/app.manifest"]);
750
    try fs::writeFile(manifest, @embed("fixtures/native_modes/missing_assembly.manifest"));
751
    try fs::writeFile(
752
        h.join(&[app, "/app.rad"]),
753
        "use util; @default fn main() -> u32 { assert util::answer() == 42; return 0; }\n"
754
    );
755
    try fs::writeFile(
756
        h.join(&[dependency, "/util.manifest"]),
757
        "Package { name: \"util\", version: \"1.0.0\", startup: \"missing.ras\" }\n"
758
    );
759
    try fs::writeFile(
760
        h.join(&[dependency, "/util.rad"]), "export fn answer() -> u32 { return 42; }\n"
761
    );
762
    let unused = h.join(&[root, "/unused.rv64"]);
763
    h.add(&["-no-cache", app, "-dump", "il", "-o", unused]);
764
    if h.compile("dump IL without reading native files", h.out(&["manifest-il-only.log"])) {
765
        h.expect("IL dump produces no executable", unused, harness::Expect::Absent);
766
    }
767
    try fs::writeFile(manifest, @embed("fixtures/native_modes/no_assembly.manifest"));
768
    let image = h.join(&[root, "/app.rv64"]);
769
    h.add(&["-no-cache", app, "-o", image]);
770
    if h.compile("link without reading dependency startup", h.out(&["manifest-start.log"])) {
771
        execute(h, image);
772
    }
773
}
774
775
/// Print the compiler identity.
776
fn version(h: &mut Harness) {
777
    h.add(&["-version"]);
778
    h.compile("print the compiler identity", h.out(&["compiler-version.log"]));
779
    h.expect(
780
        "compiler identity is readable",
781
        h.path(&["compiler-version.log"]),
782
        harness::Expect::Contains("radiance-1.0.0")
783
    );
784
}
785
786
/// Check public package re-exports and private aliases through generated interfaces.
787
fn reexports(h: &mut Harness) throws (sys::Error) {
788
    let root = h.path(&["reexports"]);
789
    try harness::makeDirs(root);
790
    let base = h.join(&[root, "/base.rad"]);
791
    let facade = h.join(&[root, "/facade.rad"]);
792
    let app = h.join(&[root, "/app.rad"]);
793
    let exported = h.join(&[root, "/exported"]);
794
    let provider = try h.load("test/packages/reexports/base.rad");
795
    try fs::writeFile(base, provider);
796
    try fs::writeFile(facade, "export use base;\n");
797
    try fs::writeFile(app, try h.load("test/packages/reexports/app.rad"));
798
    try fs::writeFile(h.join(&[root, "/facade.manifest"]), "base\n");
799
    try fs::writeFile(h.join(&[root, "/app.manifest"]), "facade\n");
800
    h.add(
801
        &[
802
            "-no-cache", "-pkg", "base", "-mod", base, "-pkg", "facade", "-mod", facade,
803
            "-pkg", "app", "-mod", app, "-entry", "app", "-ril", exported,
804
        ]
805
    );
806
    if not h.compile("export a public package alias", h.out(&["reexport.log"])) {
807
        return;
808
    }
809
    try fs::remove(base);
810
    try fs::remove(facade);
811
    h.add(
812
        &[
813
            "-no-cache", "-pkg", "facade", "-artifact", exported,
814
            "-pkg", "app", "-mod", app, "-entry", "app", "-o", h.join(&[root, "/app.rv64"]),
815
        ]
816
    );
817
    if h.compile("use a re-export without provider source", h.out(&["reexport-client.log"])) {
818
        execute(h, h.join(&[root, "/app.rv64"]));
819
    }
820
    try fs::writeFile(base, provider);
821
    try fs::writeFile(facade, "use base;\n");
822
    try fs::writeFile(h.join(&[root, "/app.manifest"]), "base\nfacade\n");
823
    h.add(
824
        &[
825
            "-no-cache", "-pkg", "base", "-mod", base, "-pkg", "facade", "-mod", facade,
826
            "-pkg", "app", "-mod", app, "-entry", "app", "-o", h.join(&[root, "/private.rv64"]),
827
        ]
828
    );
829
    let private = h.cc(h.take(), h.out(&["private-alias.log"]));
830
    h.run("preserve private package alias visibility", private, process::Outcome::Exited(1), &[]);
831
}
832
833
/// Reject explicit artifacts whose interface tree differs from the one that the image's
834
/// metadata identity covers.
835
fn integrity(h: &mut Harness, root: *[u8]) throws (sys::Error) {
836
    let extra = h.join(&[root, "/dep/interface/extra.txt"]);
837
    try fs::writeFile(extra, "");
838
    h.add(&["-no-cache", "-pkg", "dep", "-artifact", root]);
839
    let added = h.cc(h.take(), h.out(&["extra-interface.log"]));
840
    h.run("reject unlisted interface files", added, process::Outcome::Exited(1), &[]);
841
    try fs::remove(extra);
842
    let module = h.join(&[root, "/dep/interface/dep.rid"]);
843
    let original = try h.load(module);
844
    try fs::remove(module);
845
    h.add(&["-no-cache", "-pkg", "dep", "-artifact", root]);
846
    let missing = h.cc(h.take(), h.out(&["missing-interface.log"]));
847
    h.run("reject a missing root interface", missing, process::Outcome::Exited(1), &[]);
848
    try fs::writeFile(module, original);
849
}
850
851
/// Implementation edits preserve client images across a transitive dependency graph.
852
fn metadataReuse(h: &mut Harness) throws (sys::Error) {
853
    let provider = h.path(&["reuse.rad"]);
854
    let facade = h.path(&["forward.rad"]);
855
    let client = h.path(&["consumer.rad"]);
856
    try fs::writeFile(h.path(&["forward.manifest"]), "reuse\n");
857
    try fs::writeFile(h.path(&["consumer.manifest"]), "forward\n");
858
    try fs::writeFile(
859
        facade, "use reuse; export fn value() -> u32 { return reuse::value(); }\n"
860
    );
861
    try fs::writeFile(
862
        client,
863
        "use forward; @default fn main() -> u32 { assert forward::value() == 43; return 0; }\n"
864
    );
865
    for version in 0 .. 2 {
866
        try fs::writeFile(
867
            provider,
868
            "export fn value() -> u32 { return 42; }\n"
869
                if version == 0
870
                else "export fn value() -> u32 { return 43; }\n"
871
        );
872
        let output = h.path(&["reuse-first"]) if version == 0 else h.path(&["reuse-second"]);
873
        let report =
874
            h.path(&["reuse-first.log"]) if version == 0 else h.path(&["reuse-second.log"]);
875
        h.add(
876
            &[
877
                "-cache", h.path(&["reuse-cache"]),
878
                "-pkg", "reuse", "-mod", provider,
879
                "-pkg", "forward", "-mod", facade,
880
                "-pkg", "consumer", "-mod", client, "-entry", "consumer", "-ril", output,
881
            ]
882
        );
883
        if not h.compile("compile metadata reuse graph", process::Output::File(report)) {
884
            return;
885
        }
886
        if version == 1 {
887
            h.expect("implementation edit retains facade", report, harness::Expect::Contains(
888
                "cache hit forward"
889
            ));
890
            h.expect("implementation edit retains client", report, harness::Expect::Contains(
891
                "cache hit consumer"
892
            ));
893
            for name in &["forward/forward.ril.bin", "consumer/consumer.ril.bin"] {
894
                h.expect(
895
                    "implementation edit preserves client bytes",
896
                    h.join(&[output, "/", name]),
897
                    harness::Expect::Same(h.join(&[h.path(&["reuse-first"]), "/", name]))
898
                );
899
            }
900
        }
901
    }
902
    let root = h.path(&["reuse-second"]);
903
    h.add(&["-no-cache", "-pkg", "consumer", "-artifact", root, "-o", h.path(&["reuse.rv64"])]);
904
    if h.compile("link an unchanged client to the selected provider", h.out(&["reuse-link.log"])) {
905
        execute(h, h.path(&["reuse.rv64"]));
906
    }
907
}
908
909
/// A different compiler image uses its own cache entries and reads compatible artifacts.
910
fn compilerImage(h: &mut Harness, exported: *[u8]) throws (sys::Error) {
911
    let original = h.compiler;
912
    let bytes = try h.load(original);
913
    assert bytes.len >= 48 and mem::eq(&bytes[.. 8], "RADIANCE");
914
    let mut changed: *mut [u8] = &mut [];
915
    try changed.extend(bytes, h.arena) catch {
916
        throw sys::Error::TooLarge;
917
    };
918
    // The final header word is the zero-filled tail of writable data.
919
    let tail = mem::load32Le(&changed[..], 44);
920
    assert tail <= 0xfffffff7;
921
    mem::store32Le(&mut changed[..], 44, tail + 8);
922
    let alternate = h.path(&["alternate-compiler.rv64"]);
923
    try fs::writeFile(alternate, &changed[..]);
924
    set h.compiler = alternate;
925
    source(h, h.path(&["alternate.rv64"]), "-o");
926
    h.compile("compile with a different compiler image", h.out(&["alternate.log"]));
927
    h.expect(
928
        "compiler image invalidates cache",
929
        h.path(&["alternate.log"]),
930
        harness::Expect::Matching { text: "cache hit", count: 0 }
931
    );
932
    source(h, h.path(&["alternate-warm.rv64"]), "-o");
933
    h.compile("reuse the same compiler image", h.out(&["alternate-warm.log"]));
934
    h.expect(
935
        "same image reuses its cache",
936
        h.path(&["alternate-warm.log"]),
937
        harness::Expect::Contains("cache hit app")
938
    );
939
    h.add(
940
        &[
941
            "-no-cache", "-pkg", "app", "-artifact", exported,
942
            "-o", h.path(&["alternate-artifact.rv64"]),
943
        ]
944
    );
945
    h.compile("read artifacts from another compiler image", h.out(&["alternate-artifact.log"]));
946
    set h.compiler = original;
947
    execute(h, h.path(&["alternate-artifact.rv64"]));
948
}
949
950
/// Check source/artifact parity, warm reuse, source changes, and explicit artifact hashes.
951
export fn check(h: &mut Harness, args: *[*[u8]]) throws (sys::Error) {
952
    try h.begin("packages");
953
    let mark = h.failed;
954
    let dep = h.path(&["dep.rad"]);
955
    let app = h.path(&["app.rad"]);
956
    let image = h.path(&["source.rv64"]);
957
    let exported = h.path(&["exported"]);
958
    let client = try h.load("test/packages/cache/app.rad");
959
    let provider = try h.load("test/packages/cache/dep.rad");
960
    try fs::writeFile(dep, provider);
961
    try fs::writeFile(app, client);
962
    try fs::writeFile(h.path(&["app.manifest"]), "dep\n");
963
    h.add(
964
        &[
965
            "-no-cache", "-pkg", "dep", "-mod", dep,
966
            "-pkg", "app", "-mod", app, "-entry", "app",
967
        ]
968
    );
969
    if not h.compile("check uncached source without output", h.out(&["check.log"])) {
970
        return;
971
    }
972
    h.add(
973
        &[
974
            "-cache", h.path(&["disabled-cache"]), "-no-cache",
975
            "-pkg", "dep", "-mod", dep, "-pkg", "app", "-mod", app,
976
            "-entry", "app", "-o", h.path(&["uncached.rv64"]),
977
        ]
978
    );
979
    if not h.compile("compile an uncached source graph", h.out(&["uncached.log"])) {
980
        return;
981
    }
982
    h.expect("cache bypass creates no cache", h.path(&["disabled-cache"]), harness::Expect::Absent);
983
    h.expect(
984
        "uncached graph uses package interfaces",
985
        h.path(&["uncached.log"]),
986
        harness::Expect::Contains("encoding package tables")
987
    );
988
    execute(h, h.path(&["uncached.rv64"]));
989
    source(h, image, "-o");
990
    if not h.compile("compile source package graph", h.out(&["cold.log"])) {
991
        return;
992
    }
993
    execute(h, image);
994
    h.expect("uncached executable parity", h.path(&["uncached.rv64"]), harness::Expect::Same(
995
        image
996
    ));
997
    source(h, h.path(&["warm.rv64"]), "-o");
998
    if not h.compile("reuse unchanged packages", h.out(&["warm.log"])) {
999
        return;
1000
    }
1001
    h.expect("dependency cache hit", h.path(&["warm.log"]), harness::Expect::Contains(
1002
        "cache hit dep"
1003
    ));
1004
    h.expect("entry cache hit", h.path(&["warm.log"]), harness::Expect::Contains("cache hit app"));
1005
    h.expect("warm build skips parsing", h.path(&["warm.log"]), harness::Expect::Matching {
1006
        text: "parsing", count: 0
1007
    });
1008
    h.expect("warm executable parity", h.path(&["warm.rv64"]), harness::Expect::Same(image));
1009
    source(h, exported, "-ril");
1010
    if not h.compile("export complete package closure", h.out(&["export.log"])) {
1011
        return;
1012
    }
1013
    try nativeInputs(h);
1014
    try manifests(h);
1015
    try manifestNativeModes(h);
1016
    try compilerImage(h, exported);
1017
    version(h);
1018
    try integrity(h, exported);
1019
    let declarations = h.join(&[exported, "/dep/interface/dep.rid"]);
1020
    h.expect("interface omits implementation helpers", declarations, harness::Expect::Matching {
1021
        text: "fn helper(", count: 0
1022
    });
1023
    h.expect(
1024
        "interface retains callbacks from empty arrays",
1025
        declarations,
1026
        harness::Expect::Contains(
1027
            "fn emptyCallback("
1028
        )
1029
    );
1030
    h.expect("interface omits unused private types", declarations, harness::Expect::Matching {
1031
        text: "record Unused", count: 0
1032
    });
1033
    h.expect("interface omits private statics", declarations, harness::Expect::Matching {
1034
        text: "static counter", count: 0
1035
    });
1036
    h.expect(
1037
        "interface retains private opaque field types",
1038
        declarations,
1039
        harness::Expect::Contains("record Inner")
1040
    );
1041
    h.expect(
1042
        "interface retains private constant operands",
1043
        declarations,
1044
        harness::Expect::Contains("constant BASE")
1045
    );
1046
    unsafe {
1047
        try verified(h, exported);
1048
    }
1049
    h.add(
1050
        &[
1051
            "-no-cache", "-debug", "-pkg", "dep", "-artifact", exported,
1052
            "-pkg", "app", "-mod", app, "-entry", "app", "-o", h.path(&["mixed-debug.rv64"]),
1053
        ]
1054
    );
1055
    if not h.compile("debug a client of an image without locations", h.out(&["mixed-debug.log"])) {
1056
        return;
1057
    }
1058
    execute(h, h.path(&["mixed-debug.rv64"]));
1059
    h.expect("mixed debug sidecar", h.path(&["mixed-debug.rv64.debug"]), harness::Expect::Present);
1060
    try fs::remove(dep);
1061
    try fs::remove(app);
1062
    h.add(&["-no-cache", "-pkg", "app", "-artifact", exported, "-o", h.path(&["artifact.rv64"])]);
1063
    if not h.compile("compile with source unavailable", h.out(&["artifact.log"])) {
1064
        return;
1065
    }
1066
    h.expect("source-free executable parity", h.path(&["artifact.rv64"]), harness::Expect::Same(
1067
        image
1068
    ));
1069
    execute(h, h.path(&["artifact.rv64"]));
1070
    try fs::writeFile(dep, provider);
1071
    try fs::writeFileParts(app, &[client, "\n"]);
1072
    source(h, h.path(&["edited.rv64"]), "-o");
1073
    h.compile("rebuild an edited client", h.out(&["edit.log"]));
1074
    h.expect("client edit retains provider", h.path(&["edit.log"]), harness::Expect::Contains(
1075
        "cache hit dep"
1076
    ));
1077
    h.expect("client edit invalidates entry", h.path(&["edit.log"]), harness::Expect::Matching {
1078
        text: "cache hit app", count: 0
1079
    });
1080
    try fs::writeFileParts(dep, &[provider, "\n"]);
1081
    source(h, h.path(&["unchanged.rv64"]), "-o");
1082
    h.compile("rebuild an equivalent provider", h.out(&["equivalent.log"]));
1083
    h.expect(
1084
        "equivalent provider retains client",
1085
        h.path(&["equivalent.log"]),
1086
        harness::Expect::Contains("cache hit app")
1087
    );
1088
    try fs::writeFileParts(dep, &[
1089
        provider, "\nconstant PRIVATE: u32 = 1;\nrecord Private: Copy { value: u32 }\n"
1090
    ]);
1091
    source(h, h.path(&["private.rv64"]), "-o");
1092
    h.compile("rebuild a provider with private additions", h.out(&["private.log"]));
1093
    h.expect(
1094
        "unused private additions retain client",
1095
        h.path(&["private.log"]),
1096
        harness::Expect::Contains("cache hit app")
1097
    );
1098
    try fs::writeFileParts(dep, &[provider, "\nexport record Added: Copy { value: u32 }\n"]);
1099
    let changed = h.path(&["changed"]);
1100
    source(h, changed, "-ril");
1101
    h.compile("rebuild a changed compiler interface", h.out(&["interface.log"]));
1102
    h.expect(
1103
        "interface edit invalidates client",
1104
        h.path(&["interface.log"]),
1105
        harness::Expect::Matching {
1106
            text: "cache hit app", count: 0
1107
        }
1108
    );
1109
    let originalImage = try h.load(h.join(&[exported, "/dep/dep.ril.bin"]));
1110
    let changedImage = try h.load(h.join(&[changed, "/dep/dep.ril.bin"]));
1111
    assert not mem::eq(originalImage, changedImage);
1112
    try fs::writeFile(
1113
        app, "use dep; @default fn main() { let value = dep::hidden(); let bad = value.value; }\n"
1114
    );
1115
    source(h, h.path(&["opaque.rv64"]), "-o");
1116
    let inaccessible = h.cc(h.take(), h.out(&["opaque.log"]));
1117
    h.run("preserve opaque representation privacy", inaccessible, process::Outcome::Exited(1), &[
1118
        harness::Expect::Contains("opaque record representation is private")
1119
    ]);
1120
    let original = try h.load(declarations);
1121
    let mut altered: *mut [u8] = &mut [];
1122
    try! altered.extend(original, h.arena);
1123
    set altered[0] = altered[0] ^ 1;
1124
    try fs::writeFile(declarations, &altered[..]);
1125
    h.add(&["-no-cache", "-pkg", "app", "-artifact", exported, "-o", h.path(&["bad.rv64"])]);
1126
    let rejected = h.cc(h.take(), h.out(&["corrupt.log"]));
1127
    h.run(
1128
        "reject a same-length mismatched explicit interface",
1129
        rejected,
1130
        process::Outcome::Exited(1),
1131
        &[]
1132
    );
1133
    try metadataReuse(h);
1134
    try reexports(h);
1135
    try embeds(h);
1136
    try privateEmbeds(h);
1137
    try cleanCache(h);
1138
    try relocation(h);
1139
    try large(h);
1140
    h.done(mark, "packages: source-free linking, cache reuse, and integrity checks passed");
1141
}