Index: tst_unhandled_message_log/test.py =================================================================== diff -u -r517be87a624e12b2529479481a5cc2825e0827ec -r8ab173b73aee8c664388a5ad87ea39fedcc43b11 --- tst_unhandled_message_log/test.py (.../test.py) (revision 517be87a624e12b2529479481a5cc2825e0827ec) +++ tst_unhandled_message_log/test.py (.../test.py) (revision 8ab173b73aee8c664388a5ad87ea39fedcc43b11) @@ -13,8 +13,10 @@ # # NOTE: -# This test verifies the unhandled logs for the messages provided +# This test verifies the unhandled logs for the messages provided. +# Scenarios are covered based on equivalence partitioning method of testing. +import csv from dialin.ui.hd_simulator import HDSimulator from dialin.ui import utils from configuration import utility @@ -23,10 +25,15 @@ hd_simulator = HDSimulator() -UNHANDLED_MESSAGE_1 = "\n[0x2A00]\nHD_custom_data_verification_1\nU32=Reset\nU32=Health\n" -UNHANDLED_MESSAGE_2 = "\n[0x1300]\nHD_custom_data_verification_2\nU32=Reset_1\nU32=Reset_2\nU32=Reset_3\nU32=Reset_4\n" -UNHANDLED_MESSAGE_3 = "\n[0x8C00]\nHD_custom_data_verification_3\nU32=Reset\nU32=Seconds\n" -UNHANDLED_MESSAGE_4 = "\n[0x9F00]\nHD_custom_data_verification_4\nU32=Reset\nU32=Seconds\n" +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_MESSAGE = "\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" +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): @@ -37,7 +44,7 @@ @param expected_api_argument - (list) expected arguments for API. """ - utils.waitForGUI(0.2) + 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]) @@ -58,47 +65,115 @@ 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") + +def get_error_message_from_log(): + """ + This function is capable to verify the error logs from sd-card -def navigate_unhandled_message(): + @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) + if "'" in row[1]: + return row[1] + 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 modify_unhandled_configuration_file(): + """ + This function is capable to write custom API's on unhandled.conf folder. - location = '/home/denali/Projects/application/resources/settings/Messages/Unhandled.conf' - with open(location, "a") as filereader: + unhandled.conf location = '/home/denali/Projects/application/resources/settings/Messages/Unhandled.conf' + + Through this method filereader act as a handler and it will write custom unhandled messages on Unhandled.conf + NB: it is a single time callable method should only use before starting the application. it is mandatory + to use demodify_unhandled_configuration_file() at the end of the testcase. + """ + with open(LOCATION, "a") as filereader: filereader.write(UNHANDLED_MESSAGE_1) filereader.write(UNHANDLED_MESSAGE_2) filereader.write(UNHANDLED_MESSAGE_3) - filereader.write(UNHANDLED_MESSAGE_4) utils.waitForGUI(5) - + +def demodify_unhandled_configuration_file(): + """ + This function is capable to remove custom API's which is written during method "modify_unhandled_configuration_file()". + + unhandled.conf location = '/home/denali/Projects/application/resources/settings/Messages/Unhandled.conf' + + 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 + for value in UNHANDLED_MESSAGE_1: + if value == '\n': + count+=1 + with open(LOCATION, "r") as filereader: + lines = filereader.readlines() + with open(LOCATION, "w") as filereader: + filereader.writelines(lines[:-count]) + + + def main(): - navigate_unhandled_message() + modify_unhandled_configuration_file() + utils.tstStart(__file__) startApplication("denaliSquish") + + #0x3A00 + hd_simulator.cmd_send_hd_general_response(message_id = 58, accepted = 1, reason = 1) + verify_log(PREDEFINED_MESSAGE, [1, 1]) + #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") + + #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 = 1) - verify_log(UNHANDLED_MESSAGE_1, [1, 1]) + hd_simulator.cmd_send_hd_general_response(message_id = 42, accepted = 1, reason = 0) + verify_log(UNHANDLED_MESSAGE_1, [1, 0]) - #0x9 - hd_simulator.cmd_send_hd_general_response(message_id = 19, accepted = 1, reason = 1) - #verify_log(UNHANDLED_MESSAGE_2) - #0x8C00 hd_simulator.cmd_send_hd_general_response(message_id = 140, accepted = 0, reason = 0) - verify_log(UNHANDLED_MESSAGE_3, [0, 0]) + verify_log(UNHANDLED_MESSAGE_2, [0, 0]) #0x9F00 - hd_simulator.cmd_send_hd_general_response(message_id = 159, accepted = 0, reason = 1) - verify_log(UNHANDLED_MESSAGE_4, [0, 1]) + hd_simulator.cmd_send_hd_general_response(message_id = 159, accepted = 0, reason = 4) + verify_log(UNHANDLED_MESSAGE_3, [0, 262144]) + + demodify_unhandled_configuration_file() utils.tstDone() - - - - - - \ No newline at end of file