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

NVIDIA / nvrc / 20381075488

19 Dec 2025 07:59PM UTC coverage: 89.348% (+8.9%) from 80.415%
20381075488

Pull #85

github

web-flow
Merge 40e9e3e58 into 2295d6b0d
Pull Request #85: Update coverage.yaml to use cargo-llvm-cov

1233 of 1380 relevant lines covered (89.35%)

4.08 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<()> {
29✔
13
    debug!("{} {}", command, args.join(" "));
29✔
14

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

23
    if !status.success() {
19✔
24
        return Err(anyhow!("{} failed with status: {}", command, status));
10✔
25
    }
9✔
26
    Ok(())
9✔
27
}
29✔
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> {
36✔
33
    debug!("{} {}", command, args.join(" "));
36✔
34
    let kmsg_file = kmsg().context("Failed to open kmsg device")?;
36✔
35
    Command::new(command)
36✔
36
        .args(args)
36✔
37
        .stdout(Stdio::from(kmsg_file.try_clone().unwrap()))
36✔
38
        .stderr(Stdio::from(kmsg_file))
36✔
39
        .spawn()
36✔
40
        .with_context(|| format!("Failed to start {}", command))
36✔
41
}
36✔
42

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

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

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

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

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

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

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

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

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

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

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

© 2025 Coveralls, Inc