From 39e55e169fe9e365ea376115abc05a6b0e3b3af8 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 12 Jan 2021 09:41:42 +0000 Subject: Reduce runtime by not testing std::stuff and also avoid extended stress test. --- fastos/src/tests/job.h | 12 +- fastos/src/tests/thread_test_base.hpp | 46 ++---- fastos/src/tests/threadtest.cpp | 302 ++++------------------------------ 3 files changed, 40 insertions(+), 320 deletions(-) (limited to 'fastos') diff --git a/fastos/src/tests/job.h b/fastos/src/tests/job.h index 35e1d02a9d3..01f6dc108d0 100644 --- a/fastos/src/tests/job.h +++ b/fastos/src/tests/job.h @@ -11,9 +11,7 @@ enum JobCode INCREASE_NUMBER, WAIT_FOR_BREAK_FLAG, WAIT_FOR_THREAD_TO_FINISH, - WAIT_FOR_CONDITION, TEST_ID, - WAIT2SEC_AND_SIGNALCOND, SILENTNOP, NOP }; @@ -30,12 +28,8 @@ public: std::mutex *mutex; std::condition_variable *condition; FastOS_ThreadInterface *otherThread, *ownThread; - double average; int result; FastOS_ThreadId _threadId; - Job *otherjob; - int bouncewakeupcnt; - bool bouncewakeup; Job() : code(NOP), @@ -44,12 +38,8 @@ public: condition(nullptr), otherThread(nullptr), ownThread(nullptr), - average(0.0), result(-1), - _threadId(), - otherjob(nullptr), - bouncewakeupcnt(0), - bouncewakeup(false) + _threadId() { } diff --git a/fastos/src/tests/thread_test_base.hpp b/fastos/src/tests/thread_test_base.hpp index e77f61dddb3..778ba29e8dd 100644 --- a/fastos/src/tests/thread_test_base.hpp +++ b/fastos/src/tests/thread_test_base.hpp @@ -22,27 +22,22 @@ public: } virtual ~ThreadTestBase() {} - void PrintProgress (char *string) override - { + void PrintProgress (char *string) override { std::lock_guard guard(printMutex); BaseTest::PrintProgress(string); } void Run (FastOS_ThreadInterface *thread, void *arg) override; - void WaitForThreadsToFinish (Job *jobs, int count) - { + void WaitForThreadsToFinish (Job *jobs, int count) { int i; Progress(true, "Waiting for threads to finish..."); - for(;;) - { + for(;;) { bool threadsFinished=true; - for(i=0; i(number); int sleepOn = (INCREASE_NUMBER_AMOUNT/2) * 321/10000; - for(int i=0; i<(INCREASE_NUMBER_AMOUNT/2); i++) - { + for (int i=0; i<(INCREASE_NUMBER_AMOUNT/2); i++) { number = number + 2; - if(i == sleepOn) + if (i == sleepOn) std::this_thread::sleep_for(1ms); } @@ -122,8 +116,7 @@ void ThreadTestBase::Run (FastOS_ThreadInterface *thread, void *arg) case WAIT_FOR_BREAK_FLAG: { - for(;;) - { + for(;;) { std::this_thread::sleep_for(1us); if (thread->GetBreakFlag()) { @@ -141,19 +134,8 @@ void ThreadTestBase::Run (FastOS_ThreadInterface *thread, void *arg) guard = std::unique_lock(*job->mutex); } - if(job->otherThread != nullptr) - job->otherThread->Join(); - - break; - } - - case WAIT_FOR_CONDITION: - { - std::unique_lock guard(*job->mutex); - job->result = 1; - job->condition->wait(guard); - guard.unlock(); - job->result = 0; + if (job->otherThread != nullptr) + job->otherThread->Join(); break; } @@ -172,14 +154,6 @@ void ThreadTestBase::Run (FastOS_ThreadInterface *thread, void *arg) break; } - case WAIT2SEC_AND_SIGNALCOND: - { - std::this_thread::sleep_for(2s); - job->condition->notify_one(); - 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 129e067f229..3adaee58273 100644 --- a/fastos/src/tests/threadtest.cpp +++ b/fastos/src/tests/threadtest.cpp @@ -15,69 +15,28 @@ class ThreadTest : public ThreadTestBase { int Main () override; - void WaitForXThreadsToHaveWait (Job *jobs, - int jobCount, - std::mutex &mutex, - int numWait) - { - Progress(true, "Waiting for %d threads to be in wait state", numWait); - - int oldNumber=-10000; - for(;;) - { - int waitingThreads=0; - - { - std::lock_guard guard(mutex); - for(int i=0; i(malloc(100)); sprintf(jobs[i].message, "Thread %d invocation", i+1); } - for(i=0; iNewThread(this, - static_cast(&jobs[0]))); + 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]))); + } else { + bool rc = (nullptr != pool->NewThread(this, static_cast(&jobs[i]))); Progress(rc, "Creating Thread"); } }; @@ -85,8 +44,7 @@ class ThreadTest : public ThreadTestBase WaitForThreadsToFinish(jobs, MAX_THREADS); Progress(true, "Verifying result codes..."); - for(i=0; i(strlen(jobs[i].message)), "Checking result code from thread (%d==%d)", @@ -108,8 +66,7 @@ class ThreadTest : public ThreadTestBase FastOS_ThreadPool *pool = new FastOS_ThreadPool(128*1024); - if(Progress(pool != nullptr, "Allocating ThreadPool")) - { + if (Progress(pool != nullptr, "Allocating ThreadPool")) { Job job; job.code = NOP; @@ -129,8 +86,7 @@ class ThreadTest : public ThreadTestBase PrintSeparator(); } - void ThreadCreatePerformance (bool silent, int count, int outercount) - { + void ThreadCreatePerformance (bool silent, int count, int outercount) { int i; int j; bool rc; @@ -199,7 +155,7 @@ class ThreadTest : public ThreadTestBase void ClosePoolStability(void) { int i; TestHeader("ThreadPool close stability test"); - for (i = 0; i < 8000; i++) { + for (i = 0; i < 1000; i++) { // Progress(true, "Creating pool iteration %d", i + 1); ThreadCreatePerformance(true, 2, 1); } @@ -218,12 +174,10 @@ class ThreadTest : public ThreadTestBase number = 0; - for(int i=0; i(&jobs[i]))); + bool rc = (nullptr != pool.NewThread(this, static_cast(&jobs[i]))); Progress(rc, "Creating Thread %d", i+1); } @@ -233,8 +187,7 @@ class ThreadTest : public ThreadTestBase PrintSeparator(); } - void BreakFlagTest () - { + void BreakFlagTest () { TestHeader("BreakFlag Test"); FastOS_ThreadPool pool(128*1024); @@ -243,12 +196,10 @@ class ThreadTest : public ThreadTestBase Job jobs[breakFlagThreads]; - for(int i=0; i(&jobs[i]))); + bool rc = (nullptr != pool.NewThread(this, static_cast(&jobs[i]))); Progress(rc, "Creating Thread %d", i+1); } @@ -258,84 +209,8 @@ class ThreadTest : public ThreadTestBase PrintSeparator(); } - void SharedSignalAndBroadcastTest (Job *jobs, int numThreads, - std::mutex *mutex, - std::condition_variable *condition, - FastOS_ThreadPool *pool) - { - for(int i=0; iNewThread(this, - static_cast(&jobs[i])); - - bool rc=(jobs[i].ownThread != nullptr); - Progress(rc, "CreatingThread %d", i+1); - } - - WaitForXThreadsToHaveWait (jobs, numThreads, - *mutex, numThreads); - - // Threads are not guaranteed to have entered sleep yet, - // as this test only tests for result code - // Wait another second to be sure. - std::this_thread::sleep_for(1s); - } - - void SignalTest () - { - const int numThreads = 5; - - TestHeader("Signal Test"); - - FastOS_ThreadPool pool(128*1024); - Job jobs[numThreads]; - std::mutex mutex; - std::condition_variable condition; - - SharedSignalAndBroadcastTest(jobs, numThreads, &mutex, &condition, &pool); - - for(int i=0; i(&jobs[i])); + jobs[i].ownThread = pool.NewThread(this, static_cast(&jobs[i])); bool rc=(jobs[i].ownThread != nullptr); - if(rc) - jobs[i]._threadId = jobs[i].ownThread->GetThreadId(); - Progress(rc, "CreatingThread %d id:%lu", i+1, - (unsigned long)(jobs[i]._threadId)); + if (rc) { + jobs[i]._threadId = jobs[i].ownThread->GetThreadId(); + } + Progress(rc, "CreatingThread %d id:%lu", i+1, (unsigned long)(jobs[i]._threadId)); - for(j=0; j(&job)); - - Progress(job.ownThread !=nullptr, "Creating thread"); - - if(job.ownThread != nullptr) - { - std::unique_lock guard(mutex); - bool gotCond = condition.wait_for(guard, 500ms) == std::cv_status::no_timeout; - Progress(!gotCond, "We should not get the condition just yet (%s)", - gotCond ? "got it" : "didn't get it"); - gotCond = condition.wait_for(guard, 500ms) == std::cv_status::no_timeout; - Progress(!gotCond, "We should not get the condition just yet (%s)", - gotCond ? "got it" : "didn't get it"); - gotCond = condition.wait_for(guard, 5000ms) == std::cv_status::no_timeout; - Progress(gotCond, "We should have got the condition now (%s)", - gotCond ? "got it" : "didn't get it"); - } - - Progress(true, "Waiting for threads to finish using pool.Close()..."); - pool.Close(); - Progress(true, "Pool closed."); - - PrintSeparator(); - } - - void LeakTest () - { - TestHeader("Leak Test"); - - int allocCount = 2 * 1024 * 1024; - int progressIndex= allocCount/8; - int i; - - for(i=0; ilock(); - mtx->unlock(); - delete mtx; - - if ((i % progressIndex) == (progressIndex - 1)) - Progress(true, "Tested %d std::mutex instances", i + 1); - } - - for(i=0; i(elapsed).count()); - - for (int e=0; e<4; e++) { - for(i=0; ilock(); - - for(i=0; iunlock(); - - elapsed = steady_clock::now() - start; - Progress(true, "Tested %d mutexes at time: %d ms", allocCount, duration_cast(elapsed).count()); - } - for (i=0; i(elapsed).count()); - - delete [] mutexes; - - PrintSeparator(); - } - }; int ThreadTest::Main () @@ -498,21 +262,13 @@ int ThreadTest::Main () printf("grep for the string '%s' to detect failures.\n\n", failString); time_t before = time(0); - // HowManyThreadsTest(); - SynchronizationStressTest(); - LeakTest(); - TimedWaitTest(); ThreadIdTest(); - SignalTest(); - BroadcastTest(); CreateSingleThreadAndJoin(); TooManyThreadsTest(); ClosePoolTest(); BreakFlagTest(); CreateSingleThreadAndJoin(); - BroadcastTest(); - SignalTest(); - ThreadCreatePerformance(false, 500, 100); + ThreadCreatePerformance(false, 50, 10); ClosePoolStability(); { time_t now = time(0); printf("[%ld seconds]\n", now-before); before = now; } -- cgit v1.2.3