Refactor tests directory
Signed-off-by: Kamil Łepek <kamil.lepek94@gmail.com>
This commit is contained in:
parent
539029375d
commit
92b2fa362e
@ -46,12 +46,9 @@ class TestGenerator(object):
|
||||
buf += self.get_UT_includes()
|
||||
buf += self.get_includes(self.get_main_tested_dir() + self.get_tested_file_path())
|
||||
buf += self.get_empty_test_function()
|
||||
buf += self.get_test_main(self.get_tested_file_path())
|
||||
buf += self.get_test_main()
|
||||
|
||||
with open(dst_path, "w") as f:
|
||||
code = f.writelines(buf)
|
||||
|
||||
print dst_path + " generated succesfully!"
|
||||
print dst_path + " generated successfully!"
|
||||
|
||||
def get_markups(self):
|
||||
ret = "/*\n"
|
||||
@ -86,9 +83,6 @@ class TestGenerator(object):
|
||||
return textwrap.dedent(ret)
|
||||
|
||||
def get_includes(self, abs_path_to_tested_file):
|
||||
ret = []
|
||||
code = []
|
||||
|
||||
with open(abs_path_to_tested_file, "r") as f:
|
||||
code = f.readlines()
|
||||
|
||||
@ -105,7 +99,7 @@ class TestGenerator(object):
|
||||
|
||||
return ret
|
||||
|
||||
def get_test_main(self, rel_path):
|
||||
def get_test_main(self):
|
||||
ret = "int main(void)\n"
|
||||
ret += "{\n"
|
||||
ret += "\tconst struct CMUnitTest tests[] = {\n"
|
@ -15,7 +15,7 @@ from collections import defaultdict
|
||||
import tests_config
|
||||
#
|
||||
# This script purpose is to remove unused functions definitions
|
||||
# It is giving the oportunity to unit test all functions from OCF.
|
||||
# It is giving the opportunity to unit test all functions from OCF.
|
||||
# As a parameter should be given path to file containing function,
|
||||
# which is target of testing. However that file has to be after
|
||||
# preprocessing.
|
||||
@ -24,7 +24,7 @@ import tests_config
|
||||
# has to be given definitions of functions, which are used by
|
||||
# tested function.
|
||||
#
|
||||
# In brief: this script allow wraping all function calls in UT
|
||||
# In brief: this script allow wrapping all function calls in UT
|
||||
#
|
||||
|
||||
class UnitTestsSourcesGenerator(object):
|
||||
@ -58,8 +58,8 @@ class UnitTestsSourcesGenerator(object):
|
||||
|
||||
self.set_ctags_path()
|
||||
|
||||
self.set_main_UT_dir(tests_config.MAIN_DIRECTORY_OF_UNIT_TESTS)
|
||||
self.set_main_tested_dir(tests_config.MAIN_DIRECTORY_OF_TESTED_PROJECT)
|
||||
self.set_main_UT_dir()
|
||||
self.set_main_tested_dir()
|
||||
|
||||
self.test_catalouges_list = tests_config.DIRECTORIES_WITH_TESTS_LIST
|
||||
self.set_includes_to_copy_dict(tests_config.INCLUDES_TO_COPY_DICT)
|
||||
@ -179,14 +179,11 @@ class UnitTestsSourcesGenerator(object):
|
||||
test_files_paths = self.get_files_with_tests_list()
|
||||
|
||||
for test_path in test_files_paths:
|
||||
tested_file_relative_path = self.get_tested_file_path(self.get_main_UT_dir() + test_path)
|
||||
|
||||
tested_file_path = self.get_sources_to_test_repo() + test_path
|
||||
if not os.path.isfile(tested_file_path):
|
||||
print "No source to test for " + test_path + " test"
|
||||
continue
|
||||
|
||||
test_file_dir = os.path.dirname(test_path)
|
||||
test_file_path = self.get_main_UT_dir() + test_path
|
||||
|
||||
cmake_buf = self.generate_test_cmake_buf(test_file_path, tested_file_path)
|
||||
@ -248,8 +245,6 @@ class UnitTestsSourcesGenerator(object):
|
||||
return functions_list
|
||||
|
||||
def get_functions_to_leave(self, path):
|
||||
buf = ""
|
||||
|
||||
with open(path) as f:
|
||||
l = f.readlines()
|
||||
buf = ''.join(l)
|
||||
@ -315,15 +310,15 @@ class UnitTestsSourcesGenerator(object):
|
||||
self.tested_files_paths_list = self.remove_duplicates_from_list(self.tested_files_paths_list)
|
||||
|
||||
def get_tested_files_paths_list(self):
|
||||
return self.tested_files_paths_list
|
||||
return self.tested_files_paths_list
|
||||
|
||||
def get_files_with_tests_list(self):
|
||||
return self.test_files_paths_list
|
||||
|
||||
def set_files_with_tests_list(self):
|
||||
test_catalouges_list = self.get_tests_catalouges_list()
|
||||
for catalouge in test_catalouges_list:
|
||||
dir_with_tests_path = self.get_main_UT_dir() + catalouge
|
||||
test_catalogues_list = self.get_tests_catalouges_list()
|
||||
for catalogue in test_catalogues_list:
|
||||
dir_with_tests_path = self.get_main_UT_dir() + catalogue
|
||||
|
||||
for path, dirs, files in os.walk(dir_with_tests_path):
|
||||
test_files = self.get_test_files_from_dir(path + os.sep)
|
||||
@ -336,14 +331,14 @@ class UnitTestsSourcesGenerator(object):
|
||||
file_path = self.get_tested_file_path(path)
|
||||
function_name = self.get_tested_function_name(path)
|
||||
|
||||
if file_path == None:
|
||||
if file_path is None:
|
||||
print path + " file has no tested_file tag!"
|
||||
return None
|
||||
elif not os.path.isfile(self.get_main_tested_dir() + file_path):
|
||||
print "Tested file given in " + path + " not exist!"
|
||||
return None
|
||||
|
||||
if function_name == None:
|
||||
if function_name is None:
|
||||
print path + " file has no tested_function_name tag!"
|
||||
return None
|
||||
|
||||
@ -359,7 +354,6 @@ class UnitTestsSourcesGenerator(object):
|
||||
return None
|
||||
|
||||
def get_tested_file_path(self, test_file_path):
|
||||
buf = ""
|
||||
with open(test_file_path) as f:
|
||||
buf = f.readlines()
|
||||
buf = ''.join(buf)
|
||||
@ -381,7 +375,6 @@ class UnitTestsSourcesGenerator(object):
|
||||
return None
|
||||
|
||||
def get_tested_function_name(self, test_file_path):
|
||||
buf = ""
|
||||
with open(test_file_path) as f:
|
||||
buf = f.readlines()
|
||||
buf = ''.join(buf)
|
||||
@ -421,7 +414,6 @@ class UnitTestsSourcesGenerator(object):
|
||||
return ret
|
||||
|
||||
def remove_hashes(self, path):
|
||||
buf = []
|
||||
with open(path) as f:
|
||||
buf = f.readlines()
|
||||
|
||||
@ -445,7 +437,7 @@ class UnitTestsSourcesGenerator(object):
|
||||
brackets_counter = 0
|
||||
current_line_index = first_line_of_function_index
|
||||
|
||||
while(True):
|
||||
while True:
|
||||
if "{" in code_lines_list[current_line_index]:
|
||||
brackets_counter += code_lines_list[current_line_index].count("{")
|
||||
brackets_counter -= code_lines_list[current_line_index].count("}")
|
||||
@ -453,7 +445,7 @@ class UnitTestsSourcesGenerator(object):
|
||||
else:
|
||||
current_line_index += 1
|
||||
|
||||
while(brackets_counter > 0):
|
||||
while brackets_counter > 0:
|
||||
current_line_index += 1
|
||||
if "{" in code_lines_list[current_line_index]:
|
||||
brackets_counter += code_lines_list[current_line_index].count("{")
|
||||
@ -480,7 +472,6 @@ class UnitTestsSourcesGenerator(object):
|
||||
del code_lines_list[line_id + 1: last_line_id + 1]
|
||||
|
||||
def set_ctags_path(self):
|
||||
path = ""
|
||||
status, output = commands.getstatusoutput("/usr/bin/ctags --version &> /dev/null")
|
||||
if status == 0:
|
||||
path = "/usr/bin/ctags "
|
||||
@ -546,7 +537,7 @@ class UnitTestsSourcesGenerator(object):
|
||||
def get_main_tested_dir(self):
|
||||
return os.path.normpath(self.main_tested_dir) + os.sep
|
||||
|
||||
def remove_duplicates_from_list(self, l):
|
||||
def remove_duplicates_from_list(self, l):
|
||||
return list(set(l))
|
||||
|
||||
def set_framework_includes(self):
|
||||
@ -561,7 +552,7 @@ class UnitTestsSourcesGenerator(object):
|
||||
def get_includes_to_copy_dict(self):
|
||||
return self.includes_to_copy_dict
|
||||
|
||||
def set_main_UT_dir(self, path):
|
||||
def set_main_UT_dir(self):
|
||||
main_UT_dir = os.path.normpath(os.path.normpath(self.get_script_dir_path()\
|
||||
+ os.sep + tests_config.MAIN_DIRECTORY_OF_UNIT_TESTS))
|
||||
if not os.path.isdir(main_UT_dir):
|
||||
@ -570,7 +561,7 @@ class UnitTestsSourcesGenerator(object):
|
||||
|
||||
self.main_UT_dir = main_UT_dir
|
||||
|
||||
def set_main_tested_dir(self, path):
|
||||
def set_main_tested_dir(self):
|
||||
main_tested_dir = os.path.normpath(os.path.normpath(self.get_script_dir_path()\
|
||||
+ os.sep + tests_config.MAIN_DIRECTORY_OF_TESTED_PROJECT))
|
||||
if not os.path.isdir(main_tested_dir):
|
@ -29,8 +29,8 @@ status, output = commands.getstatusoutput("cp " + main_tested_dir +\
|
||||
|
||||
|
||||
if os.system(script_path + os.sep + "prepare_sources_for_testing.py") != 0:
|
||||
print "Preparing sources for testing failed!"
|
||||
exit()
|
||||
print "Preparing sources for testing failed!"
|
||||
exit()
|
||||
|
||||
|
||||
build_dir = main_UT_dir + "build" + os.sep
|
@ -5,35 +5,31 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
#
|
||||
|
||||
# ALL PATHS SHOULD BE ENDEND WITH "/" CHARACTER
|
||||
# ALL PATHS SHOULD BE ENDED WITH "/" CHARACTER
|
||||
|
||||
# Path should be absolute
|
||||
MAIN_DIRECTORY_OF_TESTED_PROJECT = "../../"
|
||||
#MAIN_DIRECTORY_OF_TESTED_PROJECT = "/root/OCFF_Linux/source/casadm/kcas/ocf/"
|
||||
MAIN_DIRECTORY_OF_TESTED_PROJECT = "../../../"
|
||||
|
||||
# Path should be absolute
|
||||
MAIN_DIRECTORY_OF_UNIT_TESTS = "../ut/"
|
||||
#MAIN_DIRECTORY_OF_UNIT_TESTS = "/root/OCFF_Linux/source/casadm/kcas/ocf/UT/"
|
||||
MAIN_DIRECTORY_OF_UNIT_TESTS = "../tests/"
|
||||
|
||||
# Paths to all direcotries, in which are stored tests. All pathts should be relative to MAIN_DIRECTORY_OF_UNIT_TESTS
|
||||
# Paths to all directories, in which tests are stored. All paths should be relative to MAIN_DIRECTORY_OF_UNIT_TESTS
|
||||
DIRECTORIES_WITH_TESTS_LIST = ["cleaning/", "metadata/", "mngt/", "concurrency/", "engine/", "eviction/", "utils/"]
|
||||
|
||||
# Paths to all directoris containing files with sources. All paths should be relative to MAIN_DIRECTORY_OF_TESTED_PROJECT
|
||||
# Paths to all directories containing files with sources. All paths should be relative to MAIN_DIRECTORY_OF_TESTED_PROJECT
|
||||
DIRECTORIES_TO_INCLUDE_FROM_PROJECT_LIST = ["src/", "src/cleaning/", "src/engine/", "src/metadata/", "src/eviction/", "src/mngt/", "src/concurrency/", "src/utils/", "inc/"]
|
||||
|
||||
# Paths to all directories from UT dir, which should also be included
|
||||
# Paths to all directories from directory with tests, which should also be included
|
||||
DIRECTORIES_TO_INCLUDE_FROM_UT_LIST = ["ocf_env/"]
|
||||
|
||||
# Paths to include, required by cmake, cmocka, cunit
|
||||
FRAMEWORK_DIRECTORIES_TO_INCLUDE_LIST = ["${CMOCKA_PUBLIC_INCLUDE_DIRS}" ,"${CMAKE_BINARY_DIR}", "${CMAKE_CURRENT_SOURCE_DIR}"]
|
||||
|
||||
# Path to direcory containing all sources after preprocessing. Should be relative to MAIN_DIRECTORY_OF_UNIT_TESTS
|
||||
# Path to directory containing all sources after preprocessing. Should be relative to MAIN_DIRECTORY_OF_UNIT_TESTS
|
||||
PREPROCESSED_SOURCES_REPOSITORY = "preprocessed_sources_repository/"
|
||||
|
||||
# Path to directory containing all sources after removing unneeded functions and cmake files for tests
|
||||
SOURCES_TO_TEST_REPOSITORY = "sources_to_test_repository/"
|
||||
|
||||
# List of includes. Directories will be recursivley copied to given destinations in directory with tests.
|
||||
# List of includes. Directories will be recursively copied to given destinations in directory with tests.
|
||||
# key - destination in dir with tests
|
||||
# value - path in tested project to dir which should be copied
|
||||
INCLUDES_TO_COPY_DICT = { 'ocf_env/ocf/' : "inc/" }
|
@ -11,7 +11,7 @@ import os
|
||||
|
||||
args = ' '.join(sys.argv[1:])
|
||||
script_path = os.path.dirname(os.path.realpath(__file__))
|
||||
framework_script_path = script_path + os.sep + "../ut-framework/add_new_test_file.py"
|
||||
framework_script_path = script_path + os.sep + "../framework/add_new_test_file.py"
|
||||
framework_script_path = os.path.normpath(framework_script_path)
|
||||
status, output = commands.getstatusoutput(framework_script_path + " " + args)
|
||||
|
Loading…
Reference in New Issue
Block a user