Index: shared/scripts/configuration/utility.py =================================================================== diff -u -r1899d5b5afc3e481360915302d8e2d37de8b08b8 -rc1c94ae0f22365e44259e382e0e9d417bb8c054b --- shared/scripts/configuration/utility.py (.../utility.py) (revision 1899d5b5afc3e481360915302d8e2d37de8b08b8) +++ shared/scripts/configuration/utility.py (.../utility.py) (revision c1c94ae0f22365e44259e382e0e9d417bb8c054b) @@ -47,7 +47,11 @@ except OSError: test.log("Directory can not be created") - +def get_current_date_and_time(date_format='%Y/%b/%d - %H:%M:%S'): + + date = datetime.now() + return str(date.strftime(date_format)) + def get_cloud_sync_input_file(): """ This function is the handler for getting file from log folder. @@ -115,5 +119,193 @@ if expected_epoch_value > minimum_epoch_value and expected_epoch_value < maximum_epoch_value : return True return False + +def is_intiger(num): + """ + This function checks the value is adaptable for integer conversion. + + @param num - (string) (string) input value for conversion. + @return True/False- (bool) returns True if the value can type casted into int, else False + """ + try: + if num.isdigit(): + return True + except ValueError: + return False + + +def get_extracted_file(): + """ + This function is the handler for getting file from log folder. + + Application log file is automatically created on '/home/denali/Desktop/sd-card/log/ {current_date}_denaliSquish.log' + + @return latest_file - (string) returns latest file that append on log folder from sd-data + """ + try: + current_date = get_current_date_and_time(date_format = "%Y_%m_%d") + latest_file = '/home/denali/Desktop/sd-card/log/'+current_date+'_denaliSquish.log' + return latest_file + except: + return False + +def get_extracted_error_file(): + """ + This function is the handler for getting error file from service folder. + + Application log file is automatically created on '/home/denali/Desktop/sd-card/service/ {current_date}_denaliSquish.err ' + + @return latest_file - (string) returns latest file that append on log folder from service + """ + try: + current_date = get_current_date_and_time(date_format = "%Y_%m_%d") + latest_file = '/home/denali/Desktop/sd-card/service/'+current_date+'_denaliSquish.err' + return latest_file + except: + return False + +def get_message_from_log(file_name, message_text): + + """ + This method intended to extract the message from application log. + For row[index], index represent column to be extracted. + + @param file_name - (string) path of the latest log file created. + @param message_text - (string) message text to be extracted. + @return message - (list) API arguments displayed in log. + """ + message = [] + count = 0 + try: + with open(file_name, 'r') as csv_file: + try: + for row in reversed(list(csv.reader(csv_file))): + if row[0].isalpha(): + pass + else: + row_length = sum(1 for values in row) + if row_length >= 4: + if row[3]!= None and row[3] == message_text: + if count == 30: + test.fail("handler unable to find message text from log file.") + message_length = sum(1 for values in row) + for column in range(4, message_length, 1): + message.append(row[column]) + count +=1 + for value in range(len(message)): + float_status = is_float(message[value]) + int_status = is_intiger(message[value]) + if float_status is True: + message[value] = float(message[value]) + if int_status is True: + message[value] = int(message[value]) + return message + else: + pass + except: + test.fail("application log data is corrupted") + except: + test.fail("Log file is not created or log file is not created based on standard log naming format.") + + +def get_ack_request_details(file_name, message_text): + """ + This method intended to extract acknowledgement request status, negative requested acknowledgement + and message id from application log. + + For row[index], were index represent column to be extracted. + + @param file_name - (string) path of the latest log file created. + @param message_text - (string) message text to be extracted from log. + @return row[3] - (string) acknowledgement request status. + @return row[4] - (string) Negative requested acknowledgement value (Sq). + @return message_id - (string) formatted message id from log. + """ + try: + message_id = " ID" + with open(file_name, 'r') as csv_file: + try: + for row in reversed(list(csv.reader(csv_file))): + if row[0].isalpha(): + pass + else: + row_length = sum(1 for values in row) + if row_length == 6 and row[3] != message_text: + if row[5].split(':')[0] == message_id: + extracted_message_id = pyInt(row[5].split(':')[1], 16) + formatted_message_id = format(extracted_message_id, '#0x') + # MSG_ID_HD_DEBUG_EVENT (0xFFF1) and MSG_ID_DG_DEBUG_EVENT (0xFFF2) hex values are reversed in log. + string_format_id = str(formatted_message_id) + first_two_char = string_format_id[2:4] + last_two_char = string_format_id[4:6] + if last_two_char != '00' and len(string_format_id) != 5: + return row[3], row[4], ('0x'+last_two_char+first_two_char) + else: + return row[3], row[4], string_format_id.replace("00", "") + else: + pass + except: + test.fail("application log data is corrupted - unable to fetch data") + except: + test.fail("Log file is not created or log file is not created based on standard log naming format.") + + +def get_bak_request_details(file_name, ack_bak_value): + """ + This method intended to extract the acknowledgement back status from application log. + + For row[index], were index represent column to be extracted. + + @param file_name - (string) path of the latest log file created. + @param ack_bak_value - (string) Positive back acknowledgement value (Sq). + @return row[3] - (string) acknowledgement back status. + """ + try: + with open(file_name, 'r') as csv_file: + try: + for row in reversed(list(csv.reader(csv_file))): + if row[0].isalpha(): + pass + else: + row_length = sum(1 for values in row) + if row_length >= 5: + if row[4] == ack_bak_value: + return row[3] + else: + pass + else: + pass + except: + test.fail("application log data is corrupted") + except: + test.fail("Log file is not created or log file is not created based on standard log naming format.") + + + +def get_current_log_details(message_ack = False, message_text = None): + """ + This function is capable to perform data analysis from application log folder. + + logs are automatically created in path :"/home/denali/Desktop/sd-card/log/*.log". + + In row[index], index represent column to be extracted. + @param message_ack - (bool) 'True' - if ack is satisfied in log / 'False' - if ack condition is not satisfied + @param message_text - (string) message text to be extracted from log. + @return content_record - (list) list contains extracted data (ack_req, ack_bak, message, message_id). + """ + content_record = [] + file_name = get_extracted_file() + if message_text != None: + message = get_message_from_log(file_name, message_text) + content_record.append(message) + if message_ack != False: + ack_req_status, ack_req_value, message_id = get_ack_request_details(file_name, message_text) + ack_bak_value = ack_req_value.replace(":-", ":") # getting negative requested ack from positive requested ack + content_record.append(ack_req_status) + content_record.append(message_id.lower()) + if message_ack != False and ack_bak_value != None: + ack_bak_status = get_bak_request_details(file_name, ack_bak_value) + content_record.append(ack_bak_status) + return content_record \ No newline at end of file Index: tst_cloud_sync - treatment_screen/test.py =================================================================== diff -u -rc4c343725fdb5ed164f5b0638d7f4dbeb0eda0c8 -rc1c94ae0f22365e44259e382e0e9d417bb8c054b --- tst_cloud_sync - treatment_screen/test.py (.../test.py) (revision c4c343725fdb5ed164f5b0638d7f4dbeb0eda0c8) +++ tst_cloud_sync - treatment_screen/test.py (.../test.py) (revision c1c94ae0f22365e44259e382e0e9d417bb8c054b) @@ -31,6 +31,59 @@ dg_simulator = DGSimulator() hd_simulator = HDSimulator() +LOCATION = '/home/denali/Projects/application/resources/settings/Messages/Unhandled.conf' + + +ERROR_MESSAGE = { +# "500" : "CS Unknown Error ", + "501" : "CS Incorrect header ", + "502" : "CS Incorrect timestamp ", + "503" : "CS Incorrect sequence ", + "504" : "CS Incorrect CRC ", + "505" : "CS Incorrect ID ", + "506" : "CS Invalid ID ", +# "507" : "CS Incorrect parameter count ", + "508" : "CS Mismatch parameter count ", + "509" : "CS Missing parameter ", + "510" : "CS No history available ", +# "511" : "CS Duplicate data ", +# "512" : "CS The log folder cannot be created. ", +# "513" : "CS Error writing to the input file. ", + "514" : "CS The credentials file does not exist. ", +# "515" : "CS The credentials folder make failed. ", +# "516" : "CS The credentials file copy failed. ", +# "517" : "CS The credentials file remove failed. ", +# "518" : "CS The credentials folder is empty. ", +# "519" : "CS No Treatment Code provided. ", + "520" : "CS The provided Treatment Code is empty. ", + "521" : "CS Out buffer empty " +} + +# eError_Unknown_500 = "1007,1," +DEVICE_FACTORY_RESET_REQUEST_1 = '' +eError_HeaderCount_501 = '1639391827,2999,3,501' +eError_Timestamp_502 = '1639391ddvgvg827,1,0,2999,0,502' +eError_Sequence_503 = '1639391827,dcdc1,0,2999,0,503' +eError_Crc_504 = '1639391827,1,0dfd,2999,0,504' +eError_MessageID_505 = '1639391827,1,0,299dfd9,0,505' +eError_InvalidID_506 = '1639391827,1,0,20,0' +# eError_ParamCount_507 = '1639391827,0,1,1006,3,507,[1,1]' +eError_ParamMismatch_508 = '1,1639391827,0,2999,0,508' +eError_ParamMissing_509 = '1639391827,1,0,2999,3,509,[8,2]' +eError_NoHistory_510 = '1639391827,1,0,2006,0' +# eErrro_Duplicate_511 = '1639391827,1,0,2999,0,511' +# eError_LogFolder_512 = '1639391827,1,0,1006,3,/tmp/credentials/dfe' +# eError_LogFileInp_513 = '1639391827,1,0,1006,3,/tmp/credentials/' +eError_CredentialMake_514 = '1657706417,7,0,2003,3,,DG1234567890123,06300216' +# eError_CredentialFile_515 = '1639391827,1,0,1006,3,/tmp/credentials/' +# eError_CredentialCopy_516 = '1639391827,1,0,1006,1,3,/tmp/credentials/' +# eError_CredentialRemove_517 = '1639391827,1,0,1006,3,/tmp/credentials/' +# eError_CredentialEmpty_518 = '1639391827,1,0,1006,3,/credentials/' +# eError_TxCodeNoParam_519 = '1639391827,1,0,1006,1,[]' +eError_TxCodeEmpty_520 = '1639391827,1,0,2008,1,' +eError_OutFileEmpty_521 = '' + + POST_TREATMENT_INSTRUCTION_COUNT = 2 CODE_DISPLAY_REQUEST = '1639391827,1,0,2008,1,Tx_code' @@ -46,7 +99,6 @@ DEVICE_HD_INFO_RESPONSE = '1639391827,1,0,1002,3,HD1234567890123,,sw_version' DEVICE_DG_INFO_RESPONSE = '1639391827,1,0,1002,3,,DG1234567890123,sw_version' - def verify_code_from_treatment_response(): """ @@ -63,8 +115,8 @@ utils.waitForGUI(1) #delay for fetching the effect text_code_label = str(waitForObjectExists(names.o_treatmentReviewConfirm_Code_Tx_code_Label).text) test.compare(message_text[config.PARAMETER_INDEX], text_code_label.split(': ')[1], "CS2UI message text for code 2008 should be verified") - - + + def set_data_in_cloud_sync_output_file(message): """ This function is capable to write message into cloud sync folder. @@ -77,7 +129,112 @@ test.log("User written message - %s into out.buf file" %message) utils.waitForGUI(3) +def verify_status(read_line): + read_line = read_line.split('[') + test.log(str(read_line[0])) + return read_line[0] + +def verify_error_message(): + +# set_data_in_cloud_sync_output_file(eError_Unknown_500) +# test.compare(str(verify_status(get_error_message_from_log())),ERROR_MESSAGE["500"], "message is not in unhandled.conf file. verified error message from .err file") +# utils.waitForGUI(2) + + set_data_in_cloud_sync_output_file(eError_HeaderCount_501) + utils.waitForGUI(2) + test.compare(str(verify_status(get_error_message_from_log())),ERROR_MESSAGE["501"], "message is not in unhandled.conf file. verified error message from .err file") + + set_data_in_cloud_sync_output_file(eError_Timestamp_502) + utils.waitForGUI(2) + test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["502"], "message is not in unhandled.conf file. verified error message from .err file") + + set_data_in_cloud_sync_output_file(eError_Sequence_503) + utils.waitForGUI(2) + test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["503"], "message is not in unhandled.conf file. verified error message from .err file") + + set_data_in_cloud_sync_output_file(eError_Crc_504) + utils.waitForGUI(2) + test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["504"], "message is not in unhandled.conf file. verified error message from .err file") + + set_data_in_cloud_sync_output_file(eError_MessageID_505) + utils.waitForGUI(2) + test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["505"], "message is not in unhandled.conf file. verified error message from .err file") + + set_data_in_cloud_sync_output_file(eError_InvalidID_506) + utils.waitForGUI(2) + test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["506"], "message is not in unhandled.conf file. verified error message from .err file") + +# set_data_in_cloud_sync_output_file(eError_ParamCount_507) +# utils.waitForGUI(2) +# test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["507"], "message is not in unhandled.conf file. verified error message from .err file") + + set_data_in_cloud_sync_output_file(eError_ParamMismatch_508) + utils.waitForGUI(2) + test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["508"], "message is not in unhandled.conf file. verified error message from .err file") + + set_data_in_cloud_sync_output_file(eError_ParamMissing_509) + utils.waitForGUI(2) + test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["509"], "message is not in unhandled.conf file. verified error message from .err file") + + set_data_in_cloud_sync_output_file(eError_NoHistory_510) + utils.waitForGUI(2) + test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["510"], "message is not in unhandled.conf file. verified error message from .err file") + +# set_data_in_cloud_sync_output_file(eErrro_Duplicate_511) +# utils.waitForGUI(2) +# test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["511"], "message is not in unhandled.conf file. verified error message from .err file") +# +# set_data_in_cloud_sync_output_file(eError_LogFolder_512) +# utils.waitForGUI(2) +# test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["512"], "message is not in unhandled.conf file. verified error message from .err file") +# set_data_in_cloud_sync_output_file(eError_LogFileInp_513) +# utils.waitForGUI(2) +# test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["513"], "message is not in unhandled.conf file. verified error message from .err file") + + set_data_in_cloud_sync_output_file(eError_CredentialMake_514) + utils.waitForGUI(2) + test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["514"], "message is not in unhandled.conf file. verified error message from .err file") +# set_data_in_cloud_sync_output_file(eError_CredentialFile_515) +# utils.waitForGUI(2) +# test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["515"], "message is not in unhandled.conf file. verified error message from .err file") +# set_data_in_cloud_sync_output_file(eError_CredentialCopy_516) +# utils.waitForGUI(2) +# test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["516"], "message is not in unhandled.conf file. verified error message from .err file") +# set_data_in_cloud_sync_output_file(eError_CredentialRemove_517) +# utils.waitForGUI(2) +# test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["517"], "message is not in unhandled.conf file. verified error message from .err file") +# set_data_in_cloud_sync_output_file(eError_CredentialEmpty_518) +# utils.waitForGUI(2) +# test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["518"], "message is not in unhandled.conf file. verified error message from .err file") +# set_data_in_cloud_sync_output_file(eError_TxCodeNoParam_519) +# utils.waitForGUI(2) +# test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["519"], "message is not in unhandled.conf file. verified error message from .err file") + + set_data_in_cloud_sync_output_file(eError_TxCodeEmpty_520) + utils.waitForGUI(2) + test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["520"], "message is not in unhandled.conf file. verified error message from .err file") + + set_data_in_cloud_sync_output_file(eError_OutFileEmpty_521) + utils.waitForGUI(2) + test.compare(verify_status(get_error_message_from_log()),ERROR_MESSAGE["521"], "message is not in unhandled.conf file. verified error message from .err file") + + + +def verify_log(api_content,error_message): + """ + This function is capable to verify the log data from sd-card + + @param api_content - (string) combination of message id, message text and arguments separated with '\n' + @param message_extracted - (list) list contains extracted data (ack_req, ack_bak, message, message_id). + """ + test.log(str(api_content)) + if api_content == error_message: + return True + else : + return False + + def verify_log_response(actual_cloudsync_data, expected_cloudsync_data): """ This function is used for verifying the expected and actual cloud-sync log data. @@ -94,6 +251,40 @@ for index in (config.CRC_INDEX, config.CODE_INDEX, config.PARAMETER_COUNT, config.PARAMETER_INDEX): test.compare(expected_cloudsync_data[index], actual_cloudsync_data[index], "cloud sync data %s is verified" %expected_cloudsync_data[index]) test.endSection() + +def get_error_message_from_log(): + """ + This function is capable to verify the error logs from sd-card + + @param api_content - (string) combination of message id, message text and arguments separated with '\n' + @param expected_api_argument - (list) expected arguments for API. + """ + utils.waitForGUI(5) + count = 0 + file_name = utility.get_extracted_error_file() + try: + with open(file_name, 'r') as csv_file: + try: + for row in reversed(list(csv.reader(csv_file))): + if row[0].isalpha(): + pass + else: + if count == 30: + test.fail("handler unable to find message text from error file.") + break + row_length = sum(1 for values in row) + try: + if row[1] != None: + return row[1] + + except: + pass + count+=1 + except: + test.fail("application error log data is corrupted") + except: + test.fail("err log file is not created or log file is not created based on standard log naming format.") + def main(): @@ -103,6 +294,7 @@ utils.tstStart(__file__) startApplication(config.AUT_NAME) utils.waitForGUI(1.5) + verify_error_message() main_item = waitForObjectExists(names.o_mainItem_Item) expected_software_version = str(object.children(main_item)[5]) @@ -133,7 +325,7 @@ hd_simulator.cmd_send_hd_operation_mode(op_mode=HDOpModes.MODE_STAN.value, sub_mode=HDOpSubModes.STANDBY_WAIT_FOR_TREATMENT_STATE .value) set_data_in_cloud_sync_output_file(DEVICE_STATE_REQUEST) device_credentials_response = utility.retrive_log_data() - verify_log_response(device_credentials_response[0], DEVICE_STATE_RESPONSE) + verify_log_response(device_credentials_response[0], DEVICE_STATE_RESPONSE) utils.tstDone()