def on_complete(failed_commands): plLogger = PLLogger.GetLogger('methodology') plLogger.LogInfo("on_complete") # call result end iterator ResultInterface.end_iterator() return True
def run(Iteration): plLogger = PLLogger.GetLogger('methodology') plLogger.LogInfo(" Run IteratorValidateCommand") hnd_reg = CHandleRegistry.Instance() this_cmd = get_this_cmd() # This is bad but there doesn't seem to be any other way of getting # the current iterator command handle while_cmd = this_cmd.GetParent() if while_cmd is not None and while_cmd.IsTypeOf("SequencerWhileCommand"): iter_cmd_hnd = while_cmd.Get("ExpressionCommand") iter_cmd = hnd_reg.Find(iter_cmd_hnd) if iter_cmd is not None and \ iter_cmd.IsTypeOf("spirent.methodology.IteratorCommand"): info_dict = ri.get_last_iteration_info_status(iter_cmd_hnd) if info_dict is not None: if info_dict[pc.STATUS][pc.VERDICT] == \ EnumVerdict.failed: this_cmd.Set("Verdict", False) else: # This is for none or passed this_cmd.Set("Verdict", True) else: plLogger.LogError("ERROR: Failed to determine the " + "verdict of this iteration") # Not too sure what to do here this_cmd.Set("Verdict", True) else: # Set the verdict to True (PASS) this_cmd.Set("Verdict", True) return True
def update_results_with_current_value(iterating_property, current_value, iteration_id, cmd_obj): """ Update current iteration value to results framework. iterating_property: Framesize, load etc """ pkg = "spirent.methodology" prop_chain_list = cmd_obj.GetObjects("PropertyChainingConfig", RelationType("PropertyChain", 1)) iter_obj = None # Get the iterator handle (follow the reverse property chain...) for prop_chain in prop_chain_list: src_obj = prop_chain.GetParent() if src_obj.IsTypeOf(pkg + ".IteratorCommand"): iter_obj = src_obj break if iter_obj is not None: ResultInterface.set_iterator_current_value(iter_obj.GetObjectHandle(), iterating_property, current_value, iteration_id)
def test_one_iterator_missing_most_calls(stc, resource_cleanup): # skip create/start # RI.create_test() # RI.start_test() framesizelist = [64, 128, 256] fs_itr_id = 1 fs_iterator_handle = 12123 for fs in framesizelist: RI.set_iterator_current_value(fs_iterator_handle, 'FrameSize', fs, fs_itr_id) RI.add_provider_result(test_utils.dummy_verify_result_failed) fs_itr_id += 1 # RI.complete_iteration() # RI.end_iterator() RI.end_test() file_data = vu.get_report_file_list() vu.validate_result_file_list(file_data['fileList'], test_utils.result_file_list_1) vu.validate_result_file_Schema(file_data) vu.verify_summary_file_info()
def test_one_iterator_missing_most_calls_stop(stc, resource_cleanup): # skip create/start # RI.create_test() # RI.start_test() framesizelist = [64, 128, 256] fs_itr_id = 1 fs_iterator_handle = 12123 for fs in framesizelist: RI.set_iterator_current_value(fs_iterator_handle, 'FrameSize', fs, fs_itr_id) RI.add_provider_result(test_utils.dummy_verify_result_failed) fs_itr_id += 1 # RI.complete_iteration() # RI.end_iterator() # RI.end_test() RI.stop_test() file_data = vu.get_report_file_list() vu.validate_result_file_list(file_data['fileList'], test_utils.result_file_list_1) vu.validate_result_file_Schema(file_data) sum_data = vu.verify_summary_file_info() sum_data = vu.verify_summary_file_info() assert ru.compare_dict_data_using_json_string(test_utils.status_exec_stopped_8, sum_data[pc.STATUS]) is True
def submit_provider_data_to_root(data): ResultInterface.add_provider_result_to_root(data)
def submit_provider_data(data): ResultInterface.add_provider_result(data)
def test_one_iterator_no_complete_iteration(stc, resource_cleanup): RI.create_test() RI.start_test() framesizelist = [64, 128, 256] fs_itr_id = 1 fs_iterator_handle = 12123 for fs in framesizelist: RI.set_iterator_current_value(fs_iterator_handle, 'FrameSize', fs, fs_itr_id) RI.add_provider_result(test_utils.dummy_verify_result_failed) fs_itr_id += 1 # result framwork should take core of missing call. # RI.complete_iteration() RI.end_iterator() RI.end_test() RI.stop_test() file_data = vu.get_report_file_list() vu.validate_result_file_list(file_data['fileList'], test_utils.result_file_list_1) vu.validate_result_file_Schema(file_data)
def test_multiple_iterator_get_status(stc, resource_cleanup): RI.create_test() RI.start_test() framesizelist = [64, 128, 256] loadlist = [10, 20] fs_itr_id = 1 fs_iterator_handle = 12123 load_handle = 5555 assert RI.get_last_iteration_info_status(fs_iterator_handle) is None assert RI.get_last_iteration_info_status(load_handle) is None for fs in framesizelist: RI.set_iterator_current_value(fs_iterator_handle, 'FrameSize', fs, fs_itr_id) if fs_itr_id == 1: assert RI.get_last_iteration_info_status(fs_iterator_handle) is None else: assert RI.get_last_iteration_info_status(fs_iterator_handle) is not None load_id = 1 for load in loadlist: RI.set_iterator_current_value(load_handle, 'Load', load, load_id) if load_id == 1: assert RI.get_last_iteration_info_status(load_handle) is None else: assert RI.get_last_iteration_info_status(load_handle) is not None RI.add_provider_result(test_utils.dummy_verify_result_failed) RI.add_provider_result(test_utils.dummy_verify_result_passed) if load_id == 1: assert RI.get_last_iteration_info_status(load_handle) is None else: assert RI.get_last_iteration_info_status(load_handle) is not None load_id += 1 RI.complete_iteration() last_itr_data = RI.get_last_iteration_info_status(load_handle) assert last_itr_data is not None assert last_itr_data[pc.STATUS][pc.VERDICT] == EnumVerdict.failed assert last_itr_data[pc.STATUS][pc.EXEC_STATUS] == EnumExecStatus.completed RI.end_iterator() # result object should be deleted for load assert RI.get_last_iteration_info_status(load_handle) is None # frame size if fs_itr_id == 1: assert RI.get_last_iteration_info_status(fs_iterator_handle) is None else: assert RI.get_last_iteration_info_status(fs_iterator_handle) is not None fs_itr_id += 1 RI.complete_iteration() last_itr_data = RI.get_last_iteration_info_status(fs_iterator_handle) assert last_itr_data is not None assert last_itr_data[pc.STATUS][pc.VERDICT] == EnumVerdict.none assert last_itr_data[pc.STATUS][pc.EXEC_STATUS] == EnumExecStatus.completed RI.end_iterator() # result object should be deleted for framesize assert RI.get_last_iteration_info_status(fs_iterator_handle) is None RI.end_test() RI.stop_test()
def test_multiple_iterator_abort_outer_loop_stop(stc, resource_cleanup): """ test must complete 2 iterations and generate report with summary. 1. framesize = 64, load = 10 2. framesize = 64, load = 20 """ RI.create_test() RI.start_test() framesizelist = [64, 128, 256] loadlist = [10, 20] fs_itr_id = 1 fs_iterator_handle = 12123 load_handle = 5555 for fs in framesizelist: RI.set_iterator_current_value(fs_iterator_handle, 'FrameSize', fs, fs_itr_id) load_id = 1 for load in loadlist: RI.set_iterator_current_value(load_handle, 'Load', load, load_id) RI.add_provider_result(test_utils.dummy_verify_result_failed) RI.add_provider_result(test_utils.dummy_verify_result_passed) load_id += 1 RI.complete_iteration() break # RI.end_test() RI.stop_test() file_data = vu.get_report_file_list() vu.validate_result_file_list(file_data['fileList'], test_utils.result_file_list_4) vu.validate_result_file_Schema(file_data) sum_data = vu.verify_summary_file_info() assert ru.compare_dict_data_using_json_string(test_utils.status_exec_stopped_8, sum_data[pc.STATUS]) is True
def test_multiple_iterator_no_complete_end(stc, resource_cleanup): # test must run all 6 iterations and generate reports RI.create_test() RI.start_test() framesizelist = [64, 128, 256] loadlist = [10, 20] fs_itr_id = 1 fs_iterator_handle = 12123 load_handle = 5555 for fs in framesizelist: RI.set_iterator_current_value(fs_iterator_handle, 'FrameSize', fs, fs_itr_id) load_id = 1 for load in loadlist: RI.set_iterator_current_value(load_handle, 'Load', load, load_id) RI.add_provider_result(test_utils.dummy_verify_result_failed) RI.add_provider_result(test_utils.dummy_verify_result_passed) load_id += 1 # RI.complete_iteration() # missing call should be handled by results # RI.end_iterator() # frame size fs_itr_id += 1 # RI.complete_iteration() # RI.end_iterator() RI.end_test() RI.stop_test() file_data = vu.get_report_file_list() vu.validate_result_file_list(file_data['fileList'], test_utils.result_file_list_2) vu.validate_result_file_Schema(file_data)
def test_multiple_iterator_add_root_result(stc, resource_cleanup): RI.create_test() RI.start_test() framesizelist = [64] loadlist = [10] fs_itr_id = 1 fs_iterator_handle = 12123 load_handle = 5555 for fs in framesizelist: RI.set_iterator_current_value(fs_iterator_handle, 'FrameSize', fs, fs_itr_id) load_id = 1 for load in loadlist: RI.set_iterator_current_value(load_handle, 'Load', load, load_id) RI.add_provider_result(test_utils.dummy_verify_result_failed) RI.add_provider_result(test_utils.dummy_verify_result_passed) # add to root RI.add_provider_result_to_root(test_utils.dummy_verify_result_passed) load_id += 1 RI.complete_iteration() RI.end_iterator() # frame size fs_itr_id += 1 RI.complete_iteration() RI.end_iterator() RI.end_test() RI.stop_test() file_data = vu.get_report_file_list() vu.validate_result_file_list(file_data['fileList'], test_utils.result_file_list_3) vu.validate_result_file_Schema(file_data) sum_data = vu.verify_summary_file_info() assert ru.compare_dict_data_using_json_string(test_utils.status_pass_2, sum_data[pc.STATUS]) is True # 2 root results, iterator and added root result root_list = sum_data[pc.DATA][rc.CHILDREN] assert len(root_list) == 2 result_data = ru.get_data_from_dictionary(root_list, '0.data.children.0') fz_data = ru.get_data_from_dictionary(root_list, '1.data.children.0') assert fz_data[pc.INFO]['param'] == 'FrameSize' # verify result data expected_string = ru.get_json_string(test_utils.dummy_verify_result_passed) assert ru.compare_dict_data_using_json_string(expected_string, result_data) is True
def test_multiple_iterator(stc, resource_cleanup): RI.create_test() RI.start_test() framesizelist = [64, 128, 256] loadlist = [10, 20] fs_itr_id = 1 fs_iterator_handle = 12123 load_handle = 5555 for fs in framesizelist: RI.set_iterator_current_value(fs_iterator_handle, 'FrameSize', fs, fs_itr_id) load_id = 1 for load in loadlist: RI.set_iterator_current_value(load_handle, 'Load', load, load_id) RI.add_provider_result(test_utils.dummy_verify_result_failed) RI.add_provider_result(test_utils.dummy_verify_result_passed) load_id += 1 RI.complete_iteration() RI.end_iterator() # frame size fs_itr_id += 1 RI.complete_iteration() RI.end_iterator() RI.end_test() RI.stop_test() file_data = vu.get_report_file_list() vu.validate_result_file_list(file_data['fileList'], test_utils.result_file_list_2) vu.validate_result_file_Schema(file_data) sum_data = vu.verify_summary_file_info() assert ru.compare_dict_data_using_json_string(test_utils.status_exec_complete_5, sum_data[pc.STATUS]) is True fz_data = ru.get_data_from_dictionary(sum_data, 'data.children.0.data.children.0') assert fz_data[pc.CLASS] == EnumDataClass.iterator_result assert fz_data[pc.DATA_FORMAT] == EnumDataFormat.group assert fz_data[pc.INFO]['param'] == 'FrameSize' assert ru.compare_dict_data_using_json_string(test_utils.status_iterator_6, fz_data[pc.STATUS]) is True itr_list = fz_data[pc.DATA][rc.CHILDREN] assert len(itr_list) == len(framesizelist) vu.verify_summary_iteration_result_type2(itr_list, framesizelist, loadlist, test_utils.result_file_list_2)
def test_end_iterator_without_iteration(stc, resource_cleanup): RI.create_test() RI.start_test() RI.complete_iteration() RI.end_iterator() RI.end_test() RI.stop_test() data = vu.validate_report_schema() assert ru.compare_dict_data_using_json_string(test_utils.status_exec_complete_1, data[pc.STATUS]) is True assert ru.compare_dict_data_using_json_string(test_utils.data_empty_1, data[pc.DATA]) is True
def test_multiple_iterator_abort_inner_loop_stop(stc, resource_cleanup): """ test must complete 1 iterations and generate report with summary. 1. framesize = 64, load = 10 """ RI.create_test() RI.start_test() framesizelist = [64, 128, 256] loadlist = [10, 20] fs_itr_id = 1 fs_iterator_handle = 12123 load_handle = 5555 for fs in framesizelist: RI.set_iterator_current_value(fs_iterator_handle, 'FrameSize', fs, fs_itr_id) load_id = 1 for load in loadlist: RI.set_iterator_current_value(load_handle, 'Load', load, load_id) RI.add_provider_result(test_utils.dummy_verify_result_failed) RI.add_provider_result(test_utils.dummy_verify_result_passed) load_id += 1 break break # abort test # RI.end_test() RI.stop_test() file_data = vu.get_report_file_list() vu.validate_result_file_list(file_data['fileList'], test_utils.result_file_list_3) vu.validate_result_file_Schema(file_data)
def run(): ResultInterface.complete_iteration() return True
def test_cmd_with_res_fmwk(stc): ctor = CScriptableCreator() sequencer = CStcSystem.Instance().GetObject("Sequencer") # Set up an iteration group group_cmd = ctor.Create(PKG + ".IterationGroupCommand", sequencer) assert group_cmd while_cmd = ctor.Create("SequencerWhileCommand", group_cmd) assert while_cmd iter_cmd = ctor.Create(PKG + ".ObjectIteratorCommand", while_cmd) valid_cmd = ctor.Create(PKG + ".IteratorValidateCommand", while_cmd) while_cmd.Set("ExpressionCommand", iter_cmd.GetObjectHandle()) while_cmd.SetCollection("CommandList", [valid_cmd.GetObjectHandle()]) group_cmd.SetCollection("CommandList", [while_cmd.GetObjectHandle()]) sequencer.SetCollection("CommandList", [group_cmd.GetObjectHandle()]) # Setup the methodology manager and the active test case meth_mgr = meth_mgr_utils.get_meth_manager() assert meth_mgr is not None methodology = ctor.Create("StmMethodology", meth_mgr) test_case = ctor.Create("StmTestCase", methodology) meth_mgr_utils.set_active_test_case(test_case) test_case_res = meth_mgr_utils.get_stm_test_result() assert test_case_res is not None # Mock get_this_cmd IteratorValidateCommand.get_this_cmd = MagicMock(return_value=valid_cmd) # Set up the results framework (passing iteration) RI.create_test() RI.start_test() fs = 128 fs_iter_id = 1 fs_iter_hnd = iter_cmd.GetObjectHandle() RI.set_iterator_current_value(fs_iter_hnd, "FrameSize", fs, fs_iter_id) RI.add_provider_result(test_utils.dummy_verify_result_passed) RI.complete_iteration() # Call the different parts of the command and verify the results res = IteratorValidateCommand.run(fs_iter_id) assert res is True assert valid_cmd.Get("Verdict") is True # Failed iteration RI.set_iterator_current_value(fs_iter_hnd, "FrameSize", fs + 128, fs_iter_id + 1) RI.add_provider_result(test_utils.dummy_verify_result_failed) RI.complete_iteration() res = IteratorValidateCommand.run(fs_iter_id + 1) assert res is True assert valid_cmd.Get("Verdict") is False