axbuild 0.4.21

An OS build lib toolkit used by arceos
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
use super::*;

#[test]
fn bug_ext4_dir_ops_is_in_system_grouped_qemu_case() {
    let workspace_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
    let system_dir = workspace_root.join("test-suit/starryos/qemu/system");
    let case_dir = system_dir.join("bugfix-bug-ext4-dir-ops");
    assert!(
        case_dir.join("CMakeLists.txt").is_file(),
        "{} must remain a system grouped C subcase",
        case_dir.display()
    );

    for arch in ["aarch64", "loongarch64", "riscv64", "x86_64"] {
        let path = system_dir.join(format!("qemu-{arch}.toml"));
        let content = fs::read_to_string(&path).unwrap();
        let config: toml::Value = toml::from_str(&content).unwrap();
        let test_commands = config
            .get("test_commands")
            .and_then(toml::Value::as_array)
            .unwrap();
        assert!(
            test_commands
                .iter()
                .filter_map(toml::Value::as_str)
                .any(|command| command.contains("/usr/bin/starry-test-suit/*")),
            "{} must scan installed system test binaries",
            path.display()
        );
        let success_regex = config
            .get("success_regex")
            .and_then(toml::Value::as_array)
            .unwrap();
        assert!(
            success_regex
                .iter()
                .filter_map(toml::Value::as_str)
                .any(|regex| regex.contains("STARRY_GROUPED_TESTS_PASSED")),
            "{} must require the system grouped success marker",
            path.display()
        );
        let fail_regex = config
            .get("fail_regex")
            .and_then(toml::Value::as_array)
            .unwrap();

        assert!(
            fail_regex
                .iter()
                .filter_map(toml::Value::as_str)
                .any(|regex| regex.contains("STARRY_GROUPED_TEST_FAILED")),
            "{} must fail when a grouped bugfix command fails",
            path.display()
        );
    }
}

#[test]
fn starry_system_grouped_qemu_configs_report_subcase_timing() {
    let workspace_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
    let system_dir = workspace_root.join("test-suit/starryos/qemu/system");

    for arch in ["aarch64", "loongarch64", "riscv64", "x86_64"] {
        let path = system_dir.join(format!("qemu-{arch}.toml"));
        let content = fs::read_to_string(&path).unwrap();
        let config: toml::Value = toml::from_str(&content).unwrap();
        let test_commands = config
            .get("test_commands")
            .and_then(toml::Value::as_array)
            .unwrap();
        let command = test_commands
            .iter()
            .filter_map(toml::Value::as_str)
            .next()
            .unwrap_or_default();

        assert!(
            command.contains("STARRY_SYSTEM_TEST_TIMING_BEGIN"),
            "{} must start a grouped subcase timing section",
            path.display()
        );
        assert!(
            command.contains("STARRY_SYSTEM_TEST_TIMING: elapsed_s="),
            "{} must report per-subcase elapsed seconds",
            path.display()
        );
        assert!(
            command.contains("status=passed bin=") && command.contains("status=failed bin="),
            "{} must include pass/fail status in timing lines",
            path.display()
        );
        assert!(
            command.contains("STARRY_SYSTEM_TEST_TIMING_END"),
            "{} must end a grouped subcase timing section",
            path.display()
        );
        assert!(
            !command.contains("sort -nr") && !command.contains("head -n"),
            "{} must not depend on external sort/head pipelines in the final timing summary",
            path.display()
        );
        assert!(
            command.contains("done < \"$timing_file\""),
            "{} must read grouped subcase timing from the timing file, not from stdin",
            path.display()
        );
        let failure_branch = command.find("else\n").unwrap_or_else(|| {
            panic!(
                "{} must contain a failure branch for grouped subcases",
                path.display()
            )
        });
        let failure_command = &command[failure_branch..];
        let exit_status_position = failure_command.find("exit_status=$?").unwrap_or_else(|| {
            panic!(
                "{} must preserve grouped subcase exit status",
                path.display()
            )
        });
        let status_failed_position = failure_command
            .find("status=failed")
            .unwrap_or_else(|| panic!("{} must mark failed grouped subcases", path.display()));
        assert!(
            exit_status_position < status_failed_position,
            "{} must capture `$?` before assigning shell variables in the failure branch",
            path.display()
        );
        assert!(
            command.contains("STARRY_GROUPED_TESTS_PASSED")
                && command.contains("STARRY_GROUPED_TEST_FAILED"),
            "{} must keep existing grouped success/fail markers",
            path.display()
        );
    }
}

