|
| 1 | +############################################################################### |
| 2 | +# |
| 3 | +# MIT License |
| 4 | +# |
| 5 | +# Copyright (c) 2025 Advanced Micro Devices, Inc. |
| 6 | +# |
| 7 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +# of this software and associated documentation files (the "Software"), to deal |
| 9 | +# in the Software without restriction, including without limitation the rights |
| 10 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | +# copies of the Software, and to permit persons to whom the Software is |
| 12 | +# furnished to do so, subject to the following conditions: |
| 13 | +# |
| 14 | +# The above copyright notice and this permission notice shall be included in all |
| 15 | +# copies or substantial portions of the Software. |
| 16 | +# |
| 17 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | +# SOFTWARE. |
| 24 | +# |
| 25 | +############################################################################### |
| 26 | +"""Functional tests for PciePlugin with --plugin-configs.""" |
| 27 | + |
| 28 | +from pathlib import Path |
| 29 | + |
| 30 | +import pytest |
| 31 | + |
| 32 | + |
| 33 | +@pytest.fixture |
| 34 | +def fixtures_dir(): |
| 35 | + """Return path to fixtures directory.""" |
| 36 | + return Path(__file__).parent / "fixtures" |
| 37 | + |
| 38 | + |
| 39 | +@pytest.fixture |
| 40 | +def pcie_config_file(fixtures_dir): |
| 41 | + """Return path to PciePlugin config file.""" |
| 42 | + return fixtures_dir / "pcie_plugin_config.json" |
| 43 | + |
| 44 | + |
| 45 | +@pytest.fixture |
| 46 | +def pcie_advanced_config_file(fixtures_dir): |
| 47 | + """Return path to PciePlugin advanced config file.""" |
| 48 | + return fixtures_dir / "pcie_plugin_advanced_config.json" |
| 49 | + |
| 50 | + |
| 51 | +def test_pcie_plugin_with_basic_config(run_cli_command, pcie_config_file, tmp_path): |
| 52 | + """Test PciePlugin using basic config file with integer values.""" |
| 53 | + assert pcie_config_file.exists(), f"Config file not found: {pcie_config_file}" |
| 54 | + |
| 55 | + log_path = str(tmp_path / "logs_pcie_basic") |
| 56 | + result = run_cli_command( |
| 57 | + ["--log-path", log_path, "--plugin-configs", str(pcie_config_file)], check=False |
| 58 | + ) |
| 59 | + |
| 60 | + assert result.returncode in [0, 1, 2] |
| 61 | + output = result.stdout + result.stderr |
| 62 | + assert len(output) > 0 |
| 63 | + assert "pcieplugin" in output.lower() or "pcie" in output.lower() |
| 64 | + |
| 65 | + |
| 66 | +def test_pcie_plugin_with_advanced_config(run_cli_command, pcie_advanced_config_file, tmp_path): |
| 67 | + """Test PciePlugin using advanced config with device-specific settings.""" |
| 68 | + assert pcie_advanced_config_file.exists(), f"Config file not found: {pcie_advanced_config_file}" |
| 69 | + |
| 70 | + log_path = str(tmp_path / "logs_pcie_advanced") |
| 71 | + result = run_cli_command( |
| 72 | + ["--log-path", log_path, "--plugin-configs", str(pcie_advanced_config_file)], |
| 73 | + check=False, |
| 74 | + ) |
| 75 | + |
| 76 | + assert result.returncode in [0, 1, 2] |
| 77 | + output = result.stdout + result.stderr |
| 78 | + assert len(output) > 0 |
| 79 | + |
| 80 | + |
| 81 | +def test_pcie_plugin_with_run_plugins_subcommand(run_cli_command, tmp_path): |
| 82 | + """Test PciePlugin using run-plugins subcommand.""" |
| 83 | + log_path = str(tmp_path / "logs_pcie_subcommand") |
| 84 | + result = run_cli_command(["--log-path", log_path, "run-plugins", "PciePlugin"], check=False) |
| 85 | + |
| 86 | + assert result.returncode in [0, 1, 2] |
| 87 | + output = result.stdout + result.stderr |
| 88 | + assert len(output) > 0 |
| 89 | + |
| 90 | + |
| 91 | +def test_pcie_plugin_with_passive_interaction(run_cli_command, pcie_config_file, tmp_path): |
| 92 | + """Test PciePlugin with PASSIVE system interaction level.""" |
| 93 | + log_path = str(tmp_path / "logs_pcie_passive") |
| 94 | + result = run_cli_command( |
| 95 | + [ |
| 96 | + "--log-path", |
| 97 | + log_path, |
| 98 | + "--sys-interaction-level", |
| 99 | + "PASSIVE", |
| 100 | + "--plugin-configs", |
| 101 | + str(pcie_config_file), |
| 102 | + ], |
| 103 | + check=False, |
| 104 | + ) |
| 105 | + |
| 106 | + assert result.returncode in [0, 1, 2] |
| 107 | + output = result.stdout + result.stderr |
| 108 | + assert len(output) > 0 |
| 109 | + |
| 110 | + |
| 111 | +def test_pcie_plugin_skip_sudo(run_cli_command, pcie_config_file, tmp_path): |
| 112 | + """Test PciePlugin with --skip-sudo flag.""" |
| 113 | + log_path = str(tmp_path / "logs_pcie_no_sudo") |
| 114 | + result = run_cli_command( |
| 115 | + [ |
| 116 | + "--log-path", |
| 117 | + log_path, |
| 118 | + "--skip-sudo", |
| 119 | + "--plugin-configs", |
| 120 | + str(pcie_config_file), |
| 121 | + ], |
| 122 | + check=False, |
| 123 | + ) |
| 124 | + |
| 125 | + assert result.returncode in [0, 1, 2] |
| 126 | + output = result.stdout + result.stderr |
| 127 | + assert len(output) > 0 |
| 128 | + |
| 129 | + |
| 130 | +def test_pcie_plugin_combined_configs( |
| 131 | + run_cli_command, pcie_config_file, pcie_advanced_config_file, tmp_path |
| 132 | +): |
| 133 | + """Test PciePlugin with multiple config files.""" |
| 134 | + log_path = str(tmp_path / "logs_pcie_combined") |
| 135 | + result = run_cli_command( |
| 136 | + [ |
| 137 | + "--log-path", |
| 138 | + log_path, |
| 139 | + "--plugin-configs", |
| 140 | + str(pcie_config_file), |
| 141 | + str(pcie_advanced_config_file), |
| 142 | + ], |
| 143 | + check=False, |
| 144 | + ) |
| 145 | + |
| 146 | + assert result.returncode in [0, 1, 2] |
| 147 | + output = result.stdout + result.stderr |
| 148 | + assert len(output) > 0 |
0 commit comments