Skip to content

Commit

Permalink
enabling flexible build dir name in testing (#1080)
Browse files Browse the repository at this point in the history
  • Loading branch information
baentsch authored Aug 28, 2021
1 parent 8a5c298 commit 3bc89ee
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ add_definitions(-DOQS_COMPILE_OPTIONS="[${OQS_COMPILE_OPTIONS}]")
# for DLL builds.
add_custom_target(
run_tests
COMMAND ${PYTHON3_EXEC} -m pytest --verbose --numprocesses=auto
COMMAND ${CMAKE_COMMAND} -E env OQS_BUILD_DIR=${CMAKE_BINARY_DIR} ${PYTHON3_EXEC} -m pytest --verbose --numprocesses=auto
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS oqs example_kem kat_kem test_kem example_sig kat_sig test_sig test_sig_mem test_kem_mem ${UNIX_TESTS}
USES_TERMINAL)
21 changes: 16 additions & 5 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def is_kem_enabled_by_name(name):
symbol = kem_symbol
break
if symbol == None: return False
header = os.path.join('build', 'include', 'oqs', 'oqsconfig.h')
header = os.path.join(get_current_build_dir_name(), 'include', 'oqs', 'oqsconfig.h')
with open(header) as fh:
for line in fh:
if line.startswith("#define OQS_ENABLE_KEM_"):
Expand Down Expand Up @@ -97,7 +97,7 @@ def is_sig_enabled_by_name(name):
symbol = sig_symbol
break
if symbol == None: return False
header = os.path.join('build', 'include', 'oqs', 'oqsconfig.h')
header = os.path.join(get_current_build_dir_name(), 'include', 'oqs', 'oqsconfig.h')
with open(header) as fh:
for line in fh:
if line.startswith("#define OQS_ENABLE_SIG_"):
Expand All @@ -118,12 +118,23 @@ def wrapper(*args, **kwargs):
return func(*args, **kwargs)
return wrapper

# So far, build dir name has been hard coded to "build".
# This function makes it dependent on the availability of the environment variable OQS_BUILD_DIR:
# OQS_BUILD_DIR must be below current working dir; if not, behave as before
# If OQS_BUILD_DIR is not set, behave as before, returning hard-coded build name
def get_current_build_dir_name():
if 'OQS_BUILD_DIR' in os.environ:
# assure this is within current dir:
if os.environ['OQS_BUILD_DIR'].startswith(os.getcwd()):
return os.environ['OQS_BUILD_DIR'][len(os.getcwd())+1:]
return 'build'

def path_to_executable(program_name):
path = "."
if sys.platform.startswith("win"):
if 'APPVEYOR_BUILD_FOLDER' not in os.environ: os.environ['APPVEYOR_BUILD_FOLDER'] = "."
path = os.path.join(path, os.environ['APPVEYOR_BUILD_FOLDER'])
path = os.path.join(path, "build", "tests")
path = os.path.join(path, get_current_build_dir_name(), "tests")
for executable in [
os.path.join(path, program_name),
os.path.join(path, program_name + ".EXE"),
Expand All @@ -134,7 +145,7 @@ def path_to_executable(program_name):

def available_use_options_by_name():
enabled_use_options = []
with open(os.path.join('build', 'include', 'oqs', 'oqsconfig.h')) as fh:
with open(os.path.join(get_current_build_dir_name(), 'include', 'oqs', 'oqsconfig.h')) as fh:
for line in fh:
if line.startswith("#define OQS_USE_"):
option_name = line.split(' ')[1][len("OQS_USE_"):].strip('\n')
Expand Down Expand Up @@ -167,7 +178,7 @@ def test_requires_valgrind_version_at_least(x,y,z):
@functools.lru_cache()
def test_requires_build_options(*options):
enabled = {opt : False for opt in options}
with open(os.path.join('build', 'include', 'oqs', 'oqsconfig.h')) as fh:
with open(os.path.join(get_current_build_dir_name(), 'include', 'oqs', 'oqsconfig.h')) as fh:
for line in fh:
opt = line.split(' ')[1] if line.startswith('#define ') else None
if opt in options:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_mem_kem(kem_name):
if not(helpers.is_kem_enabled_by_name(kem_name)):
pytest.skip('Not enabled')

Path('build/mem-benchmark').mkdir(parents=True, exist_ok=True)
Path(helpers.get_current_build_dir_name()+'/mem-benchmark').mkdir(parents=True, exist_ok=True)

for i in range(3):
helpers.run_subprocess([helpers.path_to_executable('test_kem_mem'), kem_name, str(i)])
Expand All @@ -21,7 +21,7 @@ def test_mem_sig(sig_name):
if not(helpers.is_sig_enabled_by_name(sig_name)):
pytest.skip('Not enabled')

Path('build/mem-benchmark').mkdir(parents=True, exist_ok=True)
Path(helpers.get_current_build_dir_name()+'/mem-benchmark').mkdir(parents=True, exist_ok=True)

for i in range(3):
helpers.run_subprocess([helpers.path_to_executable('test_sig_mem'), sig_name, str(i)])
Expand Down
6 changes: 3 additions & 3 deletions tests/test_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
@helpers.filtered_test
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not needed on Windows")
def test_namespace():
liboqs = glob.glob('build/lib/liboqs.*')[0]
if liboqs == 'build/lib/liboqs.dylib':
liboqs = glob.glob(helpers.get_current_build_dir_name()+'/lib/liboqs.*')[0]
if liboqs == helpers.get_current_build_dir_name()+'/lib/liboqs.dylib':
out = helpers.run_subprocess(
['nm', '-g', liboqs]
)
elif liboqs == 'build/lib/liboqs.so':
elif liboqs == helpers.get_current_build_dir_name()+'/lib/liboqs.so':
out = helpers.run_subprocess(
['nm', '-D', liboqs]
)
Expand Down

0 comments on commit 3bc89ee

Please sign in to comment.