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

NVIDIA / nvrc / 20359643527

19 Dec 2025 04:16AM UTC coverage: 77.064% (+48.4%) from 28.618%
20359643527

Pull #84

github

web-flow
Merge 3e5c89ae7 into 5b8b670d9
Pull Request #84: NVRC complete code coverage

67 of 88 new or added lines in 10 files covered. (76.14%)

16 existing lines in 5 files now uncovered.

252 of 327 relevant lines covered (77.06%)

1.37 hits per line

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

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

4
use anyhow::{Context, Result};
5

6
use crate::execute::background;
7
use crate::nvrc::NVRC;
8
use std::fs;
9

10
/// Configurable path parameters allow testing with /bin/true instead of real
11
/// NVIDIA binaries that don't exist in the test environment.
12
impl NVRC {
13
    /// nvidia-persistenced keeps GPU state warm between container invocations,
14
    /// reducing cold-start latency. UVM persistence mode enables unified memory
15
    /// optimizations. Enabled by default since most workloads benefit from it.
NEW
16
    pub fn nvidia_persistenced(&mut self) -> Result<()> {
×
NEW
17
        self.spawn_persistenced("/var/run/nvidia-persistenced", "/bin/nvidia-persistenced")
×
18
    }
19

20
    fn spawn_persistenced(&mut self, run_dir: &str, bin: &str) -> Result<()> {
1✔
21
        fs::create_dir_all(run_dir).with_context(|| format!("create_dir_all {}", run_dir))?;
1✔
22

23
        let uvm_enabled = self.uvm_persistence_mode.unwrap_or(true);
1✔
24
        let args: &[&str] = if uvm_enabled {
2✔
25
            &["--verbose", "--uvm-persistence-mode"]
1✔
26
        } else {
27
            &["--verbose"]
1✔
28
        };
29

30
        let child = background(bin, args)?;
2✔
31
        self.track_daemon("nvidia-persistenced", child);
1✔
32
        Ok(())
1✔
33
    }
34

35
    /// nv-hostengine is the DCGM backend daemon. Only started when DCGM monitoring
36
    /// is explicitly requested - not needed for basic GPU workloads.
37
    pub fn nv_hostengine(&mut self) -> Result<()> {
1✔
38
        self.spawn_hostengine("/bin/nv-hostengine")
1✔
39
    }
40

41
    fn spawn_hostengine(&mut self, bin: &str) -> Result<()> {
1✔
42
        if !self.dcgm_enabled.unwrap_or(false) {
1✔
43
            return Ok(());
1✔
44
        }
45
        let child = background(bin, &[])?;
2✔
46
        self.track_daemon("nv-hostengine", child);
1✔
47
        Ok(())
1✔
48
    }
49

50
    /// dcgm-exporter exposes GPU metrics for Prometheus. Only started when DCGM
51
    /// is enabled - adds overhead so disabled by default.
52
    pub fn dcgm_exporter(&mut self) -> Result<()> {
1✔
53
        self.spawn_dcgm_exporter("/bin/dcgm-exporter")
1✔
54
    }
55

56
    fn spawn_dcgm_exporter(&mut self, bin: &str) -> Result<()> {
1✔
57
        if !self.dcgm_enabled.unwrap_or(false) {
1✔
58
            return Ok(());
1✔
59
        }
60
        let child = background(bin, &[])?;
2✔
61
        self.track_daemon("dcgm-exporter", child);
1✔
62
        Ok(())
1✔
63
    }
64

65
    /// NVSwitch fabric manager is only needed for multi-GPU NVLink topologies.
66
    /// Disabled by default since most VMs have single GPUs.
67
    pub fn nv_fabricmanager(&mut self) -> Result<()> {
1✔
68
        self.spawn_fabricmanager("/bin/nv-fabricmanager")
1✔
69
    }
70

71
    fn spawn_fabricmanager(&mut self, bin: &str) -> Result<()> {
1✔
72
        if !self.fabricmanager_enabled.unwrap_or(false) {
1✔
73
            return Ok(());
1✔
74
        }
75
        let child = background(bin, &[])?;
2✔
76
        self.track_daemon("nv-fabricmanager", child);
1✔
77
        Ok(())
1✔
78
    }
79
}
80

