Skip to content

Commit

Permalink
Add test for loacding of packed structures
Browse files Browse the repository at this point in the history
  • Loading branch information
quajak committed Dec 30, 2023
1 parent 3cddfe7 commit 0d726b8
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Tests/Cosmos.TestRunner.Full/DefaultEngineConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public virtual IEnumerable<RunTargetEnum> RunTargets
}
}

public virtual bool RunWithGDB => false;
public virtual bool StartBochsDebugGUI => false;
public virtual bool RunWithGDB => true;
public virtual bool StartBochsDebugGUI => true;

public virtual bool DebugIL2CPU => false;
public virtual string KernelPkg => String.Empty;
Expand Down
40 changes: 20 additions & 20 deletions Tests/Cosmos.TestRunner.Full/TestKernelSets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ public static IEnumerable<Type> GetKernelTypesToRun()
// Stable kernel types: the ones that are stable and will run in AppVeyor
public static IEnumerable<Type> GetStableKernelTypes()
{
yield return typeof(BoxingTests.Kernel);
//yield return typeof(BoxingTests.Kernel);
yield return typeof(Compiler.Tests.TypeSystem.Kernel);
yield return typeof(Compiler.Tests.Bcl.Kernel);
yield return typeof(Compiler.Tests.Bcl.System.Kernel);
//yield return typeof(Cosmos.Compiler.Tests.Encryption.Kernel);
yield return typeof(Compiler.Tests.Exceptions.Kernel);
yield return typeof(Compiler.Tests.MethodTests.Kernel);
yield return typeof(Compiler.Tests.SingleEchoTest.Kernel);
yield return typeof(Kernel.Tests.Fat.Kernel);
yield return typeof(Kernel.Tests.IO.Kernel);
yield return typeof(SimpleStructsAndArraysTest.Kernel);
yield return typeof(Kernel.Tests.DiskManager.Kernel);
//yield return typeof(Compiler.Tests.Bcl.Kernel);
//yield return typeof(Compiler.Tests.Bcl.System.Kernel);
////yield return typeof(Cosmos.Compiler.Tests.Encryption.Kernel);
//yield return typeof(Compiler.Tests.Exceptions.Kernel);
//yield return typeof(Compiler.Tests.MethodTests.Kernel);
//yield return typeof(Compiler.Tests.SingleEchoTest.Kernel);
//yield return typeof(Kernel.Tests.Fat.Kernel);
//yield return typeof(Kernel.Tests.IO.Kernel);
//yield return typeof(SimpleStructsAndArraysTest.Kernel);
//yield return typeof(Kernel.Tests.DiskManager.Kernel);

//yield return typeof(KernelGen3.Boot);
yield return typeof(GraphicTest.Kernel);
////yield return typeof(KernelGen3.Boot);
//yield return typeof(GraphicTest.Kernel);

// Disable network tests due to our self hosted CI/CD limitations (VPS currently doesn't support VMWare with its CPU)
//yield return typeof(NetworkTest.Kernel);
yield return typeof(AudioTests.Kernel);
// Please see the notes on the kernel itself before enabling it
//yield return typeof(ConsoleTest.Kernel);
yield return typeof(MemoryOperationsTest.Kernel);
yield return typeof(ProcessorTests.Kernel);
//// Disable network tests due to our self hosted CI/CD limitations (VPS currently doesn't support VMWare with its CPU)
////yield return typeof(NetworkTest.Kernel);
//yield return typeof(AudioTests.Kernel);
//// Please see the notes on the kernel itself before enabling it
////yield return typeof(ConsoleTest.Kernel);
//yield return typeof(MemoryOperationsTest.Kernel);
//yield return typeof(ProcessorTests.Kernel);
}
}
}
45 changes: 45 additions & 0 deletions Tests/Kernels/Cosmos.Compiler.Tests.TypeSystem/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using IL2CPU.API.Attribs;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Sys = Cosmos.System;

namespace Cosmos.Compiler.Tests.TypeSystem
Expand Down Expand Up @@ -305,6 +306,7 @@ protected override void Run()
Assert.IsTrue(c != null, "Anonymous types are created correctly");
Assert.IsTrue(c.i == 1 && c.n == "Test", "Anonymous types have correct values");

TestPackedStruct();
TestVTablesImpl();
TestGarbageCollectorMethods();
TestGarbageCollector();
Expand Down Expand Up @@ -339,5 +341,48 @@ private static void TestReflection()
Assert.AreEqual("Int32", Type.GetType("System.Int32, System.Private.CoreLib").Name, "GetType works on Int32 with shortened assembly qualified name");
Assert.AreEqual("Int32", Type.GetType("System.Int32").Name, "GetType works on Int32 with shortened assembly qualified name");
}

PackedStruct GetPackedStruct()
{
return new PackedStruct()
{
a = 1,
b = 2,
c = 3,
d = 4,
e = 5,
f = 6
};
}

PackedStruct Re { get; set; }
private void TestPackedStruct()
{
Re = GetPackedStruct();

Assert.AreEqual(1, Re.a, "Correctly returned first field of struct");
Assert.AreEqual("1", Re.a.ToString(), "Correctly returned first field of struct as string");
Assert.AreEqual(2, Re.b, "Correctly returned second field of struct");
Assert.AreEqual("2", Re.b.ToString(), "Correctly returned second field of struct as string");
Assert.AreEqual(3, Re.c, "Correctly returned third field of struct");
Assert.AreEqual("3", Re.c.ToString(), "Correctly returned third field of struct as string");
Assert.AreEqual(4, Re.d, "Correctly returned fourth field of struct");
Assert.AreEqual("4", Re.d.ToString(), "Correctly returned fourth field of struct as string");
Assert.AreEqual(5, Re.e, "Correctly returned fifth field of struct");
Assert.AreEqual("5", Re.e.ToString(), "Correctly returned fifth field of struct as string");
Assert.AreEqual(6, Re.f, "Correctly returned sixth field of struct");
Assert.AreEqual("6", Re.f.ToString(), "Correctly returned sixth field of struct as string");
}
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct PackedStruct
{
public ushort a;
public uint b;
public ulong c;
public ushort d;
public ushort e;
public ulong f;
}
}

0 comments on commit 0d726b8

Please sign in to comment.