diff --git a/projects/rocprofiler-compute/tests/test_analyze_commands.py b/projects/rocprofiler-compute/tests/test_analyze_commands.py index 332bf8206d..ae751d05cf 100644 --- a/projects/rocprofiler-compute/tests/test_analyze_commands.py +++ b/projects/rocprofiler-compute/tests/test_analyze_commands.py @@ -5,26 +5,35 @@ import pytest from importlib.machinery import SourceFileLoader import shutil import pandas as pd +import test_utils omniperf = SourceFileLoader("omniperf", "src/omniperf").load_module() baseline_opts = ["omniperf", "analyze"] +config = {} +config["cleanup"] = False + +indir1 = "tests/workloads/vcopy/MI100" +indir2 = "tests/workloads/vcopy/MI200" + @pytest.mark.misc def test_valid_path(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", - ["omniperf", "analyze", "--path", "tests/workloads/vcopy/MI100"], + ["omniperf", "analyze", "--path", workload_dir], ): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", - ["omniperf", "analyze", "--path", "tests/workloads/vcopy/MI200"], + ["omniperf", "analyze", "--path", workload_dir], ): omniperf.main() assert e.value.code == 0 @@ -32,6 +41,7 @@ def test_valid_path(): @pytest.mark.misc def test_list_kernels(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -39,13 +49,14 @@ def test_list_kernels(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--list-stats", ], ): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -53,12 +64,13 @@ def test_list_kernels(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--list-stats", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.list_metrics @@ -68,6 +80,7 @@ def test_list_metrics_gfx90a(): omniperf.main() assert e.value.code == 1 + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -75,7 +88,7 @@ def test_list_metrics_gfx90a(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--list-metrics", "gfx90a", ], @@ -83,6 +96,7 @@ def test_list_metrics_gfx90a(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -90,13 +104,14 @@ def test_list_metrics_gfx90a(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--list-metrics", "gfx90a", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.list_metrics @@ -106,6 +121,7 @@ def test_list_metrics_gfx906(): omniperf.main() assert e.value.code == 1 + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -113,7 +129,7 @@ def test_list_metrics_gfx906(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--list-metrics", "gfx906", ], @@ -121,6 +137,7 @@ def test_list_metrics_gfx906(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -128,13 +145,14 @@ def test_list_metrics_gfx906(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--list-metrics", "gfx906", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.list_metrics @@ -144,6 +162,7 @@ def test_list_metrics_gfx908(): omniperf.main() assert e.value.code == 1 + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -151,7 +170,7 @@ def test_list_metrics_gfx908(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--list-metrics", "gfx908", ], @@ -159,6 +178,7 @@ def test_list_metrics_gfx908(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -166,17 +186,19 @@ def test_list_metrics_gfx908(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--list-metrics", "gfx908", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.filter_block def test_filter_block_1(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -184,7 +206,7 @@ def test_filter_block_1(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--block", "1", ], @@ -192,6 +214,7 @@ def test_filter_block_1(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -199,17 +222,19 @@ def test_filter_block_1(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--block", "1", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.filter_block def test_filter_block_2(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -217,7 +242,7 @@ def test_filter_block_2(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--block", "5", ], @@ -225,6 +250,7 @@ def test_filter_block_2(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -232,17 +258,19 @@ def test_filter_block_2(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--block", "5", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.filter_block def test_filter_block_3(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -250,7 +278,7 @@ def test_filter_block_3(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--block", "5.2.2", ], @@ -258,6 +286,7 @@ def test_filter_block_3(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -265,17 +294,19 @@ def test_filter_block_3(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--block", "5.2.2", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.filter_block def test_filter_block_4(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -283,7 +314,7 @@ def test_filter_block_4(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--block", "6.1", ], @@ -291,6 +322,7 @@ def test_filter_block_4(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -298,17 +330,19 @@ def test_filter_block_4(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--block", "6.1", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.filter_block def test_filter_block_5(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -316,7 +350,7 @@ def test_filter_block_5(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--block", "10", ], @@ -324,6 +358,7 @@ def test_filter_block_5(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -331,17 +366,19 @@ def test_filter_block_5(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--block", "10", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.filter_block def test_filter_block_6(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -349,7 +386,7 @@ def test_filter_block_6(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--block", "100", ], @@ -357,6 +394,7 @@ def test_filter_block_6(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -364,17 +402,19 @@ def test_filter_block_6(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--block", "100", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.serial def test_filter_kernel_1(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -382,7 +422,7 @@ def test_filter_kernel_1(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--kernel", "0", ], @@ -390,6 +430,7 @@ def test_filter_kernel_1(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -397,17 +438,19 @@ def test_filter_kernel_1(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--kernel", "0", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.serial def test_filter_kernel_2(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -415,7 +458,7 @@ def test_filter_kernel_2(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--kernel", "1", ], @@ -423,6 +466,7 @@ def test_filter_kernel_2(): omniperf.main() assert e.value.code == 1 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -430,17 +474,19 @@ def test_filter_kernel_2(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--kernel", "1", ], ): omniperf.main() assert e.value.code == 1 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.serial def test_filter_kernel_3(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -448,7 +494,7 @@ def test_filter_kernel_3(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--kernel", "0", "1", @@ -457,6 +503,7 @@ def test_filter_kernel_3(): omniperf.main() assert e.value.code == 1 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -464,7 +511,7 @@ def test_filter_kernel_3(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--kernel", "0", "1", @@ -472,10 +519,12 @@ def test_filter_kernel_3(): ): omniperf.main() assert e.value.code == 1 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.serial def test_dispatch_1(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -483,7 +532,7 @@ def test_dispatch_1(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--dispatch", "0", ], @@ -491,6 +540,7 @@ def test_dispatch_1(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -498,17 +548,19 @@ def test_dispatch_1(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--dispatch", "0", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.serial def test_dispatch_2(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -516,7 +568,7 @@ def test_dispatch_2(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--dispatch", "1", ], @@ -524,6 +576,7 @@ def test_dispatch_2(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -531,17 +584,19 @@ def test_dispatch_2(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--dispatch", "1", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.serial def test_dispatch_3(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -549,7 +604,7 @@ def test_dispatch_3(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--dispatch", "2", ], @@ -557,6 +612,7 @@ def test_dispatch_3(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -564,17 +620,19 @@ def test_dispatch_3(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--dispatch", "2", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.serial def test_dispatch_4(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -582,7 +640,7 @@ def test_dispatch_4(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--dispatch", "1", "4", @@ -591,6 +649,7 @@ def test_dispatch_4(): omniperf.main() assert e.value.code == 1 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -598,7 +657,7 @@ def test_dispatch_4(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--dispatch", "1", "4", @@ -606,10 +665,12 @@ def test_dispatch_4(): ): omniperf.main() assert e.value.code == 1 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.serial def test_dispatch_5(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -617,7 +678,7 @@ def test_dispatch_5(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--dispatch", "5", "6", @@ -626,6 +687,7 @@ def test_dispatch_5(): omniperf.main() assert e.value.code == 1 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -633,7 +695,7 @@ def test_dispatch_5(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--dispatch", "5", "6", @@ -641,10 +703,12 @@ def test_dispatch_5(): ): omniperf.main() assert e.value.code == 1 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.misc def test_gpu_ids(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -652,7 +716,7 @@ def test_gpu_ids(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--gpu-id", "2", ], @@ -660,6 +724,7 @@ def test_gpu_ids(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -667,17 +732,19 @@ def test_gpu_ids(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--gpu-id", "2", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.normal_unit def test_normal_unit_per_wave(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -685,7 +752,7 @@ def test_normal_unit_per_wave(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--normal-unit", "per_wave", ], @@ -693,6 +760,7 @@ def test_normal_unit_per_wave(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -700,17 +768,19 @@ def test_normal_unit_per_wave(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--normal-unit", "per_wave", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.normal_unit def test_normal_unit_per_cycle(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -718,7 +788,7 @@ def test_normal_unit_per_cycle(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--normal-unit", "per_cycle", ], @@ -726,6 +796,7 @@ def test_normal_unit_per_cycle(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -733,17 +804,19 @@ def test_normal_unit_per_cycle(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--normal-unit", "per_cycle", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.normal_unit def test_normal_unit_per_second(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -751,7 +824,7 @@ def test_normal_unit_per_second(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--normal-unit", "per_second", ], @@ -759,6 +832,7 @@ def test_normal_unit_per_second(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -766,17 +840,19 @@ def test_normal_unit_per_second(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--normal-unit", "per_second", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.normal_unit def test_normal_unit_per_kernel(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -784,7 +860,7 @@ def test_normal_unit_per_kernel(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--normal-unit", "per_kernel", ], @@ -792,6 +868,7 @@ def test_normal_unit_per_kernel(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -799,17 +876,19 @@ def test_normal_unit_per_kernel(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--normal-unit", "per_kernel", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.max_stat def test_max_stat_num_1(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -817,7 +896,7 @@ def test_max_stat_num_1(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--max-stat-num", "0", ], @@ -825,6 +904,7 @@ def test_max_stat_num_1(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -832,17 +912,19 @@ def test_max_stat_num_1(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--max-stat-num", "0", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.max_stat def test_max_stat_num_2(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -850,7 +932,7 @@ def test_max_stat_num_2(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--max-stat-num", "5", ], @@ -858,6 +940,7 @@ def test_max_stat_num_2(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -865,17 +948,19 @@ def test_max_stat_num_2(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--max-stat-num", "5", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.max_stat def test_max_stat_num_3(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -883,7 +968,7 @@ def test_max_stat_num_3(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--max-stat-num", "10", ], @@ -891,6 +976,7 @@ def test_max_stat_num_3(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -898,17 +984,19 @@ def test_max_stat_num_3(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--max-stat-num", "10", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.max_stat def test_max_stat_num_4(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -916,7 +1004,7 @@ def test_max_stat_num_4(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--max-stat-num", "15", ], @@ -924,6 +1012,7 @@ def test_max_stat_num_4(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -931,17 +1020,19 @@ def test_max_stat_num_4(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--max-stat-num", "15", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.time_unit def test_time_unit_s(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -949,7 +1040,7 @@ def test_time_unit_s(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--time-unit", "s", ], @@ -957,6 +1048,7 @@ def test_time_unit_s(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -964,17 +1056,19 @@ def test_time_unit_s(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--time-unit", "s", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.time_unit def test_time_unit_ms(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -982,7 +1076,7 @@ def test_time_unit_ms(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--time-unit", "ms", ], @@ -990,6 +1084,7 @@ def test_time_unit_ms(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -997,17 +1092,19 @@ def test_time_unit_ms(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--time-unit", "ms", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.time_unit def test_time_unit_us(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1015,7 +1112,7 @@ def test_time_unit_us(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--time-unit", "us", ], @@ -1023,6 +1120,7 @@ def test_time_unit_us(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1030,17 +1128,19 @@ def test_time_unit_us(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--time-unit", "us", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.time_unit def test_time_unit_ns(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1048,7 +1148,7 @@ def test_time_unit_ns(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--time-unit", "ns", ], @@ -1056,6 +1156,7 @@ def test_time_unit_ns(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1063,17 +1164,19 @@ def test_time_unit_ns(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--time-unit", "ns", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.decimal def test_decimal_1(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1081,7 +1184,7 @@ def test_decimal_1(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--decimal", "0", ], @@ -1089,6 +1192,7 @@ def test_decimal_1(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1096,17 +1200,19 @@ def test_decimal_1(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--decimal", "0", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.decimal def test_decimal_2(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1114,7 +1220,7 @@ def test_decimal_2(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + indir1, "--decimal", "1", ], @@ -1122,6 +1228,7 @@ def test_decimal_2(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1129,17 +1236,19 @@ def test_decimal_2(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--decimal", "1", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.decimal def test_decimal_3(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1147,7 +1256,7 @@ def test_decimal_3(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--decimal", "4", ], @@ -1155,6 +1264,7 @@ def test_decimal_3(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1162,19 +1272,20 @@ def test_decimal_3(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--decimal", "4", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.misc def test_save_dfs(): output_path = "tests/workloads/vcopy/saved_analysis" - + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1182,7 +1293,7 @@ def test_save_dfs(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--save-dfs", output_path, ], @@ -1190,6 +1301,7 @@ def test_save_dfs(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1197,7 +1309,7 @@ def test_save_dfs(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--save-dfs", output_path, ], @@ -1219,7 +1331,9 @@ def test_save_dfs(): assert len(df.index) >= 3 shutil.rmtree(output_path) + test_utils.clean_output_dir(config["cleanup"], workload_dir) + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1227,7 +1341,7 @@ def test_save_dfs(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--save-dfs", output_path, ], @@ -1242,10 +1356,12 @@ def test_save_dfs(): assert len(df.index) == 1 else: assert len(df.index) >= 3 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.col def test_col_1(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1253,7 +1369,7 @@ def test_col_1(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--cols", "0", ], @@ -1261,6 +1377,7 @@ def test_col_1(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1268,17 +1385,19 @@ def test_col_1(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--cols", "0", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.col def test_col_2(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1286,7 +1405,7 @@ def test_col_2(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--cols", "2", ], @@ -1294,6 +1413,7 @@ def test_col_2(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1301,17 +1421,19 @@ def test_col_2(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--cols", "2", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.col def test_col_3(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1319,7 +1441,7 @@ def test_col_3(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--cols", "0", "2", @@ -1328,6 +1450,7 @@ def test_col_3(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1335,7 +1458,7 @@ def test_col_3(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--cols", "0", "2", @@ -1343,10 +1466,12 @@ def test_col_3(): ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.misc def test_g(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1354,13 +1479,14 @@ def test_g(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "-g", ], ): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1368,16 +1494,18 @@ def test_g(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "-g", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.kernel_verbose def test_kernel_verbose_0(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1385,7 +1513,7 @@ def test_kernel_verbose_0(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--kernel-verbose", "0", ], @@ -1393,6 +1521,7 @@ def test_kernel_verbose_0(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1400,17 +1529,19 @@ def test_kernel_verbose_0(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--kernel-verbose", "0", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.kernel_verbose def test_kernel_verbose_1(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1418,7 +1549,7 @@ def test_kernel_verbose_1(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--kernel-verbose", "1", ], @@ -1426,6 +1557,7 @@ def test_kernel_verbose_1(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1433,7 +1565,7 @@ def test_kernel_verbose_1(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--kernel-verbose", "1", ], @@ -1444,6 +1576,7 @@ def test_kernel_verbose_1(): @pytest.mark.kernel_verbose def test_kernel_verbose_2(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1451,7 +1584,7 @@ def test_kernel_verbose_2(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--kernel-verbose", "2", ], @@ -1459,6 +1592,7 @@ def test_kernel_verbose_2(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1466,17 +1600,19 @@ def test_kernel_verbose_2(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--kernel-verbose", "2", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.kernel_verbose def test_kernel_verbose_3(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1484,14 +1620,14 @@ def test_kernel_verbose_3(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--kernel-verbose", "3", ], ): omniperf.main() assert e.value.code == 0 - + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1499,17 +1635,19 @@ def test_kernel_verbose_3(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--kernel-verbose", "3", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.kernel_verbose def test_kernel_verbose_4(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1517,7 +1655,7 @@ def test_kernel_verbose_4(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--kernel-verbose", "4", ], @@ -1525,6 +1663,7 @@ def test_kernel_verbose_4(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1532,17 +1671,19 @@ def test_kernel_verbose_4(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--kernel-verbose", "4", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.kernel_verbose def test_kernel_verbose_5(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1550,7 +1691,7 @@ def test_kernel_verbose_5(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--kernel-verbose", "5", ], @@ -1558,6 +1699,7 @@ def test_kernel_verbose_5(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1565,17 +1707,19 @@ def test_kernel_verbose_5(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--kernel-verbose", "5", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.kernel_verbose def test_kernel_verbose_6(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1583,7 +1727,7 @@ def test_kernel_verbose_6(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--kernel-verbose", "6", ], @@ -1591,6 +1735,7 @@ def test_kernel_verbose_6(): omniperf.main() assert e.value.code == 0 + workload_dir = test_utils.setup_workload_dir(indir2) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1598,13 +1743,14 @@ def test_kernel_verbose_6(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI200", + workload_dir, "--kernel-verbose", "6", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) @pytest.mark.misc @@ -1657,6 +1803,7 @@ def test_baseline(): @pytest.mark.misc def test_dependency_MI100(): + workload_dir = test_utils.setup_workload_dir(indir1) with pytest.raises(SystemExit) as e: with patch( "sys.argv", @@ -1664,9 +1811,10 @@ def test_dependency_MI100(): "omniperf", "analyze", "--path", - "tests/workloads/vcopy/MI100", + workload_dir, "--dependency", ], ): omniperf.main() assert e.value.code == 0 + test_utils.clean_output_dir(config["cleanup"], workload_dir) diff --git a/projects/rocprofiler-compute/tests/test_utils.py b/projects/rocprofiler-compute/tests/test_utils.py index b79dbed0b3..71df621f9b 100644 --- a/projects/rocprofiler-compute/tests/test_utils.py +++ b/projects/rocprofiler-compute/tests/test_utils.py @@ -66,6 +66,25 @@ def get_output_dir(suffix="_output", clean_existing=True): return output_dir +def setup_workload_dir(input_dir, suffix="_tmp", clean_existing=True): + """Provides a unique input workoad directory with contents of input_dir + based on the name of the calling test function. + + Setup is a NOOP when tests run serially. + """ + + if "PYTEST_XDIST_WORKER_COUNT" not in os.environ: + return input_dir + + output_dir = inspect.stack()[1].function + suffix + if clean_existing: + if os.path.exists(output_dir): + shutil.rmtree(output_dir) + + shutil.copytree(input_dir, output_dir) + return output_dir + + def clean_output_dir(cleanup, output_dir): """Remove output directory generated from omniperf execution