From ea967cf20d39d0601fa9888f62555dd9f61a8628 Mon Sep 17 00:00:00 2001 From: DerelictDrone Date: Thu, 16 Nov 2023 01:19:41 -0600 Subject: [PATCH] Ifdef test, Access CPUName + reformatting --- lua/wire/zvm/tests/example.lua | 5 +- lua/wire/zvm/tests/execute_from_iobus.lua | 5 +- lua/wire/zvm/tests/file_example.lua | 5 +- lua/wire/zvm/tests/ifdefs.lua | 88 +++++++++++++++++++ lua/wire/zvm/tests/ifdefs.txt | 38 ++++++++ lua/wire/zvm/tests/includes.lua | 1 - .../zvm/tests/intentional_compile_error.lua | 1 - .../zvm/tests/intentional_failed_test.lua | 5 +- lua/wire/zvm/tests/no_internal_mem.lua | 5 +- lua/wire/zvm/tests/virtualiobus.lua | 5 +- lua/wire/zvm/tests/virtualmembus.lua | 5 +- lua/wire/zvm/zvm_tests.lua | 4 + 12 files changed, 144 insertions(+), 23 deletions(-) create mode 100644 lua/wire/zvm/tests/ifdefs.lua create mode 100644 lua/wire/zvm/tests/ifdefs.txt diff --git a/lua/wire/zvm/tests/example.lua b/lua/wire/zvm/tests/example.lua index a6391a5..3413ca7 100644 --- a/lua/wire/zvm/tests/example.lua +++ b/lua/wire/zvm/tests/example.lua @@ -21,8 +21,7 @@ function CPUTest.RunCPU() end end -function CPUTest.CompileError() - CPUTest.TestSuite.Error('hit a compile time error') +function CPUTest.CompileError(msg) + CPUTest.TestSuite.Error('hit a compile time error '..msg) CPUTest.TestSuite.FinishTest(true) end - diff --git a/lua/wire/zvm/tests/execute_from_iobus.lua b/lua/wire/zvm/tests/execute_from_iobus.lua index da4defd..885b78b 100644 --- a/lua/wire/zvm/tests/execute_from_iobus.lua +++ b/lua/wire/zvm/tests/execute_from_iobus.lua @@ -46,8 +46,7 @@ function CPUTest.RunCPU() end end -function CPUTest.CompileError() - CPUTest.TestSuite.Error('hit a compile time error') +function CPUTest.CompileError(msg) + CPUTest.TestSuite.Error('hit a compile time error '..msg) CPUTest.TestSuite.FinishTest(true) end - diff --git a/lua/wire/zvm/tests/file_example.lua b/lua/wire/zvm/tests/file_example.lua index 9e539ba..09f48c8 100644 --- a/lua/wire/zvm/tests/file_example.lua +++ b/lua/wire/zvm/tests/file_example.lua @@ -23,8 +23,7 @@ function CPUTest.RunCPU() end end -function CPUTest.CompileError() - print('hit a compile time error') +function CPUTest.CompileError(msg) + CPUTest.TestSuite.Error('hit a compile time error '..msg) CPUTest.TestSuite.FinishTest(true) end - diff --git a/lua/wire/zvm/tests/ifdefs.lua b/lua/wire/zvm/tests/ifdefs.lua new file mode 100644 index 0000000..79c0a17 --- /dev/null +++ b/lua/wire/zvm/tests/ifdefs.lua @@ -0,0 +1,88 @@ +CPUTest = {} + +--not x and y = 14, name "Test Y" +-- x and y = 11, name "Test Y" +-- x and not y = 1, name "Test Y" + +-- culling update +-- not x and y = 12, name "Test Y" +-- x and y = 11, name "Test X and Y" +-- x and not y = 1, name "Test X" + + +CPUTest.ExpectedVariations1 = {"X","Y","X and Y","Y","Y","Y"} -- CPU Name vars +CPUTest.ExpectedVariations2 = {1,12,11,1,14,11} +CPUTest.ResultVariations1 = {} +CPUTest.ResultVariations2 = {} + +CPUTest.Variations1 = {"true","false"} +CPUTest.Variations2 = {"#define x\n","#define y\n","#define x\n#define y\n"} +CPUTest.Variation1Index = 1 +CPUTest.Variation2Index = 1 + +function CPUTest:RunTest(VM,TestSuite) + CPUTest.VM = VM + CPUTest.TestSuite = TestSuite + -- Loads a file from the testing directory and returns it as a str + CPUTest.Src = TestSuite:LoadFile("ifdefs.txt") + CPUTest.CompileNext() +end + +function CPUTest.CompileNext() + local cursrc + if CPUTest.Variation1Index <= #CPUTest.Variations1 then + cursrc = "#pragma set NewIfDefs "..CPUTest.Variations1[CPUTest.Variation1Index].."\n" + else + return CPUTest.CompareResults() + end + if CPUTest.Variation2Index <= #CPUTest.Variations2 then + cursrc = cursrc..CPUTest.Variations2[CPUTest.Variation2Index].."\n" + print(cursrc) + cursrc = cursrc..CPUTest.Src + CPUTest.TestSuite.Compile(cursrc,nil,CPUTest.LogResults,CPUTest.CompileError) + else + CPUTest.Variation1Index = CPUTest.Variation1Index + 1 + CPUTest.Variation2Index = 1 + CPUTest.CompileNext() + end +end + +function CPUTest.LogResults() + CPUTest.ResultVariations1[CPUTest.Variation2Index+#CPUTest.Variations2*(CPUTest.Variation1Index-1)] = CPUTest.TestSuite.GetCPUName() or "ERROR" + CPUTest.ResultVariations2[CPUTest.Variation2Index+#CPUTest.Variations2*(CPUTest.Variation1Index-1)] = #CPUTest.TestSuite.GetCompileBuffer()+1 or "ERROR" + CPUTest.Variation2Index = CPUTest.Variation2Index + 1 + CPUTest.CompileNext() +end + +function CPUTest.CompareResults() + local fail,results1,results2 = false,{},{} + for ind,i in ipairs(CPUTest.ExpectedVariations1) do + if CPUTest.ResultVariations1[ind] == "Test "..i then + results1[ind] = true + else + fail = true + results1[ind] = false + end + end + for ind,i in ipairs(CPUTest.ExpectedVariations2) do + if CPUTest.ResultVariations2[ind] == i then + results2[ind] = true + else + fail = true + results2[ind] = false + end + end + if fail then + CPUTest.TestSuite.Error('Unexpected test results!') + PrintTable({CPUTest.ResultVariations1,results1,CPUTest.ResultVariations2,results2}) + CPUTest.TestSuite.FinishTest(true) + else + CPUTest.TestSuite.FinishTest(false) + end +end + +function CPUTest.CompileError(msg) + CPUTest.TestSuite.Error('hit a compile time error '..msg) + CPUTest.TestSuite.FinishTest(true) +end + diff --git a/lua/wire/zvm/tests/ifdefs.txt b/lua/wire/zvm/tests/ifdefs.txt new file mode 100644 index 0000000..c0cd75c --- /dev/null +++ b/lua/wire/zvm/tests/ifdefs.txt @@ -0,0 +1,38 @@ +/*defs will be added programatically*/ + +#ifdef x +#define z +#pragma cpuname Test X + ALLOC 1 +#ifdef y +#ifdef x +#pragma cpuname Test X and Y +#endif + ALLOC 2 +#endif +//not x +#else + ALLOC 4 +#endif + +#ifdef y +#ifndef x +#pragma cpuname Test Y +#endif +ALLOC 8 +#endif +/* +#ifdef y + ALLOC 8 +#endif +*/ +//above comment intentional for making sure ifdef handler doesn't skip into the middle of a comment + +// not x and y = 14, name "Test Y" +// x and y = 11, name "Test Y" +// x and not y = 1, name "Test Y" + +// culling update +// not x and y = 12, name "Test Y" +// x and y = 11, name "Test X and Y" +// x and not y = 1, name "Test X" diff --git a/lua/wire/zvm/tests/includes.lua b/lua/wire/zvm/tests/includes.lua index 4ba52a8..09550fd 100644 --- a/lua/wire/zvm/tests/includes.lua +++ b/lua/wire/zvm/tests/includes.lua @@ -27,4 +27,3 @@ function CPUTest.CompileError(msg) CPUTest.TestSuite.Error('hit a compile time error '..msg) CPUTest.TestSuite.FinishTest(true) end - diff --git a/lua/wire/zvm/tests/intentional_compile_error.lua b/lua/wire/zvm/tests/intentional_compile_error.lua index 4bbd740..082e2fd 100644 --- a/lua/wire/zvm/tests/intentional_compile_error.lua +++ b/lua/wire/zvm/tests/intentional_compile_error.lua @@ -14,4 +14,3 @@ end function CPUTest.CompileError() CPUTest.TestSuite.FinishTest(false) end - diff --git a/lua/wire/zvm/tests/intentional_failed_test.lua b/lua/wire/zvm/tests/intentional_failed_test.lua index af014a9..c293ffd 100644 --- a/lua/wire/zvm/tests/intentional_failed_test.lua +++ b/lua/wire/zvm/tests/intentional_failed_test.lua @@ -21,8 +21,7 @@ function CPUTest.RunCPU() end end -function CPUTest.CompileError() - CPUTest.TestSuite.Error('hit a compile time error') +function CPUTest.CompileError(msg) + CPUTest.TestSuite.Error('hit a compile time error '..msg) CPUTest.TestSuite.FinishTest(true) end - diff --git a/lua/wire/zvm/tests/no_internal_mem.lua b/lua/wire/zvm/tests/no_internal_mem.lua index 6257a58..05cc47c 100644 --- a/lua/wire/zvm/tests/no_internal_mem.lua +++ b/lua/wire/zvm/tests/no_internal_mem.lua @@ -27,8 +27,7 @@ function CPUTest.RunCPU() end end -function CPUTest.CompileError() - CPUTest.TestSuite.Error('hit a compile time error') +function CPUTest.CompileError(msg) + CPUTest.TestSuite.Error('hit a compile time error '..msg) CPUTest.TestSuite.FinishTest(true) end - diff --git a/lua/wire/zvm/tests/virtualiobus.lua b/lua/wire/zvm/tests/virtualiobus.lua index 64de885..98636d9 100644 --- a/lua/wire/zvm/tests/virtualiobus.lua +++ b/lua/wire/zvm/tests/virtualiobus.lua @@ -34,8 +34,7 @@ function CPUTest.RunCPU() end end -function CPUTest.CompileError() - CPUTest.TestSuite.Error('hit a compile time error') +function CPUTest.CompileError(msg) + CPUTest.TestSuite.Error('hit a compile time error '..msg) CPUTest.TestSuite.FinishTest(true) end - diff --git a/lua/wire/zvm/tests/virtualmembus.lua b/lua/wire/zvm/tests/virtualmembus.lua index 3bf1102..db783bb 100644 --- a/lua/wire/zvm/tests/virtualmembus.lua +++ b/lua/wire/zvm/tests/virtualmembus.lua @@ -29,8 +29,7 @@ function CPUTest.RunCPU() end end -function CPUTest.CompileError() - CPUTest.TestSuite.Error('hit a compile time error') +function CPUTest.CompileError(msg) + CPUTest.TestSuite.Error('hit a compile time error '..msg) CPUTest.TestSuite.FinishTest(true) end - diff --git a/lua/wire/zvm/zvm_tests.lua b/lua/wire/zvm/zvm_tests.lua index 90c6c26..5ab9143 100644 --- a/lua/wire/zvm/zvm_tests.lua +++ b/lua/wire/zvm/zvm_tests.lua @@ -130,6 +130,10 @@ function ZVMTestSuite.GetCompileBuffer() return CPULib.Buffer end +function ZVMTestSuite.GetCPUName() + return CPULib.CPUName +end + function ZVMTestSuite.CreateVirtualMemBus(MembusSize) local virtualMemBus = {Size = MembusSize} function virtualMemBus:ReadCell(Address)