def create_loggerconf(): loggerconf_template = open(CreatorSettings.get_loggerconf_tempatepath(), mode='r', encoding="utf-8") loggerconf_content = loggerconf_template.read() loggerconf_content = loggerconf_content.replace('{log_folder}', GlobalConfig.get_logdir()) loggerconf_template.close() loogerconf_file = open(GlobalConfig.get_rootdir() + GlobalConfig.get_slash() + "logger.conf", mode='w', encoding="utf-8") loogerconf_file.write(loggerconf_content) loogerconf_file.close()
def __init__(self): ''' Constructor ''' self.create_log_dir() #print("="*50),GlobalConfig.get_logger_configpath() logging.config.fileConfig(GlobalConfig.get_logger_configpath())
def run(self, storage, controller): prog = self.create_program() funcs = self.module_config.get("funcs") try: # Compile and load eBPF program to kernel b = BPF(text=prog) for f in funcs: b.attach_uprobe(name=config.get("executable"), sym=f, fn_name="%s_on_enter" % f) while (True): count = b.get_table("count") ts = time.time() for k, v in count.iteritems(): storage.store(funcs[k.value], v.value, ts) count.clear() time.sleep(1) if controller.stopped: break except Exception as e: # stop all other threads controller.stopped = True raise e
def __init__(self, project_name, casefilename, caseid): ''' Constructor ''' GlobalConfig.TestCaseFilePath = GlobalConfig.get_testcase_filepath( project_name, casefilename) self.project_name = project_name self.testcaseid = caseid
def genreate_testcase(): rootdir = GlobalConfig.get_rootdir() projectname_list = get_projectname_list() for projectname in projectname_list: currentproject_path = CreatorSettings.get_testproject_rootdir( ) + GlobalConfig.get_slash() + projectname testcases_path = currentproject_path + GlobalConfig.get_slash( ) + "testcases" datafiles_path = currentproject_path + GlobalConfig.get_slash( ) + "datafiles" xml_report_path = currentproject_path + GlobalConfig.get_slash( ) + "report" + GlobalConfig.get_slash() + "xml" for xmlfile in os.listdir(datafiles_path): if xmlfile.endswith("cases.xml"): print("Get cases.xml file: {}".format(xmlfile)) testcaselist = get_testcaselist4xml(datafiles_path + GlobalConfig.get_slash() + xmlfile) print(testcaselist) # testcaselist=get_testcaselist(RunnerSettings.get_xml_folder()+GlobalConfig.get_slash()+xmlfile) testmethodcontent = "" for testcase in testcaselist: #print(create_testmethod_content(testcase, xmlfile)) testmethodcontent = testmethodcontent + create_testmethod_content( testcase, xmlfile) + "\n" #print(testmethodcontent) if "testcases.xml" not in xmlfile: classname_content = xmlfile.split("cases.xml")[0].replace( "test_", "Test") py_filename = xmlfile.split(".")[0] + ".py" else: classname_content = "Test" + xmlfile.split( "testcases.xml")[0] py_filename = "test_" + xmlfile.split( "testcases.xml")[0] + ".py" testclass_content = create_testclass_content( rootdir, classname_content, projectname, testmethodcontent, py_filename) testcasefile = open(testcases_path + GlobalConfig.get_slash() + py_filename, mode="w", encoding="utf-8") testcasefile.write(testclass_content) testcasefile.close() runpy_content = create_runpy_content(rootdir, xml_report_path) runpyfile = open(currentproject_path + GlobalConfig.get_slash() + "run.py", mode="w", encoding="utf-8") runpyfile.write(runpy_content) runpyfile.close()
def get_projectname_list(): projectspath = CreatorSettings.get_testproject_rootdir() projectname_list = [] for projectdir in os.listdir(projectspath): projectpath = projectspath + GlobalConfig.get_slash() + projectdir if os.path.isdir(projectpath): # python2 #project_package_init_file = file(projectpath + GlobalConfig.get_slash() + "__init__.py", "w") # python3 project_package_init_file = open( projectpath + GlobalConfig.get_slash() + "__init__.py", "w") project_package_init_file.close() if os.path.exists(projectpath + GlobalConfig.get_slash() + "datafiles"): projectname_list.append(projectdir) else: for subdir in os.listdir(projectpath): subprojectpath = projectpath + GlobalConfig.get_slash( ) + subdir if os.path.isdir(subprojectpath): if os.path.exists(subprojectpath + GlobalConfig.get_slash() + "datafiles"): projectname = projectdir + GlobalConfig.get_slash( ) + subdir subproject_package_init_file = open( subprojectpath + GlobalConfig.get_slash() + "__init__.py", "w") subproject_package_init_file.close() projectname_list.append(projectname) return projectname_list
def store(self, metric, value, timestamp=None): prefix = GlobalConfig.get('prefix', 'ajtest') msg = '{}.{} {} {}\n'.format( prefix, metric, value, timestamp if timestamp else int(time.time())) self.sock.sendall(msg.encode()) logging.debug(msg)
def create_testproject(): projectname_list = get_projectname_list() for projectname in projectname_list: currentproject_path = CreatorSettings.get_testproject_rootdir( ) + GlobalConfig.get_slash() + projectname testcases_path = currentproject_path + GlobalConfig.get_slash( ) + "testcases" logtmp_folder = currentproject_path + GlobalConfig.get_slash( ) + "logtmp" project_log_path = currentproject_path + GlobalConfig.get_slash( ) + "log" testcases_log_path = testcases_path + GlobalConfig.get_slash() + "log" if os.path.exists(testcases_path): if os.path.exists(testcases_log_path): shutil.copytree(testcases_log_path, logtmp_folder) if sys.platform == "win32": #print("win system,force remove") os.system("rmdir /s /q %s" % testcases_path) else: shutil.rmtree(testcases_path) os.makedirs(testcases_path) if os.path.exists(logtmp_folder): shutil.copytree(logtmp_folder, testcases_log_path) shutil.rmtree(logtmp_folder) else: os.makedirs(testcases_log_path) if not os.path.exists(project_log_path): os.makedirs(project_log_path) testcases_package_init_file = open( testcases_path + GlobalConfig.get_slash() + "__init__.py", "w") testcases_package_init_file.close()
def call_step_method(self, teststep): step_project_name, step_file_name = self.get_step_project_and_file_name( teststep) GlobalConfig.StepParameterFilePath = GlobalConfig.get_parameter_filepath( step_project_name, step_file_name) #instance = MethodInvoker.get_instance(teststep["@StepPackage"], teststep["@StepGroup"], teststep["@StepPackage"].split('.')) module_name = teststep["@StepPackage"] + "." + teststep["@StepModule"] instance = MethodInvoker.get_instance(module_name, teststep["@StepGroup"], module_name.split('.')) method = MethodInvoker.get_method(instance, teststep["@StepName"]) #print(method) #arglist=list() method(teststep["@StepParameterID"])
def get_step_project_and_file_name(self, teststep): step_peoject_name = "" step_file_name = "" StepParamsFileName = teststep["@StepParametersFileName"] if "/" not in StepParamsFileName: step_peoject_name = self.project_name step_file_name = StepParamsFileName else: project_and_file_list = StepParamsFileName.split("/") step_file_name = project_and_file_list[-1] project_floors = len(project_and_file_list) - 1 for i in range(project_floors): step_peoject_name += project_and_file_list[i] if i != project_floors - 1: step_peoject_name += GlobalConfig.get_slash() return step_peoject_name, step_file_name
def run(self, storage, controller): prog = self.create_program() probe_start = self.module_config['probe_start'] probe_end = self.module_config.get('probe_end') try: # Compile and load eBPF program to kernel bpf = BPF(text=prog) path = config.get("executable") bpf.attach_uprobe(name=path, sym=probe_start, fn_name='probe_start') if probe_start == probe_end or not probe_end: bpf.attach_uretprobe(name=path, sym=probe_start, fn_name='probe_end') else: bpf.attach_uprobe(name=path, sym=probe_end, fn_name='probe_end') while (True): stats = bpf.get_table("stats") ts = time.time() for k, v in stats.iteritems(): if v.value: metric = '%s.%s' % (probe_start, pow(2, k.value)) storage.store(metric, v.value, ts) stats.clear() time.sleep(1) if controller.stopped: break except Exception as e: # stop all other threads controller.stopped = True raise e
def get_method_tempatepath(): return CreatorSettings.get_template_folder() + GlobalConfig.get_slash() + "test_method.txt"
def get_testproject_rootdir(): if CreatorSettings.ROOTDIR == None: return (os.path.abspath("..") + GlobalConfig.get_slash() + GlobalConfig.AUTOPROJECTFOLDER) else: return (CreatorSettings.ROOTDIR + GlobalConfig.get_slash() + GlobalConfig.AUTOPROJECTFOLDER)
def get_template_folder(): if CreatorSettings.ROOTDIR == None: return CreatorSettings.get_rootdir() + GlobalConfig.get_slash() + "CaseCreator" + GlobalConfig.get_slash() + "templates" else: return CreatorSettings.ROOTDIR + GlobalConfig.get_slash() + "CaseCreator" + GlobalConfig.get_slash() + "templates"
def get_datafiles_folder(projectname): return CreatorSettings.get_testproject_rootdir() + GlobalConfig.get_slash() + projectname + GlobalConfig.get_slash() + "datafiles"
def get_project_runpy(): return CreatorSettings.get_template_folder() + GlobalConfig.get_slash() + "run.py"
def get_loggerconf_tempatepath(): return CreatorSettings.get_template_folder() + GlobalConfig.get_slash() + "logger.conf"
def create_log_dir(self): if not os.path.exists(GlobalConfig.get_logdir()): os.mkdir(GlobalConfig.get_logdir())
def get_testclass_tempatepath(): return CreatorSettings.get_template_folder() + GlobalConfig.get_slash() + "Test_class.txt"