aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenĂ© Meusel <[email protected]>2020-03-10 10:33:50 +0100
committerRenĂ© Meusel <[email protected]>2020-03-10 15:39:24 +0100
commit50e528820d19f4aab54223721de86dfcb5e168ec (patch)
tree993264ba300f806a5f15ef3d5e5ffccbbeb308cc
parentde054beac62d5e49fb0cdf6284b6f935df5e1a90 (diff)
add `make check`
-rw-r--r--src/build-data/makefile.in10
-rw-r--r--src/scripts/check.py74
2 files changed, 83 insertions, 1 deletions
diff --git a/src/build-data/makefile.in b/src/build-data/makefile.in
index 4766d4754..5b3a3a148 100644
--- a/src/build-data/makefile.in
+++ b/src/build-data/makefile.in
@@ -44,7 +44,7 @@ docs: %{doc_stamp_file}
# Misc targets
%{if make_supports_phony}
-.PHONY: all cli libs tests docs clean distclean install
+.PHONY: all cli libs tests check docs clean distclean install
%{endif}
%{doc_stamp_file}: %{doc_dir}/*.rst %{doc_dir}/api_ref/*.rst %{doc_dir}/dev_ref/*.rst
@@ -59,6 +59,14 @@ distclean:
install: %{install_targets}
$(PYTHON_EXE) $(SCRIPTS_DIR)/install.py --prefix="%{prefix}" --build-dir="%{build_dir}" --bindir=%{bindir} --libdir=%{libdir} --docdir=%{docdir} --includedir=%{includedir}
+check: tests
+%{if build_shared_lib}
+ $(PYTHON_EXE) $(SCRIPTS_DIR)/check.py --test-exe="%{test_exe}" --shared-lib="%{shared_lib_name}"
+%{endif}
+%{unless build_shared_lib}
+ $(PYTHON_EXE) $(SCRIPTS_DIR)/check.py --test-exe="%{test_exe}"
+%{endif}
+
# Object Files
LIBOBJS = %{join lib_objs}
diff --git a/src/scripts/check.py b/src/scripts/check.py
new file mode 100644
index 000000000..801688b5f
--- /dev/null
+++ b/src/scripts/check.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+
+"""
+Implements the "make check" target
+
+(C) 2020 Jack Lloyd, Rene Meusel
+
+Botan is released under the Simplified BSD License (see license.txt)
+"""
+
+import os
+import sys
+import optparse
+import subprocess
+import logging
+import platform
+
+def is_macos():
+ return platform.system() == "Darwin"
+
+def run_and_check(cmd_line, env=None, cwd=None):
+
+ logging.info("Starting %s", ' '.join(cmd_line))
+
+ try:
+ proc = subprocess.Popen(cmd_line, cwd=cwd, env=env)
+ proc.communicate()
+ except OSError as e:
+ logging.error("Executing %s failed (%s)", ' '.join(cmd_line), e)
+
+ if proc.returncode != 0:
+ logging.error("Error running %s", ' '.join(cmd_line))
+ sys.exit(1)
+
+
+def parse_options(args):
+ parser = optparse.OptionParser()
+ parser.add_option('--test-exe', default='botan-test', metavar='BINARY',
+ help='specify the botan-test binary name (default %default)')
+ parser.add_option('--shared-lib', default=None, metavar='SHARED_LIB',
+ help='use shared library of botan (default %default)')
+
+ (options, args) = parser.parse_args(args)
+
+ if len(args) > 1:
+ raise Exception("Unknown arguments")
+
+ return options
+
+
+def main(args=None):
+ if args is None:
+ args = sys.argv
+
+ options = parse_options(args)
+ test_exe = options.test_exe
+ shared_lib = options.shared_lib
+
+ if not os.path.isfile(test_exe) or not os.access(test_exe, os.X_OK):
+ raise Exception("Test binary not built")
+
+ if shared_lib and not os.path.isfile(shared_lib):
+ raise Exception("Shared library %s not found" % shared_lib)
+
+ env = os.environ.copy()
+ if shared_lib and is_macos():
+ env["DYLD_LIBRARY_PATH"] = "."
+
+ run_and_check([ test_exe ], env)
+
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main())