コード例 #1
0
        public static void Test_PointerManipulation()
        {
            FOS_System.String testName = "Ptr Manipulation";
            DBGMSG(testName, "START");

            errors   = 0;
            warnings = 0;

            byte *rootPtr = (byte *)FOS_System.Heap.Alloc(4096, 32);

            try
            {
                DBGMSG(testName, ((FOS_System.String) "rootPtr: ") + (uint)rootPtr);

                if (!Validate_PointerBoundaryAlignment(rootPtr, 32))
                {
                    DBGERR(testName, "Pointer not aligned on boundary correctly!");
                }

                byte *retPtr = ReturnPointer(rootPtr);
                if (retPtr != rootPtr)
                {
                    DBGERR(testName, "Passing and returning pointer via method failed.");
                }

                byte *shiftedPtr = (byte *)((uint *)rootPtr + 1);
                if (((uint)shiftedPtr) != ((uint)rootPtr) + 4)
                {
                    DBGERR(testName, ((FOS_System.String) "Shifted pointer not shifted correctly! shiftedPtr: ") + (uint)shiftedPtr);
                }

                EHCITestingObject testObj = new EHCITestingObject();
                testObj.ptr1 = rootPtr;
                testObj.ptr2 = (uint *)rootPtr;
                testObj.ptr3 = (ulong *)rootPtr;
                testObj.ptr4 = rootPtr;
                if (testObj.ptr1 != rootPtr)
                {
                    DBGERR(testName, ((FOS_System.String) "Storing test pointer 1 failed! testObj.ptr1: ") + (uint)testObj.ptr1);
                }
                if (testObj.ptr2 != rootPtr)
                {
                    DBGERR(testName, ((FOS_System.String) "Storing test pointer 2 failed! testObj.ptr2: ") + (uint)testObj.ptr2);
                }
                if (testObj.ptr3 != rootPtr)
                {
                    DBGERR(testName, ((FOS_System.String) "Storing test pointer 3 failed! testObj.ptr3: ") + (uint)testObj.ptr3);
                }
                if (testObj.ptr4 != rootPtr)
                {
                    DBGERR(testName, ((FOS_System.String) "Storing test pointer 4 failed! testObj.ptr4: ") + (uint)testObj.ptr4);
                }
            }
            catch
            {
                errors++;
                BasicConsole.SetTextColour(BasicConsole.warning_colour);
                BasicConsole.WriteLine(ExceptionMethods.CurrentException.Message);
                BasicConsole.SetTextColour(BasicConsole.default_colour);
            }
            finally
            {
                FOS_System.Heap.Free(rootPtr);
            }

            if (errors > 0)
            {
                DBGERR(testName, ((FOS_System.String) "Test failed! Errors: ") + errors + " Warnings: " + warnings);
            }
            else
            {
                if (warnings > 0)
                {
                    DBGWRN(testName, ((FOS_System.String) "Test passed with warnings: ") + warnings);
                }
                else
                {
                    DBGMSG(testName, "Test passed.");
                }
            }

            DBGMSG(testName, "END");

            BasicConsole.DelayOutput(1);
        }
コード例 #2
0
ファイル: EHCITesting.cs プロジェクト: rmhasan/FlingOS
        public static void Test_PointerManipulation()
        {
            FOS_System.String testName = "Ptr Manipulation";
            DBGMSG(testName, "START");

            errors = 0;
            warnings = 0;

            byte* rootPtr = (byte*)FOS_System.Heap.Alloc(4096, 32);
            try
            {
                DBGMSG(testName, ((FOS_System.String)"rootPtr: ") + (uint)rootPtr);

                if (!Validate_PointerBoundaryAlignment(rootPtr, 32))
                {
                    DBGERR(testName, "Pointer not aligned on boundary correctly!");
                }

                byte* retPtr = ReturnPointer(rootPtr);
                if (retPtr != rootPtr)
                {
                    DBGERR(testName, "Passing and returning pointer via method failed.");
                }

                byte* shiftedPtr = (byte*)((uint*)rootPtr + 1);
                if (((uint)shiftedPtr) != ((uint)rootPtr) + 4)
                {
                    DBGERR(testName, ((FOS_System.String)"Shifted pointer not shifted correctly! shiftedPtr: ") + (uint)shiftedPtr);
                }

                EHCITestingObject testObj = new EHCITestingObject();
                testObj.ptr1 = rootPtr;
                testObj.ptr2 = (uint*)rootPtr;
                testObj.ptr3 = (ulong*)rootPtr;
                testObj.ptr4 = rootPtr;
                if (testObj.ptr1 != rootPtr)
                {
                    DBGERR(testName, ((FOS_System.String)"Storing test pointer 1 failed! testObj.ptr1: ") + (uint)testObj.ptr1);
                }
                if (testObj.ptr2 != rootPtr)
                {
                    DBGERR(testName, ((FOS_System.String)"Storing test pointer 2 failed! testObj.ptr2: ") + (uint)testObj.ptr2);
                }
                if (testObj.ptr3 != rootPtr)
                {
                    DBGERR(testName, ((FOS_System.String)"Storing test pointer 3 failed! testObj.ptr3: ") + (uint)testObj.ptr3);
                }
                if (testObj.ptr4 != rootPtr)
                {
                    DBGERR(testName, ((FOS_System.String)"Storing test pointer 4 failed! testObj.ptr4: ") + (uint)testObj.ptr4);
                }
            }
            catch
            {
                errors++;
                BasicConsole.SetTextColour(BasicConsole.warning_colour);
                BasicConsole.WriteLine(ExceptionMethods.CurrentException.Message);
                BasicConsole.SetTextColour(BasicConsole.default_colour);
            }
            finally
            {
                FOS_System.Heap.Free(rootPtr);
            }

            if (errors > 0)
            {
                DBGERR(testName, ((FOS_System.String)"Test failed! Errors: ") + errors + " Warnings: " + warnings);
            }
            else
            {
                if (warnings > 0)
                {
                    DBGWRN(testName, ((FOS_System.String)"Test passed with warnings: ") + warnings);
                }
                else
                {
                    DBGMSG(testName, "Test passed.");
                }
            }

            DBGMSG(testName, "END");

            BasicConsole.DelayOutput(1);
        }