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

NVIDIA / nvrc / 20757892936

06 Jan 2026 06:23PM UTC coverage: 90.325% (+0.2%) from 90.137%
20757892936

Pull #89

github

web-flow
Merge 1be313cbe into 8678496dc
Pull Request #89: Improve Coverage

15 of 17 new or added lines in 6 files covered. (88.24%)

24 existing lines in 4 files now uncovered.

1251 of 1385 relevant lines covered (90.32%)

8.19 hits per line

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

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

4
use anyhow::{anyhow, Context, Result};
5
use std::process::{Child, Command, Stdio};
6

7
use crate::kmsg::kmsg;
8

9
/// Run a command and block until completion. Output goes to kmsg so it appears
10
/// in dmesg/kernel log - the only reliable log destination in minimal VMs.
11
/// Used for setup commands that must succeed before continuing (nvidia-smi, modprobe).
12
pub fn foreground(command: &str, args: &[&str]) -> Result<()> {
58✔
13
    debug!("{} {}", command, args.join(" "));
58✔
14

15
    let kmsg_file = kmsg().context("Failed to open kmsg device")?;
58✔
16
    let status = Command::new(command)
58✔
17
        .args(args)
58✔
18
        .stdout(Stdio::from(kmsg_file.try_clone().unwrap()))
58✔
19
        .stderr(Stdio::from(kmsg_file))
58✔
20
        .status()
58✔
21
        .context(format!("failed to execute {command}"))?;
58✔
22

23
    if !status.success() {
38✔
24
        return Err(anyhow!("{} failed with status: {}", command, status));
20✔
25
    }
18✔
26
    Ok(())
18✔
27
}
58✔
28

29
/// Spawn a daemon without waiting. Returns Child so caller can track it later.
30
/// Used for long-running services (nvidia-persistenced, fabricmanager) that run
31
/// alongside kata-agent. Output to kmsg for visibility in kernel log.
32
pub fn background(command: &str, args: &[&str]) -> Result<Child> {
72✔
33
    debug!("{} {}", command, args.join(" "));
72✔
34
    let kmsg_file = kmsg().context("Failed to open kmsg device")?;
72✔
35
    Command::new(command)
72✔
36
        .args(args)
72✔
37
        .stdout(Stdio::from(kmsg_file.try_clone().unwrap()))
72✔
38
        .stderr(Stdio::from(kmsg_file))
72✔
39
        .spawn()
72✔
40
        .with_context(|| format!("Failed to start {}", command))
72✔
41
}
72✔
42

43
#[cfg(test)]
44
mod tests {
45
    use super::*;
46

47
    // ==================== foreground tests ====================
48

49
    #[test]
50
    fn test_foreground_success() {
8✔
51
        let result = foreground("/bin/true", &[]);
8✔
52
        assert!(result.is_ok());
8✔
53
    }
8✔
54

55
    #[test]
56
    fn test_foreground_failure_exit_code() {
8✔
57
        // Command runs but exits non-zero
58
        let result = foreground("/bin/false", &[]);
8✔
59
        assert!(result.is_err());
8✔
60
        let err = result.unwrap_err().to_string();
8✔
61
        assert!(
8✔
62
            err.contains("failed"),
8✔
UNCOV
63
            "error should mention failure: {}",
×
64
            err
65
        );
66
    }
8✔
67

68
    #[test]
69
    fn test_foreground_not_found() {
8✔
70
        // Command doesn't exist - triggers .context() error path
71
        let result = foreground("/nonexistent/command", &[]);
8✔
72
        assert!(result.is_err());
8✔
73
        let err = result.unwrap_err().to_string();
8✔
74
        assert!(
8✔
75
            err.contains("execute"),
8✔
UNCOV
76
            "error should mention execute: {}",
×
77
            err
78
        );
79
    }
8✔
80

81
    #[test]
82
    fn test_foreground_with_args() {
8✔
83
        let result = foreground("/bin/sh", &["-c", "exit 0"]);
8✔
84
        assert!(result.is_ok());
8✔
85

86
        let result = foreground("/bin/sh", &["-c", "exit 42"]);
8✔
87
        assert!(result.is_err());
8✔
88
    }
6✔
89

90
    // ==================== background tests ====================
91

92
    #[test]
93
    fn test_background_spawns() {
8✔
94
        let result = background("/bin/sleep", &["0.01"]);
8✔
95
        assert!(result.is_ok());
8✔
96
        let mut child = result.unwrap();
8✔
97
        let status = child.wait().unwrap();
8✔
98
        assert!(status.success());
8✔
99
    }
2✔
100

101
    #[test]
102
    fn test_background_not_found() {
8✔
103
        // Command doesn't exist - triggers .with_context() error path
104
        let result = background("/nonexistent/command", &[]);
8✔
105
        assert!(result.is_err());
8✔
106
        let err = result.unwrap_err().to_string();
8✔
107
        assert!(err.contains("start"), "error should mention start: {}", err);
8✔
108
    }
8✔
109

110
    #[test]
111
    fn test_background_check_later() {
8✔
112
        let result = background("/bin/sh", &["-c", "exit 7"]);
8✔
113
        assert!(result.is_ok());
8✔
114
        let mut child = result.unwrap();
8✔
115
        let status = child.wait().unwrap();
8✔
116
        assert!(!status.success());
8✔
117
        assert_eq!(status.code(), Some(7));
8✔
118
    }
8✔
119
}
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