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

NVIDIA / nvrc / 20358693314

19 Dec 2025 03:18AM UTC coverage: 68.196% (+39.6%) from 28.618%
20358693314

Pull #84

github

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

34 of 45 new or added lines in 6 files covered. (75.56%)

4 existing lines in 4 files now uncovered.

223 of 327 relevant lines covered (68.2%)

1.33 hits per line

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

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

4
use anyhow::{Context, Result};
5
use std::fs::{self, File, OpenOptions};
6

7
/// Initialize kernel logging and tune socket buffer sizes.
8
/// Large buffers (16MB) prevent message loss during high-throughput GPU operations
9
/// where drivers may emit bursts of diagnostic data.
10
pub fn kernlog_setup() -> Result<()> {
×
11
    kernlog::init().context("kernel log init")?;
×
12
    log::set_max_level(log::LevelFilter::Off);
×
UNCOV
13
    for path in [
×
14
        "/proc/sys/net/core/rmem_default",
15
        "/proc/sys/net/core/wmem_default",
16
        "/proc/sys/net/core/rmem_max",
17
        "/proc/sys/net/core/wmem_max",
18
    ] {
19
        fs::write(path, b"16777216").with_context(|| format!("write {}", path))?;
×
20
    }
21
    Ok(())
×
22
}
23

24
/// Get a file handle for kernel message output.
25
/// Routes to /dev/kmsg when debug logging is enabled for visibility in dmesg,
26
/// otherwise /dev/null to suppress noise in production.
27
pub fn kmsg() -> Result<File> {
3✔
28
    kmsg_at(if log_enabled!(log::Level::Debug) {
10✔
29
        "/dev/kmsg"
1✔
30
    } else {
31
        "/dev/null"
3✔
32
    })
33
}
34

35
/// Internal: open the given path for writing. Extracted for testability.
36
fn kmsg_at(path: &str) -> Result<File> {
4✔
37
    OpenOptions::new()
8✔
38
        .write(true)
39
        .open(path)
4✔
40
        .with_context(|| format!("open {}", path))
6✔
41
}
42

43
#[cfg(test)]
44
mod tests {
45
    use super::*;
46
    use nix::unistd::Uid;
47
    use serial_test::serial;
48
    use std::env;
49
    use std::io::Write;
50
    use std::process::Command;
51
    use tempfile::NamedTempFile;
52

53
    fn require_root() {
54
        if Uid::effective().is_root() {
55
            return;
56
        }
57
        let args: Vec<String> = env::args().collect();
58
        let status = Command::new("sudo").args(&args).status().expect("sudo");
59
        std::process::exit(status.code().unwrap_or(1));
60
    }
61

62
    #[test]
63
    fn test_kmsg_at_dev_null() {
64
        // /dev/null is always writable, no root needed
65
        let file = kmsg_at("/dev/null");
66
        assert!(file.is_ok());
67
    }
68

69
    #[test]
70
    fn test_kmsg_at_nonexistent() {
71
        let file = kmsg_at("/nonexistent/path");
72
        assert!(file.is_err());
73
    }
74

75
    #[test]
76
    fn test_kmsg_at_temp_file() {
77
        // Create a temp file to verify we can write to it
78
        let temp = NamedTempFile::new().unwrap();
79
        let path = temp.path().to_str().unwrap();
80
        let mut file = kmsg_at(path).unwrap();
81
        assert!(file.write_all(b"test").is_ok());
82
    }
83

84
    #[test]
85
    #[serial]
86
    fn test_kmsg_routes_to_dev_null_when_log_off() {
87
        // Default log level is Off, so kmsg() should open /dev/null
88
        log::set_max_level(log::LevelFilter::Off);
89
        let file = kmsg();
90
        assert!(file.is_ok());
91
    }
92

93
    #[test]
94
    #[serial]
95
    fn test_kmsg_routes_to_kmsg_when_debug() {
96
        require_root();
97
        // When debug is enabled, kmsg() should open /dev/kmsg
98
        log::set_max_level(log::LevelFilter::Debug);
99
        let file = kmsg();
100
        assert!(file.is_ok());
101
        log::set_max_level(log::LevelFilter::Off);
102
    }
103

104
    #[test]
105
    #[serial]
106
    fn test_kernlog_setup() {
107
        require_root();
108
        // kernlog_setup requires root for /proc/sys writes.
109
        // Note: kernlog::init() can only be called once per process,
110
        // so this test may fail if other tests already initialized it.
111
        // We just test the /proc/sys writes succeed by calling them directly.
112
        for path in [
113
            "/proc/sys/net/core/rmem_default",
114
            "/proc/sys/net/core/wmem_default",
115
            "/proc/sys/net/core/rmem_max",
116
            "/proc/sys/net/core/wmem_max",
117
        ] {
118
            let result = fs::write(path, b"16777216");
119
            assert!(result.is_ok(), "failed to write {}", path);
120
        }
121
    }
122
}
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