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

NVIDIA / nvrc / 20373283300

19 Dec 2025 02:40PM UTC coverage: 79.822% (+51.2%) from 28.618%
20373283300

Pull #84

github

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

67 of 85 new or added lines in 11 files covered. (78.82%)

4 existing lines in 4 files now uncovered.

269 of 337 relevant lines covered (79.82%)

1.53 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) {
12✔
29
        "/dev/kmsg"
1✔
30
    } else {
31
        "/dev/null"
4✔
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 crate::test_utils::require_root;
47
    use serial_test::serial;
48
    use std::io::Write;
49
    use tempfile::NamedTempFile;
50

51
    #[test]
52
    fn test_kmsg_at_dev_null() {
53
        // /dev/null is always writable, no root needed
54
        let file = kmsg_at("/dev/null");
55
        assert!(file.is_ok());
56
    }
57

58
    #[test]
59
    fn test_kmsg_at_nonexistent() {
60
        let file = kmsg_at("/nonexistent/path");
61
        assert!(file.is_err());
62
    }
63

64
    #[test]
65
    fn test_kmsg_at_temp_file() {
66
        // Create a temp file to verify we can write to it
67
        let temp = NamedTempFile::new().unwrap();
68
        let path = temp.path().to_str().unwrap();
69
        let mut file = kmsg_at(path).unwrap();
70
        assert!(file.write_all(b"test").is_ok());
71
    }
72

73
    #[test]
74
    #[serial]
75
    fn test_kmsg_routes_to_dev_null_when_log_off() {
76
        // Default log level is Off, so kmsg() should open /dev/null
77
        log::set_max_level(log::LevelFilter::Off);
78
        let file = kmsg();
79
        assert!(file.is_ok());
80
    }
81

82
    #[test]
83
    #[serial]
84
    fn test_kmsg_routes_to_kmsg_when_debug() {
85
        require_root();
86
        // When debug is enabled, kmsg() should open /dev/kmsg
87
        log::set_max_level(log::LevelFilter::Debug);
88
        let file = kmsg();
89
        assert!(file.is_ok());
90
        log::set_max_level(log::LevelFilter::Off);
91
    }
92

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