diff --git a/tests/unit/framework/run_unit_tests.py b/tests/unit/framework/run_unit_tests.py index d72269c..a0a477f 100755 --- a/tests/unit/framework/run_unit_tests.py +++ b/tests/unit/framework/run_unit_tests.py @@ -19,10 +19,46 @@ def run_command(args): return result +def rmv_cmd(trgt): + """Remove target with force""" + result = run_command(["rm", "-rf", trgt]) + if result.returncode != 0: + raise Exception("Removing {} before testing failed!". + format(os.path.dirname(os.path.realpath(__file__)) + + trgt)) + + +def cleanup(): + """Delete files created by unit tests""" + script_path = os.path.dirname(os.path.realpath(__file__)) + test_dir = os.path.join(script_path, tests_config.MAIN_DIRECTORY_OF_UNIT_TESTS) + result = run_command(["cd", test_dir]) + if result.returncode != 0: + raise Exception("Cleanup before testing failed!") + + # r=root, d=directories, f = files + for r, d, f in os.walk(test_dir): + for file in f: + if '_generated_wrap' in file: + rmv_cmd(file) + + rmv_cmd("preprocessed_sources_repository") + rmv_cmd("sources_to_test_repository") + rmv_cmd("build") + + result = run_command(["cd", script_path]) + if result.returncode != 0: + raise Exception("Cleanup before testing failed!") + + +cleanup() + script_path = os.path.dirname(os.path.realpath(__file__)) main_UT_dir = os.path.join(script_path, tests_config.MAIN_DIRECTORY_OF_UNIT_TESTS) +main_env_dir = os.path.join(script_path, tests_config.MAIN_DIRECTORY_OF_ENV_FILES) + main_tested_dir = os.path.join(script_path, tests_config.MAIN_DIRECTORY_OF_TESTED_PROJECT) if not os.path.isdir(os.path.join(main_UT_dir, "ocf_env", "ocf")): @@ -31,6 +67,12 @@ if not os.path.isdir(os.path.join(main_UT_dir, "ocf_env", "ocf")): except Exception: raise Exception("Cannot create ocf_env/ocf directory!") +result = run_command(["ln", "-fs", + os.path.join(main_env_dir, "*"), + os.path.join(main_UT_dir, "ocf_env")]) +if result.returncode != 0: + raise Exception("Preparing env sources for testing failed!") + result = run_command(["cp", "-r", os.path.join(main_tested_dir, "inc", "*"), os.path.join(main_UT_dir, "ocf_env", "ocf")]) diff --git a/tests/unit/framework/tests_config.py b/tests/unit/framework/tests_config.py index 654b3cb..52c0028 100644 --- a/tests/unit/framework/tests_config.py +++ b/tests/unit/framework/tests_config.py @@ -9,6 +9,8 @@ MAIN_DIRECTORY_OF_TESTED_PROJECT = "../../../" +MAIN_DIRECTORY_OF_ENV_FILES = MAIN_DIRECTORY_OF_TESTED_PROJECT + "env/posix/" + MAIN_DIRECTORY_OF_UNIT_TESTS = "../tests/" # Paths to all directories, in which tests are stored. All paths should be relative to