diff --git a/Tst/testing_library/testlib/analyse_command_log.py b/Tst/testing_library/testlib/analyse_command_log.py index 52d5252a42f69a244ecb94f5a49850b3d669e99f..63fa98a944b13456ae706f52ae4ad8d866d2977f 100644 --- a/Tst/testing_library/testlib/analyse_command_log.py +++ b/Tst/testing_library/testlib/analyse_command_log.py @@ -2,9 +2,14 @@ """ Analyzing the log file of the Command Script. Get the information which Steps were done and which TC were sent. """ -from . import report -from . import testing_logger -from . import tcid +import confignator +import sys +sys.path.append(confignator.get_option('paths', 'ccs')) +import ccs_function_lib as cfl +cfl.add_tst_import_paths() +from testlib import report +from testlib import testing_logger +from testlib import tcid def get_sent_tcs(filename): @@ -33,7 +38,8 @@ def get_sent_tcs(filename): def get_steps(filename): """ - Get all steps which could be found in the log file + Get all steps which could be found in the log file, deprecated version (does not use step id or run id, use + get_steps_and_commands function below) :param filename: path to the log file :return: list of all steps as a dictionaries of step number and step starting timestamp (CUC) :rtype: list of dict @@ -74,9 +80,9 @@ def get_steps(filename): def get_steps_and_commands(filename): """ - ??? + Get all steps which could be found in the log file and identifiy step start/end by step_id :param filename: path to the log file - :return: + :return: all found steps :rtype: list of dict """ steps = [] @@ -146,7 +152,7 @@ def get_steps_and_commands(filename): for start_info in steps_start: for end_info in steps_end: - if start_info['step_id'] == start_info['step_id']: + if start_info['step_id'] == end_info['step_id']: start_info['end_timestamp'] = end_info['timestamp'] return steps_start diff --git a/Tst/testing_library/testlib/analyse_test_run.py b/Tst/testing_library/testlib/analyse_test_run.py index 6072bfcb42da41972e1cad7436a562ea9de8049e..89a66ee295a382291d2551df84ff57b2a6a6d8de 100644 --- a/Tst/testing_library/testlib/analyse_test_run.py +++ b/Tst/testing_library/testlib/analyse_test_run.py @@ -2,23 +2,124 @@ """ Gives a pretty print overview of the outcome of a test run. For this the log files of the executed Command and Verification scripts are used. """ -from . import analyse_verification_log -from . import analyse_command_log +import confignator +import csv +import datetime +import os +from os import listdir +from os.path import isfile, join -if __name__ == '__main__': - example_cmd_log_file = '../logs_test_runs/simple_example_command.log' - example_ver_log_file = '../logs_test_runs/simple_example_verification.log' +import sys +sys.path.append(confignator.get_option('paths', 'ccs')) +import ccs_function_lib as cfl +cfl.add_tst_import_paths() + +from testlib import analyse_verification_log +from testlib import analyse_command_log + +test_name = 'test3' + +cmd_log_file_end = '_command.log' +vrc_log_file_end = '_verification.log' +basic_log_file_path = confignator.get_option('tst-logging', 'test_run') +basic_output_file_path = confignator.get_option('tst-logging', 'test_run') # TODO: Set basic output path (Dominik) +output_file_header = ['Item', 'Description', 'Verification', 'TestResult'] + +def result_as_csv(test_name, log_file_path=None, output_file_path=None): + """ + Analyses the command and verification log file and creates a csv output table + :param str test_name: the name of the test and of its log files + :param str log_file_path: Path to the log files, None if basic one should be used + """ + if not log_file_path: + log_file_path = basic_log_file_path + if not output_file_path: + output_file_path = basic_output_file_path + + cmd_log_file = log_file_path + test_name + cmd_log_file_end + vrc_log_file = log_file_path + test_name + vrc_log_file_end + + cmd_steps = analyse_command_log.get_steps_and_commands(cmd_log_file) + vrc_steps = analyse_verification_log.get_verification_steps(vrc_log_file) + + name_start = 'IASW-{}-TS-{}-TR-'.format(test_name, cmd_steps[0]['version']) # TODO: Check which name should be used, version always same in log file? + file_versions = [] + + for file_name in listdir(output_file_path): + if file_name.startswith(name_start): + file_versions.append(int(file_name.split('-')[-1].split('.')[0])) + + file_versions.sort() + file_count = file_versions[-1] + 1 if file_versions else 1 + output_file_name_path = output_file_path + name_start + f'{file_count:03d}' + '.txt' + + with open(output_file_name_path, 'w', encoding='UTF8', newline='') as file: + writer = csv.writer(file, delimiter='|') + + # write the header + writer.writerow(output_file_header) + + # write the general info line + writer.writerow([test_name, 'Test Description', 'Test Spec. Version: ' + cmd_steps[0]['version'], 'Test Rep. Version: ' + f'{file_count:03d}']) # TODO: version always same in log file? + + # write date line + date_format = '%Y-%m-%d' + exec_date = datetime.datetime.strftime(cmd_steps[0]['exec_date'], date_format) + time_now = datetime.datetime.strftime(datetime.datetime.now(), date_format) + writer.writerow(['Date', '', exec_date, time_now]) # TODO: Make sure which dates should be shown, ok to take time from first step? + + # write Precon line + writer.writerow(['Precon.', 'This has still to be solved', '', '']) # TODO: What should be shown of the Precon + + # write comment line + writer.writerow(['Comment', 'This is NOT a comment, still working on it', '', '']) # TODO: Where is the comment given? + + # write comment line + for step in cmd_steps: + for vrc_step in vrc_steps: + if step['step_id'] == vrc_step['step_id']: + test_result = 'VERIFIED' if vrc_step['result'] else 'FAILED' + writer.writerow(['Step ' + step['step'][:-2], step['descr'], 'Probably some VRC description', test_result]) # TODO: Third coloumn is what? + + # write Postcon line + writer.writerow(['Postcon.', 'This has still to be solved', '', '']) # TODO: What should be shown of the Postcon + + +def show_basic_results(test_name, log_file_path=None): + """ + Analyses the command and verification log file and prints a basic overview of the results + :param str test_name: the name of the test and of its log files + :param str log_file_path: Path to the log files, None if basic one should be used + """ + if log_file_path: + cmd_log_file = log_file_path + test_name + cmd_log_file_end + vrc_log_file = log_file_path + test_name + vrc_log_file_end + else: + cmd_log_file = basic_log_file_path + test_name + cmd_log_file_end + vrc_log_file = basic_log_file_path + test_name + vrc_log_file_end print('\n--------------------------------------------------') print('Analysis of the Command log file:') # find and parse all TC in the example_log_file - tcs = analyse_command_log.get_sent_tcs(example_cmd_log_file) + tcs = analyse_command_log.get_sent_tcs(cmd_log_file) # find all steps in the example_log_file - steps = analyse_command_log.get_steps(example_cmd_log_file) - + steps = analyse_command_log.get_steps_and_commands(cmd_log_file) + print('\nCommand steps ({} total):'.format(len(steps))) + for item in steps: + print('Step {}: start: {}; end: {}'.format(item['step'], item['start_timestamp'], item['end_timestamp'])) print('\n--------------------------------------------------') + print('Analysis of the Verification log file:') - # find all steps in the example_log_file - vrc_steps = analyse_verification_log.get_verification_steps(example_ver_log_file) + # find all steps in the given log_file + vrc_steps = analyse_verification_log.get_verification_steps(vrc_log_file) + print('\nVerification steps ({} total):'.format(len(vrc_steps))) + for item in vrc_steps: + print('Verification Step {}: start: {}; end: {}; result: {}'.format(item['step'], item['start_timestamp'], + item['end_timestamp'], item['result'])) print('\n--------------------------------------------------') + return + +if __name__ == '__main__': + result_as_csv(test_name) + #show_basic_results(test_name) diff --git a/Tst/testing_library/testlib/analyse_verification_log.py b/Tst/testing_library/testlib/analyse_verification_log.py index ebc9549f13eeef470f7b71cc5d5d913d20357408..1e6973aac7188388173dbc62589323a47fc49d86 100644 --- a/Tst/testing_library/testlib/analyse_verification_log.py +++ b/Tst/testing_library/testlib/analyse_verification_log.py @@ -3,8 +3,13 @@ Analyzing the log file of the Verification Script. Get the information which Verifications were done and if they were successful. """ -from . import report -from . import testing_logger +import confignator +import sys +sys.path.append(confignator.get_option('paths', 'ccs')) +import ccs_function_lib as cfl +cfl.add_tst_import_paths() +from testlib import report +from testlib import testing_logger def get_verification_steps(filename): @@ -61,9 +66,9 @@ def get_verification_steps(filename): new_vrc_step['result'] = element['result'] vrc_steps.append(new_vrc_step) - print('\nVerification steps ({} total):'.format(len(vrc_start))) - for item in vrc_steps: - print('Verification Step {}: start: {}; end: {}; result: {}'.format(item['step'], item['start_timestamp'], item['end_timestamp'], item['result'])) + #print('\nVerification steps ({} total):'.format(len(vrc_start))) + #for item in vrc_steps: + # print('Verification Step {}: start: {}; end: {}; result: {}'.format(item['step'], item['start_timestamp'], item['end_timestamp'], item['result'])) return vrc_steps diff --git a/Tst/tst/data_model.py b/Tst/tst/data_model.py index 02d79e34dcb0583f7eda2382e65f6dc1d045d91a..e9db4fe320ebf90b36ee059d496c84aae68a3ff3 100644 --- a/Tst/tst/data_model.py +++ b/Tst/tst/data_model.py @@ -906,6 +906,8 @@ class TestSpecification: new_testspec.description = copy.copy(self.description) new_testspec.version = copy.copy(self.version) new_testspec.primary_counter_locked = copy.copy(self.primary_counter_locked) + new_testspec.precon = copy.copy(self.precon) + new_testspec.postcon = copy.copy(self.postcon) return new_testspec @@ -984,6 +986,8 @@ class TestSpecification: self.description = json_data['_description'] self.version = json_data['_version'] self.primary_counter_locked = json_data['_primary_counter_locked'] + self.precon = json_data['_precon'] + self.postcon = json_data['_postcon'] except KeyError as keyerror: self.logger.error('KeyError: no {} could be found in the loaded data'.format(keyerror)) diff --git a/Tst/tst/generator_templates/co_post_condition.py b/Tst/tst/generator_templates/co_post_condition.py index b2dabb58ac6ff17b81cd2aa44f134044dac45e65..6a8a27d2f4433c654c1d50412a2011006a52a33a 100644 --- a/Tst/tst/generator_templates/co_post_condition.py +++ b/Tst/tst/generator_templates/co_post_condition.py @@ -1,5 +1,5 @@ # VERIFY EVERY STEP ------------------------------------------------------------------------------------------------ - def step_verification(self, pool_name, step_start_cuc, param, summary, tc_id, ver_file, ver_class, ver_func, step_id): + def step_verification(self, pool_name, step_start_cuc, param, summary, ver_file, ver_class, ver_func, step_id): """ This functions does the verification for every step :param pool_name: str @@ -10,7 +10,6 @@ Includes the parameters of the step :param summary: report.StepSummary class object Containes a summary of the test - :param tc_id: :param ver_instance: class Instance definition If called the verification class is initialized :param ver_instance: func @@ -25,7 +24,7 @@ ver_instance_call = getattr(ver_file, ver_class) instance = ver_instance_call() ver_func_call = getattr(instance, ver_func) - success = ver_func_call(pool_name, start_cuc=step_start_cuc, tc_id=tc_id, run_id=self.run_id, step_id=step_id) + success = ver_func_call(pool_name, start_cuc=step_start_cuc, run_id=self.run_id, step_id=step_id) summary.result = success except: logger.exception('Exception in the Verification for Step {}'.format(param['step_no'])) diff --git a/Tst/tst/generator_templates/co_pre_condition.py b/Tst/tst/generator_templates/co_pre_condition.py index 2c79e9b3562081eb8df311a6fb17c7873642568f..05272b6a2db6c2fa3343e2c836eb499612e259bf 100644 --- a/Tst/tst/generator_templates/co_pre_condition.py +++ b/Tst/tst/generator_templates/co_pre_condition.py @@ -29,7 +29,6 @@ Time of the last incomming package before the step is started/ used as time of step start :return: summary: report.StepSummary class object Containes a summary of the test - :return: tc_id: """ testing_logger.cmd_log_handler(__name__) step_id = self.check_run_and_step_id(pool_name=pool_name) @@ -38,5 +37,4 @@ step_start_cuc=step_start_cuc, run_id=self.run_id, step_id=step_id) summary = report.StepSummary(step_number=param['step_no']) - tc_id = None - return step_start_cuc, summary, tc_id, step_id + return step_start_cuc, summary, step_id diff --git a/Tst/tst/generator_templates/co_step.py b/Tst/tst/generator_templates/co_step.py index d8b4591184ace07515451b8b50715683ea31894d..87902bf120cea252302a5ec6237357e3198d54d3 100644 --- a/Tst/tst/generator_templates/co_step.py +++ b/Tst/tst/generator_templates/co_step.py @@ -5,7 +5,7 @@ 'descr': '$testStepDescription', 'comment': '$testStepComment' } - step_start_cuc, summary, tc_id, step_id = self.begin_steps(pool_name=pool_name, param=param) + step_start_cuc, summary, step_id = self.begin_steps(pool_name=pool_name, param=param) try: ########---The defined step starts here---######## @@ -22,8 +22,8 @@ step_end_cuc = cfl.get_last_pckt_time(pool_name=pool_name, string=False) report.command_step_end(step_param=param, step_end_cuc=step_end_cuc, step_id=step_id) - summary =self.step_verification(pool_name=pool_name, step_start_cuc=step_start_cuc, param=param, tc_id=tc_id, - summary=summary, ver_file=${testSpecFileName}_verification, - ver_class="${testSpecClassName}Verification", ver_func="step_${testStepNumber}", step_id=step_id) + summary =self.step_verification(pool_name=pool_name, step_start_cuc=step_start_cuc, param=param, summary=summary, + ver_file=${testSpecFileName}_verification, ver_class="${testSpecClassName}Verification", + ver_func="step_${testStepNumber}", step_id=step_id) return summary diff --git a/Tst/tst/generator_templates/ver_step.py b/Tst/tst/generator_templates/ver_step.py index 5c4f77121704840fa7ffb645538c9f9d83cf96d9..33b73640478bbb9143f5d17e13446e0256ddaddf 100644 --- a/Tst/tst/generator_templates/ver_step.py +++ b/Tst/tst/generator_templates/ver_step.py @@ -1,5 +1,5 @@ # STEP $testStepNumber -------------------------------------------------------------------------------------------------------- - def step_$testStepNumber(self, pool_name, start_cuc=None, tc_id=None, run_id=None, step_id=None): + def step_$testStepNumber(self, pool_name, start_cuc=None, run_id=None, step_id=None): testing_logger.ver_log_handler(__name__) param = { 'step_no': '$testStepNumber', diff --git a/Tst/tst/view.py b/Tst/tst/view.py index 6b2e433684c5fb74861afe418efb259bb05ab7b0..1f918f5209947dfc63b593ad06d13e8709e21b9a 100644 --- a/Tst/tst/view.py +++ b/Tst/tst/view.py @@ -235,6 +235,32 @@ class Board(Gtk.Box): self.test_meta_data_desc.set_text(self.model.description) # set the version of the test specification from the data model self.test_meta_data_version.set_text(self.model.version) + # set the pre-condition name + if self.model.precon: + found = False + for index, precon_name in enumerate(self.precon_selection.get_model()): + if precon_name[0] == self.model.precon: + found = True + self.precon_selection.set_active(index) + if not found: + msg = 'Given Pre-Condition Name could not be found/loaded' + self.logger.warning(msg) + self.app.add_info_bar(message_type=Gtk.MessageType.INFO, message=msg) + self.on_precon_changed(self.precon_selection) + + # set the post-condition name + if self.model.postcon: + found = False + for index, postcon_name in enumerate(self.postcon_selection.get_model()): + if postcon_name[0] == self.model.postcon: + found = True + self.postcon_selection.set_active(index) + if not found: + msg = 'Given Post-Condition Name could not be found/loaded' + self.logger.warning(msg) + self.app.add_info_bar(message_type=Gtk.MessageType.INFO, message=msg) + self.on_postcon_changed(self.precon_selection) + def collapse_all_steps(self, button): """ Close all expander of the steps """ @@ -302,9 +328,9 @@ class Board(Gtk.Box): self.model.precon = precon_name # update the data model viewer self.app.update_model_viewer() - current_model = self.app.current_model() - if current_model: - current_model.precon = precon_name + #current_model = self.app.current_model() + #if current_model: + # current_model.precon = precon_name return def set_postcon_model(self): @@ -322,9 +348,9 @@ class Board(Gtk.Box): self.model.postcon = postcon_name # update the data model viewer self.app.update_model_viewer() - current_model = self.app.current_model() - if current_model: - current_model.postcon = postcon_name + #current_model = self.app.current_model() + #if current_model: + # current_model.postcon = postcon_name return def precon_edit_clicked(self, widget): diff --git a/egse.cfg b/egse.cfg index 89776870182010c3d463c3603bb4f4e70a66a134..c16ad820571cc3cd697e19dbd483c85f152b5815 100644 --- a/egse.cfg +++ b/egse.cfg @@ -2,14 +2,14 @@ base = ${confignator-paths:basic-path} tst = ${base}/Tst ccs = ${base}/Ccs -obsw = /home/sebastian/OBSW/implementation +obsw = /home/dominik/smile/OBSW/implementation crplm = ${obsw}/CrPlm/build/pc ia = ${obsw}/CrIa/build/pc start-simulator-log = ${logging:log-dir}/simulators/sim.log [database] -user = sebastian -password = Ego,ich1 +user = smile +password = letssmile [logging] log-dir = ${paths:base}/logs