Skip to content

CPU module: autils migration prep and tests#6279

Merged
richtja merged 2 commits intoavocado-framework:masterfrom
harvey0100:cpu
Mar 25, 2026
Merged

CPU module: autils migration prep and tests#6279
richtja merged 2 commits intoavocado-framework:masterfrom
harvey0100:cpu

Conversation

@harvey0100
Copy link
Copy Markdown
Contributor

This PR prepares the avocado.utils.cpu module for migration to autils by improving tests and documentation. It adds 29 unit tests and 14 functional tests, raising coverage from about 50% to 85%. Tests cover get_revision, get_va_bits, get_model, get_x86_amd_zen, total_count, online_count, hotplug, frequency governor, NUMA, lscpu, and error paths. The module gets RST docstrings, is removed from the pylint ignore list, and is added to the autils migration announcement workflow.

@harvey0100 harvey0100 requested review from clebergnu and richtja March 3, 2026 13:03
@mr-avocado mr-avocado bot moved this to Review Requested in Default project Mar 3, 2026
@harvey0100 harvey0100 changed the title Cpu CPU module: autils migration prep and tests Mar 3, 2026
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness and clarity of the avocado.utils.cpu module, laying the groundwork for its future migration to the autils library. By introducing a comprehensive suite of new unit and functional tests, the module's reliability is greatly improved. Concurrently, the documentation has been standardized and enriched, making the module's functionalities easier to understand and maintain. These changes collectively ensure the module is well-tested and clearly documented, facilitating its integration into a broader utility framework.

Highlights

  • Test Coverage Improvement: Added 29 new unit tests and 14 new functional tests for the avocado.utils.cpu module, significantly raising test coverage from approximately 50% to 85%.
  • Documentation Enhancement: Updated all docstrings in avocado.utils.cpu to reStructuredText (RST) format, providing more detailed and standardized documentation for functions and classes.
  • Pylint Integration: Removed cpu.py from the .pylintrc_utils ignore list, enabling static analysis for the module and ensuring code quality standards.
  • Autils Migration Preparation: Prepared the avocado.utils.cpu module for migration to autils by improving its test suite and documentation, and added it to the autils migration announcement workflow.
  • Expanded Test Scope: New tests cover a wide range of CPU functionalities including get_revision, get_va_bits, get_model, get_x86_amd_zen, total_count, online_count, hotplug capabilities, frequency governor settings, NUMA topology, lscpu parsing, and various error paths.
Changelog
  • .pylintrc_utils
    • Removed cpu.py from the ignore list to enable Pylint checks for the module.
  • avocado/utils/cpu.py
    • Updated module docstring to RST format, providing a comprehensive overview of its utilities.
    • Added a docstring to FamilyException for better clarity.
    • Refactored docstrings for _list_matches, _get_info, _get_status, cpu_has_flags, get_version, get_vendor, get_revision, get_va_bits, get_arch, get_family, get_model, get_x86_amd_zen, online_list, total_count, online_count, is_hotpluggable, online, offline, get_idle_state, _bool_to_binary, set_idle_state, set_freq_governor, get_freq_governor, get_pid_cpus, get_numa_node_has_cpus, numa_nodes_with_assigned_cpus, _deprecated, and lscpu to conform to RST format and improve descriptiveness.
    • Corrected conditional check in get_x86_amd_zen from if not family: to if family is None: for explicit None checking.
  • selftests/check.py
    • Updated the expected count for unit tests from 965 to 994.
    • Updated the expected count for functional-parallel tests from 366 to 380.
  • selftests/functional/utils/cpu.py
    • Added a new file containing 14 functional tests for the cpu module, covering basic CPU info, NUMA, process affinity, lscpu integration, and x86-specific functions.
  • selftests/unit/utils/cpu.py
    • Added new unit tests for get_vendor to cover cases where no vendor is found.
    • Added new unit tests for get_version to handle unsupported architectures.
    • Added new unit tests for get_family to test FamilyException on missing files and NotImplementedError for unsupported architectures.
    • Added new unit tests for get_idle_state to handle IOError during state file reading.
    • Added new unit tests for set_idle_state to handle IOError during state file writing.
    • Added new unit tests for get_revision to verify correct parsing and None return for missing revision.
    • Added new unit tests for get_va_bits to verify correct parsing and empty string return for missing info.
    • Added new unit tests for get_model to cover x86_64, NotImplementedError for other architectures, and None return for missing model line.
    • Added new unit tests for get_x86_amd_zen to test explicit family/model parameters and cases where no Zen generation matches.
    • Added new unit tests for total_count and online_count.
    • Added new unit tests for is_hotpluggable for both true and false scenarios.
    • Added new unit tests for online and offline functions, including failure scenarios.
    • Added new unit tests for get_freq_governor to test successful reads and IOError handling.
    • Added new unit tests for set_freq_governor to test scenarios where no current governor is found.
    • Added new unit tests for get_numa_node_has_cpus to verify correct parsing.
    • Added new unit tests for lscpu to verify correct output parsing.
    • Added a test for the total_cpus_count deprecated alias.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/autils_migration_announcement.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great step towards migrating the avocado.utils.cpu module. The addition of comprehensive unit and functional tests significantly improves the module's reliability and maintainability. The documentation has also been greatly improved with more detailed and consistent docstrings. I've found a minor typo in a deprecation warning message and suggested a fix. Overall, this is a high-quality contribution.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.10%. Comparing base (8fa8228) to head (dea3a14).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6279      +/-   ##
==========================================
+ Coverage   73.70%   74.10%   +0.40%     
==========================================
  Files         206      206              
  Lines       22620    22634      +14     
==========================================
+ Hits        16673    16774     +101     
+ Misses       5947     5860      -87     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@harvey0100 harvey0100 force-pushed the cpu branch 4 times, most recently from 64e6ca2 to c44014c Compare March 3, 2026 14:32
@harvey0100 harvey0100 force-pushed the cpu branch 4 times, most recently from 130b13c to 172a310 Compare March 12, 2026 13:46
Copy link
Copy Markdown
Contributor

@richtja richtja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @harvey0100, thank you for preparing the CPU migration. I have a couple of questions so please have a look.

Add comprehensive unit test coverage for the cpu module:

- 29 new unit tests (28->57) covering get_revision, get_va_bits, get_model,
  get_x86_amd_zen, total_count, online_count, is_hotpluggable, online/offline,
  get_freq_governor, get_numa_node_has_cpus, lscpu, plus error paths and
  edge cases (FamilyException, NotImplementedError, IOError handling)
- Update TEST_SIZE in check.py (unit: 976->1005)

Coverage increased from 50% to 85%.

Assisted-By: Cursor-Claude-4-Sonnet
Signed-off-by: Harvey Lynden <hlynden@redhat.com>
Made-with: Cursor
- Fix get_x86_amd_zen to handle model=0 and family=0 (use 'is None' check
  instead of truthiness, since 0 is valid for AMD Zen 1)
- Add module docstring and enhance function RST docstrings (pylint-compliant)
- Remove from .pylintrc_utils ignore list to enable pylint checking
- Add to autils_migration_announcement workflow
- Fix RST docstring markup for Sphinx (escape *args/**kwargs and path patterns)
- Fix deprecation message typo (deprecat+ed -> deprecated)

Assisted-By: Cursor-Claude-4-Sonnet
Signed-off-by: Harvey Lynden <hlynden@redhat.com>
Made-with: Cursor
Copy link
Copy Markdown
Contributor

@richtja richtja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @harvey0100, thanks for the updates. it LTGM.

@richtja richtja merged commit 111715e into avocado-framework:master Mar 25, 2026
60 checks passed
@github-project-automation github-project-automation bot moved this from Review Requested to Done 114 in Default project Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done 114

Development

Successfully merging this pull request may close these issues.

2 participants