@@ -851,7 +851,7 @@ void TestSHMConform_IsConformed(void** state)
851851 // needs to contain the expected setup for the virtual region
852852 g_testContext .MemorySpaceMap .Calls [0 ].ExpectedSHMTag = 1 ; // expect 1
853853 g_testContext .MemorySpaceMap .Calls [0 ].CheckSHMTag = true;
854- g_testContext .MemorySpaceMap .Calls [0 ].ExpectedLength = 0x8400 ;
854+ g_testContext .MemorySpaceMap .Calls [0 ].ExpectedLength = ( 0x8400 + 0x856 ) ;
855855 g_testContext .MemorySpaceMap .Calls [0 ].CheckLength = true;
856856 g_testContext .MemorySpaceMap .Calls [0 ].ExpectedFlags = MAPPING_PERSISTENT | MAPPING_USERSPACE | MAPPING_READONLY ;
857857 g_testContext .MemorySpaceMap .Calls [0 ].CheckFlags = true;
@@ -1678,6 +1678,112 @@ void TestSHMMap_Simple(void** state)
16781678 TeardownTest (state );
16791679}
16801680
1681+ static void __CreateExportedSHM (SHMHandle_t * shm , const void * buffer , size_t size )
1682+ {
1683+ int pageCount ;
1684+ paddr_t * pages ;
1685+ oserr_t oserr ;
1686+ paddr_t startAddress = 0x1000000 ;
1687+
1688+ // Create page array
1689+ pageCount = (int )((size + (GetMemorySpacePageSize () - 1 )) / GetMemorySpacePageSize ());
1690+ pages = test_malloc (pageCount * sizeof (paddr_t ));
1691+ assert_non_null (pages );
1692+
1693+ for (int i = 0 ; i < pageCount ; i ++ ) {
1694+ pages [i ] = startAddress + (i * GetMemorySpacePageSize ());
1695+ }
1696+
1697+ // The following function calls are expected during normal
1698+ // creation:
1699+
1700+ // 1. CreateHandle, nothing really we care enough to check here except
1701+ // that it gets invoked as expected. The default returned value is 1
1702+
1703+ // 2. GetMemorySpaceMapping
1704+ g_testContext .GetMemorySpaceMapping .ExpectedAddress = (vaddr_t )buffer ;
1705+ g_testContext .GetMemorySpaceMapping .CheckAddress = true;
1706+ g_testContext .GetMemorySpaceMapping .ExpectedPageCount = pageCount ;
1707+ g_testContext .GetMemorySpaceMapping .CheckPageCount = true;
1708+ g_testContext .GetMemorySpaceMapping .PageValues = pages ;
1709+ g_testContext .GetMemorySpaceMapping .PageValuesProvided = true;
1710+ g_testContext .GetMemorySpaceMapping .ReturnValue = OS_EOK ;
1711+
1712+ oserr = SHMExport (
1713+ (void * )buffer ,
1714+ size ,
1715+ 0 ,
1716+ 0 ,
1717+ shm
1718+ );
1719+
1720+ // free resources before asserting
1721+ test_free (pages );
1722+ assert_int_equal (oserr , OS_EOK );
1723+ }
1724+
1725+ void TestSHMMap_SimpleExported (void * * state )
1726+ {
1727+ oserr_t oserr ;
1728+ SHMHandle_t shm ;
1729+ void * buffer ;
1730+ int sgCount ;
1731+ SHMSG_t * sg ;
1732+
1733+ // Allocate a new buffer, with wierd values
1734+ buffer = (void * )0x109586 ;
1735+
1736+ // Create a normal buffer we can use. It must not be comitted. The SHM
1737+ // is already filled, which we don't want as we are trying to make a separate
1738+ // mapping that is not the original.
1739+ __CreateExportedSHM (& shm , buffer , 0xC888 );
1740+
1741+ // Ensure new mapping
1742+ shm .Buffer = NULL ;
1743+
1744+ // 1. LookupHandleOfType
1745+ g_testContext .LookupHandleOfType .ReturnValue = g_testContext .CreateHandle .Calls [0 ].CreatedResource ;
1746+
1747+ // 2. MemorySpaceMap, this is the most interesting call to check, as that
1748+ // needs to contain the expected setup for the virtual region
1749+ g_testContext .MemorySpaceMap .Calls [0 ].ExpectedSHMTag = 1 ; // expect 1
1750+ g_testContext .MemorySpaceMap .Calls [0 ].CheckSHMTag = true;
1751+ g_testContext .MemorySpaceMap .Calls [0 ].ExpectedLength = (0xC888 + 0x586 );
1752+ g_testContext .MemorySpaceMap .Calls [0 ].CheckLength = true;
1753+ g_testContext .MemorySpaceMap .Calls [0 ].ExpectedFlags = MAPPING_PERSISTENT | MAPPING_USERSPACE ;
1754+ g_testContext .MemorySpaceMap .Calls [0 ].CheckFlags = true;
1755+ g_testContext .MemorySpaceMap .Calls [0 ].ExpectedPlacement = MAPPING_VIRTUAL_PROCESS | MAPPING_PHYSICAL_FIXED ;
1756+ g_testContext .MemorySpaceMap .Calls [0 ].CheckPlacement = true;
1757+ g_testContext .MemorySpaceMap .Calls [0 ].ReturnedMapping = 0x20000 ;
1758+ g_testContext .MemorySpaceMap .Calls [0 ].ReturnedMappingProvided = true;
1759+ g_testContext .MemorySpaceMap .Calls [0 ].ReturnValue = OS_EOK ;
1760+ oserr = SHMMap (
1761+ & shm ,
1762+ 0 ,
1763+ shm .Capacity ,
1764+ SHM_ACCESS_READ | SHM_ACCESS_WRITE
1765+ );
1766+ assert_int_equal (oserr , OS_EOK );
1767+ assert_ptr_equal (shm .Buffer , (0x20000 + 0x586 ));
1768+ assert_int_equal (shm .Length , 0xC888 );
1769+
1770+ // Ensure that the SG entry shows up correctly
1771+ oserr = SHMBuildSG (shm .ID , & sgCount , NULL );
1772+ assert_int_equal (oserr , OS_EOK );
1773+ assert_int_equal (sgCount , 1 );
1774+
1775+ sg = test_malloc (sgCount * sizeof (SHMSG_t ));
1776+ assert_non_null (sg );
1777+
1778+ oserr = SHMBuildSG (shm .ID , & sgCount , sg );
1779+ assert_int_equal (oserr , OS_EOK );
1780+ assert_int_equal (sg [0 ].Address , (0x1000000 + 0x586 ));
1781+ assert_int_equal (sg [0 ].Length , 0xCA7A );
1782+
1783+ test_free (sg );
1784+ TeardownTest (state );
1785+ }
1786+
16811787void TestSHMMap_CanCommit (void * * state )
16821788{
16831789 oserr_t oserr ;
@@ -1741,7 +1847,7 @@ void TestSHMMap_CanRemap(void** state)
17411847 // 2. MemorySpaceMap, expect a new mapping of 0x3000 when we map from page 2-4
17421848 g_testContext .MemorySpaceMap .Calls [1 ].ExpectedSHMTag = 1 ; // expect 1
17431849 g_testContext .MemorySpaceMap .Calls [1 ].CheckSHMTag = true;
1744- g_testContext .MemorySpaceMap .Calls [1 ].ExpectedLength = 0x2890 ;
1850+ g_testContext .MemorySpaceMap .Calls [1 ].ExpectedLength = 0x3000 ;
17451851 g_testContext .MemorySpaceMap .Calls [1 ].CheckLength = true;
17461852 g_testContext .MemorySpaceMap .Calls [1 ].ExpectedFlags = MAPPING_PERSISTENT | MAPPING_USERSPACE ;
17471853 g_testContext .MemorySpaceMap .Calls [1 ].CheckFlags = true;
@@ -1797,6 +1903,7 @@ int main(void)
17971903 cmocka_unit_test_setup (TestSHMAttach_PrivateFailed , SetupTest ),
17981904 cmocka_unit_test_setup (TestSHMAttach_InvalidID , SetupTest ),
17991905 cmocka_unit_test_setup (TestSHMMap_Simple , SetupTest ),
1906+ cmocka_unit_test_setup (TestSHMMap_SimpleExported , SetupTest ),
18001907 cmocka_unit_test_setup (TestSHMMap_CanCommit , SetupTest ),
18011908 cmocka_unit_test_setup (TestSHMMap_CanRemap , SetupTest ),
18021909 };
0 commit comments