diff options
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r-- | src/test/test_util.c | 80 |
1 files changed, 14 insertions, 66 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index 546b3c2907..f10aed71ac 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -1,6 +1,6 @@ /* Copyright (c) 2001-2004, Roger Dingledine. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. - * Copyright (c) 2007-2020, The Tor Project, Inc. */ + * Copyright (c) 2007-2021, The Tor Project, Inc. */ /* See LICENSE for licensing information */ #include "orconfig.h" @@ -4532,7 +4532,7 @@ test_util_glob(void *ptr) #else const char *results_test3[] = {"dir1", "dir2", "file1", "file2", "forbidden"}; -#endif +#endif /* defined(_WIN32) */ TEST("*i*"); EXPECT(results_test3); @@ -4577,7 +4577,7 @@ test_util_glob(void *ptr) #else const char *results_test12[] = {"dir1", "dir2", "empty", "file1", "file2", "forbidden"}; -#endif +#endif /* defined(_WIN32) */ TEST("*"); EXPECT(results_test12); @@ -4624,7 +4624,7 @@ test_util_glob(void *ptr) tor_free(pattern); tt_assert(!results); } -#endif +#endif /* !defined(_WIN32) */ #undef TEST #undef EXPECT @@ -4636,7 +4636,7 @@ test_util_glob(void *ptr) (void) chmod(dir1_forbidden, 0700); (void) chmod(dir2_forbidden, 0700); (void) chmod(forbidden_forbidden, 0700); -#endif +#endif /* !defined(_WIN32) */ tor_free(dir1); tor_free(dir2); tor_free(forbidden); @@ -4650,11 +4650,11 @@ test_util_glob(void *ptr) SMARTLIST_FOREACH(results, char *, f, tor_free(f)); smartlist_free(results); } -#else +#else /* !defined(HAVE_GLOB) */ tt_skip(); done: return; -#endif +#endif /* defined(HAVE_GLOB) */ } static void @@ -4762,7 +4762,7 @@ test_util_get_glob_opened_files(void *ptr) // dot files are not special on windows const char *results_test3[] = {"", ".test-hidden", "dir1", "dir2", "empty", "file1", "file2", "forbidden"}; -#endif +#endif /* !defined(_WIN32) */ TEST("*"PATH_SEPARATOR"*"); EXPECT(results_test3); @@ -4774,7 +4774,7 @@ test_util_get_glob_opened_files(void *ptr) // dot files are not special on windows const char *results_test4[] = {"", ".test-hidden", "dir1", "dir2", "empty", "file1", "file2", "forbidden"}; -#endif +#endif /* !defined(_WIN32) */ TEST("*"PATH_SEPARATOR"*"PATH_SEPARATOR); EXPECT(results_test4); @@ -4839,7 +4839,7 @@ test_util_get_glob_opened_files(void *ptr) TT_FAIL(("unable to chmod a file on cleanup: %s", strerror(errno))); } } -#endif +#endif /* !defined(_WIN32) */ tor_free(dir1); tor_free(dir2); tor_free(forbidden); @@ -4853,11 +4853,11 @@ test_util_get_glob_opened_files(void *ptr) SMARTLIST_FOREACH(results, char *, f, tor_free(f)); smartlist_free(results); } -#else +#else /* !defined(HAVE_GLOB) */ tt_skip(); done: return; -#endif +#endif /* defined(HAVE_GLOB) */ } static void @@ -5920,7 +5920,7 @@ static int fd_is_cloexec(tor_socket_t fd) { int flags = fcntl(fd, F_GETFD, 0); - return (flags & FD_CLOEXEC) == FD_CLOEXEC; + return (flags & FD_CLOEXEC) != 0; } #endif /* defined(FD_CLOEXEC) */ @@ -5930,7 +5930,7 @@ static int fd_is_nonblocking(tor_socket_t fd) { int flags = fcntl(fd, F_GETFL, 0); - return (flags & O_NONBLOCK) == O_NONBLOCK; + return (flags & O_NONBLOCK) != 0; } #endif /* !defined(_WIN32) */ @@ -6768,57 +6768,6 @@ test_util_get_unquoted_path(void *arg) } static void -test_util_log_mallinfo(void *arg) -{ - (void)arg; - char *log1 = NULL, *log2 = NULL, *mem = NULL; -#ifdef HAVE_MALLINFO - setup_capture_of_logs(LOG_INFO); - tor_log_mallinfo(LOG_INFO); - expect_single_log_msg_containing("mallinfo() said: "); - mock_saved_log_entry_t *lg = smartlist_get(mock_saved_logs(), 0); - log1 = tor_strdup(lg->generated_msg); - - mock_clean_saved_logs(); - mem = tor_malloc(8192); - tor_log_mallinfo(LOG_INFO); - expect_single_log_msg_containing("mallinfo() said: "); - lg = smartlist_get(mock_saved_logs(), 0); - log2 = tor_strdup(lg->generated_msg); - - /* Make sure that the amount of used memory increased. */ - const char *used1 = strstr(log1, "uordblks="); - const char *used2 = strstr(log2, "uordblks="); - tt_assert(used1); - tt_assert(used2); - used1 += strlen("uordblks="); - used2 += strlen("uordblks="); - - int ok1, ok2; - char *next1 = NULL, *next2 = NULL; - uint64_t mem1 = tor_parse_uint64(used1, 10, 0, UINT64_MAX, &ok1, &next1); - uint64_t mem2 = tor_parse_uint64(used2, 10, 0, UINT64_MAX, &ok2, &next2); - tt_assert(ok1); - tt_assert(ok2); - tt_assert(next1); - tt_assert(next2); - if (mem2 == 0) { - /* This is a fake mallinfo that doesn't actually fill in its outputs. */ - tt_u64_op(mem1, OP_EQ, 0); - } else { - tt_u64_op(mem1, OP_LT, mem2); - } -#else /* !defined(HAVE_MALLINFO) */ - tt_skip(); -#endif /* defined(HAVE_MALLINFO) */ - done: - teardown_capture_of_logs(); - tor_free(log1); - tor_free(log2); - tor_free(mem); -} - -static void test_util_map_anon(void *arg) { (void)arg; @@ -7089,7 +7038,6 @@ struct testcase_t util_tests[] = { UTIL_TEST(monotonic_time_add_msec, 0), UTIL_TEST(htonll, 0), UTIL_TEST(get_unquoted_path, 0), - UTIL_TEST(log_mallinfo, 0), UTIL_TEST(map_anon, 0), UTIL_TEST(map_anon_nofork, 0), END_OF_TESTCASES |