1 //===-- tsan_flags_test.cpp -----------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of ThreadSanitizer (TSan), a race detector.
11 //===----------------------------------------------------------------------===//
12 #include "tsan_flags.h"
14 #include "gtest/gtest.h"
20 // At least should not crash.
22 InitializeFlags(&f
, 0);
23 InitializeFlags(&f
, "");
26 TEST(Flags
, DefaultValues
) {
29 f
.enable_annotations
= false;
30 InitializeFlags(&f
, "");
31 EXPECT_EQ(true, f
.enable_annotations
);
34 static const char *options1
=
35 " enable_annotations=0"
36 " suppress_equal_stacks=0"
38 " report_thread_leaks=0"
39 " report_destroy_locked=0"
40 " report_mutex_bugs=0"
41 " report_signal_unsafe=0"
42 " report_atomic_races=0"
43 " force_seq_cst_atomics=0"
45 " atexit_sleep_ms=222"
47 " flush_memory_ms=444"
48 " flush_symbolizer_ms=555"
49 " memory_limit_mb=666"
51 " running_on_valgrind=0"
54 " die_after_fork=true"
57 static const char *options2
=
58 " enable_annotations=true"
59 " suppress_equal_stacks=true"
61 " report_thread_leaks=true"
62 " report_destroy_locked=true"
63 " report_mutex_bugs=true"
64 " report_signal_unsafe=true"
65 " report_atomic_races=true"
66 " force_seq_cst_atomics=true"
68 " atexit_sleep_ms=123"
69 " profile_memory=bbbbb"
70 " flush_memory_ms=234"
71 " flush_symbolizer_ms=345"
72 " memory_limit_mb=456"
74 " running_on_valgrind=true"
77 " die_after_fork=false"
80 void VerifyOptions1(Flags
*f
) {
81 EXPECT_EQ(f
->enable_annotations
, 0);
82 EXPECT_EQ(f
->suppress_equal_stacks
, 0);
83 EXPECT_EQ(f
->report_bugs
, 0);
84 EXPECT_EQ(f
->report_thread_leaks
, 0);
85 EXPECT_EQ(f
->report_destroy_locked
, 0);
86 EXPECT_EQ(f
->report_mutex_bugs
, 0);
87 EXPECT_EQ(f
->report_signal_unsafe
, 0);
88 EXPECT_EQ(f
->report_atomic_races
, 0);
89 EXPECT_EQ(f
->force_seq_cst_atomics
, 0);
90 EXPECT_EQ(f
->halt_on_error
, 0);
91 EXPECT_EQ(f
->atexit_sleep_ms
, 222);
92 EXPECT_EQ(f
->profile_memory
, std::string("qqq"));
93 EXPECT_EQ(f
->flush_memory_ms
, 444);
94 EXPECT_EQ(f
->flush_symbolizer_ms
, 555);
95 EXPECT_EQ(f
->memory_limit_mb
, 666);
96 EXPECT_EQ(f
->stop_on_start
, 0);
97 EXPECT_EQ(f
->running_on_valgrind
, 0);
98 EXPECT_EQ(f
->history_size
, (uptr
)5);
99 EXPECT_EQ(f
->io_sync
, 1);
100 EXPECT_EQ(f
->die_after_fork
, true);
103 void VerifyOptions2(Flags
*f
) {
104 EXPECT_EQ(f
->enable_annotations
, true);
105 EXPECT_EQ(f
->suppress_equal_stacks
, true);
106 EXPECT_EQ(f
->report_bugs
, true);
107 EXPECT_EQ(f
->report_thread_leaks
, true);
108 EXPECT_EQ(f
->report_destroy_locked
, true);
109 EXPECT_EQ(f
->report_mutex_bugs
, true);
110 EXPECT_EQ(f
->report_signal_unsafe
, true);
111 EXPECT_EQ(f
->report_atomic_races
, true);
112 EXPECT_EQ(f
->force_seq_cst_atomics
, true);
113 EXPECT_EQ(f
->halt_on_error
, true);
114 EXPECT_EQ(f
->atexit_sleep_ms
, 123);
115 EXPECT_EQ(f
->profile_memory
, std::string("bbbbb"));
116 EXPECT_EQ(f
->flush_memory_ms
, 234);
117 EXPECT_EQ(f
->flush_symbolizer_ms
, 345);
118 EXPECT_EQ(f
->memory_limit_mb
, 456);
119 EXPECT_EQ(f
->stop_on_start
, true);
120 EXPECT_EQ(f
->running_on_valgrind
, true);
121 EXPECT_EQ(f
->history_size
, 6ul);
122 EXPECT_EQ(f
->io_sync
, 2);
123 EXPECT_EQ(f
->die_after_fork
, false);
126 static const char *test_default_options
;
127 extern "C" const char *__tsan_default_options() {
128 return test_default_options
;
131 TEST(Flags
, ParseDefaultOptions
) {
134 test_default_options
= options1
;
135 InitializeFlags(&f
, "");
138 test_default_options
= options2
;
139 InitializeFlags(&f
, "");
143 TEST(Flags
, ParseEnvOptions
) {
146 InitializeFlags(&f
, options1
);
149 InitializeFlags(&f
, options2
);
153 TEST(Flags
, ParsePriority
) {
156 test_default_options
= options2
;
157 InitializeFlags(&f
, options1
);
160 test_default_options
= options1
;
161 InitializeFlags(&f
, options2
);
165 } // namespace __tsan