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

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

80.0
/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);
×
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> {
67✔
28
    kmsg_at(if log_enabled!(log::Level::Debug) {
67✔
29
        "/dev/kmsg"
1✔
30
    } else {
31
        "/dev/null"
66✔
32
    })
33
}
67✔
34

35
/// Internal: open the given path for writing. Extracted for testability.
36
fn kmsg_at(path: &str) -> Result<File> {
70✔
37
    OpenOptions::new()
70✔
38
        .write(true)
70✔
39
        .open(path)
70✔
40
        .with_context(|| format!("open {}", path))
70✔
41
}
70✔
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() {
1✔
53
        // /dev/null is always writable, no root needed
54
        let file = kmsg_at("/dev/null");
1✔
55
        assert!(file.is_ok());
1✔
56
    }
1✔
57

58
    #[test]
59
    fn test_kmsg_at_nonexistent() {
1✔
60
        let err = kmsg_at("/nonexistent/path").unwrap_err();
1✔
61
        // Should contain the path in the error context
62
        assert!(
1✔
63
            err.to_string().contains("/nonexistent/path"),
1✔
64
            "error should mention the path: {}",
×
65
            err
66
        );
67
    }
1✔
68

69
    #[test]
70
    fn test_kmsg_at_temp_file() {
1✔
71
        // Create a temp file to verify we can write to it
72
        let temp = NamedTempFile::new().unwrap();
1✔
73
        let path = temp.path().to_str().unwrap();
1✔
74
        let mut file = kmsg_at(path).unwrap();
1✔
75
        assert!(file.write_all(b"test").is_ok());
1✔
76
    }
1✔
77

78
    #[test]
79
    #[serial]
80
    fn test_kmsg_routes_to_dev_null_when_log_off() {
1✔
81
        // Default log level is Off, so kmsg() should open /dev/null
82
        log::set_max_level(log::LevelFilter::Off);
1✔
83
        let file = kmsg();
1✔
84
        assert!(file.is_ok());
1✔
85
    }
86

87
    #[test]
88
    #[serial]
89
    fn test_kmsg_routes_to_kmsg_when_debug() {
1✔
90
        require_root();
1✔
91
        // When debug is enabled, kmsg() should open /dev/kmsg
92
        log::set_max_level(log::LevelFilter::Debug);
1✔
93
        let file = kmsg();
1✔
94
        assert!(file.is_ok());
1✔
95
        log::set_max_level(log::LevelFilter::Off);
1✔
96
    }
97

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