13
13
#include " sanitizer_common/sanitizer_platform.h"
14
14
#if SANITIZER_LINUX
15
15
16
- #include " sanitizer_common/sanitizer_linux.h"
16
+ # include < pthread.h>
17
+ # include < sched.h>
18
+ # include < stdlib.h>
17
19
18
- #include " sanitizer_common/sanitizer_common.h"
19
- #include " sanitizer_common/sanitizer_file.h"
20
- #include " gtest/gtest.h"
20
+ # include < algorithm>
21
+ # include < vector>
21
22
22
- #include < pthread.h>
23
- #include < sched.h>
24
- #include < stdlib.h>
25
-
26
- #include < algorithm>
27
- #include < vector>
23
+ # include " gtest/gtest.h"
24
+ # include " sanitizer_common/sanitizer_common.h"
25
+ # include " sanitizer_common/sanitizer_file.h"
26
+ # include " sanitizer_common/sanitizer_linux.h"
28
27
29
28
namespace __sanitizer {
30
29
@@ -109,9 +108,8 @@ void *TidReporterThread(void *argument) {
109
108
void ThreadListerTest::SpawnTidReporter (pthread_t *pthread_id, tid_t *tid) {
110
109
pthread_mutex_lock (&thread_arg.tid_reported_mutex );
111
110
thread_arg.reported_tid = -1 ;
112
- ASSERT_EQ (0 , pthread_create (pthread_id, NULL ,
113
- TidReporterThread,
114
- &thread_arg));
111
+ ASSERT_EQ (0 ,
112
+ pthread_create (pthread_id, NULL , TidReporterThread, &thread_arg));
115
113
while (thread_arg.reported_tid == (tid_t )(-1 ))
116
114
pthread_cond_wait (&thread_arg.tid_reported_cond ,
117
115
&thread_arg.tid_reported_mutex );
@@ -129,8 +127,8 @@ static std::vector<tid_t> ReadTidsToVector(ThreadLister *thread_lister) {
129
127
static bool Includes (std::vector<tid_t > first, std::vector<tid_t > second) {
130
128
std::sort (first.begin (), first.end ());
131
129
std::sort (second.begin (), second.end ());
132
- return std::includes (first.begin (), first.end (),
133
- second.begin (), second. end ());
130
+ return std::includes (first.begin (), first.end (), second. begin (),
131
+ second.end ());
134
132
}
135
133
136
134
static bool HasElement (const std::vector<tid_t > &vector, tid_t element) {
@@ -187,7 +185,7 @@ TEST(SanitizerCommon, SetEnvTest) {
187
185
EXPECT_EQ (0 , getenv (kEnvName ));
188
186
}
189
187
190
- #if (defined(__x86_64__) || defined(__i386__)) && !SANITIZER_ANDROID
188
+ # if (defined(__x86_64__) || defined(__i386__)) && !SANITIZER_ANDROID
191
189
// libpthread puts the thread descriptor at the end of stack space.
192
190
void *thread_descriptor_size_test_func (void *arg) {
193
191
uptr descr_addr = (uptr)pthread_self ();
@@ -206,48 +204,48 @@ TEST(SanitizerLinux, ThreadDescriptorSize) {
206
204
ASSERT_EQ (0 , pthread_join (tid, &result));
207
205
EXPECT_EQ ((uptr)result, ThreadDescriptorSize ());
208
206
}
209
- #endif
207
+ # endif
210
208
211
209
TEST (SanitizerCommon, LibraryNameIs) {
212
210
EXPECT_FALSE (LibraryNameIs (" " , " " ));
213
211
214
212
char full_name[256 ];
215
- const char *paths[] = { " " , " /" , " /path/to/" };
216
- const char *suffixes[] = { " " , " -linux" , " .1.2" , " -linux.1.2" };
217
- const char *base_names[] = { " lib" , " lib.0" , " lib-i386" };
218
- const char *wrong_names[] = { " " , " lib.9" , " lib-x86_64" };
213
+ const char *paths[] = {" " , " /" , " /path/to/" };
214
+ const char *suffixes[] = {" " , " -linux" , " .1.2" , " -linux.1.2" };
215
+ const char *base_names[] = {" lib" , " lib.0" , " lib-i386" };
216
+ const char *wrong_names[] = {" " , " lib.9" , " lib-x86_64" };
219
217
for (uptr i = 0 ; i < ARRAY_SIZE (paths); i++)
220
218
for (uptr j = 0 ; j < ARRAY_SIZE (suffixes); j++) {
221
219
for (uptr k = 0 ; k < ARRAY_SIZE (base_names); k++) {
222
220
internal_snprintf (full_name, ARRAY_SIZE (full_name), " %s%s%s.so" ,
223
221
paths[i], base_names[k], suffixes[j]);
224
222
EXPECT_TRUE (LibraryNameIs (full_name, base_names[k]))
225
- << " Full name " << full_name
226
- << " doesn't match base name " << base_names[k];
223
+ << " Full name " << full_name << " doesn't match base name "
224
+ << base_names[k];
227
225
for (uptr m = 0 ; m < ARRAY_SIZE (wrong_names); m++)
228
226
EXPECT_FALSE (LibraryNameIs (full_name, wrong_names[m]))
229
- << " Full name " << full_name
230
- << " matches base name " << wrong_names[m];
227
+ << " Full name " << full_name << " matches base name "
228
+ << wrong_names[m];
231
229
}
232
230
}
233
231
}
234
232
235
- #if defined(__mips64)
233
+ # if defined(__mips64)
236
234
// Effectively, this is a test for ThreadDescriptorSize() which is used to
237
235
// compute ThreadSelf().
238
236
TEST (SanitizerLinux, ThreadSelfTest) {
239
237
ASSERT_EQ (pthread_self (), ThreadSelf ());
240
238
}
241
- #endif
239
+ # endif
242
240
243
241
TEST (SanitizerCommon, StartSubprocessTest) {
244
242
int pipe_fds[2 ];
245
243
ASSERT_EQ (0 , pipe (pipe_fds));
246
- #if SANITIZER_ANDROID
244
+ # if SANITIZER_ANDROID
247
245
const char *shell = " /system/bin/sh" ;
248
- #else
246
+ # else
249
247
const char *shell = " /bin/sh" ;
250
- #endif
248
+ # endif
251
249
const char *argv[] = {shell, " -c" , " echo -n 'hello'" , (char *)NULL };
252
250
int pid = StartSubprocess (shell, argv, GetEnviron (),
253
251
/* stdin */ kInvalidFd , /* stdout */ pipe_fds[1 ]);
0 commit comments