@@ -1545,6 +1545,116 @@ TEST(Kernel, SyncWaitTicklessDuration)
15451545 CHECK_EQUAL (true , mutex.m_locked );
15461546}
15471547
1548+ static struct SyncFindWeightHigherThanContext
1549+ {
1550+ SyncFindWeightHigherThanContext ()
1551+ {
1552+ Reset ();
1553+ }
1554+
1555+ void Reset ()
1556+ {
1557+ counter = 0 ;
1558+ platform = NULL ;
1559+ sobj = NULL ;
1560+ }
1561+
1562+ uint32_t counter;
1563+ PlatformTestMock *platform;
1564+ SyncObjectMock *sobj;
1565+
1566+ void Process ()
1567+ {
1568+ platform->ProcessTick ();
1569+ ++counter;
1570+
1571+ if (counter == 1 )
1572+ {
1573+ CHECK_EQUAL (2 , sobj->FindWeightHigherThan (0 ));
1574+ }
1575+ }
1576+ }
1577+ g_SyncFindWeightHigherThan;
1578+
1579+ static void SyncFindWeightHigherThanRelaxCpu ()
1580+ {
1581+ g_SyncFindWeightHigherThan.Process ();
1582+ }
1583+
1584+ TEST (Kernel, SyncFindWeightHigherThan)
1585+ {
1586+ Kernel<KERNEL_STATIC | KERNEL_SYNC, 2 , SwitchStrategyFP32, PlatformTestMock> kernel;
1587+ PlatformTestMock *platform = static_cast <PlatformTestMock *>(kernel.GetPlatform ());
1588+ TaskMockW<1 , ACCESS_USER> task1;
1589+ TaskMockW<2 , ACCESS_USER> task2;
1590+
1591+ MutexMock mutex;
1592+ SyncObjectMock sobj;
1593+
1594+ g_SyncFindWeightHigherThan.Reset ();
1595+ g_SyncFindWeightHigherThan.platform = platform;
1596+ g_SyncFindWeightHigherThan.sobj = &sobj;
1597+ g_RelaxCpuHandler = SyncFindWeightHigherThanRelaxCpu;
1598+
1599+ kernel.Initialize ();
1600+ kernel.AddTask (&task1);
1601+ kernel.AddTask (&task2);
1602+ kernel.Start ();
1603+
1604+ // no task is waiting
1605+ CHECK_EQUAL (NO_WEIGHT, sobj.FindWeightHigherThan (0 ));
1606+
1607+ MutexMock::ScopedLock guard (mutex);
1608+
1609+ // sleep_ticks should be equal to 2 on first OnTick call
1610+ IWaitObject *wo = IKernelService::GetInstance ()->Wait (&sobj, &mutex, 5 );
1611+
1612+ CHECK_TRUE (wo != nullptr );
1613+ CHECK_EQUAL (true , mutex.m_locked );
1614+
1615+ // no task is waiting here
1616+ CHECK_EQUAL (NO_WEIGHT, sobj.FindWeightHigherThan (0 ));
1617+ }
1618+
1619+ TEST (Kernel, SyncInheritWeight)
1620+ {
1621+ Kernel<KERNEL_STATIC | KERNEL_SYNC, 2 , SwitchStrategyFP32, PlatformTestMock> kernel;
1622+ TaskMockW<1 , ACCESS_USER> task1;
1623+ TaskMockW<2 , ACCESS_USER> task2;
1624+
1625+ MutexMock mutex;
1626+ SyncObjectMock sobj;
1627+
1628+ kernel.Initialize ();
1629+ kernel.AddTask (&task1);
1630+ kernel.AddTask (&task2);
1631+ kernel.Start ();
1632+
1633+ IKernelTask *ktasks[2 ];
1634+ kernel.EnumerateKernelTasks (ktasks, 2 );
1635+
1636+ // current weight is dynamic value used by strategy with PRIORITY_INHERITANCE_API, if not overridden
1637+ // by InheritWeight should be NO_WEIGHT
1638+ CHECK_EQUAL (NO_WEIGHT, ktasks[0 ]->GetCurrentWeight ());
1639+
1640+ // original weight
1641+ CHECK_EQUAL (1 , ktasks[0 ]->GetWeight ());
1642+
1643+ IKernelService::GetInstance ()->InheritWeight (task1.GetId (), 2 );
1644+
1645+ // boosted weight
1646+ CHECK_EQUAL (2 , ktasks[0 ]->GetCurrentWeight ());
1647+ CHECK_EQUAL (2 , ktasks[0 ]->GetWeight ()); // using GetCurrentWeight
1648+
1649+ IKernelService::GetInstance ()->RestoreWeight (task1.GetId ());
1650+
1651+ // dynamic is back to NO_WEIGHT
1652+ CHECK_EQUAL (NO_WEIGHT, ktasks[0 ]->GetCurrentWeight ());
1653+
1654+ // back to own weight
1655+ CHECK_EQUAL (1 , ktasks[0 ]->GetWeight ());
1656+ }
1657+
15481658TEST (Kernel, EnumTasks)
15491659{
15501660 Kernel<KERNEL_STATIC, 2 , SwitchStrategyRR, PlatformTestMock> kernel;
0 commit comments