Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve unit test and code coverage #15

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,34 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- name: Build
run: cargo build --verbose
- name: Extract test data
run: make extract_test_data
- name: Run tests
run: cargo test --verbose
env:
CARGO_INCREMENTAL: '0'
RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
- name: rust-grcov
id: coverage
# You may pin to the exact commit or the version.
# uses: actions-rs/grcov@bb47b1ed7883a1502fa6875d562727ace2511248
uses: actions-rs/[email protected]
- name: Codecov
# You may pin to the exact commit or the version.
# uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v4.0.1
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
# Repository upload token - get it from codecov.io. Required only for private repositories
# token: # optional
# Specify whether the Codecov output should be verbose
verbose: true
fail_ci_if_error: true
fail_ci_if_error: true
file: ${{ steps.coverage.outputs.report }}
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ validate: ## Validate code

.PHONY: test
test: extract_test_data ## Run unit tests
sudo $(CARGO) test
$(CARGO) test

.PHONY: create_test_data
create_test_data: ## create test data fixtures archive
Expand Down Expand Up @@ -59,7 +59,7 @@ crate-publish: ## Publish crate

.PHONY: clean
clean: ## Cleanup
sudo rm -rf target
rm -rf target
rm -rf ./test_data/fixtures

#=================================================
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# procsys [![][img_crates]][crates] [![][img_doc]][doc]
# procsys [![][img_crates]][crates] [![][img_doc]][doc] [![][img_codecov]][codecov]

Rust library to retrieve system, kernel, and process metrics from the pseudo-filesystems /proc and /sys.

Expand Down Expand Up @@ -38,6 +38,8 @@ Licensed under the [MIT License](https://github.com/navidys/procsys/blob/main/LI

[img_crates]: https://img.shields.io/crates/v/procsys.svg
[img_doc]: https://img.shields.io/badge/rust-documentation-blue.svg
[img_codecov]: https://codecov.io/gh/navidys/procsys/branch/main/graph/badge.svg

[crates]: https://crates.io/crates/procsys
[doc]: https://docs.rs/procsys/
[codecov]: https://codecov.io/gh/navidys/procsys
26 changes: 16 additions & 10 deletions src/sysfs/class_cooling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,21 @@ mod tests {
fn cooling_devices() {
let cooling_class_path = Path::new("test_data/fixtures/sys/class/thermal/");
let cdev = collect_from(cooling_class_path).expect("collecting cooling information");
assert!(cdev.len().eq(&2));
assert!(cdev[0].name.eq("cooling_device0"));
assert!(cdev[0].cur_state.eq(&0));
assert!(cdev[0].max_state.eq(&50));
assert!(cdev[0].cooling_type.eq("Processor"));

assert!(cdev[1].name.eq("cooling_device1"));
assert!(cdev[1].cur_state.eq(&-1));
assert!(cdev[1].max_state.eq(&27));
assert!(cdev[1].cooling_type.eq("intel_powerclamp"));

for cooling in cdev {
match cooling.name.as_str() {
"cooling_device0" => {
assert!(cooling.cur_state.eq(&0));
assert!(cooling.max_state.eq(&50));
assert!(cooling.cooling_type.eq("Processor"));
}
"cooling_device1" => {
assert!(cooling.cur_state.eq(&-1));
assert!(cooling.max_state.eq(&27));
assert!(cooling.cooling_type.eq("intel_powerclamp"));
}
_ => panic!("invalid cooling device: {}", cooling.name),
}
}
}
}
2 changes: 1 addition & 1 deletion src/sysfs/class_dmi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl DMI {

/// attempts to collect dmi information
/// # Example
/// ```
/// ```no_run
/// use procsys::sysfs::class_dmi;
///
/// let dmi_info = class_dmi::collect().expect("dmi information");
Expand Down
32 changes: 19 additions & 13 deletions src/sysfs/class_thermal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,24 @@ mod tests {
let tdev =
collect_from(thermal_zone_class_path).expect("collecting system thermal information");
assert!(tdev.len().eq(&2));
assert!(tdev[0].name.eq("thermal_zone0"));
assert!(tdev[0].zone_type.eq("bcm2835_thermal"));
assert!(tdev[0].policy.eq("step_wise"));
assert!(tdev[0].mode.is_none());
assert!(tdev[0].temp.eq(&49925));
assert!(tdev[0].passive.is_none());

assert!(tdev[1].name.eq("thermal_zone1"));
assert!(tdev[1].zone_type.eq("acpitz"));
assert!(tdev[1].policy.eq("step_wise"));
assert!(tdev[1].mode.unwrap());
assert!(tdev[1].temp.eq(&-44000));
assert!(tdev[1].passive.unwrap().eq(&0));
for thermal in tdev {
match thermal.name.as_str() {
"thermal_zone0" => {
assert_eq!(thermal.zone_type, "bcm2835_thermal");
assert_eq!(thermal.policy, "step_wise");
assert!(thermal.mode.is_none());
assert!(thermal.temp.eq(&49925));
assert!(thermal.passive.is_none());
}
"thermal_zone1" => {
assert_eq!(thermal.zone_type, "acpitz");
assert_eq!(thermal.policy, "step_wise");
assert!(thermal.mode.unwrap());
assert!(thermal.temp.eq(&-44000));
assert!(thermal.passive.unwrap().eq(&0));
}
_ => panic!("invalid thermal zone: {}", thermal.name),
}
}
}
}
Loading