@@ -866,7 +866,10 @@ void TestSHMConform_IsConformed(void** state)
866866 // will be 0xFFFFF, which will cover our pages.
867867 oserr = SHMConform (
868868 handle .ID ,
869- OSMEMORYCONFORMITY_LOW ,
869+ & (SHMConformityOptions_t ) {
870+ .BufferAlignment = 0 ,
871+ .Conformity = OSMEMORYCONFORMITY_LOW ,
872+ },
870873 0 ,
871874 SHM_ACCESS_READ ,
872875 0 ,
@@ -894,7 +897,120 @@ void TestSHMConform_IsConformed(void** state)
894897 TeardownTest (state );
895898}
896899
897- void TestSHMConform_NotConformed (void * * state )
900+ void TestSHMConform_NotAlignmentConformed (void * * state )
901+ {
902+ oserr_t oserr ;
903+ SHMHandle_t handle ;
904+ SHMHandle_t conformedHandle ;
905+ int pageCount = 9 ;
906+ paddr_t page [9 ] = {
907+ 0x1000856 ,
908+ 0x1400000 ,
909+ 0x1500000 ,
910+ 0x1600000 ,
911+ 0x1700000 ,
912+ 0x1C00000 ,
913+ 0x1A00000 ,
914+ 0x2000000 ,
915+ 0x2A00000 ,
916+ };
917+
918+ // The following function calls are expected during normal
919+ // creation:
920+
921+ // 1. CreateHandle, return a non-standard id as we use it twice
922+ g_testContext .CreateHandle .Calls [0 ].ReturnedID = 0x10 ;
923+ g_testContext .CreateHandle .Calls [0 ].ReturnedIDProvided = true;
924+
925+ // 2. GetMemorySpaceMapping
926+ g_testContext .GetMemorySpaceMapping .ExpectedAddress = 0x1596856 ;
927+ g_testContext .GetMemorySpaceMapping .CheckAddress = true;
928+ g_testContext .GetMemorySpaceMapping .ExpectedPageCount = pageCount ;
929+ g_testContext .GetMemorySpaceMapping .CheckPageCount = true;
930+ g_testContext .GetMemorySpaceMapping .PageValues = & page [0 ];
931+ g_testContext .GetMemorySpaceMapping .PageValuesProvided = true;
932+ g_testContext .GetMemorySpaceMapping .ReturnValue = OS_EOK ;
933+
934+ // We use garbage values as the memory contents are not accessed
935+ oserr = SHMExport (
936+ (void * )0x1596856 ,
937+ 0x8400 ,
938+ 0 ,
939+ 0 ,
940+ & handle
941+ );
942+ assert_int_equal (oserr , OS_EOK );
943+ assert_int_equal (handle .ID , 0x10 );
944+ assert_int_equal (handle .SourceID , UUID_INVALID );
945+ assert_int_equal (handle .SourceFlags , 0 );
946+ assert_ptr_equal (handle .Buffer , 0x1596856 );
947+ assert_int_equal (handle .Capacity , 0x8400 );
948+ assert_int_equal (handle .Length , 0x8400 );
949+ assert_int_equal (handle .Offset , 0 );
950+
951+ // 3. CreateHandle, return a non-standard id as we use it twice
952+ g_testContext .CreateHandle .Calls [1 ].ReturnedID = 0x20 ;
953+ g_testContext .CreateHandle .Calls [1 ].ReturnedIDProvided = true;
954+
955+ // 4. AcquireHandleOfType. We will be acquiring the original buffer created.
956+ g_testContext .AcquireHandleOfType .Resource = g_testContext .CreateHandle .Calls [0 ].CreatedResource ;
957+ g_testContext .AcquireHandleOfType .ResourceProvided = true;
958+
959+ // 5. ArchSHMTypeToPageMask
960+ g_testContext .ArchSHMTypeToPageMask .PageMask = 0xFFFFF ;
961+ g_testContext .ArchSHMTypeToPageMask .PageMaskProvided = true;
962+ g_testContext .ArchSHMTypeToPageMask .ReturnValue = OS_EOK ;
963+
964+ // 6. MemorySpaceMap, this is the most interesting call to check, as that
965+ // needs to contain the expected setup for the virtual region
966+ g_testContext .MemorySpaceMap .Calls [0 ].ExpectedSHMTag = 0x20 ;
967+ g_testContext .MemorySpaceMap .Calls [0 ].CheckSHMTag = true;
968+ g_testContext .MemorySpaceMap .Calls [0 ].ExpectedLength = 0x83C0 ; // 0x8400-64
969+ g_testContext .MemorySpaceMap .Calls [0 ].CheckLength = true;
970+ g_testContext .MemorySpaceMap .Calls [0 ].ExpectedFlags = MAPPING_COMMIT | MAPPING_PERSISTENT | MAPPING_USERSPACE ;
971+ g_testContext .MemorySpaceMap .Calls [0 ].CheckFlags = true;
972+ g_testContext .MemorySpaceMap .Calls [0 ].ExpectedPlacement = MAPPING_VIRTUAL_PROCESS ;
973+ g_testContext .MemorySpaceMap .Calls [0 ].CheckPlacement = true;
974+ g_testContext .MemorySpaceMap .Calls [0 ].ReturnedMapping = 0x40000000 ;
975+ g_testContext .MemorySpaceMap .Calls [0 ].ReturnedMappingProvided = true;
976+ g_testContext .MemorySpaceMap .Calls [0 ].ReturnValue = OS_EOK ;
977+
978+ // We fake that the buffer is conformed. It does not matter which conformity
979+ // we test with, as we mock the translation call. In this case the PageMask
980+ // will be 0xFFFFF, which will cover our pages.
981+ oserr = SHMConform (
982+ handle .ID ,
983+ & (SHMConformityOptions_t ) {
984+ .BufferAlignment = 128 ,
985+ .Conformity = OSMEMORYCONFORMITY_LOW ,
986+ },
987+ 0 ,
988+ SHM_ACCESS_READ ,
989+ 64 ,
990+ handle .Length ,
991+ & conformedHandle
992+ );
993+ assert_int_equal (oserr , OS_EOK );
994+ assert_int_equal (conformedHandle .ID , 0x20 );
995+ assert_int_equal (conformedHandle .SourceID , 0x10 ); // This is now cloned
996+ assert_int_equal (conformedHandle .SourceFlags , 0 );
997+ assert_ptr_equal (conformedHandle .Buffer , 0x40000000 );
998+ assert_int_equal (conformedHandle .Capacity , 0x83C0 );
999+ assert_int_equal (conformedHandle .Length , 0x83C0 );
1000+ assert_int_equal (conformedHandle .Offset , 64 );
1001+
1002+ // When a handle is already conformed, SHMConform will just attach
1003+ // and map. So verify this happened as we expected
1004+ // Ensure the right number of calls were made.
1005+ assert_int_equal (g_testContext .CreateHandle .CallCount , 2 );
1006+ assert_int_equal (g_testContext .ArchSHMTypeToPageMask .Calls , 1 );
1007+ assert_int_equal (g_testContext .AcquireHandleOfType .Calls , 1 );
1008+ assert_int_equal (g_testContext .GetMemorySpaceMapping .Calls , 1 );
1009+ assert_int_equal (g_testContext .MemorySpaceMap .CallCount , 1 );
1010+ TeardownTest (state );
1011+ }
1012+
1013+ void TestSHMConform_NotMemoryConformed (void * * state )
8981014{
8991015 oserr_t oserr ;
9001016 SHMHandle_t handle ;
@@ -977,7 +1093,10 @@ void TestSHMConform_NotConformed(void** state)
9771093 // will be 0xFFFFF, which will cover our pages.
9781094 oserr = SHMConform (
9791095 handle .ID ,
980- OSMEMORYCONFORMITY_LOW ,
1096+ & (SHMConformityOptions_t ) {
1097+ .BufferAlignment = 0 ,
1098+ .Conformity = OSMEMORYCONFORMITY_LOW ,
1099+ },
9811100 0 ,
9821101 SHM_ACCESS_READ ,
9831102 0 ,
@@ -1122,7 +1241,10 @@ void TestSHMConform_NotConformedFilledOnCreation(void** state)
11221241 // will be 0xFFFFF, which will cover our pages.
11231242 oserr = SHMConform (
11241243 handle .ID ,
1125- OSMEMORYCONFORMITY_LOW ,
1244+ & (SHMConformityOptions_t ) {
1245+ .BufferAlignment = 0 ,
1246+ .Conformity = OSMEMORYCONFORMITY_LOW ,
1247+ },
11261248 SHM_CONFORM_FILL_ON_CREATION ,
11271249 SHM_ACCESS_READ ,
11281250 0 ,
@@ -1255,7 +1377,10 @@ void TestSHMConform_NotConformedBackfilledOnUnmap(void** state)
12551377 // will be 0xFFFFF, which will cover our pages.
12561378 oserr = SHMConform (
12571379 handle .ID ,
1258- OSMEMORYCONFORMITY_LOW ,
1380+ & (SHMConformityOptions_t ) {
1381+ .BufferAlignment = 0 ,
1382+ .Conformity = OSMEMORYCONFORMITY_LOW ,
1383+ },
12591384 SHM_CONFORM_BACKFILL_ON_UNMAP ,
12601385 SHM_ACCESS_READ ,
12611386 0 ,
@@ -1664,7 +1789,8 @@ int main(void)
16641789 cmocka_unit_test_setup (TestSHMExport_NotPageAligned , SetupTest ),
16651790 cmocka_unit_test_setup (TestSHMExport_PRIVATE , SetupTest ),
16661791 cmocka_unit_test_setup (TestSHMConform_IsConformed , SetupTest ),
1667- cmocka_unit_test_setup (TestSHMConform_NotConformed , SetupTest ),
1792+ cmocka_unit_test_setup (TestSHMConform_NotAlignmentConformed , SetupTest ),
1793+ cmocka_unit_test_setup (TestSHMConform_NotMemoryConformed , SetupTest ),
16681794 cmocka_unit_test_setup (TestSHMConform_NotConformedFilledOnCreation , SetupTest ),
16691795 cmocka_unit_test_setup (TestSHMConform_NotConformedBackfilledOnUnmap , SetupTest ),
16701796 cmocka_unit_test_setup (TestSHMAttach_Simple , SetupTest ),
0 commit comments