From 957bf49f9a75373c984c62f2381682c8f97ef3a6 Mon Sep 17 00:00:00 2001 From: xinsheng Ren <285808407@qq.com> Date: Wed, 8 Mar 2023 18:42:38 +0800 Subject: [PATCH] enh: coverage (#20307) * enh: coverage * enh: coverage, atomic * fix: int to int8 error * enh: delete unused code --- source/os/src/osMath.c | 14 ---- source/os/src/osSleep.c | 3 + source/os/src/osString.c | 30 ++++---- source/os/test/CMakeLists.txt | 58 +++++++++++++++- source/os/test/osAtomicTests.cpp | 115 +++++++++++++++++++++++++++++++ source/os/test/osMathTests.cpp | 62 +++++++++++++++++ source/os/test/osSignalTests.cpp | 40 +++++++++++ source/os/test/osSleepTests.cpp | 63 +++++++++++++++++ source/os/test/osStringTests.cpp | 113 ++++++++++++++++++++++++++++++ source/os/test/osSystemTests.cpp | 41 +++++++++++ source/os/test/osThreadTests.cpp | 34 +++++++++ source/os/test/osTimeTests.cpp | 48 +++++++++++++ 12 files changed, 591 insertions(+), 30 deletions(-) create mode 100644 source/os/test/osAtomicTests.cpp create mode 100644 source/os/test/osMathTests.cpp create mode 100644 source/os/test/osSignalTests.cpp create mode 100644 source/os/test/osSleepTests.cpp create mode 100644 source/os/test/osStringTests.cpp create mode 100644 source/os/test/osSystemTests.cpp create mode 100644 source/os/test/osThreadTests.cpp create mode 100644 source/os/test/osTimeTests.cpp diff --git a/source/os/src/osMath.c b/source/os/src/osMath.c index b466f89a1d..1c7c825ce8 100644 --- a/source/os/src/osMath.c +++ b/source/os/src/osMath.c @@ -18,20 +18,6 @@ #include #include "talgo.h" -#ifdef WINDOWS -void swapStr(char* j, char* J, int width) { - int i; - char tmp; - for (i = 0; i < width; i++) { - tmp = *j; - *j = *J; - *J = tmp; - j++; - J++; - } -} -#endif - int32_t qsortHelper(const void* p1, const void* p2, const void* param) { __compar_fn_t comparFn = param; return comparFn(p1, p2); diff --git a/source/os/src/osSleep.c b/source/os/src/osSleep.c index a2373f952f..f6cc7d608d 100644 --- a/source/os/src/osSleep.c +++ b/source/os/src/osSleep.c @@ -22,6 +22,7 @@ #endif void taosSsleep(int32_t s) { + if (s < 0) return; #ifdef WINDOWS Sleep(1000 * s); #else @@ -30,6 +31,7 @@ void taosSsleep(int32_t s) { } void taosMsleep(int32_t ms) { + if (ms < 0) return; #ifdef WINDOWS Sleep(ms); #else @@ -38,6 +40,7 @@ void taosMsleep(int32_t ms) { } void taosUsleep(int32_t us) { + if (us < 0) return; #ifdef WINDOWS HANDLE timer; LARGE_INTEGER interval; diff --git a/source/os/src/osString.c b/source/os/src/osString.c index ae4a8a5cad..0f459b58cd 100644 --- a/source/os/src/osString.c +++ b/source/os/src/osString.c @@ -94,21 +94,21 @@ int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes) { return 0; -#if 0 - int32_t ucs4_max_len = bytes + 4; - char *f1_mbs = taosMemoryCalloc(bytes, 1); - char *f2_mbs = taosMemoryCalloc(bytes, 1); - if (taosUcs4ToMbs(f1_ucs4, ucs4_max_len, f1_mbs) < 0) { - return -1; - } - if (taosUcs4ToMbs(f2_ucs4, ucs4_max_len, f2_mbs) < 0) { - return -1; - } - int32_t ret = strcmp(f1_mbs, f2_mbs); - taosMemoryFree(f1_mbs); - taosMemoryFree(f2_mbs); - return ret; -#endif +//#if 0 +// int32_t ucs4_max_len = bytes + 4; +// char *f1_mbs = taosMemoryCalloc(bytes, 1); +// char *f2_mbs = taosMemoryCalloc(bytes, 1); +// if (taosUcs4ToMbs(f1_ucs4, ucs4_max_len, f1_mbs) < 0) { +// return -1; +// } +// if (taosUcs4ToMbs(f2_ucs4, ucs4_max_len, f2_mbs) < 0) { +// return -1; +// } +// int32_t ret = strcmp(f1_mbs, f2_mbs); +// taosMemoryFree(f1_mbs); +// taosMemoryFree(f2_mbs); +// return ret; +//#endif } TdUcs4 *tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4) { diff --git a/source/os/test/CMakeLists.txt b/source/os/test/CMakeLists.txt index 21fb2ee630..fba4d23e3f 100644 --- a/source/os/test/CMakeLists.txt +++ b/source/os/test/CMakeLists.txt @@ -17,8 +17,64 @@ INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc) # osTests add_executable(osTests "osTests.cpp") -target_link_libraries(osTests os util gtest_main) +target_link_libraries(osTests os util gtest_main) add_test( NAME osTests COMMAND osTests +) + +add_executable(osSystemTests "osSystemTests.cpp") +target_link_libraries(osSystemTests os util gtest_main) +add_test( + NAME osSystemTests + COMMAND osSystemTests +) + +add_executable(osMathTests "osMathTests.cpp") +target_link_libraries(osMathTests os util gtest_main) +add_test( + NAME osMathTests + COMMAND osMathTests +) + +add_executable(osSignalTests "osSignalTests.cpp") +target_link_libraries(osSignalTests os util gtest_main) +add_test( + NAME osSignalTests + COMMAND osSignalTests +) + +add_executable(osSleepTests "osSleepTests.cpp") +target_link_libraries(osSleepTests os util gtest_main) +add_test( + NAME osSleepTests + COMMAND osSleepTests +) + +add_executable(osStringTests "osStringTests.cpp") +target_link_libraries(osStringTests os util gtest_main) +add_test( + NAME osStringTests + COMMAND osStringTests +) + +add_executable(osThreadTests "osThreadTests.cpp") +target_link_libraries(osThreadTests os util gtest_main) +add_test( + NAME osThreadTests + COMMAND osThreadTests +) + +add_executable(osTimeTests "osTimeTests.cpp") +target_link_libraries(osTimeTests os util gtest_main) +add_test( + NAME osTimeTests + COMMAND osTimeTests +) + +add_executable(osAtomicTests "osAtomicTests.cpp") +target_link_libraries(osAtomicTests os util gtest_main) +add_test( + NAME osAtomicTests + COMMAND osAtomicTests ) \ No newline at end of file diff --git a/source/os/test/osAtomicTests.cpp b/source/os/test/osAtomicTests.cpp new file mode 100644 index 0000000000..eebc1574c3 --- /dev/null +++ b/source/os/test/osAtomicTests.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wwrite-strings" +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wformat" +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" +#pragma GCC diagnostic ignored "-Wpointer-arith" + +#include "os.h" +#include "tlog.h" + +TEST(osAtomicTests, Exchange16) { + int16_t value = 123; + int16_t new_value = 456; + int16_t result = atomic_exchange_16(&value, new_value); + EXPECT_EQ(result, 123); + EXPECT_EQ(value, 456); +} + +TEST(osAtomicTests, Exchange32) { + int32_t value = 123; + int32_t new_value = 456; + int32_t result = atomic_exchange_32(&value, new_value); + EXPECT_EQ(result, 123); + EXPECT_EQ(value, 456); +} + +TEST(osAtomicTests, Exchange64) { + int64_t value = 123; + int64_t new_value = 456; + int64_t result = atomic_exchange_64(&value, new_value); + EXPECT_EQ(result, 123); + EXPECT_EQ(value, 456); +} + +TEST(osAtomicTests, ExchangePtr) { + int value1 = 123; + int value2 = 456; + int* ptr = &value1; + int* result = (int*)atomic_exchange_ptr(&ptr, &value2); + EXPECT_EQ(result, &value1); + EXPECT_EQ(*ptr, 456); +} + +TEST(osAtomicTests, ValCompareExchange8) { + int8_t value = 12; + int8_t oldval = 12; + int8_t newval = 45; + int8_t result = atomic_val_compare_exchange_8(&value, oldval, newval); + EXPECT_EQ(result, 12); + EXPECT_EQ(value, 45); + + oldval = 78; + result = atomic_val_compare_exchange_8(&value, oldval, newval); + EXPECT_EQ(result, 45); + EXPECT_EQ(value, 45); +} + +TEST(osAtomicTests, ValCompareExchange16) { + int16_t value = 123; + int16_t oldval = 123; + int16_t newval = 456; + int16_t result = atomic_val_compare_exchange_16(&value, oldval, newval); + EXPECT_EQ(result, 123); + EXPECT_EQ(value, 456); + + oldval = 789; + result = atomic_val_compare_exchange_16(&value, oldval, newval); + EXPECT_EQ(result, 456); + EXPECT_EQ(value, 456); +} + +TEST(osAtomicTests, TestAtomicExchange8) { + volatile int8_t value = 42; + int8_t new_value = 100; + int8_t old_value = atomic_exchange_8(&value, new_value); + EXPECT_EQ(old_value, 42); + EXPECT_EQ(value, new_value); +} + +TEST(osAtomicTests, TestAtomicAddFetch16) { + volatile int16_t value = 42; + int16_t increment = 10; + int16_t new_value = atomic_add_fetch_16(&value, increment); + EXPECT_EQ(new_value, 52); + EXPECT_EQ(value, 52); +} + +//TEST(osAtomicTests, AddFetchPtr) { +// uintptr_t val = 0; +// uintptr_t* ptr = &val; +// uintptr_t ret = atomic_add_fetch_ptr(ptr, 10); +// EXPECT_EQ(ret, 10); +// EXPECT_EQ(val, 10); +//} diff --git a/source/os/test/osMathTests.cpp b/source/os/test/osMathTests.cpp new file mode 100644 index 0000000000..93c8d1f8da --- /dev/null +++ b/source/os/test/osMathTests.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wwrite-strings" +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wformat" +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" +#pragma GCC diagnostic ignored "-Wpointer-arith" + +#include "os.h" +#include "tlog.h" + +struct TestStruct { + int a; + float b; +}; + +// Define a custom comparison function for testing +int cmpFunc(const void* a, const void* b) { + const TestStruct* pa = reinterpret_cast(a); + const TestStruct* pb = reinterpret_cast(b); + if (pa->a < pb->a) { + return -1; + } else if (pa->a > pb->a) { + return 1; + } else { + return 0; + } +} + +TEST(osMathTests, taosSort) { + // Create an array of test data + TestStruct arr[] = {{4, 2.5}, {2, 1.5}, {1, 3.5}, {3, 4.5}}; + + // Sort the array using taosSort + taosSort(arr, 4, sizeof(TestStruct), cmpFunc); + + // Check that the array is sorted correctly + EXPECT_EQ(arr[0].a, 1); + EXPECT_EQ(arr[1].a, 2); + EXPECT_EQ(arr[2].a, 3); + EXPECT_EQ(arr[3].a, 4); +} \ No newline at end of file diff --git a/source/os/test/osSignalTests.cpp b/source/os/test/osSignalTests.cpp new file mode 100644 index 0000000000..f4cc6e9e58 --- /dev/null +++ b/source/os/test/osSignalTests.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wwrite-strings" +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wformat" +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" +#pragma GCC diagnostic ignored "-Wpointer-arith" + +#include "os.h" +#include "tlog.h" + +TEST(osSignalTests, taosSetSignal) { + // Set up SIGINT handler using taosSetSignal + //taosSetSignal(SIGINT, sigint_handler); + + // Print PID for testing purposes + // printf("PID: %d\n", getpid()); + + // Wait for signal to be received +} diff --git a/source/os/test/osSleepTests.cpp b/source/os/test/osSleepTests.cpp new file mode 100644 index 0000000000..5faa837a0a --- /dev/null +++ b/source/os/test/osSleepTests.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wwrite-strings" +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wformat" +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" +#pragma GCC diagnostic ignored "-Wpointer-arith" + +#include "os.h" +#include "tlog.h" + +TEST(osSleepTests, taosUsleep) { + const int sleep_time1 = 1000; // sleep for 1000 microseconds + taosUsleep(sleep_time1); + + const int sleep_time2 = 0; // sleep for 0 microseconds + taosUsleep(sleep_time2); + + const int sleep_time3 = -1; // sleep for negative time + taosUsleep(sleep_time3); +} + +TEST(osSleepTests, taosSsleep) { + const int sleep_time1 = 1; + taosSsleep(sleep_time1); + + const int sleep_time2 = 0; + taosSsleep(sleep_time2); + + const int sleep_time3 = -1; + taosSsleep(sleep_time3); +} + +TEST(osSleepTests, taosMsleep) { + const int sleep_time1 = 1000; + taosMsleep(sleep_time1); + + const int sleep_time2 = 0; + taosMsleep(sleep_time2); + + const int sleep_time3 = -1; // sleep for negative time + taosMsleep(sleep_time3); +} diff --git a/source/os/test/osStringTests.cpp b/source/os/test/osStringTests.cpp new file mode 100644 index 0000000000..5e07636b1f --- /dev/null +++ b/source/os/test/osStringTests.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wwrite-strings" +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wformat" +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" +#pragma GCC diagnostic ignored "-Wpointer-arith" + +#include "os.h" +#include "tlog.h" + +#ifdef WINDOWS +TEST(osStringTests, strsepNormalInput) { + char str[] = "This is a test string."; + char * ptr = str; + char * tok = NULL; + const char delim[] = " "; + + while ((tok = strsep(&ptr, delim)) != NULL) { + printf("%s\n", tok); + } + EXPECT_STREQ(tok, nullptr); + EXPECT_EQ(ptr, nullptr); +} + +TEST(osStringTests, strsepEmptyInput) { + char* str = ""; + char* ptr = str; + char* tok = NULL; + const char delim[] = " "; + + while ((tok = strsep(&ptr, delim)) != NULL) { + printf("%s\n", tok); + } + + EXPECT_STREQ(tok, nullptr); + EXPECT_EQ(ptr, nullptr); +} + +TEST(osStringTests, strsepNullInput) { + char * str = NULL; + char * ptr = str; + char * tok = NULL; + const char delim[] = " "; + + while ((tok = strsep(&ptr, delim)) != NULL) { + printf("%s\n", tok); + } + + EXPECT_STREQ(tok, nullptr); + EXPECT_EQ(ptr, nullptr); +} + +TEST(osStringTests, strndupNormalInput) { + const char s[] = "This is a test string."; + int size = strlen(s) + 1; + char * s2 = strndup(s, size); + + EXPECT_STREQ(s, s2); + + free(s2); +} +#endif + +TEST(osStringTests, osUcs4Tests1) { + TdUcs4 f1_ucs4[] = {0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x0000}; + TdUcs4 f2_ucs4[] = {0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x0000}; + + EXPECT_EQ(tasoUcs4Compare(f1_ucs4, f2_ucs4, sizeof(f1_ucs4)), 0); + + TdUcs4 f3_ucs4[] = {0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x0020, 0x0077, + 0x006F, 0x0072, 0x006C, 0x0064, 0x0021, 0x0000}; + TdUcs4 f4_ucs4[] = {0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x0000}; + + EXPECT_GT(tasoUcs4Compare(f3_ucs4, f4_ucs4, sizeof(f3_ucs4)), 0); + + TdUcs4 f5_ucs4[] = {0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x0000}; + TdUcs4 f6_ucs4[] = {0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x0020, 0x0077, + 0x006F, 0x0072, 0x006C, 0x0064, 0x0021, 0x0000}; + + EXPECT_LT(tasoUcs4Compare(f5_ucs4, f6_ucs4, sizeof(f5_ucs4)), 0); +} + +TEST(osStringTests, osUcs4lenTests2) { + TdUcs4 ucs4_1[] = {'H', 'e', 'l', 'l', 'o', '\0'}; + EXPECT_EQ(taosUcs4len(ucs4_1), 5); + + TdUcs4 ucs4_2[] = {'\0'}; + EXPECT_EQ(taosUcs4len(ucs4_2), 0); + + TdUcs4 ucs4_3[] = {'C', 'h', 'i', 'n', 'a', 0x4E2D, 0x6587, '\0'}; + EXPECT_EQ(taosUcs4len(ucs4_3), 7); +} diff --git a/source/os/test/osSystemTests.cpp b/source/os/test/osSystemTests.cpp new file mode 100644 index 0000000000..dfc92a1b72 --- /dev/null +++ b/source/os/test/osSystemTests.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wwrite-strings" +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wformat" +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" +#pragma GCC diagnostic ignored "-Wpointer-arith" + +#include "os.h" +#include "tlog.h" + +TEST(osSystemTest, osSystem1) { + char tmp[4096] = "test"; +#ifdef _TD_DARWIN_64 + taosLogTraceToBuf(tmp, sizeof(tmp), 4); +#elif !defined(WINDOWS) + taosLogTraceToBuf(tmp, sizeof(tmp), 3); +#else + taosLogTraceToBuf(tmp, sizeof(tmp), 8); +#endif +} diff --git a/source/os/test/osThreadTests.cpp b/source/os/test/osThreadTests.cpp new file mode 100644 index 0000000000..e7fc4f1356 --- /dev/null +++ b/source/os/test/osThreadTests.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wwrite-strings" +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wformat" +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" +#pragma GCC diagnostic ignored "-Wpointer-arith" + +#include "os.h" +#include "tlog.h" + +TEST(osThreadTests, osThreadTests1) { + +} diff --git a/source/os/test/osTimeTests.cpp b/source/os/test/osTimeTests.cpp new file mode 100644 index 0000000000..366c3fc720 --- /dev/null +++ b/source/os/test/osTimeTests.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wwrite-strings" +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wformat" +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" +#pragma GCC diagnostic ignored "-Wpointer-arith" + +#include "os.h" +#include "tlog.h" + +TEST(osTimeTests, taosLocalTimeNolock) { + time_t currentTime; + // Test when result is NULL + struct tm* result = taosLocalTimeNolock(NULL, ¤tTime, 0); + // Test when result is not NULL + struct tm expectedTime; + result = taosLocalTimeNolock(&expectedTime, ¤tTime, 1); + EXPECT_EQ(expectedTime.tm_year, result->tm_year); + EXPECT_EQ(expectedTime.tm_mon, result->tm_mon); + EXPECT_EQ(expectedTime.tm_mday, result->tm_mday); + EXPECT_EQ(expectedTime.tm_hour, result->tm_hour); + EXPECT_EQ(expectedTime.tm_min, result->tm_min); + EXPECT_EQ(expectedTime.tm_sec, result->tm_sec); + EXPECT_EQ(expectedTime.tm_wday, result->tm_wday); + EXPECT_EQ(expectedTime.tm_yday, result->tm_yday); + EXPECT_EQ(expectedTime.tm_isdst, result->tm_isdst); +} -- GitLab