-
Notifications
You must be signed in to change notification settings - Fork 250
/
mod.rs
43 lines (39 loc) · 1.26 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use anyhow::bail;
use lazy_static::lazy_static;
use libc::{uname, utsname};
use regex::Regex;
use std::{ffi::CStr, mem};
pub mod btf_relocations;
pub mod elf;
pub mod load;
pub mod log;
pub mod rbpf;
pub mod relocations;
pub mod ring_buf;
pub mod ring_buf_async;
pub mod smoke;
pub use integration_test_macros::{integration_test, tokio_integration_test};
#[derive(Debug)]
pub struct IntegrationTest {
pub name: &'static str,
pub test_fn: fn(),
}
pub(crate) fn kernel_version() -> anyhow::Result<(u8, u8, u8)> {
lazy_static! {
static ref RE: Regex = Regex::new(r"^([0-9]+)\.([0-9]+)\.([0-9]+)").unwrap();
}
let mut data: utsname = unsafe { mem::zeroed() };
let ret = unsafe { uname(&mut data) };
assert!(ret >= 0, "libc::uname failed.");
let release_cstr = unsafe { CStr::from_ptr(data.release.as_ptr()) };
let release = release_cstr.to_string_lossy();
if let Some(caps) = RE.captures(&release) {
let major = caps.get(1).unwrap().as_str().parse().unwrap();
let minor = caps.get(2).unwrap().as_str().parse().unwrap();
let patch = caps.get(3).unwrap().as_str().parse().unwrap();
Ok((major, minor, patch))
} else {
bail!("no kernel version found");
}
}
inventory::collect!(IntegrationTest);