From 4b4d49b64e0531583dce8100110947011c656a1b Mon Sep 17 00:00:00 2001 From: Gavin Halliday Date: Tue, 7 Jan 2025 10:15:31 +0000 Subject: [PATCH] Changes following review Signed-off-by: Gavin Halliday --- common/workunit/wujobq.cpp | 3 +-- testing/unittests/dalitests.cpp | 38 +++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/common/workunit/wujobq.cpp b/common/workunit/wujobq.cpp index cd1f0d5b330..ecd34fbdee5 100644 --- a/common/workunit/wujobq.cpp +++ b/common/workunit/wujobq.cpp @@ -1269,9 +1269,8 @@ class CJobQueue: public CJobQueueBase, implements IJobQueue Owned item; if (prioritytransitiondelay) { - unsigned timeout = prioritytransitiondelay; bool usePrevPrio = true; - item.setown(dodequeue(minPrio, timeout, usePrevPrio, nullptr)); + item.setown(dodequeue(minPrio, prioritytransitiondelay, usePrevPrio, nullptr)); } if (!item) item.setown(dodequeue(minPrio, timeout-prioritytransitiondelay, false, nullptr)); diff --git a/testing/unittests/dalitests.cpp b/testing/unittests/dalitests.cpp index 1f7b46c9742..e1483e17e82 100644 --- a/testing/unittests/dalitests.cpp +++ b/testing/unittests/dalitests.cpp @@ -3269,14 +3269,14 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DaliSysInfoLoggerTester, "DaliSysInfoLogg static constexpr bool traceJobQueue = false; -static unsigned jobQueueStartTick; +static unsigned jobQueueStartTick = 0; //The following allows the tests to be slowed down to make it easier to debug problems static constexpr unsigned tickScaling = 1; static unsigned getJobQueueTick() { return (msTick() - jobQueueStartTick) / tickScaling; } -static void JobQueueSleep(unsigned ms) +static void jobQueueSleep(unsigned ms) { MilliSleep(ms * tickScaling); } @@ -3333,7 +3333,7 @@ class JobQueueTester : public CppUnit::TestFixture log.append(","); log.append(name).append("@").append(getJobQueueTick()); unsigned delay = item->getPort(); - JobQueueSleep(delay); + jobQueueSleep(delay); processedSem.signal(); return true; } @@ -3494,7 +3494,7 @@ class JobQueueTester : public CppUnit::TestFixture jobQueueStartTick = msTick(); for (auto & job : jobs) { - JobQueueSleep(job.delayMs); + jobQueueSleep(job.delayMs); if (traceJobQueue) DBGLOG("Add (%s, %d, %d) @%u", job.name, job.delayMs, job.processingMs, getJobQueueTick()); Owned item = createJobQueueItem(job.name); @@ -3527,8 +3527,28 @@ class JobQueueTester : public CppUnit::TestFixture { JobProcessor & cur = jobProcessors.item(i3); DBGLOG(" Result: '%s' '%s'", cur.queryOutput(), cur.queryLog()); -// if (i3 < expectedResults.size()) -// CPPUNIT_ASSERT_EQUAL(std::string(expectedResults.begin()[i3]), std::string(cur.queryOutput())); + + //If expected results are provided, check that the result matches one of them (it is undefined which + //processor will match which result) + if (expectedResults.size()) + { + bool matched = false; + StringBuffer expectedText; + for (auto & expected : expectedResults) + { + if (streq(expected, cur.queryOutput())) + { + matched = true; + break; + } + expectedText.append(", ").append(expected); + } + if (!matched) + { + DBGLOG("Result does not match any expected: %s", expectedText.str()+2); + CPPUNIT_ASSERT_MESSAGE("Result does not match any of the expected results", false); + } + } } } @@ -3630,9 +3650,9 @@ class JobQueueTester : public CppUnit::TestFixture void testDouble() { runTestCaseX2("2 wu, 2 standard", twoWuTest, { StandardProcessor, StandardProcessor }, { "abcd", "ABCD" }); - runTestCaseX2("lo hi wu, 2 standard", lowHighTest, { StandardProcessor, StandardProcessor }, { "aBDc" "ACbd" }); - runTestCaseX2("lo hi2 wu, 2 standard", lowHigh2Test, { StandardProcessor, StandardProcessor }, { "a"}); - runTestCaseX2("lo hi2 wu, 2 thor", lowHigh2Test, { ThorProcessor, ThorProcessor }, {}); + runTestCaseX2("lo hi wu, 2 standard", lowHighTest, { StandardProcessor, StandardProcessor }, { "abcd", "ABCD" }); + runTestCaseX2("lo hi2 wu, 2 standard", lowHigh2Test, { StandardProcessor, StandardProcessor }, { "aBDc", "ACbd" }); + runTestCaseX2("lo hi2 wu, 2 thor", lowHigh2Test, { ThorProcessor, ThorProcessor }, { "aBDc", "ACbd" }); runTestCaseX2("lo hi2 wu, 2 newthor", lowHigh2Test, { NewThorProcessor, NewThorProcessor }, {}); runTestCaseX2("lo hi3 wu, 2 thor", lowHigh3Test, { ThorProcessor, ThorProcessor }, {});