From 4020c70fc3a5a1159c92ce889d9f3e7d3c89d5b9 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 25 Aug 2015 21:37:49 +0200 Subject: [PATCH] [DEV] add correct gcov generator of result --- bin/lutin | 4 +- lutin/module.py | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ lutin/target.py | 12 ++++++ setup.py | 2 +- 4 files changed, 114 insertions(+), 2 deletions(-) diff --git a/bin/lutin b/bin/lutin index 33253af..77505e5 100755 --- a/bin/lutin +++ b/bin/lutin @@ -51,13 +51,15 @@ def usage(): color = debug.get_color_set() # generic argument displayed : myArgs.display() - print(" All target can finish with '?clean' '?dump' ... ?action") + print(" All target can finish with '?clean' '?dump' '?gcov' ... ?action") print(" " + color['green'] + "all" + color['default']) print(" build all (only for the current selected board) (bynary and packages)") print(" " + color['green'] + "clean" + color['default']) print(" clean all (same as previous)") print(" " + color['green'] + "dump" + color['default']) print(" Dump all the module dependency and properties") + print(" " + color['green'] + "gcov" + color['default']) + print(" Parse all the code of the library with the gcov resolution") listOfAllModule = module.list_all_module_with_desc() for mod in listOfAllModule: print(" " + color['green'] + mod[0] + color['default']) diff --git a/lutin/module.py b/lutin/module.py index 26cb96e..6c8d09a 100644 --- a/lutin/module.py +++ b/lutin/module.py @@ -170,6 +170,104 @@ class Module: debug.debug("Might copy folder : " + source + "==>" + destination) tools.copy_anything_target(target, self.origin_folder + "/" + source, destination) + def gcov(self, target, generate_output=False): + if self.type == 'PREBUILD': + debug.error("Can not generate gcov on prebuid system ... : '" + self.name + "'"); + return + # remove uncompilable elements: + list_file = tools.filter_extention(self.src, self.extention_order_build, True) + global_list_file = "" + for file in list_file: + debug.verbose(" gcov : " + self.name + " <== " + file); + file_dst = target.get_full_name_destination(self.name, self.origin_folder, file, "o") + global_list_file += file_dst + " " + cmd = "gcov --branch-counts --preserve-paths " + if generate_output == False: + cmd += "--no-output " + cmd += global_list_file + debug.extreme_verbose(" " + cmd); + ret = multiprocess.run_command_direct(cmd) + # parsing ret : + ret = ret.split('\n'); + debug.verbose("*** Gcov result parsing ..."); + useful_list = [] + remove_next = False + last_file = "" + executed_lines = 0 + executable_lines = 0 + for elem in ret: + if remove_next == True: + remove_next = False + continue; + if elem[:10] == "Creating '" \ + or elem[:10] == "Removing '": + remove_next = True + continue + if elem[:6] == "File '" \ + and self.origin_folder != elem[6:len(self.origin_folder)+6]: + remove_next = True + continue + if elem[:6] == "File '": + last_file = elem[6+len(self.origin_folder)+1:-1] + continue + start_with = "Lines executed:" + if elem[:len(start_with)] != start_with: + debug.warning(" gcov ret : " + str(elem)); + debug.warning(" ==> does not start with : " + start_with); + debug.warning(" Parsing error"); + continue + out = elem[len(start_with):].split("% of ") + if len(out) != 2: + debug.warning(" gcov ret : " + str(elem)); + debug.warning(" Parsing error of '% of '"); + continue + pourcent = float(out[0]) + total_line_count = int(out[1]) + total_executed_line = int(float(total_line_count)*pourcent/100.0) + useful_list.append([last_file, pourcent, total_executed_line, total_line_count]) + executed_lines += total_executed_line + executable_lines += total_line_count + last_file = "" + ret = useful_list[:-1] + #for elem in ret: + # debug.info(" " + str(elem)); + for elem in ret: + if elem[1]<10.0: + debug.info(" % " + str(elem[1]) + "\r\t\t" + str(elem[0])); + elif elem[1]<100.0: + debug.info(" % " + str(elem[1]) + "\r\t\t" + str(elem[0])); + else: + debug.info(" % " + str(elem[1]) + "\r\t\t" + str(elem[0])); + pourcent = 100.0*float(executed_lines)/float(executable_lines) + # generate json file: + json_file_name = target.get_build_folder(self.name) + "/" + self.name + "_coverage.json" + debug.debug("generate json file : " + json_file_name) + tmp_file = open(json_file_name, 'w') + tmp_file.write('{\n') + tmp_file.write(' "lib-name":"' + self.name + '",\n') + #tmp_file.write(' "coverage":"' + str(pourcent) + '",\n') + tmp_file.write(' "executed":"' + str(executed_lines) + '",\n') + tmp_file.write(' "executable":"' + str(executable_lines) + '",\n') + tmp_file.write(' "list":[\n') + val = 0 + for elem in ret: + if val == 0 : + tmp_file.write(' {\n') + else: + tmp_file.write(' }, {\n') + val += 1 + tmp_file.write(' "file":"' + elem[0] + '",\n') + #tmp_file.write(' "coverage":' + str(elem[1]) + ',\n') + tmp_file.write(' "executed":' + str(elem[2]) + ',\n') + tmp_file.write(' "executable":' + str(elem[3]) + '\n') + tmp_file.write(' }\n') + tmp_file.write(' ]\n') + tmp_file.write('}\n') + tmp_file.flush() + tmp_file.close() + # print debug: + debug.print_element("coverage", self.name, ":", str(pourcent) + "% " + str(executed_lines) + "/" + str(executable_lines)) + # call here to build the module def build(self, target, package_name): # ckeck if not previously build diff --git a/lutin/target.py b/lutin/target.py index 9e2b5b6..82a38b7 100644 --- a/lutin/target.py +++ b/lutin/target.py @@ -374,6 +374,9 @@ class Target: return def build(self, name, packagesName=None, optionnal=False): + if name == "gcov": + debug.info("gcov all") + debug.error("must set the gcov parsig on a specific library or binary ==> not supported now for all") if name == "dump": debug.info("dump all") self.load_all() @@ -400,6 +403,10 @@ class Target: # get the action an the module .... gettedElement = name.split("?") moduleName = gettedElement[0] + if len(gettedElement)>=3: + sub_action_name = gettedElement[2] + else: + sub_action_name = "" if len(gettedElement)>=2: actionName = gettedElement[1] else : @@ -426,6 +433,11 @@ class Target: elif actionName == "clean": debug.info("clean module '" + moduleName + "'") return mod.clean(self) + elif actionName == "gcov": + debug.debug("gcov on module '" + moduleName + "'") + if sub_action_name == "output": + return mod.gcov(self, generate_output=True) + return mod.gcov(self, generate_output=False) elif actionName == "build": debug.debug("build module '" + moduleName + "'") if optionnal == True: diff --git a/setup.py b/setup.py index f7415e9..06b70fd 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ def readme(): # https://pypi.python.org/pypi?%3Aaction=list_classifiers setup(name='lutin', - version='0.6.0', + version='0.6.1', description='Lutin generic builder', long_description=readme(), url='http://github.com/HeeroYui/lutin',