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

NVIDIA / nvrc / 20885173282

10 Jan 2026 10:13PM UTC coverage: 97.615% (+0.002%) from 97.613%
20885173282

Pull #94

github

web-flow
Merge 77312f8f8 into 3ba850701
Pull Request #94: README: add updated readme

11 of 11 new or added lines in 2 files covered. (100.0%)

4 existing lines in 2 files now uncovered.

1228 of 1258 relevant lines covered (97.62%)

9.27 hits per line

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

98.46
/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
use std::sync::Once;
7

8
static KERNLOG_INIT: Once = Once::new();
9

10
/// Socket buffer size (16MB = 16 * 1024 * 1024 = 16777216 bytes).
11
/// Large buffers prevent message loss during high-throughput GPU operations
12
/// where NVIDIA drivers may emit bursts of diagnostic data.
13
const SOCKET_BUFFER_SIZE: &str = "16777216";
14

15
/// Initialize kernel logging and tune socket buffer sizes.
16
/// Large buffers (16MB) prevent message loss during high-throughput GPU operations
17
/// where drivers may emit bursts of diagnostic data.
18
pub fn kernlog_setup() -> Result<()> {
2✔
19
    KERNLOG_INIT.call_once(|| {
2✔
20
        let _ = kernlog::init();
2✔
21
    });
2✔
22
    log::set_max_level(log::LevelFilter::Off);
2✔
23
    for path in [
8✔
24
        "/proc/sys/net/core/rmem_default",
25
        "/proc/sys/net/core/wmem_default",
2✔
26
        "/proc/sys/net/core/rmem_max",
2✔
27
        "/proc/sys/net/core/wmem_max",
2✔
28
    ] {
29
        fs::write(path, SOCKET_BUFFER_SIZE.as_bytes()).with_context(|| format!("write {}", path))?;
8✔
30
    }
31
    Ok(())
2✔
32
}
2✔
33

34
/// Get a file handle for kernel message output.
35
/// Routes to /dev/kmsg when debug logging is enabled for visibility in dmesg,
36
/// otherwise /dev/null to suppress noise in production.
37
pub fn kmsg() -> Result<File> {
127✔
38
    kmsg_at(if log_enabled!(log::Level::Debug) {
127✔
39
        "/dev/kmsg"
2✔
40
    } else {
41
        "/dev/null"
125✔
42
    })
43
}
127✔
44

45
/// Internal: open the given path for writing. Extracted for testability.
46
fn kmsg_at(path: &str) -> Result<File> {
133✔
47
    OpenOptions::new()
133✔
48
        .write(true)
133✔
49
        .open(path)
133✔
50
        .with_context(|| format!("open {}", path))
133✔
51
}
133✔
52

53
#[cfg(test)]
54
mod tests {
55
    use super::*;
56
    use crate::test_utils::require_root;
57
    use serial_test::serial;
58
    use std::io::Write;
59
    use tempfile::NamedTempFile;
60

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

68
    #[test]
69
    fn test_kmsg_at_nonexistent() {
2✔
70
        let err = kmsg_at("/nonexistent/path").unwrap_err();
2✔
71
        // Should contain the path in the error context
72
        assert!(
2✔
73
            err.to_string().contains("/nonexistent/path"),
2✔
UNCOV
74
            "error should mention the path: {}",
×
75
            err
76
        );
77
    }
2✔
78

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

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

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

108
    #[test]
109
    #[serial]
110
    fn test_kernlog_setup() {
2✔
111
        require_root();
2✔
112

113
        const PATHS: [&str; 4] = [
114
            "/proc/sys/net/core/rmem_default",
115
            "/proc/sys/net/core/wmem_default",
116
            "/proc/sys/net/core/rmem_max",
117
            "/proc/sys/net/core/wmem_max",
118
        ];
119

120
        // RAII guard to restore original values after test
121
        struct Restore(Vec<(&'static str, String)>);
122
        impl Drop for Restore {
123
            fn drop(&mut self) {
2✔
124
                for (path, value) in &self.0 {
10✔
125
                    let _ = fs::write(path, value.as_bytes());
8✔
126
                }
8✔
127
            }
2✔
128
        }
129

130
        let saved: Vec<_> = PATHS
2✔
131
            .iter()
2✔
132
            .filter_map(|&p| fs::read_to_string(p).ok().map(|v| (p, v)))
8✔
133
            .collect();
2✔
134
        let _restore = Restore(saved);
2✔
135

136
        assert!(kernlog_setup().is_ok());
2✔
137

138
        for &path in &PATHS {
10✔
139
            let v = fs::read_to_string(path).expect("should read sysctl");
8✔
140
            assert_eq!(v.trim(), SOCKET_BUFFER_SIZE, "sysctl {} should be {}", path, SOCKET_BUFFER_SIZE);
8✔
141
        }
142
    }
143
}
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