diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2017-01-23 11:56:41 +0100 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2017-07-13 12:10:20 +0200 |
commit | c0710abfebd320903a3edb23d4b1441ea351b0be (patch) | |
tree | d0a02eceed8c830cfc7a1da2bc7d14d70c8a69aa /vcl/qa | |
parent | dc63cc326ee5757124cef45e470d290e6e32002e (diff) |
Add some Scheduler unit tests and logging
1. calling Start() for invoked tasks
2. correctly schedule by priority
3. self-stopping AutoTimer
This also adds SAL_INFO output to Scheduler and Task to log the
scheduling processing tasks.
Change-Id: I3c8a708d1fd51c550320f8af3f9486c43c32e358
Diffstat (limited to 'vcl/qa')
-rw-r--r-- | vcl/qa/cppunit/timer.cxx | 123 |
1 files changed, 111 insertions, 12 deletions
diff --git a/vcl/qa/cppunit/timer.cxx b/vcl/qa/cppunit/timer.cxx index 47439ad19e8b..83b0a7cc01e5 100644 --- a/vcl/qa/cppunit/timer.cxx +++ b/vcl/qa/cppunit/timer.cxx @@ -64,9 +64,12 @@ public: void testAutoTimer(); void testMultiAutoTimers(); #endif - void testRecursiveTimer(); + void testAutoTimerStop(); + void testNestedTimer(); void testSlowTimerCallback(); void testTriggerIdleFromIdle(); + void testInvokedReStart(); + void testPriority(); CPPUNIT_TEST_SUITE(TimerTest); CPPUNIT_TEST(testIdle); @@ -79,9 +82,12 @@ public: CPPUNIT_TEST(testAutoTimer); CPPUNIT_TEST(testMultiAutoTimers); #endif - CPPUNIT_TEST(testRecursiveTimer); + CPPUNIT_TEST(testAutoTimerStop); + CPPUNIT_TEST(testNestedTimer); CPPUNIT_TEST(testSlowTimerCallback); CPPUNIT_TEST(testTriggerIdleFromIdle); + CPPUNIT_TEST(testInvokedReStart); + CPPUNIT_TEST(testPriority); CPPUNIT_TEST_SUITE_END(); }; @@ -100,7 +106,7 @@ class IdleBool : public Idle bool &mrBool; public: explicit IdleBool( bool &rBool ) : - Idle(), mrBool( rBool ) + Idle( "IdleBool" ), mrBool( rBool ) { SetPriority( TaskPriority::LOWEST ); Start(); @@ -117,7 +123,7 @@ void TimerTest::testIdle() { bool bTriggered = false; IdleBool aTest( bTriggered ); - Scheduler::ProcessTaskScheduling( true ); + while ( Application::Reschedule() ); CPPUNIT_ASSERT_MESSAGE("idle triggered", bTriggered); } @@ -148,7 +154,7 @@ class TimerBool : public Timer bool &mrBool; public: TimerBool( sal_uLong nMS, bool &rBool ) : - Timer(), mrBool( rBool ) + Timer( "TimerBool" ), mrBool( rBool ) { SetTimeout( nMS ); Start(); @@ -180,17 +186,26 @@ void TimerTest::testDurations() class AutoTimerCount : public AutoTimer { sal_Int32 &mrCount; + const sal_Int32 mnMaxCount; + public: - AutoTimerCount( sal_uLong nMS, sal_Int32 &rCount ) : - AutoTimer(), mrCount( rCount ) + AutoTimerCount( sal_uLong nMS, sal_Int32 &rCount, + const sal_Int32 nMaxCount = -1 ) + : AutoTimer( "AutoTimerCount" ) + , mrCount( rCount ) + , mnMaxCount( nMaxCount ) { SetTimeout( nMS ); Start(); mrCount = 0; } + virtual void Invoke() override { - mrCount++; + ++mrCount; + CPPUNIT_ASSERT( mnMaxCount < 0 || mrCount <= mnMaxCount ); + if ( mrCount == mnMaxCount ) + Stop(); } }; @@ -296,11 +311,22 @@ void TimerTest::testMultiAutoTimers() } #endif // TEST_TIMERPRECISION +void TimerTest::testAutoTimerStop() +{ + sal_Int32 nTimerCount = 0; + const sal_Int32 nMaxCount = 5; + AutoTimerCount aAutoTimer( 0, nTimerCount, nMaxCount ); + while ( nMaxCount != nTimerCount ) + Application::Yield(); + CPPUNIT_ASSERT( !aAutoTimer.IsActive() ); + CPPUNIT_ASSERT( !Application::Reschedule() ); +} + class YieldTimer : public Timer { public: - explicit YieldTimer( sal_uLong nMS ) : Timer() + explicit YieldTimer( sal_uLong nMS ) : Timer( "YieldTimer" ) { SetTimeout( nMS ); Start(); @@ -312,7 +338,7 @@ public: } }; -void TimerTest::testRecursiveTimer() +void TimerTest::testNestedTimer() { sal_Int32 nCount = 0; YieldTimer aCount(5); @@ -328,7 +354,7 @@ class SlowCallbackTimer : public Timer bool &mbSlow; public: SlowCallbackTimer( sal_uLong nMS, bool &bBeenSlow ) : - Timer(), mbSlow( bBeenSlow ) + Timer( "SlowCallbackTimer" ), mbSlow( bBeenSlow ) { SetTimeout( nMS ); Start(); @@ -362,7 +388,7 @@ class TriggerIdleFromIdle : public Idle TriggerIdleFromIdle* mpOther; public: explicit TriggerIdleFromIdle( bool* pTriggered, TriggerIdleFromIdle* pOther ) : - Idle(), mpTriggered(pTriggered), mpOther(pOther) + Idle( "TriggerIdleFromIdle" ), mpTriggered(pTriggered), mpOther(pOther) { } virtual void Invoke() override @@ -388,6 +414,79 @@ void TimerTest::testTriggerIdleFromIdle() CPPUNIT_ASSERT_MESSAGE("idle triggered", bTriggered2); } + +class IdleInvokedReStart : public Idle +{ + sal_Int32 &mrCount; +public: + IdleInvokedReStart( sal_Int32 &rCount ) + : Idle( "IdleInvokedReStart" ), mrCount( rCount ) + { + Start(); + } + virtual void Invoke() override + { + mrCount++; + if ( mrCount < 2 ) + Start(); + } +}; + +void TimerTest::testInvokedReStart() +{ + sal_Int32 nCount = 0; + IdleInvokedReStart aIdle( nCount ); + while ( Application::Reschedule() ); + CPPUNIT_ASSERT_EQUAL( nCount, sal_Int32(2) ); +} + + +class IdleSerializer : public Idle +{ + sal_uInt32 mnPosition; + sal_uInt32 &mrProcesed; +public: + IdleSerializer( const sal_Char *pDebugName, + sal_uInt32 nPosition, sal_uInt32 &rProcesed ) + : Idle( pDebugName ) + , mnPosition( nPosition ) + , mrProcesed( rProcesed ) + { + Start(); + } + virtual void Invoke() override + { + ++mrProcesed; + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Ignored prio", mnPosition, mrProcesed ); + } +}; + +void TimerTest::testPriority() +{ + // scope, so tasks are deleted + { + // Start: 1st Idle low, 2nd high + sal_uInt32 nProcessed = 0; + IdleSerializer aLowPrioIdle( "IdleSerializer LowPrio", 2, nProcessed ); + aLowPrioIdle.SetPriority( TaskPriority::LOWEST ); + IdleSerializer aHighPrioIdle( "IdleSerializer HighPrio", 1, nProcessed ); + aHighPrioIdle.SetPriority( TaskPriority::HIGHEST ); + while ( Application::Reschedule() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Not all idles processed", sal_uInt32(2), nProcessed ); + } + + { + // Start: 1st Idle high, 2nd low + sal_uInt32 nProcessed = 0; + IdleSerializer aHighPrioIdle( "IdleSerializer HighPrio", 1, nProcessed ); + aHighPrioIdle.SetPriority( TaskPriority::HIGHEST ); + IdleSerializer aLowPrioIdle( "IdleSerializer LowPrio", 2, nProcessed ); + aLowPrioIdle.SetPriority( TaskPriority::LOWEST ); + while ( Application::Reschedule() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Not all idles processed", sal_uInt32(2), nProcessed ); + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(TimerTest); CPPUNIT_PLUGIN_IMPLEMENT(); |