diff --git a/src/test/README b/src/test/README index 556582a94e4d94326c04fa562bd25cf2ff8a1b2b..50e6dfec6c0e471fbae326c5bac37d2fe495c1a8 100644 --- a/src/test/README +++ b/src/test/README @@ -189,13 +189,14 @@ test run, it can use this line: Using the unittest library, the C programs run during unit testing get their output and tracing information logged to various files. These are named with -the test number embedded in them, so a script called TEST0 would commonly +the test number embedded in them and stored inside folders for each build type, +so a script called TEST0 run with (check/none/debug) build type would commonly produce: - err0.log log of stderr - out0.log log of stdout - trace0.log trace points from unittest library - pmem0.log trace from libpmem (PMEM_LOG_FILE points here) + logs/check/none/debug/err0.log log of stderr + logs/check/none/debug/out0.log log of stdout + logs/check/none/debug/trace0.log trace points from unittest library + logs/check/none/debug/pmem0.log trace from libpmem (PMEM_LOG_FILE points here) Although the above log files are the common case, the TEST* scripts are free to create any files. It is recommended, however, that the script creates files diff --git a/src/test/unittest/basetest.py b/src/test/unittest/basetest.py index c32c36908529138b756ab413fd52da25e0f127f6..5cd3b279001a8aaee0b96ac85a778a69938eb09c 100644 --- a/src/test/unittest/basetest.py +++ b/src/test/unittest/basetest.py @@ -14,6 +14,7 @@ from os import path from configurator import Configurator import futils import test_types +import shutil if not hasattr(builtins, 'testcases'): @@ -100,7 +101,7 @@ class BaseTest(metaclass=_TestCase): self.elapsed = (datetime.now() - start_time).total_seconds() self.ctx.check() - self.check() + self.check(c) except futils.Fail: self._on_fail() @@ -133,7 +134,7 @@ class BaseTest(metaclass=_TestCase): raise NotImplementedError('{} does not implement run() method'.format( self.__class__)) - def check(self): + def check(self, ctx): """Run additional test checks - not implemented by BaseTest""" pass @@ -191,6 +192,18 @@ class Test(BaseTest): with open(file) as f: self.ctx.dump_n_lines(f) + def _move_log_files(self, ctx): + """ + Move all log files for given tests + """ + path = "logs" + sub_dir = str(ctx).replace(':', '') + logs_dir = os.path.join(path, sub_dir) + os.makedirs(logs_dir, exist_ok=True) + log_files = self.get_log_files() + for file in log_files: + shutil.copy2(file, logs_dir) + def remove_log_files(self): """ Removes log files for given test @@ -210,10 +223,11 @@ class Test(BaseTest): def _on_fail(self): self._print_log_files() - def check(self): + def check(self, ctx): """Run additional test checks""" if self.match: self._run_match() + self._move_log_files(ctx) def _run_match(self): """Match log files""" diff --git a/src/test/unittest/unittest.ps1 b/src/test/unittest/unittest.ps1 index 043f3d410a05d084539625ba1058c77ff31b2fb7..0e5010a115cc339ac0e7a4522bff8b3322cbea8d 100644 --- a/src/test/unittest/unittest.ps1 +++ b/src/test/unittest/unittest.ps1 @@ -640,6 +640,16 @@ function check { if ($listing) { match $listing } + + # Move logs to build folder + $LOGS_DIR="logs\$Env:TYPE\$Global:REAL_FS\$Env:BUILD" + If(!(test-path $LOGS_DIR)) + { + [void](New-Item -path $LOGS_DIR -ItemType Directory) + } + foreach ($f in $(get_files "[a-zA-Z_]*${Env:UNITTEST_NUM}\.log$")) { + Move-Item $f $LOGS_DIR\$f -force + } } # diff --git a/src/test/unittest/unittest.sh b/src/test/unittest/unittest.sh index 5c39a5d0bf1d90991e1dcfb6fe93fdaf4044d709..30f95228fb6f5b99fbf3a251599851bffe91a23b 100644 --- a/src/test/unittest/unittest.sh +++ b/src/test/unittest/unittest.sh @@ -2831,6 +2831,12 @@ function check() { match $option $FILES fi fi + # Move logs to build folder + LOG_DIR=logs/$TEST/$REAL_FS/$BUILD$MCSTR$PROV$PM + if [ ! -d $LOG_DIR ]; then mkdir --parents $LOG_DIR; fi + for f in $(get_files ".*[a-zA-Z_]${UNITTEST_NUM}\.log"); do + mv -f $f $LOG_DIR/$f + done } #