Changeset View
Changeset View
Standalone View
Standalone View
contrib/devtools/test-security-check.py
#!/usr/bin/env python2 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2016 The Bitcoin Core developers | # Copyright (c) 2015-2017 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
''' | ''' | ||||
Test script for security-check.py | Test script for security-check.py | ||||
''' | ''' | ||||
from __future__ import division, print_function | |||||
import subprocess | import subprocess | ||||
import unittest | import unittest | ||||
def write_testcode(filename): | def write_testcode(filename): | ||||
with open(filename, 'w', encoding="utf8") as f: | with open(filename, 'w', encoding="utf8") as f: | ||||
f.write(''' | f.write(''' | ||||
#include <stdio.h> | #include <stdio.h> | ||||
int main() | int main() | ||||
{ | { | ||||
printf("the quick brown fox jumps over the lazy god\\n"); | printf("the quick brown fox jumps over the lazy god\\n"); | ||||
return 0; | return 0; | ||||
} | } | ||||
''') | ''') | ||||
def call_security_check(cc, source, executable, options): | def call_security_check(cc, source, executable, options): | ||||
subprocess.check_call([cc, source, '-o', executable] + options) | subprocess.check_call([cc, source, '-o', executable] + options) | ||||
p = subprocess.Popen(['./security-check.py', executable], | p = subprocess.Popen(['./security-check.py', executable], stdout=subprocess.PIPE, | ||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) | stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True) | ||||
(stdout, stderr) = p.communicate() | (stdout, stderr) = p.communicate() | ||||
return (p.returncode, stdout.rstrip()) | return (p.returncode, stdout.rstrip()) | ||||
class TestSecurityChecks(unittest.TestCase): | class TestSecurityChecks(unittest.TestCase): | ||||
def test_ELF(self): | def test_ELF(self): | ||||
source = 'test1.c' | source = 'test1.c' | ||||
executable = 'test1' | executable = 'test1' | ||||
Show All 30 Lines |