55'''
66Test script for security-check.py
77'''
8+ import os
89import subprocess
910import unittest
1011
@@ -19,6 +20,10 @@ def write_testcode(filename):
1920 }
2021 ''' )
2122
23+ def clean_files (source , executable ):
24+ os .remove (source )
25+ os .remove (executable )
26+
2227def call_security_check (cc , source , executable , options ):
2328 subprocess .run ([cc ,source ,'-o' ,executable ] + options , check = True )
2429 p = subprocess .run (['./contrib/devtools/security-check.py' ,executable ], stdout = subprocess .PIPE , universal_newlines = True )
@@ -44,6 +49,8 @@ def test_ELF(self):
4449 self .assertEqual (call_security_check (cc , source , executable , ['-Wl,-znoexecstack' ,'-fstack-protector-all' ,'-Wl,-zrelro' ,'-Wl,-z,now' ,'-pie' ,'-fPIE' , '-Wl,-z,separate-code' ]),
4550 (0 , '' ))
4651
52+ clean_files (source , executable )
53+
4754 def test_PE (self ):
4855 source = 'test1.c'
4956 executable = 'test1.exe'
@@ -61,6 +68,8 @@ def test_PE(self):
6168 self .assertEqual (call_security_check (cc , source , executable , ['-Wl,--nxcompat' ,'-Wl,--dynamicbase' ,'-Wl,--high-entropy-va' ,'-pie' ,'-fPIE' ]),
6269 (0 , '' ))
6370
71+ clean_files (source , executable )
72+
6473 def test_MACHO (self ):
6574 source = 'test1.c'
6675 executable = 'test1'
@@ -80,6 +89,8 @@ def test_MACHO(self):
8089 self .assertEqual (call_security_check (cc , source , executable , ['-Wl,-pie' ,'-Wl,-bind_at_load' ,'-fstack-protector-all' ]),
8190 (0 , '' ))
8291
92+ clean_files (source , executable )
93+
8394if __name__ == '__main__' :
8495 unittest .main ()
8596
0 commit comments