Index: shared/scripts/configuration/config.py =================================================================== diff -u -r0cc92d3b75bfb96dc4ecafd760a9ce15e455033b -r763c81a696187aea9bc076c1fc07f236446aae6b --- shared/scripts/configuration/config.py (.../config.py) (revision 0cc92d3b75bfb96dc4ecafd760a9ce15e455033b) +++ shared/scripts/configuration/config.py (.../config.py) (revision 763c81a696187aea9bc076c1fc07f236446aae6b) @@ -32,3 +32,8 @@ BLOOD_PRIMING_TEXT = "Blood Priming" SALINE_UNIT = "mL" BLOOD_PRIMING_DEFAULT_VALUE = "0 mL" + +RESET_BINARY = "0" +SET_BINARY = "1" #Message binaries appending with for easy identification +ACK_REQ_STATUS = 'Ack Req' +ACK_BAK_STATUS = 'Ack Bak' \ No newline at end of file Index: shared/scripts/configuration/utility.py =================================================================== diff -u -r0cc92d3b75bfb96dc4ecafd760a9ce15e455033b -r763c81a696187aea9bc076c1fc07f236446aae6b --- shared/scripts/configuration/utility.py (.../utility.py) (revision 0cc92d3b75bfb96dc4ecafd760a9ce15e455033b) +++ shared/scripts/configuration/utility.py (.../utility.py) (revision 763c81a696187aea9bc076c1fc07f236446aae6b) @@ -12,13 +12,22 @@ # ############################################################################ - import sys +import csv +import os import test +import glob import squish -from configuration import config +from dialin.ui.hd_simulator import HDSimulator from builtins import int as pyInt +from builtins import int as pyInt +from builtins import format +from datetime import datetime +from dialin.common.msg_ids import MsgIds +hd_simulator = HDSimulator() + +LOG_LOCATION = "/home/denali/Desktop/sd-card/log/*.log" def start_application(app_name): """ @@ -108,3 +117,153 @@ raise LookupError("zone object is not in view to the user after " + \ "trying 100 times") + +def get_extracted_file(): + """ + This function is the handler for getting file from log folder. + + This handler will go inside log folder and looks for newly added log based on current time. + if it satisfied that condition, it will return the exact path of newly created log. + + @return latest_file - (string) returns latest file that append on log folder from sd-data + """ + try: + list_of_files = glob.glob(LOG_LOCATION) + latest_file = max(list_of_files, key=os.path.getctime) + return latest_file + except: + test.fail("log file is not created during application interaction") + return False + + +def get_message_from_log(file_name, message_text): + + """ + This method intended to extract the message from application log. + + The handler find a match between time displayed on log and occurrences time of event to + extract the details. 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 - (string) binary message for the event. + """ + message = "" # Message binaries appending with for easy identification + 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: + message_length = sum(1 for values in row) + for column in range((message_length-1), 3, -1): + message = row[column] + message + return message + else: + pass + except: + test.fail("application log data is corrupted") + except: + test.fail("application log is protected") + + +def get_ack_request_details(file_name, message_text): + """ + This method intended to extract the ack request from application log. + + The handler find a match between time displayed on log and occurrences time of event + along with message id to extract the request acknowledgement. + For row[index], were index represent column to be extracted. + + @param file_name - (string) path of the latest log file created. + @return row[3] - (string) acknowledgement request status. + @return row[4] - (string) Negative requested acknowledgement value (Sq) + """ + 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') + return row[3], row[4], formatted_message_id.replace("00", "") + else: + pass + except: + test.fail("application log data is corrupted - unable to fetch data") + except: + test.fail("application log is protected") + + +def get_bak_request_details(file_name, ack_bak_value): + """ + This method intended to extract the ack from application log. + + The handler find a match between time displayed on log and occurrences time of event + along with message id to extract the request acknowledgement. + For row[index], were index represent column to be extracted. + + @param file_name - (string) path of the latest log file created. + @param message_id - (string) message text to be extracted. + @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) + log_time = row[0].split(':') + 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("application log is protected") + + + +def get_current_log_details(message_ack = None, 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 - (string) 'Y' - if ack is satisfied in log / 'N' - if ack condition is not satisfied + @param message_text - (string) message text to be extracted from log. + @param message_id - (string) message id to be extracted from log. + @return content_record - (list) list contains extracted data (ack_req, ack_bak, message). + """ + 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 != None: + 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 != None 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 Index: tst_ui_logs/test.py =================================================================== diff -u --- tst_ui_logs/test.py (revision 0) +++ tst_ui_logs/test.py (revision 763c81a696187aea9bc076c1fc07f236446aae6b) @@ -0,0 +1,231 @@ +# -*- coding: utf-8 -*- +# from dialin.hd.alarms import * +# from dialin.ui.hd_simulator_alarms import HDAlarmsSimulator, NONE +# import logging +# from dialin.protocols.CAN import DenaliCanMessenger +from dialin.ui import HDSimulator +from dialin.ui import DGSimulator +from dialin.ui import utils +# from dialin.hd.ui_proxy import HDUIProxy +from configuration import utility +from configuration import config +import builtins +# from email import message +from dialin.ui.utils import waitForGUI +from dialin.common.msg_ids import MsgIds + +hd = HDSimulator() +dg = DGSimulator() + +yes = 'Y' + + +def verify_log(msg_id, ack = None, msg = None): + utils.waitForGUI(0.1) + message_extracted = utility.get_current_log_details(message_ack = ack, message_text = msg) + if ack == yes: + 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") +# if msg != None: +# test.verify(msg in message_extracted, "message is verified") + + message_id_hex = builtins.hex(builtins.int(msg_id)) + message_id_str = builtins.str(message_id_hex) + test.log(message_id_str) + test.log(str(message_extracted)) + test.verify(message_id_str in message_extracted, "message ID is verified") + + +def main(): + startApplication("denaliSquish") + + #HD Broadcast + + #0x0D00 + hd.cmd_set_treatment_time(200,60) + verify_log(msg_id = MsgIds.MSG_ID_TREATMENT_TIME.value, ack = yes, msg = "TreatmentTime") + + #0x0500 + hd.cmd_set_treatment_blood_flow_rate(flow_set_pt=20, measured_flow=10.5, + rot_speed = 112.2 , mot_speed = 120.3, mc_speed = 100.0, + mc_current = 12.5, pwm = 32.3, rotor_count = 30) + verify_log(msg_id = MsgIds.MSG_ID_BLOOD_FLOW_DATA.value, ack = yes, msg = "BloodFlow") + + #0x0800 + hd.cmd_set_treatment_dialysate_flow_rate(flow_set_pt=20, measured_flow=10.5, + rot_speed = 112.2 , mot_speed = 120.3, mc_speed = 100.0, + mc_current = 12.5, pwm = 32.3) + verify_log(msg_id = MsgIds.MSG_ID_DIALYSATE_FLOW_DATA.value, ack = yes, msg = "DialysateFlow") + + #0x0900 + hd.cmd_set_pressure_occlusion_data(arterial_prs = 54.5, venous_prs = 20.1, blood_pump_occlusion = 3, + dialysate_inlet_pump_occlusion = 2, dialysate_outlet_pump_occlusion = 5) + verify_log(msg_id = MsgIds.MSG_ID_PRESSURE_OCCLUSION_DATA.value, ack = yes, msg = "Pressure/Occlusion") + + #0x0B00 + hd.cmd_set_treatment_ultrafiltration_outlet_flow_data(ref_uf_vol = 77.5, measured_uf_vol = 22.6, + rot_speed = 54.0, mot_speed = 66.2, mc_speed = 33.3, + mc_current = 21.2, pwm = 322.2) + verify_log(msg_id = MsgIds.MSG_ID_DIALYSATE_OUT_FLOW_DATA.value, ack = yes, msg = "OutletFlow") + + #0x1A00 + hd.cmd_set_treatment_parameter_ranges(min_treatment_duration = 300, max_treatment_duration = 500, + min_uf_volume = 22.6, max_uf_volume = 34.2, + min_dialysate_flow_rate = 3, max_dialysate_flow_rate = 5) + + verify_log(msg_id = str(MsgIds.MSG_ID_TREATMENT_PARAM_CHANGE_RANGES.value), ack = yes, msg = "TreatmentRanges") + + #0x2F00 + hd.cmd_set_treatment_saline_bolus_data(target = 2, cumulative = 90.0, delivered = 67.2) + verify_log(msg_id = MsgIds.MSG_ID_SALINE_BOLUS_DATA.value, ack = yes, msg = "Saline") + + #0x4D00 + hd.cmd_set_treatment_heparin_data(cumulative = 4) + verify_log(msg_id = MsgIds.MSG_ID_HD_HEPARIN_DATA_BROADCAST.value, ack = yes, msg = "Heparin") + + #0x3300 + hd.cmd_send_accelerometer_hd_data(x = 12.3, y = 22.2, z = 4.0, + x_max = 14.0, y_max = 30.2, z_max = 10.5, + x_tilt = 11.0, y_tilt = 22.1, z_tilt = 5.5) + verify_log(msg_id = MsgIds.MSG_ID_HD_ACCELEROMETER_DATA.value, ack = yes, msg = "Accel") + + #0x3A00 + hd.cmd_send_hd_general_response(message_id = 58, accepted = 1, reason = 1) + verify_log(msg_id = MsgIds.MSG_ID_HD_VALVES_DATA.value, ack = yes, msg = "~HD_Valves_Data") + + #0x3E00 + #hd.cmd_send_hd_general_response(message_id = 62, accepted = 1, reason = 1) + hd.cmd_send_hd_air_trap_data(lower_level = 1, upper_level = 10) + verify_log(msg_id = MsgIds.MSG_ID_HD_AIR_TRAP_DATA.value, ack = yes, msg = "AirTrap") + + #0x6900 + hd.cmd_send_hd_general_response(message_id = 105, accepted = 1, reason = 1) + verify_log(msg_id = MsgIds.MSG_ID_HD_SYRINGE_PUMP_DATA.value, ack = yes) + + #0x6A00 + hd.cmd_send_hd_general_response(message_id = 106, accepted = 1, reason = 1) + verify_log(msg_id = MsgIds.MSG_ID_HD_FLUID_LEAK_STATE.value, ack = yes, msg = "~HD_Fluid_Leak_Data") + + #0x6C00 + hd.cmd_send_hd_blood_leak_data(blood_leak_status = 0, blood_leak_state = 1, + blood_leak_zero_status_counter = 2, blood_leak_counter = 3, + blood_leak_zeroed_status = 2, blood_leak_detect_set_point = 1, + blood_leak_detect_level = 1, blood_leak_st_count = 1, + blood_leak_led_intensity = 2, blood_leak_register_counter = 3) + verify_log(msg_id = MsgIds.MSG_ID_HD_BLOOD_LEAK_DATA.value, ack = yes, msg = "BloodLeak") + + #0x9300 + hd.cmd_send_hd_air_bubble_data(venous_air_bubble_status = 2, venous_air_bubble_state = 0) + verify_log(msg_id = MsgIds.MSG_ID_HD_BUBBLES_DATA.value, ack = yes, msg = "AirBubble") + + #0x7B00 + hd.cmd_send_hd_general_response(message_id = 123, accepted = 1, reason = 1) + verify_log(msg_id = MsgIds.MSG_ID_HD_VOLTAGES_DATA.value, ack = yes, msg = "~HD_Voltages_Data") + + #0x7D00 + hd.cmd_send_hd_general_response(message_id = 125, accepted = 1, reason = 1) + verify_log(msg_id = MsgIds.MSG_ID_HD_ALARM_INFORMATION.value, ack = yes, msg = "~HD_Alarm_Information") + + #0xA200 + hd.cmd_send_hd_general_response(message_id = 162, accepted = 1, reason = 1) + verify_log(msg_id = MsgIds.MSG_ID_HD_SWITCHES_DATA.value, ack = yes, msg = "~HD_Switches_Data") + + #0x9D00 + hd.cmd_send_hd_general_response(message_id = 157, accepted = 1, reason = 1) + verify_log(msg_id = MsgIds.MSG_ID_HD_TEMPERATURES_DATA.value, ack = yes, msg = "~HD_Temperature_Data") + + #0xA300 + hd.cmd_send_hd_general_response(message_id = 163, accepted = 1, reason = 1) + verify_log(msg_id = MsgIds.MSG_ID_HD_FANS_DATA.value, ack = yes, msg = "~HD_Fans_Data") + + #0xA800 + hd.cmd_send_hd_general_response(message_id = 168, accepted = 1, reason = 1) + verify_log(msg_id = MsgIds.MSG_ID_HD_RESERVOIRS_DATA.value, ack = yes, msg = "~HD_Reservoirs_Data") + + + #HD Operation Mode + #0x2500 + for mode in range(9): + hd.cmd_send_hd_operation_mode(op_mode = mode) + verify_log(msg_id = MsgIds.MSG_ID_HD_OP_MODE.value, ack = yes, msg = "OpMode") + + #0x5C00 + for s_mode in range(9): + hd.cmd_send_pre_treatment_state_data(sub_mode = s_mode, water_sample_state = 0, consumables_self_test_state = 0, + no_cartridge_self_test_state = 0, installation_state = 0, + dry_self_test_state = 0, prime_state = 0, + recirculate_state = 0, patient_connection_state = 0) + verify_log(msg_id = MsgIds.MSG_ID_PRE_TREATMENT_STATE.value, ack = yes, msg = "PreTreatmentStates") + + #0x0F00 + for s_mode in range(3): + hd.cmd_set_treatment_states_data(sub_mode = s_mode, uf_state = 0, saline_state = 0, heparin_state = 0, + rinseback_state = 0, recirculate_state = 0, blood_prime_state = 0, + treatment_end_state = 0, treatment_stop_state = 0, dialysis_state = 0) + verify_log(msg_id = MsgIds.MSG_ID_TREATMENT_STATE.value, ack = yes, msg = "TreatmentStates") + + #0x7700 + #for s_mode in range(3): + hd.cmd_send_hd_general_response(message_id = 119, accepted = 1, reason = 1) + verify_log(msg_id = MsgIds.MSG_ID_HD_POST_TREATMENT_STATE.value, ack = yes, msg = "PostTreatmentStates") + + #0x7E00 + for s_mode in range(3): + hd.cmd_send_hd_disinfection_state(sub_mode = s_mode, flush_mode = 0, heat_mode = 0, chemical_mode = 0) + verify_log(msg_id = MsgIds.MSG_ID_HD_DISINFECT_STANDBY_DATA.value, ack = yes, msg = "DisinfectStates") + + #0x9A00 UI-HD + + #0x9B00 +# hd.cmd_send_hd_disinfect_response(accepted = True, reason =1) + hd.cmd_send_hd_general_response(message_id = 155, accepted = 1, reason = 1) + verify_log(msg_id = MsgIds.MSG_ID_HD_SET_STANDBY_DISINFECT_SUB_MODE_RESPONSE.value, ack = yes, msg = "~HD_Set_Standby_Disinfect_State_Response") + + #RINSEBACK + + #0x5200 UI-HD + + #0x5300 + hd.cmd_send_treatment_adjust_rinseback_response(accepted = 1, reason = 0) + verify_log(msg_id = MsgIds.MSG_ID_HD_RINSEBACK_CMD_RESPONSE.value, ack = yes, msg = "AdjustRinseback") + + #0x5400 + + #0x5500 + hd.cmd_send_treatment_adjust_recirculate_response(accepted = 1, reason = 0) + verify_log(msg_id = MsgIds.MSG_ID_HD_RECIRC_CMD_RESPONSE.value, ack = yes, msg = "AdjustRecirculate") + + #0x5600 + hd.cmd_send_treatment_rinseback_data(target_vol = 2.4, current_vol = 1.9, flow_rate = 1, timeout = 4, + timeout_countdown = 8, is_completed = False) + verify_log(msg_id = MsgIds.MSG_ID_HD_RINSEBACK_PROGRESS.value, ack = yes, msg = "Rinseback") + + #0x5A00 + hd.cmd_send_treatment_recirculate_data(timeout_total = 200, timeout_count_down = 100) + verify_log(msg_id = MsgIds.MSG_ID_HD_RECIRC_PROGRESS.value, ack = yes, msg = "Recirculate") + + #0x5800 + hd.cmd_send_treatment_adjust_end_response(accepted = 1, reason = 0) + verify_log(msg_id = MsgIds.MSG_ID_HD_TX_END_CMD_RESPONSE.value, ack = yes, msg = "AdjustTxEnd") + + #0x5900 + hd.cmd_send_treatment_blood_prime_data(target = 22.2, current = 33.3) + verify_log(msg_id = MsgIds.MSG_ID_HD_BLOOD_PRIME_PROGRESS.value, ack = yes, msg = "BloodPrime") + + #0x4900 + hd.cmd_send_hd_general_response(message_id = 73, accepted = 1, reason = 1) + verify_log(msg_id = MsgIds.MSG_ID_HD_TREATMENT_STOP_TIMER_DATA.value, ack = yes, msg = "Stop") + + #RTC + + #0x0A00 + hd.cmd_send_hd_general_response(message_id = 10, accepted = 1, reason = 1) + verify_log(msg_id = MsgIds.MSG_ID_RTC_EPOCH.value, ack = yes, msg = "~HD_RTC_Epoch_Data") + + #0x6E00 + hd.cmd_send_set_rtc_response(response = 1, reason = 0) + verify_log(msg_id = MsgIds.MSG_ID_HD_UI_SET_RTC_RESPONSE.value, ack = yes, msg = "AdjustHDDateTime") + + #0x7000 + dg.cmd_send_set_rtc_response(response = 1, reason = 0) + verify_log(msg_id = MsgIds.MSG_ID_DG_UI_SET_RTC_RESPONSE.value, ack = yes, msg = "AdjustDGDateTime")