Skip to content

Commit 3da6dc9

Browse files
committed
Test: Make sure type section validation fails correctly
This commit adds tests and invalid wasm testfiles that checks the type section. The file invalid_form.wasm is based on testsuite/address.wasm and was edited to have the first entry of the type section include an invalid form (0x60 => 0x61). The file invalid_retcount.wasm is also based on testsuite/address.wasm and was edited to have the first type section entry include two return values instead of one.
1 parent 98a57cf commit 3da6dc9

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

test/sectionvalidation.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,55 @@
88
success = Colors.green + "SUCCESS: " + Colors.ENDC
99
fail = Colors.red + "FAIL: " + Colors.ENDC
1010

11-
def ObjectList():
11+
def ObjectList(directory):
1212
obj_list = []
1313
cwd = os.getcwd()
14-
for file in os.listdir(cwd + "/testsuite"):
14+
15+
for file in os.listdir(cwd + directory):
1516
if file.endswith(".wasm"):
16-
obj_list.append(cwd + "/testsuite/" + file)
17+
obj_list.append(cwd + directory + "/" + file)
1718

1819
return(obj_list)
1920

21+
def section_validation_fail(directory):
22+
return_list = []
23+
obj_list = ObjectList(directory)
24+
for testfile in obj_list:
25+
pid = os.fork()
26+
# I dont have a bellybutton
27+
if pid == 0:
28+
# @DEVI-FIXME-pipe stdout and stderr to a file instead of the
29+
# bitbucket
30+
sys.stdout = open('/dev/null', 'w')
31+
sys.stderr = open('/dev/null', 'w')
32+
33+
interpreter = PythonInterpreter()
34+
module = interpreter.parse(testfile)
35+
interpreter.appendmodule(module)
36+
interpreter.dump_sections(module)
37+
if "type" in directory:
38+
if not interpreter.TypeSection():
39+
sys.exit(1)
40+
sys.exit()
41+
# the parent process
42+
elif pid > 0:
43+
# @DEVI-FIXME-we are intentionally blocking. later i will fix this
44+
# so we can use multicores to run our reg tests faster.
45+
cpid, status = os.waitpid(pid, 0)
46+
return_list.append(status)
47+
if status != 0:
48+
print(success + testfile)
49+
else:
50+
print(fail + testfile)
51+
else:
52+
# basically we couldnt fork a child
53+
print(fail + 'return code:' + pid)
54+
raise Exception("could not fork child")
55+
56+
2057
def section_validation():
2158
return_list = []
22-
obj_list = ObjectList()
59+
obj_list = ObjectList("/testsuite")
2360
for testfile in obj_list:
2461
pid = os.fork()
2562
# I dont have a bellybutton

test/test.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,6 @@ def Spwn(self):
6262
print(fail + 'return code:' + pid)
6363
raise Exception("could not fork child")
6464

65-
66-
def ObjectList():
67-
obj_list = []
68-
cwd = os.getcwd()
69-
for file in os.listdir(cwd + "/testsuite"):
70-
if file.endswith(".wasm"):
71-
obj_list.append(cwd + "/testsuite/" + file)
72-
73-
return(obj_list)
74-
7565
################################################################################
7666
class LEB128EncodeTest(Void_Spwner):
7767
def Legacy(self):
@@ -91,7 +81,19 @@ def GetName(self):
9181

9282
class SectionValidationTest(Void_Spwner):
9383
def Legacy(self):
84+
fail_dir = "/testsuite_fail/"
9485
section_validation()
86+
section_validation_fail(fail_dir + "type")
87+
#section_validation_fail(fail_dir + "import")
88+
#section_validation_fail(fail_dir + "function")
89+
#section_validation_fail(fail_dir + "table")
90+
#section_validation_fail(fail_dir + "memory")
91+
#section_validation_fail(fail_dir + "global")
92+
#section_validation_fail(fail_dir + "export")
93+
#section_validation_fail(fail_dir + "start")
94+
#section_validation_fail(fail_dir + "element")
95+
#section_validation_fail(fail_dir + "code")
96+
#section_validation_fail(fail_dir + "data")
9597

9698
def GetName(self):
9799
return('sectionvalidationtest')
393 Bytes
Binary file not shown.
394 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)