Re: [PATCH v2] Adding stressor validation for stress-ng

John Kacur <[email protected]>
Newsgroups org.kernel.vger.linux-rt-users
Message-ID <[email protected]>
Hi Sana,

I have one suggestion about error handling:

**Issue: Silent failure when stress-ng is not installed**

In `get_valid_stressors()`, when stress-ng is not found, the function returns an empty list:

```python
except (subprocess.CalledProcessError, FileNotFoundError):
    return []
```

Then in `validate_stressor()`, this empty list causes validation to silently pass:

```python
if not valid:
    return  # Allows any stressor name through
```

**Suggested fix:**

```python
def get_valid_stressors():
    """Query stress-ng for list of valid stressor names."""
    try:
        result = subprocess.run(['stress-ng', '--stressors'],
                                capture_output=True, text=True, check=True)
        return result.stdout.strip().split()
    except FileNotFoundError:
        print("stress-ng is not installed. Please install the stress-ng package.")
        sys.exit(1)
    except subprocess.CalledProcessError as e:
        print(f"Failed to query stress-ng stressors: {e}")
        sys.exit(1)
```

This follows the pattern used in rteval/cpupower.py and gives users a clear error message during `_WorkloadPrepare()` instead of a cryptic failure later.

Thanks
John Kacur
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.