81
#[cfg(test)]
82
mod tests {
83
    use super::*;
84
    use tempfile::TempDir;
85

86
    // ==================== skip path tests ====================
87

88
    #[test]
89
    fn test_nv_hostengine_skipped_by_default() {
90
        // DCGM disabled by default - should be a no-op, no daemon spawned
91
        let mut nvrc = NVRC::default();
92
        assert!(nvrc.nv_hostengine().is_ok());
93
        assert!(nvrc.check_daemons().is_ok());
94
    }
95

96
    #[test]
97
    fn test_dcgm_exporter_skipped_by_default() {
98
        let mut nvrc = NVRC::default();
99
        assert!(nvrc.dcgm_exporter().is_ok());
100
    }
101

102
    #[test]
103
    fn test_nv_fabricmanager_skipped_by_default() {
104
        let mut nvrc = NVRC::default();
105
        assert!(nvrc.nv_fabricmanager().is_ok());
106
    }
107

108
    // ==================== success path tests with fake binaries ====================
109

110
    #[test]
111
    fn test_spawn_persistenced_success() {
112
        let tmpdir = TempDir::new().unwrap();
113
        let run_dir = tmpdir.path().join("nvidia-persistenced");
114

115
        let mut nvrc = NVRC::default();
116
        let result = nvrc.spawn_persistenced(run_dir.to_str().unwrap(), "/bin/true");
117
        assert!(result.is_ok());
118

119
        // Directory should be created
120
        assert!(run_dir.exists());
121

122
        // Daemon should be tracked and exit cleanly
123
        assert!(nvrc.check_daemons().is_ok());
124
    }
125

126
    #[test]
127
    fn test_spawn_persistenced_uvm_disabled() {
128
        let tmpdir = TempDir::new().unwrap();
129
        let run_dir = tmpdir.path().join("nvidia-persistenced");
130

131
        let mut nvrc = NVRC::default();
132
        nvrc.uvm_persistence_mode = Some(false); // Tests the else branch for args
133
        let result = nvrc.spawn_persistenced(run_dir.to_str().unwrap(), "/bin/true");
134
        assert!(result.is_ok());
135
    }
136

137
    #[test]
138
    fn test_spawn_hostengine_success() {
139
        let mut nvrc = NVRC::default();
140
        nvrc.dcgm_enabled = Some(true);
141
        let result = nvrc.spawn_hostengine("/bin/true");
142
        assert!(result.is_ok());
143
        assert!(nvrc.check_daemons().is_ok());
144
    }
145

146
    #[test]
147
    fn test_spawn_dcgm_exporter_success() {
148
        let mut nvrc = NVRC::default();
149
        nvrc.dcgm_enabled = Some(true);
150
        let result = nvrc.spawn_dcgm_exporter("/bin/true");
151
        assert!(result.is_ok());
152
    }
153

154
    #[test]
155
    fn test_spawn_fabricmanager_success() {
156
        let mut nvrc = NVRC::default();
157
        nvrc.fabricmanager_enabled = Some(true);
158
        let result = nvrc.spawn_fabricmanager("/bin/true");
159
        assert!(result.is_ok());
160
    }
161

162
    // ==================== error path tests ====================
163

164
    #[test]
165
    fn test_spawn_persistenced_binary_not_found() {
166
        let tmpdir = TempDir::new().unwrap();
167
        let run_dir = tmpdir.path().join("nvidia-persistenced");
168

169
        let mut nvrc = NVRC::default();
170
        let result = nvrc.spawn_persistenced(run_dir.to_str().unwrap(), "/nonexistent/binary");
171
        assert!(result.is_err());
172
    }
173

174
    #[test]
175
    fn test_check_daemons_empty() {
176
        let mut nvrc = NVRC::default();
177
        assert!(nvrc.check_daemons().is_ok());
178
    }
179
}
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