Add valgrind support to our cmake files (#5296)

This commit is contained in:
Changming Sun 2020-09-28 09:31:08 -07:00 committed by GitHub
parent fec890a09a
commit 1a04b8f8b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 9 deletions

View file

@ -42,6 +42,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Enable CTest
enable_testing()
include(Dart)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Build type not set - using RelWithDebInfo")
@ -128,6 +129,9 @@ option(onnxruntime_ENABLE_TRAINING "Enable training functionality." OFF)
option(onnxruntime_ENABLE_TRAINING_E2E_TESTS "Enable training end-to-end tests." OFF)
option(onnxruntime_USE_HOROVOD "Build with HOROVOD support" OFF)
option(onnxruntime_USE_NCCL "Build with NCCL support" ON)
#A special option just for debugging and sanitize check. Please do not enable in option in retail builds.
#The option has no effect on Windows.
option(onnxruntime_USE_VALGRIND "Build with valgrind hacks" OFF)
# A special build option only used for gathering code coverage info
option(onnxruntime_RUN_MODELTEST_IN_DEBUG_MODE "Run model tests even in debug mode" OFF)
@ -144,6 +148,10 @@ if(MSVC AND WIN32 AND onnxruntime_FUZZ_TEST AND onnxruntime_BUILD_SHARED_LIB AND
set(onnxruntime_FUZZ_ENABLED ON)
endif()
if(onnxruntime_USE_VALGRIND AND NOT WIN32)
add_definitions(-DRE2_ON_VALGRIND=1)
endif()
if (onnxruntime_ENABLE_NVTX_PROFILE)
add_definitions(-DENABLE_NVTX_PROFILE=1)
endif()

View file

@ -755,7 +755,7 @@ TEST(CApiTest, end_profiling) {
char* profile_file = session_1.EndProfiling(allocator.get());
ASSERT_TRUE(std::string(profile_file).find("profile_prefix") != std::string::npos);
allocator->Free(profile_file);
// Create session with profiling disabled
Ort::SessionOptions session_options_2;
#ifdef _WIN32
@ -765,8 +765,8 @@ TEST(CApiTest, end_profiling) {
#endif
Ort::Session session_2(*ort_env, MODEL_WITH_CUSTOM_MODEL_METADATA, session_options_2);
profile_file = session_2.EndProfiling(allocator.get());
ASSERT_TRUE(std::string(profile_file) == std::string());
allocator->Free(profile_file);
}
TEST(CApiTest, get_profiling_start_time) {
@ -780,14 +780,16 @@ TEST(CApiTest, get_profiling_start_time) {
#endif
uint64_t before_start_time = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch()).count(); // get current time
std::chrono::high_resolution_clock::now().time_since_epoch())
.count(); // get current time
Ort::Session session_1(*ort_env, MODEL_WITH_CUSTOM_MODEL_METADATA, session_options);
uint64_t profiling_start_time = session_1.GetProfilingStartTimeNs();
uint64_t after_start_time = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch()).count();
std::chrono::high_resolution_clock::now().time_since_epoch())
.count();
// the profiler's start time needs to be between before_time and after_time
ASSERT_TRUE(before_start_time <= profiling_start_time && profiling_start_time <= after_start_time);
ASSERT_TRUE(before_start_time <= profiling_start_time && profiling_start_time <= after_start_time);
}
TEST(CApiTest, model_metadata) {
@ -899,8 +901,8 @@ TEST(CApiTest, TestSharedAllocatorUsingCreateAndRegisterAllocator) {
OrtMemoryInfo* mem_info = nullptr;
const auto& api = Ort::GetApi();
std::unique_ptr<OrtMemoryInfo, decltype(api.ReleaseMemoryInfo)> rel_info(mem_info, api.ReleaseMemoryInfo);
ASSERT_TRUE(api.CreateCpuMemoryInfo(OrtArenaAllocator, OrtMemTypeDefault, &mem_info) == nullptr);
std::unique_ptr<OrtMemoryInfo, decltype(api.ReleaseMemoryInfo)> rel_info(mem_info, api.ReleaseMemoryInfo);
OrtArenaCfg arena_cfg{0, -1, -1, -1};
ASSERT_TRUE(api.CreateAndRegisterAllocator(env_ptr, mem_info, &arena_cfg) == nullptr);
@ -978,4 +980,4 @@ TEST(CApiTest, TestSharingOfInitializer) {
expected_dims_y,
expected_values_y,
nullptr);
}
}

View file

@ -1251,7 +1251,7 @@ def run_onnxruntime_tests(args, source_dir, ctest_path, build_dir, configs):
source_dir, 'cmake\\codeconv.runsettings')] + executables,
cwd=cwd2, dll_path=dll_path)
else:
ctest_cmd = [ctest_path, "--build-config", config, "--verbose"]
ctest_cmd = [ctest_path, "--build-config", config, "--verbose", "--timeout", "3600"]
run_subprocess(ctest_cmd, cwd=cwd, dll_path=dll_path)
if args.enable_pybind: