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

dev: run all tests in CI #483

Merged
merged 9 commits into from
Mar 6, 2025
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
6 changes: 4 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ jobs:
- name: Update repos
run: sudo apt update
- name: Install dependencies
run: sudo apt install -y libgtk-4-dev pkg-config libvulkan-dev libdrm-dev blueprint-compiler
run: sudo apt install -y libgtk-4-dev pkg-config libvulkan-dev libdrm-dev blueprint-compiler curl fuse3 libfuse-dev
- name: Update pci.ids
run: sudo curl -o /usr/share/hwdata/pci.ids https://pci-ids.ucw.cz/v2.2/pci.ids
- name: Build
run: cargo build
- name: Run tests
run: cargo test --verbose --no-default-features -p lact
run: cargo test --verbose

check-format:
runs-on: ubuntu-24.04
Expand Down
27 changes: 23 additions & 4 deletions lact-daemon/src/server/gpu_controller/intel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,30 @@ impl IntelGpuController {
debug!("writing value '{contents}' to '{file_prefix}*{file_suffix}'");

if let Some(hwmon_path) = &self.hwmon_path {
let mut files = Vec::with_capacity(1);

let entries = fs::read_dir(hwmon_path)?;
for entry in entries.flatten() {
if let Some(name) = entry.file_name().to_str() {
if name.starts_with(file_prefix) && name.ends_with(file_suffix) {
return self.write_file(entry.path(), contents);
if let Some(infix) = name
.strip_prefix(file_prefix)
.and_then(|name| name.strip_suffix(file_suffix))
{
if !infix.contains('_') {
files.push(entry.path());
}
}
}
}
}
files.sort_unstable();

Err(anyhow!("File not found"))
if let Some(entry) = files.first() {
self.write_file(entry, contents)
} else {
Err(anyhow!("File not found"))
}
} else {
Err(anyhow!("No hwmon available"))
}
Expand Down Expand Up @@ -302,10 +316,15 @@ impl IntelGpuController {
fn get_power_usage(&self) -> Option<f64> {
self.read_hwmon_file::<u64>("power", "_input")
.or_else(|| {
let energy = self.read_hwmon_file("energy", "_input")?;
let energy = self.read_hwmon_file::<u64>("energy", "_input")?;
let timestamp = Instant::now();

match self.last_energy_value.replace(Some((timestamp, energy))) {
#[cfg(not(test))]
let last_value = self.last_energy_value.replace(Some((timestamp, energy)));
#[cfg(test)]
let last_value: Option<(Instant, u64)> = None;

match last_value {
Some((last_timestamp, last_energy)) => {
let time_delta = timestamp - last_timestamp;
let energy_delta = energy - last_energy;
Expand Down
2 changes: 2 additions & 0 deletions lact-daemon/src/tests/data/intel/a380-i915/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
power_cap: 60
max_core_clock: 2100
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
source: lact-daemon/src/tests/mod.rs
expression: write_commands
---
[
"card1/gt_max_freq_mhz: 2100",
"card1/device/hwmon/hwmon1/power1_max: 60000000",
]
2 changes: 1 addition & 1 deletion lact-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Ilya Zlobintsev <ilya.zl@protonmail.com>"]
edition = "2021"

[features]
default = ["gtk-tests"]
default = []
gtk-tests = []
adw = ["dep:adw", "relm4/libadwaita"]
bench = ["dep:divan"]
Expand Down