public void DecrementRefCount_Test() { uint minUsedBlocks = Heap.FBlock->used; int startNumObjs = Kernel.FOS_System.GC.NumObjs; Kernel.FOS_System.Type newObjType = new TestType(); byte* newObjPtr = (byte*)Kernel.FOS_System.GC.NewObj(newObjType); GCHeader* newObjHeaderPtr = (GCHeader*)(newObjPtr - sizeof(GCHeader)); Assert.AreEqual(1u, newObjHeaderPtr->RefCount, "Ref count not set to 1!"); Kernel.FOS_System.GC._DecrementRefCount(newObjPtr); Assert.AreEqual(0u, newObjHeaderPtr->RefCount, "Ref count not decremented!"); Assert.AreEqual(startNumObjs, Kernel.FOS_System.GC.NumObjs, "Num objs not decremented!"); Assert.AreEqual(minUsedBlocks, Heap.FBlock->used, "Memory not free'd after ref count hit 0!"); }
public void NewObj_Test() { int startNumObjs = Kernel.FOS_System.GC.NumObjs; Kernel.FOS_System.Type newObjType = new TestType(); byte* newObjPtr = (byte*)Kernel.FOS_System.GC.NewObj(newObjType); GCHeader* newObjHeaderPtr = (GCHeader*)(newObjPtr - sizeof(GCHeader)); Assert.IsTrue(Kernel.FOS_System.GC.CheckSignature(newObjHeaderPtr), "Signature not set properly!"); Assert.AreEqual(1u, newObjHeaderPtr->RefCount, "Ref count not set to 1!"); Assert.AreEqual(startNumObjs + 1, Kernel.FOS_System.GC.NumObjs, "NumObjs not set correctly!"); for (int i = 0; i < newObjType.Size; i++) { Assert.AreEqual(0u, newObjPtr[i], "Memory not initialised to 0 properly!"); } }
public void IncrementRefCount_Test() { Kernel.FOS_System.Type newObjType = new TestType(); byte* newObjPtr = (byte*)Kernel.FOS_System.GC.NewObj(newObjType); GCHeader* newObjHeaderPtr = (GCHeader*)(newObjPtr - sizeof(GCHeader)); Assert.AreEqual(1u, newObjHeaderPtr->RefCount, "Ref count not set to 1!"); Kernel.FOS_System.GC._IncrementRefCount(newObjPtr); Assert.AreEqual(2u, newObjHeaderPtr->RefCount, "Ref count not incremented!"); }