Make main() suitable to being called from python

Don't call sys.exit(), and don't clobber the working directory.

Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
This commit is contained in:
Bence Szépkúti 2021-11-02 13:48:39 +01:00
parent 19a124d677
commit 559f1ce0a3

View File

@ -18,7 +18,7 @@ EXPECTED_FAILURES = {
PSA_ARCH_TESTS_REPO = 'https://github.com/ronald-cron-arm/psa-arch-tests.git' PSA_ARCH_TESTS_REPO = 'https://github.com/ronald-cron-arm/psa-arch-tests.git'
PSA_ARCH_TESTS_REF = 'crypto1.0-3.0' PSA_ARCH_TESTS_REF = 'crypto1.0-3.0'
#pylint: disable=too-many-statements #pylint: disable=too-many-branches,too-many-statements
def main(): def main():
mbedtls_dir = os.getcwd() mbedtls_dir = os.getcwd()
@ -30,6 +30,7 @@ def main():
os.mkdir(psa_arch_tests_dir) os.mkdir(psa_arch_tests_dir)
except FileExistsError: except FileExistsError:
pass pass
try:
os.chdir(psa_arch_tests_dir) os.chdir(psa_arch_tests_dir)
subprocess.check_call(['git', 'init']) subprocess.check_call(['git', 'init'])
@ -46,7 +47,8 @@ def main():
#pylint: disable=bad-continuation #pylint: disable=bad-continuation
subprocess.check_call([ subprocess.check_call([
'cmake', '..', '-GUnix Makefiles', 'cmake', '..',
'-GUnix Makefiles',
'-DTARGET=tgt_dev_apis_stdc', '-DTARGET=tgt_dev_apis_stdc',
'-DTOOLCHAIN=HOST_GCC', '-DTOOLCHAIN=HOST_GCC',
'-DSUITE=CRYPTO', '-DSUITE=CRYPTO',
@ -100,11 +102,13 @@ def main():
'EXPECTED_FAILURES in tests/scripts/compliance_test.py') 'EXPECTED_FAILURES in tests/scripts/compliance_test.py')
print() print()
print('FAILED') print('FAILED')
sys.exit(1) return 1
else: else:
os.chdir(mbedtls_dir)
shutil.rmtree(psa_arch_tests_dir) shutil.rmtree(psa_arch_tests_dir)
print('SUCCESS') print('SUCCESS')
return 0
finally:
os.chdir(mbedtls_dir)
if __name__ == '__main__': if __name__ == '__main__':
main() sys.exit(main())