def resolve_xml(self): """Resolve the matched xml files. Searching order in the configuration trees: 1. $LETP_TESTS 2. letp-internal 3. LeTP """ if "$LETP_TESTS" in self.config_path: xml_file = os.path.expandvars(self.config_path) return self._find_xml_config(xml_file) else: current_path = pathlib.Path(os.path.abspath(__file__)) letp_test_config_dir = os.path.expandvars("$LETP_TESTS") letp_internal_config_dir = os.path.expandvars( "$LETP_INTERNAL_PATH") letp_config_dir = os.path.join(current_path.parent) for dir_name in [ letp_test_config_dir, letp_internal_config_dir, letp_config_dir, ]: if not (dir_name and os.path.exists(dir_name)): continue xml_file_path = os.path.join(dir_name, self.config_path) resolved_xml_file = self._find_xml_config(xml_file_path) if resolved_xml_file: swilog.info("{} will be used".format(resolved_xml_file)) return resolved_xml_file swilog.error("Cannot resolve {}".format(self.config_path)) return None
def are_apps_running(target, app_names): """Check the applications are running. Args: target: target fixture to communicate with the module app_name: names of the application Returns: True if all applications are running, False instead and None if it was not possible to determine the status. """ _exit, rsp = target.run("app status", withexitstatus=True) if _exit != 0: swilog.error("Unable to get apps status") return None app_list = rsp.strip().split("\r\n") for app in app_list: status, app_name = app.strip().split(" ") if app_name not in app_names: continue if status != "[running]": swilog.info("%s is not running" % app_name) return False app_names.remove(app_name) if len(app_names) != 0: swilog.info("The following apps have not been found: %s" % ",".join(app_names)) return False return True
def are_apps_installed(target, apps): """Check if apps with the given name exists. The format is either {app_name: version, ...} or [app_name, ...] """ _exit, rsp = target.run("app list", withexitstatus=True) if _exit != 0: swilog.error("Unable to list the apps installed") return None app_list = rsp.strip().split("\r\n") for app in app_list: if app in apps: swilog.info("Application %s exists. Now checking the version" % app) if isinstance(apps, dict): expected_version = apps[app] if expected_version and expected_version != "": ver_check = version_validity(expected_version) if ver_check == 0: swilog.info("%s has no version" % app) else: _exit, rsp = target.run("app version %s" % app, withexitstatus=1) found_version = rsp.strip().split(" ")[1] if found_version == expected_version: apps.pop(app) else: # No version to check apps.pop(app) else: # No version to check apps.remove(app) return len(apps) == 0
def login(self, timeout=90): """Login to the embedded Linux console.""" delay = 10 count = int(timeout / delay) while self.check_communication() != 0: count -= 1 if count <= 0: swilog.error("No communication with the target after %ds.", timeout) break swilog.warning( "No communication with the target. Trying again in %ds.", delay) time.sleep(delay) try: super(target_ssh_qct, self).login(self.target_ip, "root", auto_prompt_reset=False, port=self.ssh_port) setup_linux_login(self) except Exception as inst: if not setup_linux_login(self): raise ComException("Unable to login") exit_code = 1 count = 0 while exit_code != 0: exit_code, rsp = self.run("stty columns %d" % TTY_SIZE, withexitstatus=1) count += 1 assert count != 5, "Impossible to send command stty to target"
def test_AT_commands_expect(target): """Send a command and expect/search for regexp patterns. Args: target: fixture to communicate with the target """ # target.run_at_cmd uses low level functions: send + expect. # They can be used to control what to send and what to receive. # Send ATI9, wait for IMEI SV rsp = target.send("/usr/bin/microcom /dev/ttyAT\r\n") target.send("ATI9\r") # expect will find patterns in a list and return # which pattern it has found rsp = target.expect([pexpect.TIMEOUT, "IMEI SV: "], 10) if rsp == 0: # Found the first pattern (pexpect.TIMEOUT) swilog.error("Timeout") elif rsp == 1: # Found the second element: "IMEI SV: " # Now get the IMEI SV rsp = target.expect([pexpect.TIMEOUT, r"\d+\r"], 10) # target.at.before is the content of the received data # target.at.after is the content of the regexp swilog.info("IMEI SV is %s" % target.after.strip()) # get the end of the command rsp = target.expect(["OK"], 10) target.sendcontrol("x")
def wait_for_device_up(self, timeout=0): """Wait for the device to be up.""" if self.slink1: return self.slink1.wait_for_device_up(timeout) elif self.ssh: return self.ssh.wait_for_device_up(timeout) swilog.error("No link available.") raise SlinkException
def test_debug_level(): """Test debug values in different levels.""" print("test debug starts") swilog.debug("debug level message") swilog.info("info level message") swilog.warning("warning level message") swilog.error("error level message") swilog.critical("critical level message") print("test debug ends")
def verify_when_build_successful(ipc_type_str, interface_opts_str, build_cmd_str, is_binded_str, api_type_str): """Verify if the building is successful. Args: ipc_type_str: ipc type client-side IPC server-side IPC interface_opts_str: interface optionals [optional] [optional] [manual-start] [optional] [types-only] build_cmd_str: build command mkapp: command to make application mksys: command to make system is_binded_str: binding string bound not bound api_type_str: directory name of API type legato API customized API """ if ipc_type_str in "client-side IPC": if (interface_opts_str in "[optional]") or (interface_opts_str in "[optional] [manual-start]"): # Build succesful when client-side IPC # With interface options [optional]/[optional] [manual-start] swilog.info("%s doesn't complain when the %s API is %s to %s " "with the interface options: %s" % ( build_cmd_str, ipc_type_str, is_binded_str, api_type_str, interface_opts_str, )) else: # Build successful when client-side IPC # With interface options [optional] [types-only] swilog.error("%s doesn't complain when the %s API is %s to %s " "with the interface options: %s" % ( build_cmd_str, ipc_type_str, is_binded_str, api_type_str, interface_opts_str, )) else: # Build successful when server-side IPC # With interface options that contain optional swilog.error( "%s doesn't complain when the %s provides %s " "with interface options: %s" % (build_cmd_str, ipc_type_str, api_type_str, interface_opts_str))
def test_swilog_call(): """Activate the debug level to see all the messages. Usage:: "letp run --dbg-lvl 0 test/host/scenario/test_swilog.py" """ swilog.debug("debug message") swilog.info("info message") # to highlight a particular step in the test swilog.step("step message") swilog.warning("warning message") swilog.error("error message") swilog.critical("critical message")
def is_directory_on_target(target, path, directory): """Check for <directory> relative to path. Args: target: fixture to communicate with the target path: path of directory directory: name of directory """ exit_status, rsp = target.run("[ -d %s/%s ]" % (path, directory), withexitstatus=True) swilog.debug(rsp) if exit_status == 0: swilog.info("Found bundled directory %s" % directory) else: swilog.error("Could not find bundled directroy %s" % directory)
def L_MY_TEST_0001(target): """Test AT port of the target. Args: target: Object received by the test function to communicate with the target. """ # Print a message swilog.info("This is my test") # Send AT command. Expect OK. Timeout of 1s target.run_at_cmd("AT", 1) # Send AT+CPIN? command. Expect +CPIN: READY, then OK target.run_at_cmd("AT+CPIN?", 1, [r"\+CPIN: READY\r", "OK\r"]) # Send AT+CPIN=530 command. Expect ERROR rsp = target.run_at_cmd("AT+CPIN=530", 1, ["ERROR"]) # print the content of the received data swilog.info("Receive %s" % rsp) # target.run_at_cmd uses low level functions: send + expect. # They can be used to control # what to send and what to receive. # Send ATI9, wait for IMEI-SV rsp = target.send("/usr/bin/microcom /dev/ttyAT \r\n") target.send("ATI9\r\n") # expect will find patterns in a list and return which pattern it has found rsp = target.expect([pexpect.TIMEOUT, r"IMEI.SV: "], 10) if rsp == 0: # Found the first pattern (pexpect.TIMEOUT) swilog.error("Timeout") elif rsp == 1: # Found the second element: "IMEI-SV: " # Now get the IMEI-SV target.expect([pexpect.TIMEOUT, r"\d+\r"], 10) # target.at.before is the content of the received data before the found regexp # target.at.after is the content of the regexp swilog.info("IMEI SV is %s" % target.after.strip()) # get the end of the command target.expect(["OK"], 10) # Expect some patterns in a list (in order of the list) # Send ATI9, wait for first atSwi, then UBOOT, then Apps and then OK target.send("ATI9\r") rsp = target.expect_in_order([r"IMEI.SV", "OK"], 10) swilog.info("Receive: %s" % rsp) target.sendcontrol("x") target.run("cm info")
def metrics(request, read_config): """Fixture to collect and export fine grained metrics data. Users need to define metrics module to upload the performance data. e.g. elasticsearch. """ try: # pylint: disable=import-outside-toplevel from letp_internal.metrics import Metrics except ModuleNotFoundError: swilog.error("metrics module was not implemented.") return collector = Metrics(request) yield collector collector.export(read_config)
def L_SecureStorage_0004(legato): """Multiple apps have independent access to the secured storage. Verification: This test case will mark as "failed" when 1. both apps can't read its independent written contents This script will 1. In one Legato app, use the "write" API of the secure storage component to write data to the secured storage, with a particular storage item name. 2. In a different Legato app, use the "write" API and the same storage item name as step 1, write different data from step 1 to the secured storage. 3. Verify that the data in the two different apps are independently stored, by using the "read" API in both apps, and check that the data read are as per the originally written data in steps 1 and 2. :param legato: fixture to call useful functions regarding legato :param test_app: fixture regarding to build, install and remove app """ swilog.step("Execute L_SecureStorage_0004") legato.clear_target_log() legato.runProc("%s" % TEST_APP_A, "--exe=%s" % TEST_APP_A, "write") legato.runProc("%s" % TEST_APP_B, "--exe=%s" % TEST_APP_B, "write") legato.runProc("%s" % TEST_APP_A, "--exe=%s" % TEST_APP_A, "read") legato.runProc("%s" % TEST_APP_B, "--exe=%s" % TEST_APP_B, "read") time.sleep(10) rsp1 = legato.find_in_target_log( "appA successfully read" " its own written content" ) rsp2 = legato.find_in_target_log( "appB successfully read" " its own written content" ) if not rsp1: swilog.error("%s doesn't read what it wrote" % TEST_APP_A) if not rsp2: swilog.error("%s doesn't read what it wrote" % TEST_APP_B) failed_testcases_list = swilog.get_error_list() if failed_testcases_list != []: assert 0, "Some tests failed:\n%s" % "\n".join(failed_testcases_list) else: swilog.info("[PASSED] L_SecureStorage_0004")
def L_CDEF_0004(legato): """Verify the provides and requires sections of cdef files. Args: legato: fixture to call useful functions regarding legato """ # Provide/Require Section: # Look for string to ensure apps are communicating using API rsp = legato.find_in_target_log("Client says 'Hello, world!'") if rsp: swilog.info("Found Server response string") else: swilog.error("Did not find Server response string") failed_testcases_list = swilog.get_error_list() if failed_testcases_list != []: assert 0, "Some tests failed:\n%s" % "\n".join(failed_testcases_list)
def is_file_on_target(target, path, file_name): """Check for <file> relative to path. Args: target: fixture to communicate with the target legato: fixture to call useful functions regarding legato path: path of file file_name: the name of file """ exit_status, rsp = target.run("[ -f %s/%s ]" % (path, file_name), withexitstatus=True) swilog.debug(rsp) if exit_status == 0: swilog.info("Found bundled file %s" % file_name) else: swilog.error("Could not find bundled file %s" % file_name)
def is_app_running(target, app_name): """Check the application is running. Args: target: fixture to communicate with the target app_name: name of the application Return: True if the application is running, False instead and None if it was not possible to determine the status. """ _exit, rsp = target.run("app status %s" % (app_name), withexitstatus=True) if _exit != 0: swilog.error("Unable to determine if app %s is running or not" % app_name) return None return "[running]" in rsp
def L_CDEF_0028(target, legato): """Verify the binding is not existed after app's deployment. when its client-side IPC API is not bounded to any server-side API with the interface option: [optional] Verification: This test case will mark as "failed" when 1. Arbitrary binding is existed in the output of the command line \ "sdir list" This script will 1. Build and install the test app, optional_withoutBindings 2. Run the command line in the target, "sdir list" 3. Check the existence of the binding :param target: fixture to communicate with the target :param legato: fixture to call useful functions regarding legato """ cmd = "/legato/systems/current/bin/sdir list" # LogClient is the default hardcoded binding which created # When any user app has been deployed onto the target log_client_binding_name = "LogClient" # Make and install legato.make_install(APP_NAME, APP_PATH) rsp = target.run(cmd) if re.search(APP_NAME, rsp): if re.search(log_client_binding_name, rsp): swilog.info("Arbitrary binding does not exist after app's " "deployment when its client-side IPC API is not " "bounded to any server-side API with the interface " "option: [optional]") else: swilog.error("Arbitrary binding does not exist after app's deployment " "when its client-side IPC API is not bounded to any " "server-side API with the interface option: [optional]") failed_testcases_list = swilog.get_error_list() if failed_testcases_list != []: assert 0, "Some tests failed:\n%s" % "\n".join(failed_testcases_list)
def set_mac(self, mac_addr): """Set the ethernet MAC address. If mac_addr is "auto", set a mac address based on the FSN. """ if mac_addr is None or mac_addr == "": # Do nothing return elif mac_addr == "auto": # Mac address based on FSN # Get Device FSN number fsn = self.target.run("/legato/systems/current/bin/cm info fsn") fsn = fsn.replace("\r", "").replace("\n", "") rsplen = len(fsn) if rsplen and fsn.find("Invalid") == -1: # Build the unique MAC address mac_bytes_list = [ "EE", fsn[2:4], fsn[4:6], fsn[6:8], fsn[8:10], fsn[10:12], ] mac_new_addr = ":".join(mac_bytes_list) else: swilog.error("No FSN defined. Can't set auto mac address!") return else: mac_new_addr = mac_addr swilog.debug("New Addr: %s" % mac_new_addr.upper()) # Check MAC address not already set mac_old_addr = self.target.run("cat /sys/class/net/eth0/address") mac_old_addr = mac_old_addr.replace("\n", "").replace("\r", "") swilog.debug("Old Addr: %s" % mac_old_addr.upper()) if mac_old_addr.upper().strip("\n") == mac_new_addr.upper(): swilog.debug("MAC already updated. Nothing to do") else: setnet_cmd = "/legato/systems/current/bin/setNet mac %s" % ( mac_new_addr) self.target.run(setnet_cmd) self.target.reboot()
def restore_golden_legato(target, timeout=60): """Restore the stable legato.""" for loop in range(0, 2): if loop != 0: swilog.info( "Try to execute restore golden legato {} times".format(loop)) target.reboot(timeout) legato_stop(target) rsp = get_legato_status(target) if "NOT running" in rsp: rsp = target.run("/bin/rm -rf /legato/apps /legato/systems", check=False) if not re.search("can't remove '/legato/systems/current'", rsp): break else: swilog.error("[FAILED] Unable to restore the stable legato.") target.reboot() current_system_index = get_current_system_index(target) swilog.info("Current system index is %s" % current_system_index) return current_system_index == 0
def check_current_system_info(target, version="", status="", index=""): """Check current Legato system status.""" _exit_code = 0 if version != "": current_version = get_legato_version(target) # If version does not contains md5 string. # Need to get the current_version without md5 string also. search_md5 = re.search(r"(.*)_([\d\w]{20,})", version) if not search_md5: search_current_md5 = re.search(r"(.*)_([\d\w]{20,})", current_version) if search_current_md5: current_version = search_current_md5.group(1) if current_version.strip() != version.strip(): swilog.error( "[FAILED] Mismatch system version [Expected: %s, Actual: %s]." % (version, current_version)) _exit_code = 1 if status != "": current_status = get_current_system_status(target) if current_status != status: swilog.error( "[FAILED] Mismatch system status [Expected: %s, Actual: %s]." % (status, current_status)) _exit_code = 1 if status != "": current_index = get_current_system_index(target) if current_index != index: swilog.error( "[FAILED] Mismatch system index [Expected: %s, Actual: %s]." % (str(index), str(current_index))) _exit_code = 1 return _exit_code
def identify_port(self, com_port_name=com.ComPortType.CLI.name): """Identify the port based on com_port_name and com_port_checklist.""" if ( com_port_name is not com.ComPortType.CLI.name and com_port_name is not com.ComPortType.AT.name ): swilog.error("Unknown port type!") return False if not self.com_port_checklist: return False checklist = self.com_port_checklist.get(com_port_name) if not checklist: return False for cmd, rsp in checklist: if not self._is_resp_expected(cmd, rsp): return False return True
def L_Tools_Kmod_0008(target, legato, create_temp_workspace): """Verify that kmod command is not able to. 1. Create an update package with a dependence to an application (load:auto)and update the target with it 2 Verify module is loaded and application is running 3. Unload module 4. Load back the module 5. Compile the default package and update the target with it :param target: fixture to communicate with the target :param legato: fixture to call useful functions regarding legato :param create_temp_workspace: fixture to create a temporary folder """ # Initialisation: # Verify existence of environment variables and files needed. # Prepare compilation test_name = "L_Tools_Kmod_0008" test_passed = True # Compile and update target swilog.step("Step 1: Compiling...") install_system(target, legato, create_temp_workspace, test_name) swilog.step("Step 2: Verify mod has been loaded and app is running...") if not check_presence(legato, test_name): test_passed = False swilog.error("Step 2: Kernel module has not been properly loaded") if not legato.is_app_running("LoopingHelloWorld"): test_passed = False swilog.error("Step 2: App is not running") swilog.step("Step 3: Unloading...") (returned_value, returned_index) = check_unloading(target, test_name, RESULT_OK) if not returned_value: test_passed = False swilog.error("Step 3: Kernel module has not been properly unloaded") swilog.step("Step 5: Loading...") (returned_value, returned_index) = check_loading(target, test_name, RESULT_OK) if not returned_value: test_passed = False swilog.error("Step 5: Kernel module has not been properly loaded") swilog.debug(returned_index) # End of script: Build the default package to reinitialise the target # And clean the LEGATO_ROOT directory assert test_passed, display_errors()
def L_Tools_Kmod_0006(target, legato, create_temp_workspace): """Verify kmod cmd should not be able to load if it already loaded. 1. Create an update package (Same modules as L_Tools_Kmod_0004) and update the target with it 2. Verify loading of the module 3. Try to load the module 4. It must fail 5. Compile the default package and update the target with it :param target: fixture to communicate with the target :param legato: fixture to call useful functions regarding legato :param create_temp_workspace: fixture to create a temporary folder """ # Initialisation: # Verify existence of environment variables and files needed. # Prepare compilation test_name = "L_Tools_Kmod_0004" test_passed = True # Compile and update target swilog.step("Step 1: Compiling...") install_system(target, legato, create_temp_workspace, test_name) swilog.step("Step 2: Verify mod has been loaded...") if not check_presence(legato, test_name): test_passed = False swilog.error("Step 2: Kernel module has not been properly loaded") swilog.step("Step 5: Loading...") (returned_value, returned_index) = check_loading(target, test_name, RESULT_DUPLICATE) if not returned_value: test_passed = False swilog.error("Step 5: Loading should have been forbidden.") swilog.debug(returned_index) # End of script: Build the default package to reinitialise the target # And clean the LEGATO_ROOT directory assert test_passed, display_errors()
def L_Tools_Kmod_0007(target, legato, create_temp_workspace): """Verify kmod cmd should not be able to unload kernel module. 1. Create an update package with a dependence to an other module (load:auto) and update the target with it 2. Verify loading of both modules 3. Try to unload the required module: it must fail 4. Try to unload the primary module: it must fail 5. Compile the default package and update the target with it :param target: fixture to communicate with the target :param legato: fixture to call useful functions regarding legato :param create_temp_workspace: fixture to create a temporary folder """ # Initialisation: # Verify existence of environment variables and files needed. # Prepare compilation test_name = "L_Tools_Kmod_0007" test_passed = True # Compile and update target swilog.step("Step 1: Compiling...") install_system(target, legato, create_temp_workspace, test_name) swilog.step("Step 2: Verify mods have been loaded...") check_presence_0004 = check_presence(legato, "L_Tools_Kmod_0004") check_presence_0007 = check_presence(legato, test_name) if (not check_presence_0007) or (not check_presence_0004): test_passed = False swilog.error("Step 2: Kernel module have not been properly loaded") # Unloading required module swilog.step("Step 3: Unloading required module...") (returned_value, returned_index) = check_unloading(target, "L_Tools_Kmod_0004", RESULT_BUSY) if not returned_value: test_passed = False swilog.error("Step 3: Unloading should have been forbidden.") # Unloading primary module swilog.step("Step 5: Unloading primary module...") (returned_value, returned_index) = check_unloading(target, test_name, RESULT_OK) if not returned_value: test_passed = False swilog.error("Step 5: Unloading should have been forbidden.") swilog.debug(returned_index) # End of script: Build the default package to reinitialise the target # And clean the LEGATO_ROOT directory assert test_passed, display_errors()
def L_Tools_Kmod_0005(target, legato, create_temp_workspace): """Verify that kmod command able to load. And unload the kernel module with manual load 1. Create an update package (load: manual) 2. Verify loading of the module has not been performed 3. Load the module 4. Unload the module 5. Compile the default package and update the target with it :param target: fixture to communicate with the target :param legato: fixture to call useful functions regarding legato :param create_temp_workspace: fixture to create a temporary folder """ # Verify existence of environment variables and files needed. # Prepare compilation test_name = "L_Tools_Kmod_0005" test_passed = True # Compile and update target swilog.step("Step 1: Compiling...") install_system(target, legato, create_temp_workspace, test_name) swilog.step("Step 2: Verify mod has not been loaded...") if check_presence(legato, test_name): test_passed = False swilog.error("Step 2: Kernel module has been unexpectedly loaded") swilog.step("Step 3: Loading...") (returned_value, returned_index) = check_loading(target, test_name, RESULT_OK) if not returned_value: test_passed = False swilog.error("Step 3: Kernel module has not been properly loaded") swilog.step("Step 5: Unloading...") (returned_value, returned_index) = check_unloading(target, test_name, RESULT_OK) if not returned_value: test_passed = False swilog.error("Step 5: Kernel module has not been properly unloaded") swilog.debug(returned_index) # End of script: Build the default package to reinitialise the target # And clean the LEGATO_ROOT directory assert test_passed, display_errors()
def test_swilog_error_memorization(target): """Execute several tests and capture swilog errors. Use swilog.error to log all the encountered errors. The final verdict will be passed if there is no stored errors. Args: target: fixture to communicate with the target """ if " legato " not in target.run("ls /"): swilog.error("/legato is not present") if " tmp " not in target.run("ls /"): swilog.error("/tmp is not present") if " my_test_folder " not in target.run("ls /tmp"): swilog.error("/tmp/my_test_folder is not present") # Test is PASS if only /legato, /tmp and /tmp/my_test_folder are present failed_testcases_list = swilog.get_error_list() if failed_testcases_list != []: assert 0, "Some tests failed:\n%s" % "\n".join(failed_testcases_list)
def verify_run_correctly(legato): """Verify the application is run correctly. Args: legato: Fixture to call useful functions regarding legato """ rsp = legato.find_in_target_log("Server started") if rsp: swilog.info("Server started.") else: swilog.error("Server did not start.") rsp = legato.find_in_target_log("foo_f is called") if rsp: swilog.info("C1 started and successfully called foo_f on the server.") else: swilog.error("C1 may not have called.") rsp = legato.find_in_target_log("bar_f is called") if rsp: swilog.info("C2 started and successfully called bar_f on the server.") else: swilog.error("C2 may not have called bar_f on the server.")
def L_UpdateCtrl_MarkGood_0001(target, request, legato, install_and_clean_app): """Verify that le_updateCtrl_MarkGood(True) returns LE_OK, marks current. system as 'good' and terminates probation period when the system is under probation. Initial Condition: 1. Current system is under probation 2. Current system index is "N" Test Procedures: 1. Install the app that invokes le_updateCtrl_MarkGood(True) onto the target device 2. During the probation period, run the app 3. Check the current system index is "N+ 1" and the current system state is marked as "good" 4. Check "return LE_OK : The system was marked Good" is shown from system log (Notes: the current system index, the current system state and the current system status can be verified by the command line "legato status") :param target: fixture to communicate with the target :param request: object to access data :param legato: fixture to call useful functions regarding legato :param install_and_clean_app: initial and build app for testing """ swilog.step("Test L_UpdateCtrl_MarkGood_0001") old_sys_index = 0 new_sys_index = 0 is_leok_return = False is_tc_passed = False old_sys_index = install_and_clean_app # Store the current system index which refers to the index # after the testUpdateCtrl app has installed onto the target new_sys_index = legato.get_current_system_index() # Set the parameter of the testUpdateCtrl app to "markGood" # "1" to run this test case target.run("config set apps/%s/procs/%s/args/1" " markGood" % (APP_NAME_01, APP_NAME_01)) target.run("config set apps/%s/procs/%s/args/2 1" % (APP_NAME_01, APP_NAME_01)) target.run("app start %s" % APP_NAME_01, withexitstatus=True) # Store the current system status after le_updateCtrl_MarkGood(True) # is called during the probation period for verification system_status = legato.get_current_system_status() # Capture "return LE_OK: The system was marked Good" from the system log # after le_updateCtrl_MarkGood(True) is called during the # probation period for verification if legato.find_in_target_log("return LE_OK:" " The system was marked Good"): is_leok_return = True # After le_updateCtrl_MarkGood(True) is called during # the probation period, if the current system status # is not marked as "good"; "return LE_OK: # The system was marked Good" wasn't captured in the system log; # The current system index is not greater than # the system index before running this test case by 1, mark # This test case failed if is_leok_return is False: swilog.error("[FAILED] MarkGood(True) doesn't return" " LE_OK when system is under probation " "and without any probation lock") elif system_status != "good": swilog.error("[FAILED] MarkGood(True) doesn't mark the current system" " as 'good' when the system is under probation and" " without any probation lock") elif (new_sys_index - old_sys_index) != 1: swilog.error("[FAILED] MarkGood(True) doesn't mark the current system" " as 'good' when the system is under probation and" " without any probation lock") else: swilog.info("[PASSED] MarkGood(True) marks the current system" " as 'good' and returns LE_OK when the system" " is under probation and without any probation lock") is_tc_passed = True end_test(is_tc_passed, request)
def L_UpdateCtrl_MarkGood_0006(target, request, legato, install_and_clean_app): """Verify that le_updateCtrl_MarkGood(False) returns LE_DUPLICATE when. the system is already marked as "good". Initial Conditions: 1. Current system state is marked as "good" 2. Probation period is 10ms Test Procedures: 1. Install the app that invokes le_updateCtrl_MarkGood(False) onto the target device 2. After the probation period, run the app 3. Check the current system state is marked as "good" 4. Check "return LE_DUPLICATE : Probation has expired: the system has already been marked" is shown from system log (Notes: the current system index, the current system state and the current system status can be verified by the command line "legato status") :param target: fixture to communicate with the target :param request: object to access data :param legato: fixture to call useful functions regarding legato :param install_and_clean_app: initial and build app for testing """ swilog.step("Test L_UpdateCtrl_MarkGood_0006") old_sys_index = 0 new_sys_index = 0 is_leduplicate_return = False is_tc_passed = False swilog.debug(install_and_clean_app) # Set the probation period to 1s to turn the system into "good" status legato.set_probation_timer(1) # Wait 3s to allow the probation period to pass time.sleep(3) # Set the parameter of the testUpdateCtrl app to "markGood" # "5" to run this test case target.run("config set apps/%s/procs/%s/args/1 markGood" % (APP_NAME_01, APP_NAME_01)) target.run("config set apps/%s/procs/%s/args/2 6" % (APP_NAME_01, APP_NAME_01)) # Store the current system index before le_updateCtrl_MarkGood(True) # is called for verification old_sys_index = legato.get_current_system_index() target.run("app start %s" % APP_NAME_01, withexitstatus=True) # Store the current system status after le_updateCtrl_MarkGood(False) # is called when the current status is 'good' for verification system_status = legato.get_current_system_status() # Store the current system index after le_updateCtrl_MarkGood(False) # is called when the current status is 'good' for verification new_sys_index = legato.get_current_system_index() # Capture "return LE_DUPLICATE: Probation has expired - # the system has already been marked Good" # from the system log after le_updateCtrl_MarkGood(False) # is called when the current status is 'good' for verification msg_log = ("return LE_DUPLICATE: Probation has expired - the system" " has already been marked Good") if legato.find_in_target_log(msg_log): is_leduplicate_return = True # After le_updateCtrl_MarkGood(False) is called # when the current status is 'good', # if the "return LE_DUPLICATE: Probation has expired - # the system has already been marked Good" # keyword is not appeared in the system log; # the current system status is not marked as "good"; # the current system index is equal to the system index # before le_updateCtrl_MarkGood(False) is called, # mark this test case failed if is_leduplicate_return is False: swilog.error("[FAILED] MarkGood(False) doesn't return LE_DUPLICATE" " when the current system is already marked as 'good'") elif old_sys_index != new_sys_index: swilog.error("[FAILED] MarkGood(False) modifies the system index when" " the current system is already marked as 'good'") elif system_status != "good": swilog.error("[FAILED] MarkGood(False) modifies" " the current system status when " "the current system is already marked as 'good'") else: swilog.info("[PASSED] MarkGood(False) only returns LE_DUPLICATE when" " the current system is already marked as 'good'") is_tc_passed = True end_test(is_tc_passed, request)
def L_UpdateCtrl_MarkGood_0004(target, request, legato, install_and_clean_app): """Verify that le_updateCtrl_MarkGood(False) returns LE_BUSY if someone. holds a probation lock. Initial Condition: 1. le_updateCtrl_LockProbation() is verified current system is under probation Test Procedures: 1. Install the app that invokes le_updateCtrl_LockProbation() first and le_updateCtrl_MarkGood(False) second onto the target device. 2. During the probation period, run the app 3. Check "return LE_BUSY: Someone holds a probation lock" is shown from system log 4. Check the system is under probation (Notes: the current system index, the current system state and the current system status can be verified by the command line "legato status") :param target: fixture to communicate with the target :param request: object to access data :param legato: fixture to call useful functions regarding legato :param install_and_clean_app: initial and build app for testing """ swilog.step("Test L_UpdateCtrl_MarkGood_0004") old_sys_index = 0 new_sys_index = 0 is_lebusy_return = False is_tc_passed = False old_sys_index = install_and_clean_app # Set the parameter of the testUpdateCtrl app # to "markGood" "4" to run this testcase target.run("config set apps/%s/procs/%s/args/1 markGood" % (APP_NAME_01, APP_NAME_01)) target.run("config set apps/%s/procs/%s/args/2 4" % (APP_NAME_01, APP_NAME_01)) rsp = target.run("app start %s" % APP_NAME_01, withexitstatus=True) swilog.info(rsp) # Now, the current system has a probation lock # store the current system index after after le_updateCtrl_MarkGood(False) # is called when there is a probation lock for verification new_sys_index = legato.get_current_system_index() # Store the current system status after le_updateCtrl_MarkGood(False) # is called when there is a probation lock for verification system_status = legato.get_current_system_status() # Capture "return LE_BUSY: Someone holds a probation lock" # from the system log after le_updateCtrl_MarkGood(False) is called when # there is a probation lock for verification if legato.find_in_target_log("return LE_BUSY:" " Someone holds a probation lock"): is_lebusy_return = True # After le_updateCtrl_MarkGood(False) is called when there is a probation # lock, if the current system status is not under probation; # "return LE_BUSY: Someone holds a probation lock" is not appeared # in the system log; the current system # index is not greater than the system index before running # this test case by 1, # Mark this test case "failed" if is_lebusy_return is False: swilog.error("[FAILED] MarkGood(False) doesn't return LE_BUSY when" " the system is under probation " "and there is a probation lock") elif system_status[0:5] != "tried": swilog.error("[FAILED] MarkGood(False) ends the probation period when" " the system is under probation and" " there is a probation lock") elif (new_sys_index - old_sys_index) != 1: swilog.error("[FAILED] MarkGood(False) modifies the system" " index when the system is under probation and" " there is a probation lock") else: swilog.info("[PASSED] MarkGood(False) only returns LE_BUSY when the " "system is under probation and there is a probation lock") is_tc_passed = True # After StartTC, the current system is marked as "good' and # the current system holds a probation lock reboot the system to clear # the probation lock before performing the clean up on the target target.reboot() end_test(is_tc_passed, request)