From f96b2dbc653016ba22f452b963ec4ff0438ba54e Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 26 Jul 2024 17:38:02 +0800 Subject: [PATCH] fix: ut return code --- source/os/test/osSemaphoreTests.cpp | 72 +++++++++++------------ source/os/test/osSystemTests.cpp | 12 ++-- source/os/test/osTests.cpp | 90 ++++++++++++++--------------- 3 files changed, 87 insertions(+), 87 deletions(-) diff --git a/source/os/test/osSemaphoreTests.cpp b/source/os/test/osSemaphoreTests.cpp index 09fbe27f55..9347254b10 100644 --- a/source/os/test/osSemaphoreTests.cpp +++ b/source/os/test/osSemaphoreTests.cpp @@ -58,17 +58,17 @@ TEST(osSemaphoreTests, Destroy) { TEST(osSemaphoreTests, WaitTime0) { tsem_t sem; - tsem_init(&sem, 0, 0); + (void)tsem_init(&sem, 0, 0); EXPECT_NE(tsem_timewait(&sem, 1000), 0); - tsem_destroy(&sem); + (void)tsem_destroy(&sem); } TEST(osSemaphoreTests, WaitTime1) { tsem_t sem; - tsem_init(&sem, 0, 1); + (void)tsem_init(&sem, 0, 1); EXPECT_EQ(tsem_timewait(&sem, 1000), 0); EXPECT_NE(tsem_timewait(&sem, 1000), 0); - tsem_destroy(&sem); + (void)tsem_destroy(&sem); } TEST(osSemaphoreTests, WaitAndPost) { @@ -78,7 +78,7 @@ TEST(osSemaphoreTests, WaitAndPost) { std::thread([&sem]() { std::this_thread::sleep_for(std::chrono::milliseconds(100)); - tsem_post(&sem); + (void)tsem_post(&sem); }).detach(); result = tsem_wait(&sem); @@ -96,7 +96,7 @@ TEST(osSemaphoreTests, TimedWait) { std::thread([&sem]() { std::this_thread::sleep_for(std::chrono::milliseconds(100)); - tsem_post(&sem); + (void)tsem_post(&sem); }).detach(); result = tsem_timewait(&sem, 1000); @@ -110,80 +110,80 @@ TEST(osSemaphoreTests, Performance1_1) { tsem_t sem; const int count = 100000; - tsem_init(&sem, 0, 0); + (void)tsem_init(&sem, 0, 0); std::thread([&sem, count]() { for (int i = 0; i < count; ++i) { - tsem_post(&sem); + (void)tsem_post(&sem); } }).detach(); for (int i = 0; i < count; ++i) { - tsem_wait(&sem); + (void)tsem_wait(&sem); } - tsem_destroy(&sem); + (void)tsem_destroy(&sem); } TEST(osSemaphoreTests, Performance1_2) { tsem2_t sem; const int count = 100000; - tsem2_init(&sem, 0, 0); + (void)tsem2_init(&sem, 0, 0); std::thread([&sem, count]() { for (int i = 0; i < count; ++i) { - tsem2_post(&sem); + (void)tsem2_post(&sem); } }).detach(); for (int i = 0; i < count; ++i) { - tsem2_wait(&sem); + (void)tsem2_wait(&sem); } - tsem2_destroy(&sem); + (void)tsem2_destroy(&sem); } TEST(osSemaphoreTests, Performance2_1) { tsem_t sem; const int count = 50000; - tsem_init(&sem, 0, 0); + (void)tsem_init(&sem, 0, 0); std::thread([&sem, count]() { for (int i = 0; i < count; ++i) { - tsem_post(&sem); + (void)tsem_post(&sem); } }).detach(); std::thread([&sem, count]() { for (int i = 0; i < count; ++i) { - tsem_post(&sem); + (void)tsem_post(&sem); } }).detach(); for (int i = 0; i < count * 2; ++i) { - tsem_wait(&sem); + (void)tsem_wait(&sem); } - tsem_destroy(&sem); + (void)tsem_destroy(&sem); } TEST(osSemaphoreTests, Performance2_2) { tsem2_t sem; const int count = 50000; - tsem2_init(&sem, 0, 0); + (void)tsem2_init(&sem, 0, 0); std::thread([&sem, count]() { for (int i = 0; i < count; ++i) { - tsem2_post(&sem); + (void)tsem2_post(&sem); } }).detach(); std::thread([&sem, count]() { for (int i = 0; i < count; ++i) { - tsem2_post(&sem); + (void)tsem2_post(&sem); } }).detach(); for (int i = 0; i < count * 2; ++i) { - tsem2_wait(&sem); + (void)tsem2_wait(&sem); } - tsem2_destroy(&sem); + (void)tsem2_destroy(&sem); } TEST(osSemaphoreTests, Performance3_1) { @@ -191,9 +191,9 @@ TEST(osSemaphoreTests, Performance3_1) { for (int i = 0; i < count; ++i) { tsem_t sem; - tsem_init(&sem, 0, 1); + (void)tsem_init(&sem, 0, 1); EXPECT_EQ(tsem_timewait(&sem, 1000), 0); - tsem_destroy(&sem); + (void)tsem_destroy(&sem); } } @@ -202,9 +202,9 @@ TEST(osSemaphoreTests, Performance3_2) { for (int i = 0; i < count; ++i) { tsem2_t sem; - tsem2_init(&sem, 0, 1); + (void)tsem2_init(&sem, 0, 1); EXPECT_EQ(tsem2_timewait(&sem, 1000), 0); - tsem2_destroy(&sem); + (void)tsem2_destroy(&sem); } } @@ -212,14 +212,14 @@ TEST(osSemaphoreTests, Performance4_1) { const int count = 1000; for (int i = 0; i < count; ++i) { tsem_t sem; - tsem_init(&sem, 0, 0); + (void)tsem_init(&sem, 0, 0); std::thread([&sem, count]() { - tsem_post(&sem); + (void)tsem_post(&sem); }).detach(); - tsem_timewait(&sem, 1000); + (void)tsem_timewait(&sem, 1000); - tsem_destroy(&sem); + (void)tsem_destroy(&sem); } } @@ -227,13 +227,13 @@ TEST(osSemaphoreTests, Performance4_2) { const int count = 1000; for (int i = 0; i < count; ++i) { tsem2_t sem; - tsem2_init(&sem, 0, 0); + (void)tsem2_init(&sem, 0, 0); std::thread([&sem, count]() { - tsem2_post(&sem); + (void)tsem2_post(&sem); }).detach(); - tsem2_timewait(&sem, 1000); + (void)tsem2_timewait(&sem, 1000); - tsem2_destroy(&sem); + (void)tsem2_destroy(&sem); } } diff --git a/source/os/test/osSystemTests.cpp b/source/os/test/osSystemTests.cpp index 86c600f135..3712e45451 100644 --- a/source/os/test/osSystemTests.cpp +++ b/source/os/test/osSystemTests.cpp @@ -45,18 +45,18 @@ TEST(osSystemTest, osSystem1) { int64_t mem_system; // KB taosGetCpuUsage(&cpu_system, &cpu_engine); - taosGetCpuCores(&cpu_cores, false); + (void)taosGetCpuCores(&cpu_cores, false); - taosGetProcMemory(&mem_engine); - taosGetSysMemory(&mem_system); - printf("cpu_engine: %f cpu_system: %f\n", cpu_engine, cpu_system); - printf("cpu_cores: %f\n", cpu_cores); + (void)taosGetProcMemory(&mem_engine); + (void)taosGetSysMemory(&mem_system); + (void)printf("cpu_engine: %f cpu_system: %f\n", cpu_engine, cpu_system); + (void)printf("cpu_cores: %f\n", cpu_cores); ASSERT_GT(cpu_cores, 0); ASSERT_GE(mem_engine, 0); ASSERT_GE(mem_system, 0); float numOfCores = 0; int32_t res = taosGetCpuInfo(tmp, 4096, &numOfCores); - printf("cpu info: %s\n", tmp); + (void)printf("cpu info: %s\n", tmp); ASSERT_EQ(res, 0); } diff --git a/source/os/test/osTests.cpp b/source/os/test/osTests.cpp index f5a2394bbd..9786886c56 100644 --- a/source/os/test/osTests.cpp +++ b/source/os/test/osTests.cpp @@ -46,10 +46,10 @@ TEST(osTest, osFQDNSuccess) { struct in_addr addr; addr.s_addr = htonl(ipv4); - snprintf(ipString, INET_ADDRSTRLEN, "%u.%u.%u.%u", (unsigned int)(addr.s_addr >> 24) & 0xFF, + (void)snprintf(ipString, INET_ADDRSTRLEN, "%u.%u.%u.%u", (unsigned int)(addr.s_addr >> 24) & 0xFF, (unsigned int)(addr.s_addr >> 16) & 0xFF, (unsigned int)(addr.s_addr >> 8) & 0xFF, (unsigned int)(addr.s_addr) & 0xFF); - printf("fqdn:%s ip:%s\n", fqdn, ipString); + (void)printf("fqdn:%s ip:%s\n", fqdn, ipString); } TEST(osTest, osFQDNFailed) { @@ -60,7 +60,7 @@ TEST(osTest, osFQDNFailed) { ASSERT_NE(code, 0); terrno = TSDB_CODE_RPC_FQDN_ERROR; - printf("fqdn:%s transfer to ip failed!\n", fqdn); + (void)printf("fqdn:%s transfer to ip failed!\n", fqdn); } #endif // WINDOWS @@ -74,27 +74,27 @@ TEST(osTest, osSystem) { const int sysLen = 64; char osSysName[sysLen]; int ret = taosGetOsReleaseName(osSysName, NULL, NULL, sysLen); - printf("os system name:%s\n", osSysName); + (void)printf("os system name:%s\n", osSysName); ASSERT_EQ(ret, 0); } void fileOperateOnFree(void *param) { char * fname = (char *)param; TdFilePtr pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE); - printf("On free thread open file\n"); + (void)printf("On free thread open file\n"); ASSERT_NE(pFile, nullptr); int ret = taosLockFile(pFile); - printf("On free thread lock file ret:%d\n", ret); + (void)printf("On free thread lock file ret:%d\n", ret); ASSERT_EQ(ret, 0); ret = taosUnLockFile(pFile); - printf("On free thread unlock file ret:%d\n", ret); + (void)printf("On free thread unlock file ret:%d\n", ret); ASSERT_EQ(ret, 0); ret = taosCloseFile(&pFile); ASSERT_EQ(ret, 0); - printf("On free thread close file ret:%d\n", ret); + (void)printf("On free thread close file ret:%d\n", ret); } void *fileOperateOnFreeThread(void *param) { fileOperateOnFree(param); @@ -103,19 +103,19 @@ void *fileOperateOnFreeThread(void *param) { void fileOperateOnBusy(void *param) { char * fname = (char *)param; TdFilePtr pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE); - printf("On busy thread open file\n"); + (void)printf("On busy thread open file\n"); if (pFile == NULL) return; // ASSERT_NE(pFile, nullptr); int ret = taosLockFile(pFile); - printf("On busy thread lock file ret:%d\n", ret); + (void)printf("On busy thread lock file ret:%d\n", ret); ASSERT_NE(ret, 0); ret = taosUnLockFile(pFile); - printf("On busy thread unlock file ret:%d\n", ret); + (void)printf("On busy thread unlock file ret:%d\n", ret); ret = taosCloseFile(&pFile); - printf("On busy thread close file ret:%d\n", ret); + (void)printf("On busy thread close file ret:%d\n", ret); ASSERT_EQ(ret, 0); } void *fileOperateOnBusyThread(void *param) { @@ -128,41 +128,41 @@ TEST(osTest, osFile) { TdFilePtr pOutFD = taosCreateFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); ASSERT_NE(pOutFD, nullptr); - printf("create file success\n"); - taosCloseFile(&pOutFD); + (void)printf("create file success\n"); + (void)taosCloseFile(&pOutFD); - taosCloseFile(&pOutFD); + (void)taosCloseFile(&pOutFD); TdFilePtr pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE); - printf("open file\n"); + (void)printf("open file\n"); ASSERT_NE(pFile, nullptr); int ret = taosLockFile(pFile); - printf("lock file ret:%d\n", ret); + (void)printf("lock file ret:%d\n", ret); ASSERT_EQ(ret, 0); TdThreadAttr thattr; - taosThreadAttrInit(&thattr); + (void)taosThreadAttrInit(&thattr); TdThread thread1, thread2; - taosThreadCreate(&(thread1), &thattr, fileOperateOnBusyThread, (void *)fname); - taosThreadAttrDestroy(&thattr); + (void)taosThreadCreate(&(thread1), &thattr, fileOperateOnBusyThread, (void *)fname); + (void)taosThreadAttrDestroy(&thattr); - taosThreadJoin(thread1, NULL); + (void)taosThreadJoin(thread1, NULL); taosThreadClear(&thread1); ret = taosUnLockFile(pFile); - printf("unlock file ret:%d\n", ret); + (void)printf("unlock file ret:%d\n", ret); ASSERT_EQ(ret, 0); ret = taosCloseFile(&pFile); - printf("close file ret:%d\n", ret); + (void)printf("close file ret:%d\n", ret); ASSERT_EQ(ret, 0); - taosThreadCreate(&(thread2), &thattr, fileOperateOnFreeThread, (void *)fname); - taosThreadAttrDestroy(&thattr); + (void)taosThreadCreate(&(thread2), &thattr, fileOperateOnFreeThread, (void *)fname); + (void)taosThreadAttrDestroy(&thattr); - taosThreadJoin(thread2, NULL); + (void)taosThreadJoin(thread2, NULL); taosThreadClear(&thread2); //int ret = taosRemoveFile(fname); @@ -201,8 +201,8 @@ int64_t fillBufferWithRandomWords(char *buffer, int64_t maxBufferSize) { size_t wordLen = strlen(word); if (len + wordLen + 1 < maxBufferSize) { - strcat(buffer, word); - strcat(buffer, " "); + (void)strcat(buffer, word); + (void)strcat(buffer, " "); len += wordLen + 1; } else { break; @@ -240,7 +240,7 @@ int64_t calculateMin(int64_t arr[], int size) { } TEST(osTest, osFilePerformance) { - printf("os file performance testting...\n"); + (void)printf("os file performance testting...\n"); int64_t WriteFileCost; int64_t ReadFileCost; int64_t OpenForWriteCloseFileCost; @@ -254,47 +254,47 @@ TEST(osTest, osFilePerformance) { TdFilePtr pOutFD = taosCreateFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); ASSERT_NE(pOutFD, nullptr); - taosCloseFile(&pOutFD); + (void)taosCloseFile(&pOutFD); - printf("os file performance start write...\n"); + (void)printf("os file performance start write...\n"); int64_t t1 = taosGetTimestampUs(); for (int i = 0; i < TESTTIMES; ++i) { TdFilePtr pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_WRITE_THROUGH); ASSERT_NE(pFile, nullptr); - taosWriteFile(pFile, writeBuffer, size); - taosFsyncFile(pFile); - taosCloseFile(&pFile); + (void)taosWriteFile(pFile, writeBuffer, size); + (void)taosFsyncFile(pFile); + (void)taosCloseFile(&pFile); } int64_t t2 = taosGetTimestampUs(); WriteFileCost = t2 - t1; - printf("os file performance start read...\n"); + (void)printf("os file performance start read...\n"); for (int i = 0; i < TESTTIMES; ++i) { TdFilePtr pFile = taosOpenFile(fname, TD_FILE_READ); ASSERT_NE(pFile, nullptr); - taosReadFile(pFile, readBuffer, size); - taosCloseFile(&pFile); + (void)taosReadFile(pFile, readBuffer, size); + (void)taosCloseFile(&pFile); int readLine = strlen(readBuffer); ASSERT_EQ(size, readLine); } int64_t t3 = taosGetTimestampUs(); ReadFileCost = t3 - t2; - printf("os file performance start open1...\n"); + (void)printf("os file performance start open1...\n"); for (int i = 0; i < TESTTIMES; ++i) { TdFilePtr pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE); ASSERT_NE(pFile, nullptr); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); } int64_t t4 = taosGetTimestampUs(); OpenForWriteCloseFileCost = t4 - t3; - printf("os file performance start open2...\n"); + (void)printf("os file performance start open2...\n"); for (int i = 0; i < TESTTIMES; ++i) { TdFilePtr pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_READ); ASSERT_NE(pFile, nullptr); - taosCloseFile(&pFile); + (void)taosCloseFile(&pFile); } int64_t t5 = taosGetTimestampUs(); OpenForReadCloseFileCost = t5 - t4; @@ -336,10 +336,10 @@ TEST(osTest, osFilePerformance) { taosMemoryFree(writeBuffer); taosMemoryFree(readBuffer); - printf("Test Write file %d times, cost: %" PRId64 "us\n", TESTTIMES, WriteFileCost); - printf("Test Read file %d times, cost: %" PRId64 "us\n", TESTTIMES, ReadFileCost); - printf("Test OpenForWrite & Close file %d times, cost: %" PRId64 "us\n", TESTTIMES, OpenForWriteCloseFileCost); - printf("Test OpenForRead & Close file %d times, cost: %" PRId64 "us\n", TESTTIMES, OpenForReadCloseFileCost); + (void)printf("Test Write file %d times, cost: %" PRId64 "us\n", TESTTIMES, WriteFileCost); + (void)printf("Test Read file %d times, cost: %" PRId64 "us\n", TESTTIMES, ReadFileCost); + (void)printf("Test OpenForWrite & Close file %d times, cost: %" PRId64 "us\n", TESTTIMES, OpenForWriteCloseFileCost); + (void)printf("Test OpenForRead & Close file %d times, cost: %" PRId64 "us\n", TESTTIMES, OpenForReadCloseFileCost); } #endif // OSFILE_PERFORMANCE_TEST