Index: tst_unhandled_message_log/test.py =================================================================== diff -u -r202db82fbc4b2e68aa017afd7996245610ccdb59 -r79c4043b5b7174481a3ec7826d114a98dbfe3100 --- tst_unhandled_message_log/test.py (.../test.py) (revision 202db82fbc4b2e68aa017afd7996245610ccdb59) +++ tst_unhandled_message_log/test.py (.../test.py) (revision 79c4043b5b7174481a3ec7826d114a98dbfe3100) @@ -21,54 +21,63 @@ from dialin.ui import utils from configuration import utility from configuration import config +from dialin.utils.conversions import float_to_bytearray, integer_to_bytearray,unsigned_integer_to_bytearray hd_simulator = HDSimulator() LOCATION = '/home/denali/Projects/application/resources/settings/Messages/Unhandled.conf' -UNHANDLED_MESSAGE_1 = "\n[0x2A00]\nHD_custom_data_verification_1\nU32=unsigned_32bit\nU32=argument_2\n" -UNHANDLED_MESSAGE_2 = "\n[0x8C00]\nHD_custom_data_verification_2\nF32=float_argument\nS16=argument_2\n" -UNHANDLED_MESSAGE_3 = "\n[0x9F00]\nHD_custom_data_verification_3\nU16=unsigned_16bit\nS32=argument_2\n" -PREDEFINED_UNHANDLED_MESSAGE_1 = "\n[0x3A00]\nHD_Valves_Data\nU32=ValveID\nU32=PosID\nS16=Position\nS16=Next Position\nF32=Current\nS16=PositionC\nS16=PositionA\nS16=PositionB\nU32=PWM DC\nU32=Air Trap Valve State\n" -PREDEFINED_UNHANDLED_MESSAGE_2 = "\n[0x7A00]\nDG_Flush_Data\nU32=State\nU32=Time\nU32=State Time\n" -PREDEFINED_UNHANDLED_MESSAGE_3 = "\n[0x4500]\nDG_Thermistors_Data\nU32=F32=Board Temp\nU32=F32=PS1 Temp\nU32=F32=PS2 Temp\n" +DUMMY_FLOAT_VALUE_1 = 1.250 +DUMMY_FLOAT_VALUE_2 = 5.855 +DUMMY_INT_VALUE_1 = 25 +DUMMY_INT_VALUE_2 = 32 +DUMMY_UNSIGNED_INT_VALUE = 5 +UNHANDLED_MESSAGE_1 = "\n[0xBB00]\nHD_custom_data_verification_1\nU32=unsigned_32bit\nU32=argument_2\n" +UNHANDLED_MESSAGE_2 = "\n[0xAA00]\nHD_custom_data_verification_2\nF32=float_argument\nS32=argument_2\n" + ERROR_MESSAGE = { "0x1300" : "Incorrect data length (9 of 32) for received Message with ID '0x1300'", "0x0900" : "Incorrect data length (9 of 20) for received Message with ID '0x0900'" } -def verify_log(api_content, expected_api_argument): +def verify_log(api_content): """ 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 expected_api_argument - (list) expected arguments for API. + @param message_extracted - (list) list contains extracted data (ack_req, ack_bak, message, message_id). """ - utils.waitForGUI(2) - api_content = api_content.split('\n') - test.log(str(api_content[2])) - message_extracted = utility.get_current_log_details(message_ack = True, message_text = '~'+api_content[2]) + utils.waitForGUI(5) + test.log(str(api_content)) + message_extracted = utility.get_current_log_details(message_ack = True, message_text = '~'+api_content) test.log(str(message_extracted)) #loop to remove default arguments present in API, here it is '?' while('?' in message_extracted[0]): message_extracted[0].remove('?') - - #step to remove square bracket and padded zeros from standard UNHANDLED_MESSAGE format. - formated_meassage_id = api_content[1].replace('[', "") + + return message_extracted + + +def convert_message_id_from_unhandled_file_format_to_standared_format(message_id): + """ + This function is capable to remove square bracket and to convert message id into firmware support format. + + @param message_id - (string) message id from unhandled.conf file. + @return expected_meassage_id - (string) message id in the standared format. + """ + formated_meassage_id = message_id.replace('[', "") formated_meassage_id = formated_meassage_id.replace(']', "") if formated_meassage_id[-2:] == '00' and len(formated_meassage_id) == 6: - expected_meassage_id = formated_meassage_id.replace("00", "") - - test.compare(expected_meassage_id.lower(), message_extracted[2], "message id should be "+str(api_content[1])) - test.compare(str(expected_api_argument), str(message_extracted[0]), "API arguments should be "+str(expected_api_argument)) - test.verify(config.ACK_REQ_STATUS in message_extracted, "ack request is verified") - test.verify(config.ACK_BAK_STATUS in message_extracted, "ack back is verified") - + expected_meassage_id = formated_meassage_id.replace("00", "") + return expected_meassage_id + else: + return formated_meassage_id + def get_error_message_from_log(): """ @@ -91,8 +100,13 @@ test.fail("handler unable to find message text from error file.") break row_length = sum(1 for values in row) - if "'" in row[1]: - return row[1] + try: + if "'" in row[1]: + return row[1] + if "Unhandled Message ID (HD)" in row[1]: + return True + except: + pass count+=1 except: test.fail("application error log data is corrupted") @@ -113,7 +127,6 @@ with open(LOCATION, "a") as filereader: filereader.write(UNHANDLED_MESSAGE_1) filereader.write(UNHANDLED_MESSAGE_2) - filereader.write(UNHANDLED_MESSAGE_3) utils.waitForGUI(5) @@ -126,9 +139,6 @@ NB: it is a single time callable method should use only after calling "modify_unhandled_configuration_file()" method. """ count = 0 - for value in UNHANDLED_MESSAGE_3: - if value == '\n': - count+=1 for value in UNHANDLED_MESSAGE_2: if value == '\n': count+=1 @@ -148,42 +158,85 @@ utils.tstStart(__file__) startApplication(config.AUT_NAME) - - #0x3A00 - hd_simulator.cmd_send_hd_general_response(message_id = 58, accepted = 1, reason = 1) - verify_log(PREDEFINED_UNHANDLED_MESSAGE_1, [1, 1]) - #0x8600 - hd_simulator.cmd_send_hd_general_response(message_id = 122, accepted = 0, reason = 1) - verify_log(PREDEFINED_UNHANDLED_MESSAGE_2, [0, 1]) + #checking if the message is not in the unhandled (err) + hd_simulator.cmd_send_hd_general_response(message_id = 275, accepted = 1, reason = 1) + unhandled_status = get_error_message_from_log() + test.verify(unhandled_status == True, "message is not in unhandled.conf file. verified error message from .err file") - #0x4500 - hd_simulator.cmd_send_hd_general_response(message_id = 69, accepted = 1, reason = 0) - verify_log(PREDEFINED_UNHANDLED_MESSAGE_3, [1.4013e-45, 0]) - + #checking if the message is not in the unhandled (err) + hd_simulator.cmd_send_hd_general_response(message_id = 276, accepted = 1, reason = 1) + unhandled_status = get_error_message_from_log() + test.verify(unhandled_status == True, "message is not in unhandled.conf file. verified error message from .err file") + + + #checking the id exists and parameters passed is not correct regarding the definition in the conf. (err) #0x1300 hd_simulator.cmd_send_hd_general_response(message_id = 19, accepted = 1, reason = 1) error_message = get_error_message_from_log() test.compare(error_message, ERROR_MESSAGE["0x1300"], "error code should be verified in log file") + #checking the id exists and parameters passed is not correct regarding the definition in the conf. (err) #0x0900 hd_simulator.cmd_send_hd_general_response(message_id = 9, accepted = 0, reason = 0) error_message = get_error_message_from_log() test.compare(error_message, ERROR_MESSAGE["0x0900"], "error code should be verified in log file") - - #0x2A00 - hd_simulator.cmd_send_hd_general_response(message_id = 42, accepted = 1, reason = 0) - verify_log(UNHANDLED_MESSAGE_1, [1, 0]) - #0x8C00 - hd_simulator.cmd_send_hd_general_response(message_id = 140, accepted = 0, reason = 0) - verify_log(UNHANDLED_MESSAGE_2, [0, 0]) - #0x9F00 - hd_simulator.cmd_send_hd_general_response(message_id = 159, accepted = 0, reason = 4) - verify_log(UNHANDLED_MESSAGE_3, [0, 262144]) + #checking the number of parameters are correct but the type is not correct. (err) + #0x0A00 + payload = float_to_bytearray(DUMMY_FLOAT_VALUE_1) #expected negative scenario verification + hd_simulator.cmd_send_hd_general_response(message_id = 10, accepted = 1, reason = 1, is_pure_data = False, has_parameters = True, parameters_payload = payload) + log_data = verify_log("HD_RTC_Epoch_Data") + test.verify(DUMMY_FLOAT_VALUE_1 not in log_data, "parameters type should show deviation in negative scenario.") + + #checking the number of parameters are correct but the type is not correct. (err) + #0x7D00 + payload = integer_to_bytearray(DUMMY_INT_VALUE_1) + payload += float_to_bytearray(DUMMY_FLOAT_VALUE_1) + payload += float_to_bytearray(DUMMY_FLOAT_VALUE_2) + payload += float_to_bytearray(DUMMY_FLOAT_VALUE_1) + payload += float_to_bytearray(DUMMY_INT_VALUE_2) #expected negative scenario verification + hd_simulator.cmd_send_hd_general_response(message_id = 125, accepted = 1, reason = 1, is_pure_data = False, has_parameters = True, parameters_payload = payload) + log_data = verify_log("HD_Alarm_Information") + test.verify([DUMMY_INT_VALUE_1, DUMMY_FLOAT_VALUE_1, DUMMY_FLOAT_VALUE_2, DUMMY_FLOAT_VALUE_1, DUMMY_INT_VALUE_1] not in log_data, "parameters type should show deviation in negative scenario.") + + + #checking everything is passed correctly. (log) + #0xBB00 + payload = integer_to_bytearray(DUMMY_INT_VALUE_1) + payload += integer_to_bytearray(DUMMY_INT_VALUE_2) + hd_simulator.cmd_send_hd_general_response(message_id = 187, accepted = 1, reason = 1, is_pure_data = False, has_parameters = True, parameters_payload = payload) + unhandled_message = UNHANDLED_MESSAGE_1.split('\n') + #unhandled_message[2] is the expected message in unhandled.conf after API call + #unhandled_message[1] is the expected message id in unhandled.conf after API call + log_data = verify_log(unhandled_message[2]) + message_id = convert_message_id_from_unhandled_file_format_to_standared_format(unhandled_message[1]) + test.verify(message_id.lower() in log_data, "message id should be "+str(unhandled_message[1])) + test.verify([DUMMY_INT_VALUE_1, DUMMY_INT_VALUE_2] in log_data, "API arguments should be "+str([DUMMY_INT_VALUE_1, DUMMY_INT_VALUE_2])) + test.verify(config.ACK_REQ_STATUS in log_data, "ack request is verified") + test.verify(config.ACK_BAK_STATUS in log_data, "ack back is verified") + + + #checking everything is passed correctly. (log) + #0xAA00 + payload = float_to_bytearray(DUMMY_FLOAT_VALUE_1) + payload += unsigned_integer_to_bytearray(DUMMY_UNSIGNED_INT_VALUE) + hd_simulator.cmd_send_hd_general_response(message_id = 170, accepted = 1, reason = 0, is_pure_data = False, has_parameters = True, parameters_payload = payload) + + unhandled_message = UNHANDLED_MESSAGE_2.split('\n') + #unhandled_message[2] is the expected message in unhandled.conf after API call + #unhandled_message[1] is the expected message id in unhandled.conf after API call + log_data = verify_log(unhandled_message[2]) + message_id = convert_message_id_from_unhandled_file_format_to_standared_format(unhandled_message[1]) + test.verify(message_id.lower() in log_data, "message id should be "+str(unhandled_message[1])) + test.verify([DUMMY_FLOAT_VALUE_1, DUMMY_UNSIGNED_INT_VALUE] in log_data, "API arguments should be "+str([DUMMY_FLOAT_VALUE_1, DUMMY_UNSIGNED_INT_VALUE, 0])) + test.verify(config.ACK_REQ_STATUS in log_data, "ack request is verified") + test.verify(config.ACK_BAK_STATUS in log_data, "ack back is verified") + + demodify_unhandled_configuration_file() utils.tstDone()