Add clean up fixture for trace cache temporary files (#1836)

* Add clean up fixture for trace cache tmp files

* Switch to bash instead of cmake running command
This commit is contained in:
Milan Radosavljevic
2025-11-14 03:01:04 +01:00
zatwierdzone przez GitHub
rodzic 4830979f0e
commit 833c250c27
3 zmienionych plików z 42 dodań i 34 usunięć
@@ -131,29 +131,6 @@ get_cache_files()
return cache_map;
}
std::vector<std::string>
get_all_cache_files()
{
const auto tmp_files = list_dir_files(tmp_directory);
std::vector<std::string> result{};
auto parse_and_fill_cache = [&](const std::string& filename) {
const std::regex buff_regex(R"(buffered_storage.*\.bin)");
const std::regex meta_regex(R"(metadata.*\.json)");
std::smatch match;
if(std::regex_match(filename, match, buff_regex))
{
result.push_back(tmp_directory + filename);
}
else if(std::regex_match(filename, match, meta_regex))
{
result.push_back(tmp_directory + filename);
}
};
std::for_each(tmp_files.begin(), tmp_files.end(), parse_and_fill_cache);
return result;
}
} // namespace
cache_manager&
@@ -238,13 +215,16 @@ cache_manager::post_process_bulk()
}
}
ROCPROFSYS_PRINT("Removing all cached temporary files...\n");
ROCPROFSYS_PRINT("Removing cached temporary files...\n");
auto all_cache_files = get_all_cache_files();
for(const auto& filename : all_cache_files)
for(const auto& [pid, files] : _cache_files)
{
ROCPROFSYS_PRINT("Removing cached temporary file: %s\n", filename.c_str());
remove_if_exists(filename);
ROCPROFSYS_PRINT("Removing cached temporary file: %s\n",
files.buff_storage.c_str());
ROCPROFSYS_PRINT("Removing cached temporary file: %s\n",
files.metadata.c_str());
remove_if_exists(files.buff_storage.c_str());
remove_if_exists(files.metadata.c_str());
}
}
}
@@ -51,3 +51,25 @@ include(${CMAKE_CURRENT_LIST_DIR}/rocprof-sys-roctx-tests.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/rocprof-sys-rocm-hip-stream.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/rocprof-sys-binary-tests.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/rocprof-sys-thread-limit-tests.cmake)
# -------------------------------------------------------------------------------------- #
#
# Global cleanup test for temporary files
# This runs once after ALL tests complete to clean up trace cache temporary files
# Uses FIXTURES_CLEANUP to ensure it runs after all tests requiring the fixture
#
# -------------------------------------------------------------------------------------- #
add_test(
NAME rocprofsys-cleanup-tmp-files
COMMAND sh -c "rm -f /tmp/buffered_storage*.bin /tmp/metadata*.json"
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
set_tests_properties(
rocprofsys-cleanup-tmp-files
PROPERTIES
FIXTURES_CLEANUP rocprofsys-global-tmp-files
LABELS "cleanup;global"
TIMEOUT 30
)
@@ -789,7 +789,7 @@ function(ROCPROFILER_SYSTEMS_ADD_TEST)
list(APPEND _environ "ROCPROFSYS_CI_TIMEOUT=${_timeout}")
rocprofiler_systems_check_pass_fail_regex("${TEST_NAME}-${_TEST}"
"${_PASS_REGEX}" "${_FAIL_REGEX}"
"${_PASS_REGEX}" "${_FAIL_REGEX}"
)
if(TEST ${TEST_NAME}-${_TEST})
rocprofiler_systems_write_test_config(${TEST_NAME}-${_TEST}.cfg _environ)
@@ -804,6 +804,7 @@ function(ROCPROFILER_SYSTEMS_ADD_TEST)
SKIP_REGULAR_EXPRESSION "${${_SKIP_REGEX}}"
WILL_FAIL ${TEST_WILL_FAIL}
DISABLED ${TEST_DISABLED}
FIXTURES_REQUIRED rocprofsys-global-tmp-files
${_props}
)
endif()
@@ -840,7 +841,7 @@ function(ROCPROFILER_SYSTEMS_ADD_CAUSAL_TEST)
if(NOT DEFINED TEST_CAUSAL_MODE)
rocprofiler_systems_message(FATAL_ERROR
"${TEST_NAME} :: CAUSAL_MODE must be defined"
"${TEST_NAME} :: CAUSAL_MODE must be defined"
)
endif()
@@ -971,7 +972,7 @@ function(ROCPROFILER_SYSTEMS_ADD_CAUSAL_TEST)
list(APPEND _environ "ROCPROFSYS_CI_TIMEOUT=${_timeout}")
rocprofiler_systems_write_test_config(${_NAME}.cfg _environ)
rocprofiler_systems_check_pass_fail_regex("${_NAME}" "${_PASS_REGEX}"
"${_FAIL_REGEX}"
"${_FAIL_REGEX}"
)
set_tests_properties(
${_NAME}
@@ -982,6 +983,7 @@ function(ROCPROFILER_SYSTEMS_ADD_CAUSAL_TEST)
PASS_REGULAR_EXPRESSION "${${_PASS_REGEX}}"
FAIL_REGULAR_EXPRESSION "${${_FAIL_REGEX}}"
SKIP_REGULAR_EXPRESSION "${${_SKIP_REGEX}}"
FIXTURES_REQUIRED rocprofsys-global-tmp-files
${_props}
)
endforeach()
@@ -1096,7 +1098,7 @@ function(ROCPROFILER_SYSTEMS_ADD_PYTHON_TEST)
set(_FAIL_REGEX TEST_FAIL_REGEX)
rocprofiler_systems_check_pass_fail_regex("${_TEST}" "${_PASS_REGEX}"
"${_FAIL_REGEX}"
"${_FAIL_REGEX}"
)
set_tests_properties(
${_TEST}
@@ -1109,6 +1111,7 @@ function(ROCPROFILER_SYSTEMS_ADD_PYTHON_TEST)
FAIL_REGULAR_EXPRESSION "${${_FAIL_REGEX}}"
SKIP_REGULAR_EXPRESSION "${TEST_SKIP_REGEX}"
REQUIRED_FILES "${TEST_FILE}"
FIXTURES_REQUIRED rocprofsys-global-tmp-files
${_TEST_PROPERTIES}
)
endforeach()
@@ -1132,7 +1135,7 @@ if(NOT ROCPROFSYS_USE_PYTHON)
if(NOT ROCPROFSYS_VALIDATION_PYTHON_PERFETTO EQUAL 0)
rocprofiler_systems_message(AUTHOR_WARNING
"Python3 found but perfetto support is disabled"
"Python3 found but perfetto support is disabled"
)
endif()
endif()
@@ -1306,7 +1309,7 @@ function(ROCPROFILER_SYSTEMS_ADD_VALIDATION_TEST)
endif()
rocprofiler_systems_check_pass_fail_regex("${_TEST}" "TEST_PASS_REGEX"
"TEST_FAIL_REGEX"
"TEST_FAIL_REGEX"
)
set_tests_properties(
${_TEST}
@@ -1319,6 +1322,7 @@ function(ROCPROFILER_SYSTEMS_ADD_VALIDATION_TEST)
FAIL_REGULAR_EXPRESSION "${TEST_FAIL_REGEX}"
SKIP_REGULAR_EXPRESSION "${TEST_SKIP_REGEX}"
REQUIRED_FILES "${TEST_FILE}"
FIXTURES_REQUIRED rocprofsys-global-tmp-files
${TEST_PROPERTIES}
)
endforeach()
@@ -1410,6 +1414,7 @@ function(ROCPROFILER_SYSTEMS_ADD_BIN_TEST)
PASS_REGULAR_EXPRESSION "${TEST_PASS_REGEX}"
FAIL_REGULAR_EXPRESSION "${TEST_FAIL_REGEX}"
SKIP_REGULAR_EXPRESSION "${TEST_SKIP_REGEX}"
FIXTURES_REQUIRED rocprofsys-global-tmp-files
${TEST_PROPERTIES}
)
elseif(TARGET ${TEST_TARGET})
@@ -1429,6 +1434,7 @@ function(ROCPROFILER_SYSTEMS_ADD_BIN_TEST)
PASS_REGULAR_EXPRESSION "${TEST_PASS_REGEX}"
FAIL_REGULAR_EXPRESSION "${TEST_FAIL_REGEX}"
SKIP_REGULAR_EXPRESSION "${TEST_SKIP_REGEX}"
FIXTURES_REQUIRED rocprofsys-global-tmp-files
${TEST_PROPERTIES}
)
elseif(ROCPROFSYS_BUILD_TESTING)