Skip to content

Commit 35441b6

Browse files
committed
functional test
1 parent 306b68d commit 35441b6

File tree

5 files changed

+255
-1
lines changed

5 files changed

+255
-1
lines changed

test/functional/conftest.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
"""Shared fixtures for functional tests."""
27+
28+
import subprocess
29+
import sys
30+
from typing import List
31+
32+
import pytest
33+
34+
35+
@pytest.fixture
36+
def run_cli_command():
37+
"""Fixture that returns a function to run CLI commands."""
38+
39+
def _run_command(args: List[str], check: bool = False):
40+
"""Run a node-scraper CLI command.
41+
42+
Args:
43+
args: List of command-line arguments
44+
check: If True, raise CalledProcessError on non-zero exit
45+
46+
Returns:
47+
subprocess.CompletedProcess instance
48+
"""
49+
cmd = [sys.executable, "-m", "nodescraper.cli.cli"] + args
50+
return subprocess.run(
51+
cmd,
52+
capture_output=True,
53+
text=True,
54+
check=check,
55+
)
56+
57+
return _run_command
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"global_args": {},
3+
"plugins": {
4+
"PciePlugin": {
5+
"analysis_args": {
6+
"exp_speed": 5,
7+
"exp_width": 16,
8+
"exp_sriov_count": 8,
9+
"exp_gpu_count_override": 4,
10+
"exp_max_payload_size": {
11+
"29631": 256,
12+
"29711": 512
13+
},
14+
"exp_max_rd_req_size": {
15+
"29631": 512,
16+
"29711": 1024
17+
},
18+
"exp_ten_bit_tag_req_en": {
19+
"29631": 1,
20+
"29711": 0
21+
}
22+
}
23+
}
24+
},
25+
"result_collators": {},
26+
"name": "PciePlugin advanced config",
27+
"desc": "Advanced config for testing PciePlugin with device-specific settings"
28+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"global_args": {},
3+
"plugins": {
4+
"PciePlugin": {
5+
"analysis_args": {
6+
"exp_speed": 5,
7+
"exp_width": 16,
8+
"exp_sriov_count": 8,
9+
"exp_gpu_count_override": 4,
10+
"exp_max_payload_size": 256,
11+
"exp_max_rd_req_size": 512,
12+
"exp_ten_bit_tag_req_en": 1
13+
}
14+
}
15+
},
16+
"result_collators": {},
17+
"name": "PciePlugin config",
18+
"desc": "Config for testing PciePlugin"
19+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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

test/unit/plugin/test_sysctl_analyzer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ def test_analyzer_mismatch(analyzer, correct_data):
3838
args = SysctlAnalyzerArgs(exp_vm_swappiness=3, exp_vm_numa_balancing=4)
3939
result = analyzer.analyze_data(correct_data, args)
4040
assert result.status == ExecutionStatus.ERROR
41-
assert "2 sysctl parameter(s) mismatched. (1 errors)" in result.message
41+
assert "2 sysctl parameter(s) mismatched." in result.message
42+
assert "1 errors" in result.message
43+
assert "Sysctl mismatch detected" in result.message

0 commit comments

Comments
 (0)