Skip to content

Commit f993308

Browse files
Enable asserts in drmemtrace tests in release build (#7460)
Many drmemtrace tests use assert() for their test logic. Some locally undo NDEBUG so they still perform checks in release build, but many do not. This PR adopts a more systematic approach: it disables the re-addition of NDEBUG in the drcachesim CMake code for all tests, and includes test_helpers.h in each test. To this header we add a sanity check for NDEBUG to detect regressions.
1 parent 371926b commit f993308

38 files changed

+175
-131
lines changed

clients/drcachesim/CMakeLists.txt

Lines changed: 90 additions & 89 deletions
Large diffs are not rendered by default.

clients/drcachesim/tests/analysis_unit_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
/* Unit tests for trace analysis APIs. */
3434

35+
#include "test_helpers.h"
3536
#include <assert.h>
3637

3738
#include <atomic>

clients/drcachesim/tests/burst_aarch64_sys.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2020-2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2020-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -34,6 +34,8 @@
3434
* a "burst" of execution in the middle of the application. It then detaches.
3535
* It then post-processes the acquired trace and confirms various assertions.
3636
*/
37+
38+
#include "test_helpers.h"
3739
#include "scheduler.h"
3840
#include "dr_api.h"
3941
#include "drmemtrace/drmemtrace.h"

clients/drcachesim/tests/burst_futex.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2023-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -35,6 +35,7 @@
3535
* trace is analyzed to confirm that futex parameters were included.
3636
*/
3737

38+
#include "test_helpers.h"
3839
#include "dr_api.h"
3940
#include "drmemtrace/drmemtrace.h"
4041
#include "analysis_tool.h"

clients/drcachesim/tests/burst_gencode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2016-2024 Google, Inc. All rights reserved.
2+
* Copyright (c) 2016-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -36,6 +36,7 @@
3636
// This is set globally in CMake for other tests so easier to undef here.
3737
#undef DR_REG_ENUM_COMPATIBILITY
3838

39+
#include "test_helpers.h"
3940
#include "configure.h"
4041
#include "dr_api.h"
4142
#include "drmemtrace/drmemtrace.h"

clients/drcachesim/tests/burst_malloc.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2016-2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2016-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -38,6 +38,7 @@
3838

3939
/* Like burst_static we deliberately do not include configure.h here */
4040

41+
#include "test_helpers.h"
4142
#include "dr_api.h"
4243
#include "drmemtrace/drmemtrace.h"
4344
#include "scheduler.h"

clients/drcachesim/tests/burst_maps.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2017-2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2017-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -36,6 +36,7 @@
3636
* being 32-bit reachable from any available space for the code cache.
3737
*/
3838

39+
#include "test_helpers.h"
3940
/* Like burst_static we deliberately do not include configure.h here. */
4041
#include "dr_api.h"
4142
#include "../../common/utils.h"

clients/drcachesim/tests/burst_noreach.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2017-2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2017-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -36,6 +36,7 @@
3636
* being 32-bit reachable from any available space for the code cache.
3737
*/
3838

39+
#include "test_helpers.h"
3940
/* Like burst_static we deliberately do not include configure.h here. */
4041
#include "dr_api.h"
4142
#include <assert.h>

clients/drcachesim/tests/burst_reattach.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2016-2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2016-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -36,6 +36,7 @@
3636
* statically linked DR with a very high number of re-attaches.
3737
*/
3838

39+
#include "test_helpers.h"
3940
/* Like burst_static we deliberately do not include configure.h here */
4041
#include "dr_api.h"
4142
#include "drmemtrace/drmemtrace.h"

clients/drcachesim/tests/burst_replace.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2016-2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2016-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -34,6 +34,7 @@
3434
* a "burst" of execution in the middle of the application. It then detaches.
3535
*/
3636

37+
#include "test_helpers.h"
3738
/* We deliberately do not include configure.h here to simulate what an
3839
* actual app will look like. configure_DynamoRIO_static sets DR_APP_EXPORTS
3940
* for us.

clients/drcachesim/tests/burst_replaceall.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2016-2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2016-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -34,6 +34,7 @@
3434
* a "burst" of execution in the middle of the application. It then detaches.
3535
*/
3636

37+
#include "test_helpers.h"
3738
/* We deliberately do not include configure.h here to simulate what an
3839
* actual app will look like. configure_DynamoRIO_static sets DR_APP_EXPORTS
3940
* for us.

clients/drcachesim/tests/burst_static.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2016-2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2016-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -34,6 +34,7 @@
3434
* a "burst" of execution in the middle of the application. It then detaches.
3535
*/
3636

37+
#include "test_helpers.h"
3738
/* We deliberately do not include configure.h here to simulate what an
3839
* actual app will look like. configure_DynamoRIO_static sets DR_APP_EXPORTS
3940
* for us.

clients/drcachesim/tests/burst_syscall_inject.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@
3838
// This is set globally in CMake for other tests so easier to undef here.
3939
#undef DR_REG_ENUM_COMPATIBILITY
4040

41-
// Enable asserts in release build testing too.
42-
#undef NDEBUG
43-
41+
#include "test_helpers.h"
4442
#include "analyzer.h"
4543
#include "tools/basic_counts.h"
4644
#include "tools/invariant_checker.h"

clients/drcachesim/tests/burst_syscall_pt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2016-2024 Google, Inc. All rights reserved.
2+
* Copyright (c) 2016-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -37,6 +37,7 @@
3737
// This is set globally in CMake for other tests so easier to undef here.
3838
#undef DR_REG_ENUM_COMPATIBILITY
3939

40+
#include "test_helpers.h"
4041
#include "analyzer.h"
4142
#include "tools/basic_counts.h"
4243
#include "dr_api.h"

clients/drcachesim/tests/burst_threadfilter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2018-2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2018-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -35,6 +35,7 @@
3535
* It tests the thread filtering feature.
3636
*/
3737

38+
#include "test_helpers.h"
3839
/* We deliberately do not include configure.h here to simulate what an
3940
* actual app will look like. configure_DynamoRIO_static sets DR_APP_EXPORTS
4041
* for us.

clients/drcachesim/tests/burst_threads.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2016-2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2016-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -34,6 +34,7 @@
3434
* a "burst" of execution in the middle of the application. It then detaches.
3535
*/
3636

37+
#include "test_helpers.h"
3738
/* We deliberately do not include configure.h here to simulate what an
3839
* actual app will look like. configure_DynamoRIO_static sets DR_APP_EXPORTS
3940
* for us.

clients/drcachesim/tests/burst_traceopts.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2019-2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2019-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -37,6 +37,8 @@
3737
*/
3838

3939
#ifndef ASM_CODE_ONLY /* C code */
40+
41+
# include "test_helpers.h"
4042
# include "dr_api.h"
4143
# include "drmemtrace/drmemtrace.h"
4244
# include "drcovlib.h"

clients/drcachesim/tests/cache_replacement_policy_unit_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2016-2022 Google, Inc. All rights reserved.
2+
* Copyright (c) 2016-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -32,7 +32,6 @@
3232

3333
// Unit tests for cache replacement policies
3434
#include <iostream>
35-
#undef NDEBUG
3635
#include <assert.h>
3736
#include <memory>
3837
#include <random>
@@ -43,6 +42,7 @@
4342
#include "simulator/policy_lfu.h"
4443
#include "simulator/policy_lru.h"
4544
#include "simulator/tlb.h"
45+
#include "test_helpers.h"
4646

4747
namespace dynamorio {
4848
namespace drmemtrace {

clients/drcachesim/tests/core_sharded_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* DAMAGE.
3131
*/
3232

33+
#include "test_helpers.h"
3334
#include <assert.h>
3435
#include <iostream>
3536
#include <regex>
@@ -62,9 +63,9 @@ run_analyzer(int argc, const char *args[])
6263
}
6364
analyzer_multi_t analyzer;
6465
assert(!!analyzer);
65-
IF_DEBUG(bool res =) analyzer.run();
66+
bool res = analyzer.run();
6667
assert(res);
67-
IF_DEBUG(res =) analyzer.print_stats();
68+
res = analyzer.print_stats();
6869
assert(res);
6970

7071
std::cerr.rdbuf(prev_buf);

clients/drcachesim/tests/drcachesim_unit_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2016-2024 Google, Inc. All rights reserved.
2+
* Copyright (c) 2016-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -37,7 +37,6 @@
3737
#include <random>
3838
#include <regex>
3939

40-
#undef NDEBUG
4140
#include <assert.h>
4241
#include "config_reader_unit_test.h"
4342
#include "v2p_reader_unit_test.h"
@@ -50,6 +49,7 @@
5049
#include "simulator/prefetcher.h"
5150
#include "../common/memref.h"
5251
#include "../common/utils.h"
52+
#include "test_helpers.h"
5353

5454
namespace dynamorio {
5555
namespace drmemtrace {

clients/drcachesim/tests/drmemtrace_shared_raw2trace_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2023-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -36,6 +36,7 @@
3636
#include "drmemtrace.h"
3737
#include "trace_entry.h"
3838
#include "raw2trace_shared.h"
39+
#include "test_helpers.h"
3940

4041
namespace dynamorio {
4142
namespace drmemtrace {

clients/drcachesim/tests/flexible_queue_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2023-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -32,6 +32,7 @@
3232

3333
/* Unit tests for flexible_queue. */
3434

35+
#include "test_helpers.h"
3536
#include "scheduler/flexible_queue.h"
3637

3738
#include <assert.h>

clients/drcachesim/tests/multiproc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2015-2016 Google, Inc. All rights reserved.
2+
* Copyright (c) 2015-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -32,6 +32,7 @@
3232

3333
/* Multi-process test */
3434

35+
#include "test_helpers.h"
3536
#include "tools.h"
3637

3738
#ifdef UNIX

clients/drcachesim/tests/prefetch_analyzer_launcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2020-2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2020-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*

clients/drcachesim/tests/raw2trace_io.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2017-2023 Google, Inc. All rights reserved.
2+
* Copyright (c) 2017-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -38,6 +38,7 @@
3838
* because raw2trace uses drmodtrack, which doesn't isolate under static memtrace.
3939
*/
4040

41+
#include "test_helpers.h"
4142
#include "droption.h"
4243
#include "tracer/raw2trace.h"
4344
#include "tracer/raw2trace_directory.h"

clients/drcachesim/tests/raw2trace_unit_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "mock_reader.h"
3838
#include "tracer/raw2trace.h"
3939
#include "tracer/raw2trace_directory.h"
40+
#include "test_helpers.h"
4041
#include <iostream>
4142
#include <sstream>
4243

clients/drcachesim/tests/reg_id_set_unit_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* **********************************************************
2-
* Copyright (c) 2020 Google, Inc. All rights reserved.
2+
* Copyright (c) 2020-2025 Google, Inc. All rights reserved.
33
* **********************************************************/
44

55
/*
@@ -35,6 +35,7 @@
3535
* (fewer executables reduces the limited-resource CI time).
3636
*/
3737

38+
#include "test_helpers.h"
3839
#include <assert.h>
3940
#include "tracer/instru.h"
4041

0 commit comments

Comments
 (0)