Skip to content

Commit

Permalink
Ifdef test, Access CPUName + reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
DerelictDrone committed Nov 16, 2023
1 parent c2e89b5 commit ea967cf
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 23 deletions.
5 changes: 2 additions & 3 deletions lua/wire/zvm/tests/example.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

5 changes: 2 additions & 3 deletions lua/wire/zvm/tests/execute_from_iobus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

5 changes: 2 additions & 3 deletions lua/wire/zvm/tests/file_example.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

88 changes: 88 additions & 0 deletions lua/wire/zvm/tests/ifdefs.lua
Original file line number Diff line number Diff line change
@@ -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

38 changes: 38 additions & 0 deletions lua/wire/zvm/tests/ifdefs.txt
Original file line number Diff line number Diff line change
@@ -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"
1 change: 0 additions & 1 deletion lua/wire/zvm/tests/includes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ function CPUTest.CompileError(msg)
CPUTest.TestSuite.Error('hit a compile time error '..msg)
CPUTest.TestSuite.FinishTest(true)
end

1 change: 0 additions & 1 deletion lua/wire/zvm/tests/intentional_compile_error.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ end
function CPUTest.CompileError()
CPUTest.TestSuite.FinishTest(false)
end

5 changes: 2 additions & 3 deletions lua/wire/zvm/tests/intentional_failed_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

5 changes: 2 additions & 3 deletions lua/wire/zvm/tests/no_internal_mem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

5 changes: 2 additions & 3 deletions lua/wire/zvm/tests/virtualiobus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

5 changes: 2 additions & 3 deletions lua/wire/zvm/tests/virtualmembus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 4 additions & 0 deletions lua/wire/zvm/zvm_tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ea967cf

Please sign in to comment.