From 735a85b5bc87f6b989fbb573ca547f090982bb9d Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 7 Jan 2021 17:43:49 +0000 Subject: GC unused code and tests with no value. --- fastos/src/tests/CMakeLists.txt | 7 --- fastos/src/tests/job.h | 8 +-- fastos/src/tests/thread_bounce_test.cpp | 98 ------------------------------- fastos/src/tests/thread_joinwait_test.cpp | 13 ++-- fastos/src/tests/thread_stats_test.cpp | 8 ++- fastos/src/tests/thread_test_base.hpp | 39 +----------- fastos/src/tests/threadtest.cpp | 59 +------------------ 7 files changed, 16 insertions(+), 216 deletions(-) delete mode 100644 fastos/src/tests/thread_bounce_test.cpp (limited to 'fastos') diff --git a/fastos/src/tests/CMakeLists.txt b/fastos/src/tests/CMakeLists.txt index 34007afb8d5..8c0d255df32 100644 --- a/fastos/src/tests/CMakeLists.txt +++ b/fastos/src/tests/CMakeLists.txt @@ -26,13 +26,6 @@ vespa_add_executable(fastos_thread_joinwait_test_app TEST fastos ) vespa_add_test(NAME fastos_thread_joinwait_test_app NO_VALGRIND COMMAND fastos_thread_joinwait_test_app) -vespa_add_executable(fastos_thread_bounce_test_app TEST - SOURCES - thread_bounce_test.cpp - DEPENDS - fastos -) -vespa_add_test(NAME fastos_thread_bounce_test_app NO_VALGRIND COMMAND fastos_thread_bounce_test_app) vespa_add_executable(fastos_threadtest_app TEST SOURCES threadtest.cpp diff --git a/fastos/src/tests/job.h b/fastos/src/tests/job.h index 1d35ec95270..35e1d02a9d3 100644 --- a/fastos/src/tests/job.h +++ b/fastos/src/tests/job.h @@ -7,17 +7,13 @@ enum JobCode { - PRINT_MESSAGE_AND_WAIT3SEC, + PRINT_MESSAGE_AND_WAIT3MSEC, INCREASE_NUMBER, - PRIORITY_TEST, WAIT_FOR_BREAK_FLAG, WAIT_FOR_THREAD_TO_FINISH, WAIT_FOR_CONDITION, - BOUNCE_CONDITIONS, TEST_ID, WAIT2SEC_AND_SIGNALCOND, - HOLD_MUTEX_FOR2SEC, - WAIT_2_SEC, SILENTNOP, NOP }; @@ -34,7 +30,6 @@ public: std::mutex *mutex; std::condition_variable *condition; FastOS_ThreadInterface *otherThread, *ownThread; - double *timebuf; double average; int result; FastOS_ThreadId _threadId; @@ -49,7 +44,6 @@ public: condition(nullptr), otherThread(nullptr), ownThread(nullptr), - timebuf(nullptr), average(0.0), result(-1), _threadId(), diff --git a/fastos/src/tests/thread_bounce_test.cpp b/fastos/src/tests/thread_bounce_test.cpp deleted file mode 100644 index 488002341e9..00000000000 --- a/fastos/src/tests/thread_bounce_test.cpp +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "tests.h" -#include "job.h" -#include "thread_test_base.hpp" - -using namespace std::chrono; - -class Thread_Bounce_Test : public ThreadTestBase -{ - int Main () override; - - void BounceTest(void) - { - TestHeader("Bounce Test"); - - FastOS_ThreadPool pool(128 * 1024); - std::mutex mutex1; - std::condition_variable cond1; - std::mutex mutex2; - std::condition_variable cond2; - Job job1; - Job job2; - int cnt1; - int cnt2; - int cntsum; - int lastcntsum; - - job1.code = BOUNCE_CONDITIONS; - job2.code = BOUNCE_CONDITIONS; - job1.otherjob = &job2; - job2.otherjob = &job1; - job1.mutex = &mutex1; - job1.condition = &cond1; - job2.mutex = &mutex2; - job2.condition = &cond2; - - job1.ownThread = pool.NewThread(this, static_cast(&job1)); - job2.ownThread = pool.NewThread(this, static_cast(&job2)); - - lastcntsum = -1; - for (int iter = 0; iter < 8; iter++) { - steady_clock::time_point start = steady_clock::now(); - - nanoseconds left = steady_clock::now() - start; - while (left < 1000ms) { - std::this_thread::sleep_for(1000ms - left); - left = steady_clock::now() - start; - } - - mutex1.lock(); - cnt1 = job1.bouncewakeupcnt; - mutex1.unlock(); - mutex2.lock(); - cnt2 = job2.bouncewakeupcnt; - mutex2.unlock(); - cntsum = cnt1 + cnt2; - Progress(lastcntsum != cntsum, "%d bounces", cntsum); - lastcntsum = cntsum; - } - - job1.ownThread->SetBreakFlag(); - mutex1.lock(); - job1.bouncewakeup = true; - cond1.notify_one(); - mutex1.unlock(); - - job2.ownThread->SetBreakFlag(); - mutex2.lock(); - job2.bouncewakeup = true; - cond2.notify_one(); - mutex2.unlock(); - - pool.Close(); - Progress(true, "Pool closed."); - PrintSeparator(); - } - -}; - -int Thread_Bounce_Test::Main () -{ - printf("grep for the string '%s' to detect failures.\n\n", failString); - time_t before = time(0); - - BounceTest(); - - { time_t now = time(0); printf("[%ld seconds]\n", now-before); before = now; } - printf("END OF TEST (%s)\n", _argv[0]); - return allWasOk() ? 0 : 1; -} - -int main (int argc, char **argv) -{ - Thread_Bounce_Test app; - setvbuf(stdout, nullptr, _IOLBF, 8192); - return app.Entry(argc, argv); -} diff --git a/fastos/src/tests/thread_joinwait_test.cpp b/fastos/src/tests/thread_joinwait_test.cpp index 7153a05f836..6330a52b5f0 100644 --- a/fastos/src/tests/thread_joinwait_test.cpp +++ b/fastos/src/tests/thread_joinwait_test.cpp @@ -45,9 +45,9 @@ class Thread_JoinWait_Test : public ThreadTestBase break; } - if(rc) + if (rc) { - jobs[lastThreadNum].code = (((variant & 2) != 0) ? NOP : PRINT_MESSAGE_AND_WAIT3SEC); + jobs[lastThreadNum].code = (((variant & 2) != 0) ? NOP : PRINT_MESSAGE_AND_WAIT3MSEC); jobs[lastThreadNum].message = strdup("This is the thread that others wait for."); FastOS_ThreadInterface *lastThread; @@ -59,10 +59,9 @@ class Thread_JoinWait_Test : public ThreadTestBase rc = (lastThread != nullptr); Progress(rc, "Creating last thread"); - if(rc) + if (rc) { - for(i=0; iJoin(); diff --git a/fastos/src/tests/thread_stats_test.cpp b/fastos/src/tests/thread_stats_test.cpp index ff868383a5c..9dadda20a14 100644 --- a/fastos/src/tests/thread_stats_test.cpp +++ b/fastos/src/tests/thread_stats_test.cpp @@ -50,6 +50,9 @@ class Thread_Stats_Test : public ThreadTestBase job[0].ownThread->Join(); job[1].ownThread->Join(); + while (pool.GetNumInactiveThreads() != 2) { + std::this_thread::sleep_for(1ms); + } inactiveThreads = pool.GetNumInactiveThreads(); Progress(inactiveThreads == 2, "Inactive threads = %d", inactiveThreads); @@ -58,7 +61,6 @@ class Thread_Stats_Test : public ThreadTestBase startedThreads = pool.GetNumStartedThreads(); Progress(startedThreads == 2, "Started threads = %d", startedThreads); - Progress(true, "Repeating process in the same pool..."); job[0].code = WAIT_FOR_BREAK_FLAG; @@ -87,7 +89,9 @@ class Thread_Stats_Test : public ThreadTestBase job[0].ownThread->Join(); job[1].ownThread->Join(); - std::this_thread::sleep_for(1s); + while (pool.GetNumInactiveThreads() != 2) { + std::this_thread::sleep_for(1ms); + } inactiveThreads = pool.GetNumInactiveThreads(); Progress(inactiveThreads == 2, "Inactive threads = %d", inactiveThreads); diff --git a/fastos/src/tests/thread_test_base.hpp b/fastos/src/tests/thread_test_base.hpp index 60a3dfedb6f..e77f61dddb3 100644 --- a/fastos/src/tests/thread_test_base.hpp +++ b/fastos/src/tests/thread_test_base.hpp @@ -84,12 +84,12 @@ void ThreadTestBase::Run (FastOS_ThreadInterface *thread, void *arg) break; } - case PRINT_MESSAGE_AND_WAIT3SEC: + case PRINT_MESSAGE_AND_WAIT3MSEC: { Progress(true, "Thread printing message: [%s]", job->message); job->result = strlen(job->message); - std::this_thread::sleep_for(3s); + std::this_thread::sleep_for(3ms); break; } @@ -158,24 +158,6 @@ void ThreadTestBase::Run (FastOS_ThreadInterface *thread, void *arg) break; } - case BOUNCE_CONDITIONS: - { - while (!thread->GetBreakFlag()) { - { - std::lock_guard guard(*job->otherjob->mutex); - job->otherjob->bouncewakeupcnt++; - job->otherjob->bouncewakeup = true; - job->otherjob->condition->notify_one(); - } - std::unique_lock guard(*job->mutex); - while (!job->bouncewakeup) { - job->condition->wait_for(guard, 1ms); - } - job->bouncewakeup = false; - } - break; - } - case TEST_ID: { job->mutex->lock(); // Initially the parent threads owns the lock @@ -198,23 +180,6 @@ void ThreadTestBase::Run (FastOS_ThreadInterface *thread, void *arg) break; } - case HOLD_MUTEX_FOR2SEC: - { - { - std::lock_guard guard(*job->mutex); - std::this_thread::sleep_for(2s); - } - job->result = 1; - break; - } - - case WAIT_2_SEC: - { - std::this_thread::sleep_for(2s); - job->result = 1; - break; - } - default: Progress(false, "Unknown jobcode"); break; diff --git a/fastos/src/tests/threadtest.cpp b/fastos/src/tests/threadtest.cpp index 1fa9820c8d7..129e067f229 100644 --- a/fastos/src/tests/threadtest.cpp +++ b/fastos/src/tests/threadtest.cpp @@ -6,7 +6,6 @@ #include #include -#define MUTEX_TEST_THREADS 6 #define MAX_THREADS 7 using namespace std::chrono; @@ -62,7 +61,7 @@ class ThreadTest : public ThreadTestBase for(i=0; i(malloc(100)); sprintf(jobs[i].message, "Thread %d invocation", i+1); } @@ -103,62 +102,6 @@ class ThreadTest : public ThreadTestBase PrintSeparator(); } - - void HowManyThreadsTest () - { - #define HOW_MAX_THREADS (1024) - TestHeader("How Many Threads Test"); - - FastOS_ThreadPool *pool = new FastOS_ThreadPool(128*1024, HOW_MAX_THREADS); - - if(Progress(pool != nullptr, "Allocating ThreadPool")) - { - int i; - Job jobs[HOW_MAX_THREADS]; - - for(i=0; i(malloc(100)); - sprintf(jobs[i].message, "Thread %d invocation", i+1); - } - - for(i=0; iNewThread(this, - static_cast(&jobs[0]))); - Progress(rc, "Creating too many threads should fail."); - } - else - { - bool rc = (nullptr != pool->NewThread(this, - static_cast(&jobs[i]))); - Progress(rc, "Creating Thread"); - } - }; - - WaitForThreadsToFinish(jobs, HOW_MAX_THREADS); - - Progress(true, "Verifying result codes..."); - for(i=0; i(strlen(jobs[i].message)), - "Checking result code from thread (%d==%d)", - jobs[i].result, strlen(jobs[i].message)); - } - - Progress(true, "Closing threadpool..."); - pool->Close(); - - Progress(true, "Deleting threadpool..."); - delete(pool); - } - PrintSeparator(); - } - void CreateSingleThreadAndJoin () { TestHeader("Create Single Thread And Join Test"); -- cgit v1.2.3