• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NVIDIA / nvrc / 26844780112

02 Jun 2026 08:02PM UTC coverage: 94.195%. First build
26844780112

Pull #166

github

web-flow
Merge 0bfe218c6 into 8ceda0162
Pull Request #166: hash: log version and sha256 of /proc/self/exe at boot

99 of 104 new or added lines in 3 files covered. (95.19%)

2012 of 2136 relevant lines covered (94.19%)

17.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/src/init.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// Copyright (c) NVIDIA CORPORATION
3

4
use crate::hash;
5

6
/// NVRC's init duties (mounts, module loads, daemon forks, the poweroff panic
7
/// hook) would wreck a normal host, so they must only run as PID 1. Anywhere
8
/// else (CI smoke test, dev shell) report identity and exit before the caller
9
/// touches anything.
NEW
10
pub fn as_pid1() {
×
NEW
11
    as_pid1_with(running_as_init(), || std::process::exit(0));
×
NEW
12
}
×
13

14
// Production exits the process; tests inject a no-op to observe the bail path
15
// without killing the runner (cf. lockdown::set_panic_hook_with).
16
fn as_pid1_with<F: FnOnce()>(is_init: bool, exit: F) {
10✔
17
    if is_init {
10✔
18
        return;
5✔
19
    }
5✔
20
    // No logger on this path, so print to stdout rather than via the dropped
21
    // log macros; this is the CI smoke test's only observable output.
22
    println!("{}", hash::version_line());
5✔
23
    exit();
5✔
24
}
10✔
25

26
// Raw SYS_getpid syscall: stays on the pure-syscall path hardened_std targets,
27
// and needs no /proc (unmounted this early, mount::setup runs later).
28
fn running_as_init() -> bool {
5✔
29
    unsafe { libc::syscall(libc::SYS_getpid) == 1 }
5✔
30
}
5✔
31

32
#[cfg(test)]
33
mod tests {
34
    use super::*;
35
    use std::cell::Cell;
36

37
    #[test]
38
    fn test_running_as_init_false_for_test_harness() {
5✔
39
        // The test runner is never PID 1, so the real syscall must report so.
40
        assert!(!running_as_init());
5✔
41
    }
5✔
42

43
    #[test]
44
    fn test_as_pid1_returns_without_exiting_when_init() {
5✔
45
        let exited = Cell::new(false);
5✔
46
        as_pid1_with(true, || exited.set(true));
5✔
47
        assert!(
5✔
48
            !exited.get(),
5✔
49
            "must fall through to the caller's init sequence"
50
        );
51
    }
5✔
52

53
    #[test]
54
    fn test_as_pid1_exits_when_not_init() {
5✔
55
        let exited = Cell::new(false);
5✔
56
        as_pid1_with(false, || exited.set(true));
5✔
57
        assert!(exited.get(), "non-PID-1 must report identity and exit");
5✔
58
    }
5✔
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc