Skip to content

Comments

[avocado-utils] : add validation for perf binary in ensure_tool()#6272

Open
Sumitupadhyay1 wants to merge 3 commits intoavocado-framework:masterfrom
Sumitupadhyay1:ensure_tools_perf
Open

[avocado-utils] : add validation for perf binary in ensure_tool()#6272
Sumitupadhyay1 wants to merge 3 commits intoavocado-framework:masterfrom
Sumitupadhyay1:ensure_tools_perf

Conversation

@Sumitupadhyay1
Copy link

@Sumitupadhyay1 Sumitupadhyay1 commented Feb 16, 2026

Testcases that depend on tools like perf, which may be a part of distro packages or custom-installed in a specific location, fail in an ungraceful manner when the binary of those tools is missing or non-functional.

  • This patch introduces a function ensure_tool() to check if the tool is present and the binary is valid.
  • If not, the function proceeds to install the tool.
  • In this way, failures due to the above-mentioned scenarios are handled gracefully.

- Added ensure_tool() function to validate availability of tools
  from either a custom binary path or distro packages.
- Returns tool version string after validation.
- Handles error cases:
  * Missing custom path
  * Non-functional binary
  * Missing package map
- Integrates with install_distro_packages() for dependency handling.

Signed-off-by: Sumit Kumar <sumitkum@amd.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello @Sumitupadhyay1, 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 enhances the avocado utility by introducing a standardized mechanism to ensure external tools, like perf, are correctly set up and functional before tests execute. This change aims to improve the reliability and reproducibility of test environments by centralizing tool validation and providing clear error feedback, whether the tool is provided via a custom path or installed through system packages.

Highlights

  • New ensure_tool() function: Introduced a new utility function ensure_tool() to validate the availability and functionality of a given tool, either from a custom binary path or by installing it via distro packages.
  • Custom Path Validation: The ensure_tool() function now checks if a tool's binary exists at a specified custom_path and verifies its functionality by attempting to run it with --version.
  • Distro Package Integration: If no custom path is provided, the function attempts to install the tool using distro_pkg_map and then validates its functionality post-installation.
  • Robust Error Handling: Added specific RuntimeError exceptions for scenarios such as a missing custom binary path, a non-functional binary, or the absence of a package map when required.
  • Version String Return: Upon successful validation, the function returns the tool's version string, ensuring that tests can confirm the correct tool is in use.
Changelog
  • avocado/utils/software_manager/distro_packages.py
    • Added ensure_tool() function to validate tool availability and return its version string.
    • Implemented checks for custom binary paths, including existence and functionality.
    • Integrated distro package installation and post-installation functionality checks.
    • Introduced error handling for missing paths, non-functional binaries, and missing package maps.
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.

@mr-avocado mr-avocado bot moved this to Review Requested in Default project Feb 16, 2026
Copy link

@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

The pull request introduces a new ensure_tool function to validate the availability and functionality of a given tool, either from a custom path or by installing it via distro packages, which improves the reliability and reproducibility of tests. However, this new utility function is vulnerable to command injection due to the use of shell=True with unvalidated user input (tool_name and custom_path). It is recommended to remove shell=True to prevent the shell from interpreting metacharacters and consider using shlex.quote() for inputs that might contain spaces. The error handling for missing paths, non-functional binaries, and missing package maps is otherwise clear and appropriate.

Sumitupadhyay1 and others added 2 commits February 16, 2026 13:20
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@Sumitupadhyay1 Sumitupadhyay1 changed the title utils/s : add validation for perf binary in ensure_tool() [avocado-utils] : add validation for perf binary in ensure_tool() Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Review Requested

Development

Successfully merging this pull request may close these issues.

1 participant