5
5
'''
6
6
Test script for security-check.py
7
7
'''
8
+ import os
8
9
import subprocess
9
10
import unittest
10
11
@@ -19,6 +20,10 @@ def write_testcode(filename):
19
20
}
20
21
''' )
21
22
23
+ def clean_files (source , executable ):
24
+ os .remove (source )
25
+ os .remove (executable )
26
+
22
27
def call_security_check (cc , source , executable , options ):
23
28
subprocess .run ([cc ,source ,'-o' ,executable ] + options , check = True )
24
29
p = subprocess .run (['./contrib/devtools/security-check.py' ,executable ], stdout = subprocess .PIPE , universal_newlines = True )
@@ -44,6 +49,8 @@ def test_ELF(self):
44
49
self .assertEqual (call_security_check (cc , source , executable , ['-Wl,-znoexecstack' ,'-fstack-protector-all' ,'-Wl,-zrelro' ,'-Wl,-z,now' ,'-pie' ,'-fPIE' , '-Wl,-z,separate-code' ]),
45
50
(0 , '' ))
46
51
52
+ clean_files (source , executable )
53
+
47
54
def test_PE (self ):
48
55
source = 'test1.c'
49
56
executable = 'test1.exe'
@@ -61,6 +68,8 @@ def test_PE(self):
61
68
self .assertEqual (call_security_check (cc , source , executable , ['-Wl,--nxcompat' ,'-Wl,--dynamicbase' ,'-Wl,--high-entropy-va' ,'-pie' ,'-fPIE' ]),
62
69
(0 , '' ))
63
70
71
+ clean_files (source , executable )
72
+
64
73
def test_MACHO (self ):
65
74
source = 'test1.c'
66
75
executable = 'test1'
@@ -80,6 +89,8 @@ def test_MACHO(self):
80
89
self .assertEqual (call_security_check (cc , source , executable , ['-Wl,-pie' ,'-Wl,-bind_at_load' ,'-fstack-protector-all' ]),
81
90
(0 , '' ))
82
91
92
+ clean_files (source , executable )
93
+
83
94
if __name__ == '__main__' :
84
95
unittest .main ()
85
96
0 commit comments