#[test]
fn signal_interrupt_eintr_subcase_bounds_child_wait() {
    let workspace_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
    let source_path = workspace_root
        .join("test-suit/starryos/qemu/system/test-signal-interrupt-eintr/src/main.c");
    let source = fs::read_to_string(&source_path)
        .unwrap_or_else(|err| panic!("failed to read {}: {err}", source_path.display()));

    assert!(
        source.contains("poll(&pfd, 1, -1)") && source.matches("kill(child, SIGUSR1)").count() >= 2,
        "{} must preserve the poll EINTR check and retry SIGUSR1 while the child is still running",
        source_path.display()
    );
    assert!(
        source.contains("TEST_TIMEOUT_MS") && source.contains("WNOHANG"),
        "{} must bound the parent wait for the interruptible child",
        source_path.display()
    );
    assert!(
        source.contains("read_ready_byte(")
            && source.contains("errno == EINTR")
            && source.contains("parent read child ready pipe"),
        "{} must retry the parent ready-pipe read on EINTR and report why it failed",
        source_path.display()
    );
    assert!(
        !source.contains("waitpid(child, &status, 0)"),
        "{} must not let a stuck child consume the whole grouped QEMU timeout",
        source_path.display()
    );
}

#[test]
fn tty_console_input_burst_uses_injected_guest_script() {
    let workspace_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
    let case_dir = workspace_root.join("test-suit/starryos/qemu/tty-console-input-burst");
    let script_path = case_dir.join("sh/tty-input-burst.sh");
    assert!(
        script_path.is_file(),
        "{} must inject the burst script through the rootfs instead of pasting it over the console",
        script_path.display()
    );

    let script = fs::read_to_string(&script_path)
        .unwrap_or_else(|err| panic!("failed to read {}: {err}", script_path.display()));
    assert!(
        script.contains("while [ \"$i\" -lt 120 ]")
            && script.contains("STARRY_TTY_INPUT_BURST_PASSED"),
        "{} must preserve the burst payload checks and success marker",
        script_path.display()
    );

    for arch in ["aarch64", "loongarch64", "riscv64", "x86_64"] {
        let path = case_dir.join(format!("qemu-{arch}.toml"));
        let content = fs::read_to_string(&path).unwrap();
        let config: toml::Value = toml::from_str(&content).unwrap();
        let command = config
            .get("shell_init_cmd")
            .and_then(toml::Value::as_str)
            .unwrap_or_default();

        assert_eq!(
            command,
            "/usr/bin/tty-input-burst.sh",
            "{} must only send a short command through the console",
            path.display()
        );
        assert!(
            !content.contains("cat > /tmp/tty-input-burst.sh"),
            "{} must not paste a long heredoc through the console",
            path.display()
        );
    }
}

#[test]
fn qemu_system_case_has_riscv64_runtime_config() {
    let workspace_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
    let config = workspace_root.join("test-suit/starryos/qemu/system/qemu-riscv64.toml");

    assert!(
        config.is_file(),
        "{} must keep riscv64 coverage in the unified SMP4 qemu/system case",
        config.display()
    );
}

#[test]
fn qemu_affinity_flaky_arches_are_filtered() {
    let workspace_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
    let cases = [
        (
            "affinity-bug-sched-affinity-migrate",
            "^(aarch64|x86_64)",
            "bug-sched-affinity-migrate skipped on loongarch64/riscv64 qemu",
        ),
        (
            "affinity-bug-sched-affinity-pid",
            "^(aarch64|x86_64)",
            "bug-sched-affinity-pid skipped on loongarch64/riscv64 qemu",
        ),
    ];

    for (case, arch_regex, skip_message) in cases {
        let cmake_path = workspace_root
            .join("test-suit/starryos/qemu/system")
            .join(case)
            .join("CMakeLists.txt");
        let cmake = fs::read_to_string(&cmake_path)
            .unwrap_or_else(|err| panic!("failed to read {}: {err}", cmake_path.display()));

        assert!(
            cmake.contains("starry_arch_filtered_executable")
                && cmake.contains(arch_regex)
                && cmake.contains(skip_message),
            "{} must skip flaky qemu affinity probes instead of letting them consume the grouped \
             QEMU timeout",
            cmake_path.display()
        );
    }
}

#[test]
fn zombie_bugfix_commands_are_in_system_grouped_qemu_case() {
    let workspace_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
    let system_dir = workspace_root.join("test-suit/starryos/qemu/system");
    let zombie_commands = [
        "/usr/bin/bug-kill-zombie-esrch",
        "/usr/bin/bug-kill-zombie-perm",
        "/usr/bin/bug-zombie-syscalls",
        "/usr/bin/bug-waitid-basic",
    ];

    for command in zombie_commands {
        let name = command.trim_start_matches("/usr/bin/");
        assert!(
            system_dir
                .join(format!("zombie-bugfix-{name}"))
                .join("CMakeLists.txt")
                .is_file(),
            "{} must be built in the system grouped case",
            command
        );
    }

    for arch in ["aarch64", "loongarch64", "riscv64", "x86_64"] {
        let system_path = system_dir.join(format!("qemu-{arch}.toml"));
        let system_content = fs::read_to_string(&system_path).unwrap();
        let system_config: toml::Value = toml::from_str(&system_content).unwrap();
        let system_commands = system_config
            .get("test_commands")
            .and_then(toml::Value::as_array)
            .unwrap();
        assert!(
            system_commands
                .iter()
                .filter_map(toml::Value::as_str)
                .any(|command| command.contains("/usr/bin/starry-test-suit/*")),
            "{} must scan installed system test binaries",
            system_path.display()
        );
    }
}

