cargo testThis will run all tests except those marked with #[ignore] which require sudo privileges on macOS.
- Linux: All tests run without requiring sudo
- macOS: Some tests are skipped by default as they require sudo for PowerMetrics functionality
- CI/GitHub Actions: Tests automatically skip sudo requirements
On macOS, some tests require elevated privileges for PowerMetrics functionality.
sudo cargo test -- --include-ignored --test-threads=1sudo cargo test -- --ignored --test-threads=1Tests that require sudo are automatically skipped in the following scenarios:
- When running in CI/GitHub Actions
- When running without sudo privileges
- When
SKIP_SUDO_TESTS=1environment variable is set
# Skip sudo tests explicitly
SKIP_SUDO_TESTS=1 cargo testcargo test --libcargo test --test '*'# Test specific module
cargo test device::
cargo test ui::
cargo test utils::Tests in CI automatically skip sudo-requiring tests to avoid failures. The CI environment is detected through:
CIenvironment variableGITHUB_ACTIONSenvironment variable
Mark tests that require sudo with #[ignore]:
#[test]
#[ignore] // Requires sudo
fn test_powermetrics_manager() {
// Test code
}Use the helper macros provided in utils::test_helpers:
use crate::skip_without_sudo;
#[test]
fn test_that_might_need_sudo() {
skip_without_sudo!();
// Test code that requires sudo
}Or skip in CI:
use crate::skip_in_ci;
#[test]
fn test_not_for_ci() {
skip_in_ci!();
// Test code that shouldn't run in CI
}The tests/ directory contains comprehensive shell scripts for testing various aspects of all-smi, particularly containerized environments and resource detection. These scripts test real-world scenarios that unit tests cannot easily cover.
# Show all available test targets
cd tests && make help
# Run all structured tests
make all
# Run specific test
make container-cpu-frequencyFor detailed information about shell script tests, see: tests/README.md
- Container Tests: Test all-smi behavior inside Docker containers with resource limits
- CPU Frequency Detection: Validate frequency detection in various environments (x86, ARM, containers)
- Memory Limit Detection: Test cgroups v1/v2 memory limit detection
- Build-in-Container Tests: All tests build all-smi inside containers for realistic scenarios
This error occurs when running tests that require sudo without proper authentication. Solutions:
- Run tests with sudo:
sudo cargo test - Skip sudo tests:
SKIP_SUDO_TESTS=1 cargo test - Use
--excludeto skip specific test files
Some tests might hang if they're waiting for sudo password input. Use:
cargo test -- --test-threads=1 --nocaptureThis will show what's happening and run tests sequentially.