aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-07-27 11:14:44 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2017-07-27 11:14:44 +0200
commitc8f695d0a4336016d7fb67475b0c8eebfdc7f806 (patch)
tree80f06ac8256bad73c6a7aee54eeb44e3f0272b2e
parenttest/all.bat: code style (diff)
downloadaes-tools-c8f695d0a4336016d7fb67475b0c8eebfdc7f806.tar.gz
aes-tools-c8f695d0a4336016d7fb67475b0c8eebfdc7f806.zip
test: support running scripts from other dirs
Diffstat (limited to '')
-rw-r--r--test/all.bat10
-rw-r--r--test/cavp.py14
-rw-r--r--test/file.py15
-rw-r--r--test/nist.py12
4 files changed, 36 insertions, 15 deletions
diff --git a/test/all.bat b/test/all.bat
index 7497637..d1890df 100644
--- a/test/all.bat
+++ b/test/all.bat
@@ -1,12 +1,14 @@
@setlocal enabledelayedexpansion
-@if "%~1" == "" goto exit_with_usage
+@set "script_dir=%~dp0"
+
+@if "%~1"=="" goto exit_with_usage
@set "utils_dir=%~1"
-nist.py --path "%utils_dir%" || exit /b !errorlevel!
-cavp.py --path "%utils_dir%" || exit /b !errorlevel!
-file.py --path "%utils_dir%" || exit /b !errorlevel!
+"%script_dir%nist.py" --path "%utils_dir%" || exit /b !errorlevel!
+"%script_dir%cavp.py" --path "%utils_dir%" || exit /b !errorlevel!
+"%script_dir%file.py" --path "%utils_dir%" || exit /b !errorlevel!
@goto :eof
diff --git a/test/cavp.py b/test/cavp.py
index e52f19f..83dfa36 100644
--- a/test/cavp.py
+++ b/test/cavp.py
@@ -183,11 +183,15 @@ class TestArchive(zipfile.ZipFile):
for path in self.namelist():
yield TestFile(self.extract(path, tmp_dir))
+_script_dir = os.path.dirname(__file__)
+_script_name = os.path.splitext(os.path.basename(__file__))[0]
+
def _build_default_log_path():
- return datetime.now().strftime('{}_%Y-%m-%d_%H-%M-%S.log').format(
- os.path.splitext(os.path.basename(__file__))[0])
+ timestamp = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
+ fn = '{}_{}.log'.format(_script_name, timestamp)
+ return os.path.join(_script_dir, fn)
-def run_tests(archive_path, tools_path=(), use_sde=False, use_boxes=False, log_path=None):
+def _setup_logging(log_path=None):
if log_path is None:
log_path = _build_default_log_path()
@@ -196,6 +200,8 @@ def run_tests(archive_path, tools_path=(), use_sde=False, use_boxes=False, log_p
format='%(asctime)s | %(module)s | %(levelname)s | %(message)s',
level=logging.DEBUG)
+def run_tests(archive_path, tools_path=(), use_sde=False, use_boxes=False, log_path=None):
+ _setup_logging(log_path)
tools = Tools(tools_path, use_sde=use_sde)
archive = TestArchive(archive_path)
exit_codes = []
@@ -228,7 +234,7 @@ def _parse_args(args=None):
parser.add_argument('--boxes', '-b', action='store_true', dest='use_boxes',
help='use the "boxes" interface')
parser.add_argument('--archive', '-a', dest='archive_path', metavar='PATH',
- default='KAT_AES.zip',
+ default=os.path.join(_script_dir, 'KAT_AES.zip'),
help='set test vectors archive file path')
parser.add_argument('--log', '-l', dest='log_path', metavar='PATH',
help='set log file path')
diff --git a/test/file.py b/test/file.py
index 2a7707e..c0cf910 100644
--- a/test/file.py
+++ b/test/file.py
@@ -154,11 +154,15 @@ def enum_tests(suite_dir):
ciphertext_path = _extract_ciphertext_path(key_path)
yield algorithm, mode, key, plaintext_path, ciphertext_path, iv
+_script_dir = os.path.dirname(__file__)
+_script_name = os.path.splitext(os.path.basename(__file__))[0]
+
def _build_default_log_path():
- return datetime.now().strftime('{}_%Y-%m-%d_%H-%M-%S.log').format(
- os.path.splitext(os.path.basename(__file__))[0])
+ timestamp = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
+ fn = '{}_{}.log'.format(_script_name, timestamp)
+ return os.path.join(_script_dir, fn)
-def run_tests(suite_path, tools_path=(), log_path=None, use_sde=False, force=False):
+def _setup_logging(log_path=None):
if log_path is None:
log_path = _build_default_log_path()
@@ -167,6 +171,8 @@ def run_tests(suite_path, tools_path=(), log_path=None, use_sde=False, force=Fal
format='%(asctime)s | %(module)s | %(levelname)s | %(message)s',
level=logging.DEBUG)
+def run_tests(suite_path, tools_path=(), log_path=None, use_sde=False, force=False):
+ _setup_logging(log_path)
tools = Tools(tools_path, use_sde=use_sde)
exit_codes = []
@@ -199,7 +205,8 @@ def _parse_args(args=None):
help='set log file path')
parser.add_argument('--force', '-f', action='store_true',
help='overwrite ciphertext files')
- parser.add_argument('--suite', '-s', dest='suite_path', default='file/',
+ parser.add_argument('--suite', '-s', dest='suite_path',
+ default=os.path.join(_script_dir, 'file'),
help='set test suite directory path')
return parser.parse_args(args)
diff --git a/test/nist.py b/test/nist.py
index d0fd6ce..f7a119f 100644
--- a/test/nist.py
+++ b/test/nist.py
@@ -217,11 +217,15 @@ def run_decryption_test(tools, algorithm, mode, use_boxes=False):
logging.exception(e)
return TestExitCode.ERROR
+_script_dir = os.path.dirname(__file__)
+_script_name = os.path.splitext(os.path.basename(__file__))[0]
+
def _build_default_log_path():
- return datetime.now().strftime('{}_%Y-%m-%d_%H-%M-%S.log').format(
- os.path.splitext(os.path.basename(__file__))[0])
+ timestamp = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
+ fn = '{}_{}.log'.format(_script_name, timestamp)
+ return os.path.join(_script_dir, fn)
-def run_tests(tools_path=(), use_sde=False, use_boxes=False, log_path=None):
+def _setup_logging(log_path=None):
if log_path is None:
log_path = _build_default_log_path()
@@ -230,6 +234,8 @@ def run_tests(tools_path=(), use_sde=False, use_boxes=False, log_path=None):
format='%(asctime)s | %(module)s | %(levelname)s | %(message)s',
level=logging.DEBUG)
+def run_tests(tools_path=(), use_sde=False, use_boxes=False, log_path=None):
+ _setup_logging(log_path)
tools = Tools(tools_path, use_sde=use_sde)
exit_codes = []