#[test]
fn tty_bugfix_commands_are_in_system_grouped_qemu_case() {
    let workspace_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
    let system_dir = workspace_root.join("test-suit/starryos/qemu/system");
    let tty_commands = [
        "/usr/bin/bug-raw-terminal-polling",
        "/usr/bin/bug-tty-cursor-report",
    ];

    for command in tty_commands {
        let name = command.trim_start_matches("/usr/bin/");
        assert!(
            system_dir
                .join(format!("tty-bugfix-{name}"))
                .join("CMakeLists.txt")
                .is_file(),
            "{} must be built in the system grouped case",
            command
        );
    }

    for arch in ["aarch64", "loongarch64", "riscv64", "x86_64"] {
        let system_path = system_dir.join(format!("qemu-{arch}.toml"));
        let system_content = fs::read_to_string(&system_path).unwrap();
        let system_config: toml::Value = toml::from_str(&system_content).unwrap();
        let system_commands = system_config
            .get("test_commands")
            .and_then(toml::Value::as_array)
            .unwrap();
        assert!(
            system_commands
                .iter()
                .filter_map(toml::Value::as_str)
                .any(|command| command.contains("/usr/bin/starry-test-suit/*")),
            "{} must scan installed system test binaries",
            system_path.display()
        );
    }
}

#[test]
fn apk_curl_equivalence_is_in_system_grouped_qemu_case() {
    let workspace_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
    let system_dir = workspace_root.join("test-suit/starryos/qemu/system");
    let subcase_dir = system_dir.join("apk-curl-equivalence");
    let cmake_path = subcase_dir.join("CMakeLists.txt");
    let prebuild_path = system_dir.join("prebuild.sh");
    let script_path = subcase_dir.join("src/apk-curl-equivalence.sh");

    let cmake = fs::read_to_string(&cmake_path)
        .unwrap_or_else(|err| panic!("failed to read {}: {err}", cmake_path.display()));
    let prebuild = fs::read_to_string(&prebuild_path)
        .unwrap_or_else(|err| panic!("failed to read {}: {err}", prebuild_path.display()));
    let script = fs::read_to_string(&script_path)
        .unwrap_or_else(|err| panic!("failed to read {}: {err}", script_path.display()));

    assert!(
        cmake.contains("set(CURL_BIN")
            && cmake.contains("install(PROGRAMS \"${CURL_BIN}\"")
            && cmake.contains("DESTINATION usr/bin/starry-test-suit")
            && cmake.contains("RENAME apk-curl-equivalence"),
        "{} must install curl and the apk-curl equivalence script into the grouped runner",
        cmake_path.display()
    );
    assert!(
        prebuild.contains("apk add") && prebuild.contains("curl"),
        "{} must install curl into the staging rootfs",
        prebuild_path.display()
    );
    assert!(
        !subcase_dir.join("qemu-x86_64.toml").exists(),
        "{} must not carry its own qemu config; qemu/system owns runtime config",
        subcase_dir.display()
    );
    assert!(
        script.contains("APK_CURL_EQUIVALENCE_TEST_PASSED")
            && script.contains("APK_CURL_EQUIVALENCE_TEST_FAILED")
            && script.contains("curl --connect-timeout")
            && script.contains("10.0.2.2")
            && script.contains("20971520")
            && script.contains("sha256sum -c")
            && script.contains("48b6fb8f1c2fec38d030604889d674722c4af237733c913b698400b59c9294b4"),
        "{} must download the local 20MiB HTTP fixture, write it to disk, then read it back and \
         compare sha256",
        script_path.display()
    );

    for (arch, port) in [
        ("x86_64", 18380_i64),
        ("aarch64", 18381_i64),
        ("riscv64", 18382_i64),
        ("loongarch64", 18383_i64),
    ] {
        let config_path = system_dir.join(format!("qemu-{arch}.toml"));
        let content = fs::read_to_string(&config_path).unwrap();
        let config: toml::Value = toml::from_str(&content).unwrap();
        let host_http_server = config
            .get("host_http_server")
            .and_then(toml::Value::as_table)
            .unwrap_or_else(|| {
                panic!(
                    "{} must start a local host HTTP fixture for apk-curl-equivalence",
                    config_path.display()
                )
            });

        assert_eq!(
            host_http_server.get("bind").and_then(toml::Value::as_str),
            Some("127.0.0.1")
        );
        assert_eq!(
            host_http_server
                .get("port")
                .and_then(toml::Value::as_integer),
            Some(port)
        );
        assert_eq!(
            host_http_server
                .get("body_size")
                .and_then(toml::Value::as_integer),
            Some(20 * 1024 * 1024)
        );
        assert_eq!(
            host_http_server
                .get("body_byte")
                .and_then(toml::Value::as_integer),
            Some(i64::from(b'a'))
        );
    }
}