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

NVIDIA / nvrc / 20375622957

19 Dec 2025 04:10PM UTC coverage: 80.415% (+51.8%) from 28.618%
20375622957

push

github

web-flow
Merge pull request #84 from zvonkok/coreutils-100percent

NVRC complete code coverage

69 of 83 new or added lines in 11 files covered. (83.13%)

3 existing lines in 3 files now uncovered.

271 of 337 relevant lines covered (80.42%)

1.62 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 err = kmsg_at("/nonexistent/path").unwrap_err();
61
        // Should contain the path in the error context
62
        assert!(
63
            err.to_string().contains("/nonexistent/path"),
64
            "error should mention the path: {}",
65
            err
66
        );
67
    }
68

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

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

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

98
    #[test]
99
    #[serial]
100
    fn test_kernlog_setup() {
101
        require_root();
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 [
107
            "/proc/sys/net/core/rmem_default",
108
            "/proc/sys/net/core/wmem_default",
109
            "/proc/sys/net/core/rmem_max",
110
            "/proc/sys/net/core/wmem_max",
111
        ] {
112
            let result = fs::write(path, b"16777216");
113
            assert!(result.is_ok(), "failed to write {}", path);
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