Alexey Samsonov | 603c4be | 2012-06-04 13:55:19 +0000 | [diff] [blame] | 1 | //===-- tsan_flags_test.cc ------------------------------------------------===// |
Kostya Serebryany | da4edd8 | 2012-05-10 14:18:22 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file is a part of ThreadSanitizer (TSan), a race detector. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | #include "tsan_flags.h" |
| 14 | #include "tsan_rtl.h" |
| 15 | #include "gtest/gtest.h" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 16 | #include <string> |
Kostya Serebryany | da4edd8 | 2012-05-10 14:18:22 +0000 | [diff] [blame] | 17 | |
| 18 | namespace __tsan { |
| 19 | |
| 20 | TEST(Flags, Basic) { |
Kostya Serebryany | da4edd8 | 2012-05-10 14:18:22 +0000 | [diff] [blame] | 21 | // At least should not crash. |
Alexey Samsonov | e64c3b6 | 2012-09-18 08:33:37 +0000 | [diff] [blame] | 22 | Flags f; |
Kostya Serebryany | da4edd8 | 2012-05-10 14:18:22 +0000 | [diff] [blame] | 23 | InitializeFlags(&f, 0); |
| 24 | InitializeFlags(&f, ""); |
| 25 | } |
| 26 | |
Alexey Samsonov | f3be706 | 2012-07-09 13:21:39 +0000 | [diff] [blame] | 27 | TEST(Flags, DefaultValues) { |
Alexey Samsonov | e64c3b6 | 2012-09-18 08:33:37 +0000 | [diff] [blame] | 28 | Flags f; |
Kostya Serebryany | da4edd8 | 2012-05-10 14:18:22 +0000 | [diff] [blame] | 29 | |
| 30 | f.enable_annotations = false; |
Kostya Serebryany | da4edd8 | 2012-05-10 14:18:22 +0000 | [diff] [blame] | 31 | f.exitcode = -11; |
Alexey Samsonov | f3be706 | 2012-07-09 13:21:39 +0000 | [diff] [blame] | 32 | InitializeFlags(&f, ""); |
| 33 | EXPECT_EQ(66, f.exitcode); |
| 34 | EXPECT_EQ(true, f.enable_annotations); |
Kostya Serebryany | da4edd8 | 2012-05-10 14:18:22 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 37 | static const char *options1 = |
| 38 | " enable_annotations=0" |
| 39 | " suppress_equal_stacks=0" |
| 40 | " suppress_equal_addresses=0" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 41 | " report_bugs=0" |
| 42 | " report_thread_leaks=0" |
| 43 | " report_destroy_locked=0" |
| 44 | " report_mutex_bugs=0" |
| 45 | " report_signal_unsafe=0" |
| 46 | " report_atomic_races=0" |
| 47 | " force_seq_cst_atomics=0" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 48 | " print_benign=0" |
| 49 | " exitcode=111" |
| 50 | " halt_on_error=0" |
| 51 | " atexit_sleep_ms=222" |
| 52 | " profile_memory=qqq" |
| 53 | " flush_memory_ms=444" |
| 54 | " flush_symbolizer_ms=555" |
| 55 | " memory_limit_mb=666" |
| 56 | " stop_on_start=0" |
| 57 | " running_on_valgrind=0" |
| 58 | " history_size=5" |
| 59 | " io_sync=1" |
| 60 | " die_after_fork=true" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 61 | ""; |
| 62 | |
| 63 | static const char *options2 = |
| 64 | " enable_annotations=true" |
| 65 | " suppress_equal_stacks=true" |
| 66 | " suppress_equal_addresses=true" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 67 | " report_bugs=true" |
| 68 | " report_thread_leaks=true" |
| 69 | " report_destroy_locked=true" |
| 70 | " report_mutex_bugs=true" |
| 71 | " report_signal_unsafe=true" |
| 72 | " report_atomic_races=true" |
| 73 | " force_seq_cst_atomics=true" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 74 | " print_benign=true" |
| 75 | " exitcode=222" |
| 76 | " halt_on_error=true" |
| 77 | " atexit_sleep_ms=123" |
| 78 | " profile_memory=bbbbb" |
| 79 | " flush_memory_ms=234" |
| 80 | " flush_symbolizer_ms=345" |
| 81 | " memory_limit_mb=456" |
| 82 | " stop_on_start=true" |
| 83 | " running_on_valgrind=true" |
| 84 | " history_size=6" |
| 85 | " io_sync=2" |
| 86 | " die_after_fork=false" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 87 | ""; |
| 88 | |
| 89 | void VerifyOptions1(Flags *f) { |
| 90 | EXPECT_EQ(f->enable_annotations, 0); |
| 91 | EXPECT_EQ(f->suppress_equal_stacks, 0); |
| 92 | EXPECT_EQ(f->suppress_equal_addresses, 0); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 93 | EXPECT_EQ(f->report_bugs, 0); |
| 94 | EXPECT_EQ(f->report_thread_leaks, 0); |
| 95 | EXPECT_EQ(f->report_destroy_locked, 0); |
| 96 | EXPECT_EQ(f->report_mutex_bugs, 0); |
| 97 | EXPECT_EQ(f->report_signal_unsafe, 0); |
| 98 | EXPECT_EQ(f->report_atomic_races, 0); |
| 99 | EXPECT_EQ(f->force_seq_cst_atomics, 0); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 100 | EXPECT_EQ(f->print_benign, 0); |
| 101 | EXPECT_EQ(f->exitcode, 111); |
| 102 | EXPECT_EQ(f->halt_on_error, 0); |
| 103 | EXPECT_EQ(f->atexit_sleep_ms, 222); |
| 104 | EXPECT_EQ(f->profile_memory, std::string("qqq")); |
| 105 | EXPECT_EQ(f->flush_memory_ms, 444); |
| 106 | EXPECT_EQ(f->flush_symbolizer_ms, 555); |
| 107 | EXPECT_EQ(f->memory_limit_mb, 666); |
| 108 | EXPECT_EQ(f->stop_on_start, 0); |
| 109 | EXPECT_EQ(f->running_on_valgrind, 0); |
| 110 | EXPECT_EQ(f->history_size, 5); |
| 111 | EXPECT_EQ(f->io_sync, 1); |
| 112 | EXPECT_EQ(f->die_after_fork, true); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void VerifyOptions2(Flags *f) { |
| 116 | EXPECT_EQ(f->enable_annotations, true); |
| 117 | EXPECT_EQ(f->suppress_equal_stacks, true); |
| 118 | EXPECT_EQ(f->suppress_equal_addresses, true); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 119 | EXPECT_EQ(f->report_bugs, true); |
| 120 | EXPECT_EQ(f->report_thread_leaks, true); |
| 121 | EXPECT_EQ(f->report_destroy_locked, true); |
| 122 | EXPECT_EQ(f->report_mutex_bugs, true); |
| 123 | EXPECT_EQ(f->report_signal_unsafe, true); |
| 124 | EXPECT_EQ(f->report_atomic_races, true); |
| 125 | EXPECT_EQ(f->force_seq_cst_atomics, true); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 126 | EXPECT_EQ(f->print_benign, true); |
| 127 | EXPECT_EQ(f->exitcode, 222); |
| 128 | EXPECT_EQ(f->halt_on_error, true); |
| 129 | EXPECT_EQ(f->atexit_sleep_ms, 123); |
| 130 | EXPECT_EQ(f->profile_memory, std::string("bbbbb")); |
| 131 | EXPECT_EQ(f->flush_memory_ms, 234); |
| 132 | EXPECT_EQ(f->flush_symbolizer_ms, 345); |
| 133 | EXPECT_EQ(f->memory_limit_mb, 456); |
| 134 | EXPECT_EQ(f->stop_on_start, true); |
| 135 | EXPECT_EQ(f->running_on_valgrind, true); |
| 136 | EXPECT_EQ(f->history_size, 6); |
| 137 | EXPECT_EQ(f->io_sync, 2); |
| 138 | EXPECT_EQ(f->die_after_fork, false); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static const char *test_default_options; |
| 142 | extern "C" const char *__tsan_default_options() { |
| 143 | return test_default_options; |
| 144 | } |
| 145 | |
| 146 | TEST(Flags, ParseDefaultOptions) { |
| 147 | Flags f; |
| 148 | |
| 149 | test_default_options = options1; |
| 150 | InitializeFlags(&f, ""); |
| 151 | VerifyOptions1(&f); |
| 152 | |
| 153 | test_default_options = options2; |
| 154 | InitializeFlags(&f, ""); |
| 155 | VerifyOptions2(&f); |
| 156 | } |
| 157 | |
| 158 | TEST(Flags, ParseEnvOptions) { |
| 159 | Flags f; |
| 160 | |
| 161 | InitializeFlags(&f, options1); |
| 162 | VerifyOptions1(&f); |
| 163 | |
| 164 | InitializeFlags(&f, options2); |
| 165 | VerifyOptions2(&f); |
| 166 | } |
| 167 | |
| 168 | TEST(Flags, ParsePriority) { |
| 169 | Flags f; |
| 170 | |
| 171 | test_default_options = options2; |
| 172 | InitializeFlags(&f, options1); |
| 173 | VerifyOptions1(&f); |
| 174 | |
| 175 | test_default_options = options1; |
| 176 | InitializeFlags(&f, options2); |
| 177 | VerifyOptions2(&f); |
| 178 | } |
| 179 | |
Kostya Serebryany | da4edd8 | 2012-05-10 14:18:22 +0000 | [diff] [blame] | 180 | } // namespace __tsan |