@@ -222,3 +222,146 @@ def test_bad_splits_ubuntu(collector, conn_mock, command_results):
222222 ]
223223 res , _ = collector .collect_data ()
224224 assert res .status == ExecutionStatus .OK
225+
226+
227+ def test_rocm_package_filtering_default_regex (collector , conn_mock , command_results ):
228+ """Test ROCm package filtering with default regex pattern."""
229+ # Mock Ubuntu system with ROCm packages
230+ ubuntu_packages = """rocm-core 5.7.0
231+ hip-runtime-amd 5.7.0
232+ hsa-rocr 1.9.0
233+ amdgpu-dkms 6.3.6
234+ gcc 11.4.0
235+ python3 3.10.12"""
236+
237+ conn_mock .run_command .side_effect = [
238+ CommandArtifact (
239+ command = "" ,
240+ exit_code = 0 ,
241+ stdout = command_results ["ubuntu_rel" ],
242+ stderr = "" ,
243+ ),
244+ CommandArtifact (
245+ command = "" ,
246+ exit_code = 0 ,
247+ stdout = ubuntu_packages ,
248+ stderr = "" ,
249+ ),
250+ ]
251+
252+ res , data = collector .collect_data ()
253+ assert res .status == ExecutionStatus .OK
254+ # Check that ROCm packages are found
255+ assert "rocm" in res .message .lower ()
256+ assert data is not None
257+ # Verify all packages are collected
258+ assert len (data .version_info ) == 6
259+
260+
261+ def test_rocm_package_filtering_custom_regex (collector , conn_mock , command_results ):
262+ """Test ROCm package filtering with custom regex pattern."""
263+ from nodescraper .plugins .inband .package .analyzer_args import PackageAnalyzerArgs
264+
265+ # Mock Ubuntu system with ROCm packages
266+ ubuntu_packages = """rocm-core 5.7.0
267+ hip-runtime-amd 5.7.0
268+ hsa-rocr 1.9.0
269+ amdgpu-dkms 6.3.6
270+ gcc 11.4.0
271+ python3 3.10.12"""
272+
273+ conn_mock .run_command .side_effect = [
274+ CommandArtifact (
275+ command = "" ,
276+ exit_code = 0 ,
277+ stdout = command_results ["ubuntu_rel" ],
278+ stderr = "" ,
279+ ),
280+ CommandArtifact (
281+ command = "" ,
282+ exit_code = 0 ,
283+ stdout = ubuntu_packages ,
284+ stderr = "" ,
285+ ),
286+ ]
287+
288+ # Use custom regex that only matches 'rocm' and 'hip'
289+ args = PackageAnalyzerArgs (rocm_regex = "rocm|hip" )
290+ res , data = collector .collect_data (args )
291+ assert res .status == ExecutionStatus .OK
292+ # Check that ROCm packages are found
293+ assert "found 2 rocm-related packages" in res .message .lower ()
294+ assert data is not None
295+
296+
297+ def test_rocm_package_filtering_no_matches (collector , conn_mock , command_results ):
298+ """Test ROCm package filtering when no ROCm packages are installed."""
299+ from nodescraper .plugins .inband .package .analyzer_args import PackageAnalyzerArgs
300+
301+ # Mock Ubuntu system without ROCm packages
302+ ubuntu_packages = """gcc 11.4.0
303+ python3 3.10.12
304+ vim 8.2.3995"""
305+
306+ conn_mock .run_command .side_effect = [
307+ CommandArtifact (
308+ command = "" ,
309+ exit_code = 0 ,
310+ stdout = command_results ["ubuntu_rel" ],
311+ stderr = "" ,
312+ ),
313+ CommandArtifact (
314+ command = "" ,
315+ exit_code = 0 ,
316+ stdout = ubuntu_packages ,
317+ stderr = "" ,
318+ ),
319+ ]
320+
321+ args = PackageAnalyzerArgs (rocm_regex = "rocm|hip|hsa" )
322+ res , data = collector .collect_data (args )
323+ assert res .status == ExecutionStatus .OK
324+ # No ROCm packages found, so message should not mention them
325+ assert "rocm" not in res .message .lower () or res .message == ""
326+ assert data is not None
327+ assert len (data .version_info ) == 3
328+
329+
330+ def test_filter_rocm_packages_method (collector ):
331+ """Test _filter_rocm_packages method directly."""
332+ packages = {
333+ "rocm-core" : "5.7.0" ,
334+ "hip-runtime-amd" : "5.7.0" ,
335+ "hsa-rocr" : "1.9.0" ,
336+ "amdgpu-dkms" : "6.3.6" ,
337+ "gcc" : "11.4.0" ,
338+ "python3" : "3.10.12" ,
339+ }
340+
341+ # Test with default-like pattern
342+ rocm_pattern = "rocm|hip|hsa|amdgpu"
343+ filtered = collector ._filter_rocm_packages (packages , rocm_pattern )
344+
345+ assert len (filtered ) == 4
346+ assert "rocm-core" in filtered
347+ assert "hip-runtime-amd" in filtered
348+ assert "hsa-rocr" in filtered
349+ assert "amdgpu-dkms" in filtered
350+ assert "gcc" not in filtered
351+ assert "python3" not in filtered
352+
353+
354+ def test_filter_rocm_packages_case_insensitive (collector ):
355+ """Test that ROCm package filtering is case-insensitive."""
356+ packages = {
357+ "ROCM-Core" : "5.7.0" ,
358+ "HIP-Runtime-AMD" : "5.7.0" ,
359+ "gcc" : "11.4.0" ,
360+ }
361+
362+ rocm_pattern = "rocm|hip"
363+ filtered = collector ._filter_rocm_packages (packages , rocm_pattern )
364+
365+ assert len (filtered ) == 2
366+ assert "ROCM-Core" in filtered
367+ assert "HIP-Runtime-AMD" in filtered
0 commit comments