Skip to content

Commit 7f3288e

Browse files
committed
Test: Move section validation tests to its own file
1 parent 81ff655 commit 7f3288e

File tree

2 files changed

+74
-37
lines changed

2 files changed

+74
-37
lines changed

test/sectionvalidation.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import sys
2+
import os
3+
sys.path.append('../')
4+
from utils import Colors
5+
from argparser import *
6+
from TBInit import *
7+
8+
success = Colors.green + "SUCCESS: " + Colors.ENDC
9+
fail = Colors.red + "FAIL: " + Colors.ENDC
10+
11+
def ObjectList():
12+
obj_list = []
13+
cwd = os.getcwd()
14+
for file in os.listdir(cwd + "/testsuite"):
15+
if file.endswith(".wasm"):
16+
obj_list.append(cwd + "/testsuite/" + file)
17+
18+
return(obj_list)
19+
20+
def section_validation():
21+
return_list = []
22+
obj_list = ObjectList()
23+
for testfile in obj_list:
24+
pid = os.fork()
25+
# I dont have a bellybutton
26+
if pid == 0:
27+
# @DEVI-FIXME-pipe stdout and stderr to a file instead of the
28+
# bitbucket
29+
sys.stdout = open('/dev/null', 'w')
30+
sys.stderr = open('/dev/null', 'w')
31+
32+
interpreter = PythonInterpreter()
33+
module = interpreter.parse(testfile)
34+
interpreter.appendmodule(module)
35+
interpreter.dump_sections(module)
36+
interpreter.runValidations()
37+
vm = VM(interpreter.getmodules())
38+
ms = vm.getState()
39+
# interpreter.dump_sections(module)
40+
DumpIndexSpaces(ms)
41+
DumpLinearMems(ms.Linear_Memory, 1000)
42+
sys.exit()
43+
# the parent process
44+
elif pid > 0:
45+
# @DEVI-FIXME-we are intentionally blocking. later i will fix this
46+
# so we can use multicores to run our reg tests faster.
47+
cpid, status = os.waitpid(pid, 0)
48+
return_list.append(status)
49+
if status == 0:
50+
print(success + testfile)
51+
else:
52+
print(fail + testfile)
53+
else:
54+
# basically we couldnt fork a child
55+
print(fail + 'return code:' + pid)
56+
raise Exception("could not fork child")
57+
58+
def main():
59+
sectionvalidation(False)
60+
sectionvalidation(True)
61+
62+
if __name__ == '__main__':
63+
main()

test/test.py

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from test_LEB128 import test_unsigned_LEB128
1111
from leb128s import leb128sencodedecodeexhaustive
1212
from leb128s import leb128uencodedecodeexhaustive
13+
from sectionvalidation import *
1314
from abc import ABCMeta, abstractmethod
1415
sys.path.append('../')
1516
from utils import Colors
@@ -88,52 +89,25 @@ def Legacy(self):
8889
def GetName(self):
8990
return('leb128exhaustive')
9091

92+
class SectionValidationTest(Void_Spwner):
93+
def Legacy(self):
94+
section_validation()
95+
96+
def GetName(self):
97+
return('sectionvalidationtest')
98+
9199
################################################################################
92100
def main():
93-
return_list = []
94101
# LEB128 tests
95102
leb128encodetest = LEB128EncodeTest()
96103
leb128encodetest.Spwn()
97104
# leb128s exhaustive
98105
leb128sex = LEB128Exhaustive()
99106
leb128sex.Spwn()
100-
# parser test on the WASM testsuite
101-
obj_list = ObjectList()
102-
for testfile in obj_list:
103-
pid = os.fork()
104-
# I dont have a bellybutton
105-
if pid == 0:
106-
# @DEVI-FIXME-pipe stdout and stderr to a file instead of the
107-
# bitbucket
108-
sys.stdout = open('/dev/null', 'w')
109-
sys.stderr = open('/dev/null', 'w')
110-
111-
interpreter = PythonInterpreter()
112-
module = interpreter.parse(testfile)
113-
interpreter.appendmodule(module)
114-
interpreter.dump_sections(module)
115-
interpreter.runValidations()
116-
vm = VM(interpreter.getmodules())
117-
ms = vm.getState()
118-
# interpreter.dump_sections(module)
119-
DumpIndexSpaces(ms)
120-
DumpLinearMems(ms.Linear_Memory, 1000)
121-
sys.exit()
122-
# the parent process
123-
elif pid > 0:
124-
# @DEVI-FIXME-we are intentionally blocking. later i will fix this
125-
# so we can use multicores to run our reg tests faster.
126-
cpid, status = os.waitpid(pid, 0)
127-
return_list.append(status)
128-
if status == 0:
129-
print(success + testfile)
130-
else:
131-
print(fail + testfile)
132-
else:
133-
# basically we couldnt fork a child
134-
print(fail + 'return code:' + pid)
135-
raise Exception("could not fork child")
136107

108+
# parser test on the WASM testsuite
109+
sectionvalidation = SectionValidationTest()
110+
sectionvalidation.Spwn()
137111

138112
if __name__ == '__main__':
139113
main()

0 commit comments

Comments
 (0)