From f1364ddc46937e978a1099f0c627e334ccd3ce77 Mon Sep 17 00:00:00 2001 From: Yuuki Wesp Date: Fri, 22 May 2020 03:36:20 +0300 Subject: [PATCH] add module loader test --- test/vm_test/ModulesTest.cs | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/vm_test/ModulesTest.cs diff --git a/test/vm_test/ModulesTest.cs b/test/vm_test/ModulesTest.cs new file mode 100644 index 0000000..c87c4af --- /dev/null +++ b/test/vm_test/ModulesTest.cs @@ -0,0 +1,55 @@ +namespace vm_test +{ + using System.Linq; + using ancient.runtime; + using ancient.runtime.emit; + using ancient.runtime.emit.sys; + using ancient.runtime.hardware; + using NUnit.Framework; + + [TestFixture] + public class ModulesTest : VMBehaviour + { + [OneTimeSetUp] + public void Setup() => IntConverter.Register(); + + + [Test] + [Author("Yuuki Wesp", "ls-micro@ya.ru")] + [Description("parse functions in module class test")] + public void ParseFunctionsTest() + { + Module.Boot(bus); + var mem = new Instruction[] + { + new ldx(0x11, 0x1), + new sig("test1", 0, "void"), + new lpstr("test1"), + new ldi(0x0, 0x5), + new ret(), + new sig("test2", 0, "void"), + new lpstr("test2"), + new ldi(0x1, 0x6), + new call_i("test1()"), + new ret(), + new sig("test3", 0, "void"), new lpstr("test3"), + new call_i("test2()"), + new mul(0x3, 0x0, 0x1), + new ret(), + new call_i("test3()"), + new nop(), + }.Reverse().ToArray(); + + var assembly = new DynamicAssembly("test"); + var ilGen = assembly.GetGenerator(); + ilGen.Emit(mem.Select(x => (OpCode)x).ToArray()); + var module = new Module("test.module"); + Module.modules.Add(module.GetHashCode(), module); + state.LoadMeta(mem.Reverse().SelectMany(x => x.GetMetaDataILBytes()).ToArray()); + + var functions = Module.ImportFunctions(assembly.GetILCode(), module); + + Assert.AreEqual(3, functions.Length); + } + } +} \ No newline at end of file