mirror of
https://github.com/open-quantum-safe/liboqs.git
synced 2025-10-08 00:03:38 -04:00
Switch free check to Python test suite
This commit is contained in:
parent
3ab9044f51
commit
da44cbca68
@ -1,37 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
###
|
||||
# Checks that "free" is not used unprotected in the main OQS code.
|
||||
###
|
||||
|
||||
set -e
|
||||
|
||||
source $(dirname $0)/defs.sh
|
||||
|
||||
RET=0
|
||||
|
||||
# We need to temporarily remove bash fail-on-error for the last command, because grep returns with error code 1 when there are no lines found
|
||||
set +e
|
||||
FREE=$(find src -name '*.c' | grep -v upstream | grep -v 'picnic/external' | xargs grep '[^_]free' | grep "free(" | grep -v 'IGNORE free-check')
|
||||
ERROR_CODE=$?
|
||||
set -e
|
||||
|
||||
if [ ${ERROR_CODE} -ne 1 ];
|
||||
then
|
||||
${PRINT_RED}
|
||||
echo "'free' is used in the following non-upstream files. These should be changed to 'OQS_MEM_secure_free' or 'OQS_MEM_insecure_free' as appropriate.";
|
||||
${PRINT_RESET}
|
||||
echo -n ${FREE} | tr ';' '\n' | sed -e 's/^ //'
|
||||
${PRINT_RED}
|
||||
echo "If you are sure you want to use 'free' in a particular spot, add the comment"
|
||||
echo " // IGNORE free-check"
|
||||
echo "on the line where 'free' occurs."
|
||||
${PRINT_RESET}
|
||||
RET=1
|
||||
else
|
||||
${PRINT_GREEN}
|
||||
echo "No uses of 'free' detected in non-upstream files.";
|
||||
${PRINT_RESET}
|
||||
fi;
|
||||
|
||||
exit ${RET}
|
@ -48,8 +48,9 @@ def run_subprocess(command, working_dir='.', env=None, expected_returncode=0, in
|
||||
cwd=working_dir,
|
||||
env=env,
|
||||
)
|
||||
print(stdout.decode('utf-8'))
|
||||
assert retcode == expected_returncode, "Got unexpected return code {}".format(retcode)
|
||||
if retcode != expected_returncode:
|
||||
print(stdout.decode('utf-8'))
|
||||
assert False, "Got unexpected return code {}".format(retcode)
|
||||
return stdout.decode('utf-8')
|
||||
|
||||
def available_kems_by_name():
|
||||
|
28
tests/test_lint.py
Normal file
28
tests/test_lint.py
Normal file
@ -0,0 +1,28 @@
|
||||
import helpers
|
||||
import os
|
||||
import os.path
|
||||
import pytest
|
||||
import sys
|
||||
|
||||
###
|
||||
# Checks that "free" is not used unprotected in the main OQS code.
|
||||
###
|
||||
@helpers.filtered_test
|
||||
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not needed on Windows")
|
||||
def test_free():
|
||||
files = helpers.run_subprocess(['find', 'src', '-name', '*.c'])
|
||||
files = helpers.run_subprocess(['grep', '-v', 'picnic/external'], input=files.encode('utf8'))
|
||||
lines = helpers.run_subprocess(['xargs', 'grep', '[^_]free('], input=files.encode('utf8'))
|
||||
lines = lines.split("\n")
|
||||
okay = True
|
||||
for line in lines:
|
||||
if line == "": continue
|
||||
if not('IGNORE free-check' in line):
|
||||
okay = False
|
||||
print("Suspicious `free` in " + line)
|
||||
assert okay, "'free' is used in some files. These should be changed to 'OQS_MEM_secure_free' or 'OQS_MEM_insecure_free' as appropriate. If you are sure you want to use 'free' in a particular spot, add the comment '// IGNORE free-check' on the line where 'free' occurs."
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
pytest.main(sys.argv)
|
||||
|
Loading…
x
Reference in New Issue
Block a user