示例#1
0
def load_logcats(log_dir):
    json_files = list()
    for file in FileUtils.list_files_in_dir(log_dir):
        if file.endswith(".json"):
            json_dict = FileUtils.load_json(log_dir + file)
            json_files.append(json_dict)
    return json_files
示例#2
0
    def prepare_session_devices(self, avd_set, avd_schemas):
        avd_ports = PortManager.get_open_ports(avd_set)
        for avd in avd_set.avd_list:
            instances_of_schema = avd.instances
            for i in range(instances_of_schema):
                avd_schema = copy.deepcopy(avd_schemas[avd.avd_name])
                avd_schema.avd_name = avd_schema.avd_name + "-" + str(i)
                port = avd_ports.pop(0)

                log_file = FileUtils.clean_path(
                    GlobalConfig.OUTPUT_AVD_LOG_DIR + avd_schema.avd_name +
                    ".txt")
                FileUtils.create_file(GlobalConfig.OUTPUT_AVD_LOG_DIR,
                                      avd_schema.avd_name, "txt")
                Printer.system_message(
                    self.TAG, "Created file " + Color.GREEN + log_file +
                    Color.BLUE + ".")

                session_device = SessionVirtualDevice(
                    avd_schema, port, log_file, self.avdmanager_controller,
                    self.emulator_controller, self.adb_controller,
                    self.adb_package_manager_controller,
                    self.adb_settings_controller)
                self.session_devices.append(session_device)
                Printer.system_message(
                    self.TAG,
                    "Android Virtual Device model was created according to schema "
                    + Color.GREEN + avd_schema.avd_name + Color.BLUE +
                    ". Instance number: " + str(i) + ". Assigned to port: " +
                    str(port) + ".")
示例#3
0
def dump_saved_files_history():
    nothing_to_display = True

    if FileUtils.dir_exists(GlobalConfig.OUTPUT_AVD_LOG_DIR):
        nothing_to_display = False
        saved_avd_logs = FileUtils.list_files_in_dir(
            GlobalConfig.OUTPUT_AVD_LOG_DIR)
        Printer.system_message(
            TAG,
            "Directory " + Color.GREEN + str(GlobalConfig.OUTPUT_AVD_LOG_DIR) +
            Color.BLUE + " (" + Color.GREEN + str(len(saved_avd_logs)) +
            " files" + Color.BLUE + ")")
        for saved_file in FileUtils.list_files_in_dir(
                GlobalConfig.OUTPUT_AVD_LOG_DIR):
            Printer.system_message(TAG, "  * " + saved_file + ".")

    if FileUtils.dir_exists(GlobalConfig.OUTPUT_TEST_LOG_DIR):
        nothing_to_display = False
        saved_test_summaries = FileUtils.list_files_in_dir(
            GlobalConfig.OUTPUT_TEST_LOG_DIR)
        Printer.system_message(
            TAG, "Directory " + Color.GREEN +
            str(GlobalConfig.OUTPUT_TEST_LOG_DIR) + Color.BLUE + " (" +
            Color.GREEN + str(len(saved_test_summaries)) + " files" +
            Color.BLUE + ")")
        for saved_file in FileUtils.list_files_in_dir(
                GlobalConfig.OUTPUT_TEST_LOG_DIR):
            Printer.system_message(TAG, "  * " + saved_file + ".")

    if FileUtils.dir_exists(GlobalConfig.OUTPUT_TEST_LOGCAT_DIR):
        nothing_to_display = False
        saved_logcats_summaries = FileUtils.list_files_in_dir(
            GlobalConfig.OUTPUT_TEST_LOGCAT_DIR)
        Printer.system_message(
            TAG, "Directory " + Color.GREEN +
            str(GlobalConfig.OUTPUT_TEST_LOGCAT_DIR) + Color.BLUE + " (" +
            Color.GREEN + str(len(saved_logcats_summaries)) + " files" +
            Color.BLUE + ")")
        for saved_file in saved_logcats_summaries:
            Printer.system_message(TAG, "  * " + saved_file + ".")

    if GlobalConfig.SHOULD_RECORD_TESTS:
        if FileUtils.dir_exists(GlobalConfig.OUTPUT_TEST_RECORDINGS_DIR):
            nothing_to_display = False
            saved_recordings_summaries = FileUtils.list_files_in_dir(
                GlobalConfig.OUTPUT_TEST_RECORDINGS_DIR)
            Printer.system_message(
                TAG, "Directory " + Color.GREEN +
                str(GlobalConfig.OUTPUT_TEST_RECORDINGS_DIR) + Color.BLUE +
                " (" + Color.GREEN + str(len(saved_recordings_summaries)) +
                " files" + Color.BLUE + ")")
            for saved_file in saved_recordings_summaries:
                Printer.system_message(TAG, "  * " + saved_file + ".")

    if nothing_to_display:
        Printer.system_message(TAG, "No files were saved during session.")
示例#4
0
 def _create_apk_dir_if_not_exists(self):
     if FileUtils.dir_exists(GlobalConfig.APK_DIR):
         Printer.system_message(
             self.TAG, "Directory " + Color.GREEN + GlobalConfig.APK_DIR +
             Color.BLUE + " was found.")
     else:
         Printer.system_message(
             self.TAG, "Directory " + Color.GREEN + GlobalConfig.APK_DIR +
             Color.BLUE + " not found. Creating...")
         FileUtils.create_dir(GlobalConfig.APK_DIR)
def load_summary(log_dir):
    files_in_summary_dir = FileUtils.list_files_in_dir(log_dir)

    if len(files_in_summary_dir) != 1:
        message = (
            "Something went wrong! There should be one file with name 'session_summary.json' in '" + log_dir
            + "' directory but " + str(len(files_in_summary_dir)) + " were found.")
        raise Exception(message)

    json_dict = FileUtils.load_json(log_dir + files_in_summary_dir[0])
    return json_dict
示例#6
0
def save_session_summary():
    if GlobalConfig.OUTPUT_SUMMARY_LOG_DIR is not None and os.path.exists(GlobalConfig.OUTPUT_SUMMARY_LOG_DIR):
        session_log_json_dict = copy.deepcopy(session_log)
        session_log_json_dict.time_summary = vars(session_log.time_summary)
        session_log_json_dict.apk_summary = vars(session_log.apk_summary)
        session_log_json_dict.test_summary = vars(session_log.test_summary)
        session_log_json_dict.device_summaries = list()
        for device_name, device_summary in session_log.device_summaries.items():
            session_log_json_dict.device_summaries.append(vars(device_summary))
        session_log_json_dict = vars(session_log_json_dict)

        FileUtils.save_json_dict_to_json(GlobalConfig.OUTPUT_SUMMARY_LOG_DIR, session_log_json_dict, "session_summary")
示例#7
0
def _create_logcats():
    logcat_html_path = GlobalConfig.OUTPUT_LOGCAT_HTML_DIR
    if not os.path.isdir(logcat_html_path):
        FileUtils.create_dir(logcat_html_path)

    logcats = load_logcats(GlobalConfig.OUTPUT_TEST_LOGCAT_DIR)
    for logcat_dict in logcats:
        file_dir = logcat_html_path
        file_name = logcat_dict["test_name"]
        file_extension = "html"
        file = "{}{}.{}".format(file_dir, file_name, file_extension)

        with open(file, "w", encoding="utf-8") as html_file:
            html_content = _generate_logcat_html(logcat_dict)
            html_file.write(html_content)
def _create_summary_file():
    file_dir = GlobalConfig.OUTPUT_DIR

    file_path = GlobalConfig.OUTPUT_INDEX_HTML_DIR
    filepath_parts = file_path.split("/")
    filename_with_extension = filepath_parts[len(filepath_parts) - 1]
    filename_parts = filename_with_extension.split(".")

    file_name = filename_parts[0]
    file_extension = filename_parts[1]

    FileUtils.create_file(file_dir, file_name, file_extension)

    with open(GlobalConfig.OUTPUT_INDEX_HTML_DIR, "w", encoding="utf-8") as html_file:
        html_content = _generate_summary_html()
        html_file.write(html_content)
示例#9
0
    def run(self):
        self.created_files = list()

        for test_summary in self.test_summary_list:
            test_summary_json_dict = vars(test_summary)
            created_file_path = FileUtils.save_json_dict_to_json(
                GlobalConfig.OUTPUT_TEST_LOG_DIR, test_summary_json_dict,
                test_summary_json_dict["test_name"] + "_" +
                self.device.adb_name + "_" + self.TEST_SUMMARY_APPENDIX)
            self.created_files.append(created_file_path)
    def __init__(self, manifest_dir):
        self.avd_manifest_source = FileUtils.load_json(manifest_dir)
        self.avd_schema_dict = dict()
        self.avd_set_dict = dict()

        for avd_schema in self.avd_manifest_source["avd_schema_list"]:
            self.avd_schema_dict.update(
                {avd_schema["avd_name"]: AvdSchema(avd_schema)})

        for avd_set in self.avd_manifest_source["avd_set_list"]:
            self.avd_set_dict.update({avd_set["set_name"]: AvdSet(avd_set)})
示例#11
0
    def _find_candidates(self, test_set):
        name_part = test_set.apk_name_part.replace(".apk", "")
        Printer.system_message(
            self.TAG,
            "Checking " + Color.GREEN + GlobalConfig.APK_DIR + Color.BLUE +
            " directory for .*apk" + " list with names containing " +
            Color.GREEN + name_part + Color.BLUE + ":")

        app_apk_list = self.get_list_with_application_apk(
            name_part, GlobalConfig.APK_DIR)
        test_apk_list = self.get_list_with_test_apk(name_part,
                                                    GlobalConfig.APK_DIR)

        path = 0
        name = 1
        if app_apk_list:
            for apk in app_apk_list:
                apk_filename = apk[name]
                apk_filepath = FileUtils.clean_folder_only_dir(
                    FileUtils.add_ending_slash(apk[path])) + apk[name]

                apk_test_filename = ""
                apk_test_filepath = ""
                for test_apk in test_apk_list:
                    if apk_filename.replace(
                            ".apk", ""
                    ) in test_apk[name] and "-androidTest" in test_apk[name]:
                        apk_test_filename = test_apk[name]
                        apk_test_filepath = FileUtils.clean_folder_only_dir(
                            FileUtils.add_ending_slash(
                                test_apk[path])) + test_apk[name]

                dump = self.aapt_controller.dump_badging(apk_filepath)
                version_code = re.findall("versionCode='(.+?)'", dump)
                version_code = int(version_code[0])

                self.apk_candidates.append(
                    ApkCandidate(apk_filename, apk_filepath, apk_test_filename,
                                 apk_test_filepath, version_code))
        else:
            Printer.system_message(self.TAG, "  * No .apk* files found.")
示例#12
0
    def prepare_output_directories(self):
        if FileUtils.dir_exists(GlobalConfig.OUTPUT_DIR):
            Printer.system_message(
                self.TAG, "Directory " + Color.GREEN +
                GlobalConfig.OUTPUT_DIR + Color.BLUE +
                " found!. Only session related directories and files will be cleaned."
            )
        else:
            Printer.system_message(
                self.TAG,
                "Directory " + Color.GREEN + GlobalConfig.OUTPUT_DIR +
                Color.BLUE + " not found. Creating...")

        for directory in [
                GlobalConfig.OUTPUT_SUMMARY_LOG_DIR,
                GlobalConfig.OUTPUT_AVD_LOG_DIR,
                GlobalConfig.OUTPUT_TEST_LOG_DIR,
                GlobalConfig.OUTPUT_TEST_LOGCAT_DIR,
                GlobalConfig.OUTPUT_STYLES_FOLDER_DIR,
                GlobalConfig.OUTPUT_LOGCAT_HTML_DIR,
                GlobalConfig.OUTPUT_TEST_RECORDINGS_DIR
        ]:

            if FileUtils.dir_exists(directory):
                files_num = 0 if FileUtils.list_files_in_dir(
                    directory) is None else len(
                        FileUtils.list_files_in_dir(directory))
                Printer.system_message(
                    self.TAG, "Directory " + Color.GREEN + directory +
                    Color.BLUE + " was found. Removing (" + Color.GREEN +
                    str(files_num) + " files" + Color.BLUE + ").")
                FileUtils.clear_dir(directory)
            else:
                Printer.system_message(
                    self.TAG, "Directory " + Color.GREEN + directory +
                    Color.BLUE + " not found. Creating...")
                FileUtils.create_dir(directory)

        if FileUtils.file_exists(GlobalConfig.OUTPUT_INDEX_HTML_DIR):
            Printer.system_message(
                self.TAG, "Removing " + Color.GREEN +
                GlobalConfig.OUTPUT_INDEX_HTML_DIR + Color.BLUE +
                " file from previous session.")
示例#13
0
    def __init__(self, manifest_dir):
        self.path_manifest_source = FileUtils.load_json(manifest_dir)
        self.test_package_list = dict()
        self.test_set_list = dict()

        for test_package_dict in self.path_manifest_source["test_list"]:
            self.test_package_list.update({
                test_package_dict["test_package_name"]:
                TestPackage(test_package_dict)
            })

        for test_set_dict in self.path_manifest_source["test_set_list"]:
            self.test_set_list.update(
                {test_set_dict["set_name"]: TestSet(test_set_dict)})
def add_rerun_number_to_filename_in_dir(path, filename):
    rerun_count = 0
    for filename_in_dir in FileUtils.list_files_in_dir(path):
        if filename in filename_in_dir:
            rerun_count += 1

    if rerun_count > 0:
        if "." in filename:
            filename_parts = filename.split(".")
            filename = filename_parts[0] + "_rerun_no_{}".format(rerun_count) + filename_parts[1]
        else:
            filename += "_rerun_no_{}".format(rerun_count)

    return filename
示例#15
0
    def run(self):
        self.created_files = list()

        for logcat in self.test_logcat_list:
            logcat_lines_json_dict = list()
            for logcat_line in logcat.lines:
                logcat_lines_json_dict.append(vars(logcat_line))
            logcat.lines = logcat_lines_json_dict

            logcat_json_dict = vars(logcat)
            created_file_path = FileUtils.save_json_dict_to_json(
                GlobalConfig.OUTPUT_TEST_LOGCAT_DIR, logcat_json_dict,
                logcat_json_dict["test_name"] + "_" + self.device.adb_name +
                "_" + self.TEST_LOGCAT_APPENDIX)
            self.created_files.append(created_file_path)
示例#16
0
    def run(self):
        self.created_files = list()

        for test_summary in self.test_summary_list:
            test_summary_json_dict = vars(test_summary)

            filename = test_summary_json_dict["test_name"] + "_" + self.device.adb_name + "_" \
                       + self.TEST_SUMMARY_APPENDIX

            if test_summary.rerun_count > 0:
                filename = filename.replace(".json", "_rerun_no_{}.json".format(test_summary.rerun_count))

            created_file_path = FileUtils.save_json_dict_to_json(
                GlobalConfig.OUTPUT_TEST_LOG_DIR, test_summary_json_dict, filename)

            self.created_files.append(created_file_path)
示例#17
0
    def run(self):
        self.created_files = list()

        for logcat in self.test_logcat_list:
            logcat_lines_json_dict = list()
            for logcat_line in logcat.lines:
                logcat_lines_json_dict.append(vars(logcat_line))
            logcat.lines = logcat_lines_json_dict

            logcat_json_dict = vars(logcat)

            filename = logcat_json_dict["test_name"] + "_" + self.device.adb_name + "_" + self.TEST_LOGCAT_APPENDIX

            if logcat.rerun_count > 0:
                filename = filename.replace(".json", "_rerun_no_{}.json".format(logcat.rerun_count))

            created_file_path = FileUtils.save_json_dict_to_json(
                GlobalConfig.OUTPUT_TEST_LOGCAT_DIR, logcat_json_dict, filename)

            self.created_files.append(created_file_path)
 def __init__(self, manifest_dir):
     self.path_manifest_source = FileUtils.load_json(manifest_dir)
     self.path_set_list = dict()
     for path_set in self.path_manifest_source["path_set_list"]:
         self.path_set_list.update(
             {path_set["set_name"]: PathSet(path_set)})
示例#19
0
    def _run_tests(self, devices, test_cmd_templates, is_rerunning=False):
        device_commands_dict = self._prepare_device_control_cmds(devices)

        threads_finished = False
        logcat_threads_num = len(devices)
        recording_threads_num = len(
            devices) if GlobalConfig.SHOULD_RECORD_TESTS else 0
        test_threads_num = len(test_cmd_templates)

        logcat_threads = list()
        test_threads = list()
        test_log_saving_threads = list()
        logcat_saving_threads = list()
        test_recording_saving_threads = list()

        try:
            while not threads_finished:
                if len(logcat_threads) != logcat_threads_num:
                    for device in devices:
                        logcat_thread = TestLogCatMonitorThread(
                            device, device_commands_dict.get(device),
                            GlobalConfig.SHOULD_RECORD_TESTS)
                        logcat_threads.append(logcat_thread)
                        logcat_thread.start()

                if len(test_recording_saving_threads) != recording_threads_num:
                    for device in devices:
                        test_recording_saving_thread = TestRecordingSavingThread(
                            device)
                        test_recording_saving_threads.append(
                            test_recording_saving_thread)
                        test_recording_saving_thread.start()

                if len(test_threads) != test_threads_num and all(
                        t.logcat_process is not None for t in logcat_threads):
                    for device in devices:
                        if not any(t.device.adb_name == device.adb_name and t.is_alive() for t in test_threads) \
                                and len(test_cmd_templates) > 0:
                            launch_cmd_template = test_cmd_templates.pop(0)
                            launch_cmd = launch_cmd_template.replace(
                                self.DEVICE_NAME_PLACEHOLDER, device.adb_name)

                            instance = "packages" if not is_rerunning else "tests"
                            Printer.system_message(
                                self.TAG,
                                str(len(test_cmd_templates)) +
                                " {} to run left...".format(instance))

                            self.adb_package_manager_controller.clear_package_cache(
                                device.adb_name, GlobalConfig.APP_PACKAGE)

                            test_thread = TestThread(launch_cmd, device)
                            test_threads.append(test_thread)
                            test_thread.start()

                for test_thread in test_threads:
                    if len(test_thread.logs) > 0:
                        current_test_logs = copy.deepcopy(test_thread.logs)
                        self.test_store.store_test_status(current_test_logs)

                        for test_log in current_test_logs:
                            contain_count = self.test_store.test_contain_count(
                                test_log.test_name)

                            if contain_count > 1:
                                test_log.rerun_count += contain_count - 1

                            if is_rerunning:
                                session_logger.update_flaky_candidate(test_log)
                            else:
                                if test_log.test_status == "success":
                                    session_logger.increment_passed_tests()

                                if test_log.test_status == "failure":
                                    session_logger.increment_failed_tests()

                        test_log_saving_thread = TestSummarySavingThread(
                            test_thread.device, current_test_logs)

                        test_log_saving_threads.append(test_log_saving_thread)
                        test_log_saving_thread.start()
                        test_thread.logs.clear()

                for logcat_thread in logcat_threads:
                    if len(logcat_thread.logs) > 0:
                        current_logcats = copy.deepcopy(logcat_thread.logs)
                        self.test_store.store_test_logcat(current_logcats)

                        for test_logcat in current_logcats:
                            contain_count = self.test_store.test_logcat_contain_count(
                                test_logcat.test_name)

                            if contain_count > 1:
                                test_logcat.rerun_count += contain_count - 1

                        logcat_saving_thread = TestLogcatSavingThread(
                            logcat_thread.device, current_logcats)
                        logcat_saving_threads.append(logcat_saving_thread)
                        logcat_saving_thread.start()
                        logcat_thread.logs.clear()

                    if len(logcat_thread.recordings) > 0:
                        device = logcat_thread.device
                        current_recordings = copy.deepcopy(
                            logcat_thread.recordings)

                        for recording_saving_thread in test_recording_saving_threads:
                            if recording_saving_thread.device.adb_name == device.adb_name:
                                pull_cmd_list = list()
                                clear_cmd_list = list()
                                for recording_name in current_recordings:
                                    recording_dir = FileUtils.add_ending_slash(
                                        FileUtils.clean_path(
                                            GlobalConfig.
                                            DEVICE_VIDEO_STORAGE_DIR)
                                    ) + recording_name
                                    pull_cmd_list.append(
                                        self._prepare_pull_recording_cmd(
                                            device, recording_dir))
                                    clear_cmd_list.append(
                                        self._prepare_remove_recording_cmd(
                                            device, recording_dir))

                                    recording_saving_thread.add_recordings(
                                        current_recordings)
                                    recording_saving_thread.add_pull_recording_cmds(
                                        pull_cmd_list)
                                    recording_saving_thread.add_clear_recordings_cmd(
                                        clear_cmd_list)

                        logcat_thread.recordings.clear()

                if len(test_threads) == test_threads_num \
                        and all(not t.is_alive() for t in test_threads) \
                        and all(t.is_finished() for t in test_log_saving_threads) \
                        and all(t.is_finished() for t in logcat_saving_threads):

                    for test_thread in test_threads:
                        test_thread.kill_processes()
                        test_thread.join()

                    for logcat_thread in logcat_threads:
                        logcat_thread.kill_processes()
                        logcat_thread.join()

                    for test_log_saving_thread in test_log_saving_threads:
                        test_log_saving_thread.join()

                    for logcat_saving_thread in logcat_saving_threads:
                        logcat_saving_thread.join()

                    test_threads.clear()
                    logcat_threads.clear()
                    test_log_saving_threads.clear()
                    logcat_saving_threads.clear()

                if len(test_recording_saving_threads) > 0 and len(
                        logcat_threads) == 0:
                    if all(
                            len(t.recordings) == 0
                            for t in test_recording_saving_threads):
                        for recording_thread in test_recording_saving_threads:
                            recording_thread.kill_processes()
                            recording_thread.join()

                        test_recording_saving_threads.clear()

                threads_finished = len(logcat_threads) == 0 and len(
                    test_threads) == 0 and len(
                        test_log_saving_threads) == 0 and len(
                            logcat_saving_threads) == 0 and len(
                                test_recording_saving_threads) == 0 and len(
                                    test_cmd_templates) == 0
        except Exception as e:
            message = "Error has occurred during test session: \n" + str(e)
            raise LauncherFlowInterruptedException(self.TAG, message)
        finally:
            if len(test_threads) > 0:
                for test_thread in test_threads:
                    test_thread.kill_processes()
                    test_thread.join()

            if len(logcat_threads) > 0:
                for logcat_thread in logcat_threads:
                    logcat_thread.kill_processes()
                    logcat_thread.join()

            if len(test_log_saving_threads) > 0:
                for test_log_saving_thread in test_log_saving_threads:
                    test_log_saving_thread.join()

            if len(logcat_saving_threads) > 0:
                for logcat_saving_thread in logcat_saving_threads:
                    logcat_saving_thread.join()

            if len(test_recording_saving_threads) > 0:
                for recording_thread in test_recording_saving_threads:
                    recording_thread.kill_processes()
                    recording_thread.join()

            test_threads.clear()
            logcat_threads.clear()
            test_log_saving_threads.clear()
            logcat_saving_threads.clear()
            test_recording_saving_threads.clear()
示例#20
0
    def run_tests(self, test_set, test_list):
        devices = self.device_store.get_devices()
        test_packages = self.test_store.get_packages(test_set, test_list)

        launch_variant_string = "TESTS SPLIT INTO SHARDS" if test_set.shard else "EACH TEST ON EACH DEVICE"
        Printer.system_message(
            self.TAG,
            "According to test set settings, tests will be run with following variant: "
            + Color.GREEN + launch_variant_string + Color.BLUE + ".")

        device_commands_dict = self._prepare_device_control_cmds(devices)
        test_cmd_templates = self._prepare_launch_test_cmds_for_run(
            test_packages, devices, test_set.shard)

        threads_finished = False
        logcat_threads_num = len(devices)
        recording_threads_num = len(
            devices) if GlobalConfig.SHOULD_RECORD_TESTS else 0
        test_threads_num = len(test_cmd_templates)

        logcat_threads = list()
        test_threads = list()
        test_log_saving_threads = list()
        logcat_saving_threads = list()
        test_recording_saving_threads = list()

        try:
            while not threads_finished:
                if len(logcat_threads) != logcat_threads_num:
                    for device in devices:
                        logcat_thread = TestLogCatMonitorThread(
                            device, device_commands_dict.get(device),
                            GlobalConfig.SHOULD_RECORD_TESTS)
                        logcat_threads.append(logcat_thread)
                        logcat_thread.start()

                if len(test_recording_saving_threads) != recording_threads_num:
                    for device in devices:
                        test_recording_saving_thread = TestRecordingSavingThread(
                            device)
                        test_recording_saving_threads.append(
                            test_recording_saving_thread)
                        test_recording_saving_thread.start()

                if len(test_threads) != test_threads_num and all(
                        t.logcat_process is not None for t in logcat_threads):
                    for device in devices:
                        if not any(t.device.adb_name == device.adb_name and t.is_alive() for t in test_threads) \
                                and len(test_cmd_templates) > 0:
                            launch_cmd_template = test_cmd_templates.pop(0)
                            launch_cmd = launch_cmd_template.replace(
                                self.DEVICE_NAME_PLACEHOLDER, device.adb_name)

                            Printer.system_message(
                                self.TAG,
                                str(len(test_cmd_templates)) +
                                " packages to run left...")

                            self.adb_package_manager_controller.clear_package_cache(
                                device.adb_name, GlobalConfig.APP_PACKAGE)

                            test_thread = TestThread(launch_cmd, device)
                            test_threads.append(test_thread)
                            test_thread.start()

                for test_thread in test_threads:
                    if len(test_thread.logs) > 0:
                        current_test_logs = copy.deepcopy(test_thread.logs)

                        for log in current_test_logs:
                            if log.test_status == "success":
                                session_logger.increment_passed_tests()

                            if log.test_status == "failure":
                                session_logger.increment_failed_tests()

                        test_log_saving_thread = TestSummarySavingThread(
                            test_thread.device, current_test_logs)
                        test_log_saving_threads.append(test_log_saving_thread)
                        test_log_saving_thread.start()
                        test_thread.logs.clear()

                for logcat_thread in logcat_threads:
                    if len(logcat_thread.logs) > 0:
                        current_logcats = copy.deepcopy(logcat_thread.logs)
                        logcat_saving_thread = TestLogcatSavingThread(
                            logcat_thread.device, current_logcats)
                        logcat_saving_threads.append(logcat_saving_thread)
                        logcat_saving_thread.start()
                        logcat_thread.logs.clear()

                    if len(logcat_thread.recordings) > 0:
                        device = logcat_thread.device
                        current_recordings = copy.deepcopy(
                            logcat_thread.recordings)

                        for recording_saving_thread in test_recording_saving_threads:
                            if recording_saving_thread.device.adb_name == device.adb_name:
                                pull_cmd_list = list()
                                clear_cmd_list = list()
                                for recording_name in current_recordings:
                                    recording_dir = FileUtils.add_ending_slash(
                                        FileUtils.clean_path(
                                            GlobalConfig.
                                            DEVICE_VIDEO_STORAGE_DIR)
                                    ) + recording_name
                                    pull_cmd_list.append(
                                        self._prepare_pull_recording_cmd(
                                            device, recording_dir))
                                    clear_cmd_list.append(
                                        self._prepare_remove_recording_cmd(
                                            device, recording_dir))

                                    recording_saving_thread.add_recordings(
                                        current_recordings)
                                    recording_saving_thread.add_pull_recording_cmds(
                                        pull_cmd_list)
                                    recording_saving_thread.add_clear_recordings_cmd(
                                        clear_cmd_list)

                        logcat_thread.recordings.clear()

                if len(test_threads) == test_threads_num \
                        and all(not t.is_alive() for t in test_threads) \
                        and all(t.is_finished() for t in test_log_saving_threads) \
                        and all(t.is_finished() for t in logcat_saving_threads):

                    for test_thread in test_threads:
                        test_thread.kill_processes()
                        test_thread.join()

                    for logcat_thread in logcat_threads:
                        logcat_thread.kill_processes()
                        logcat_thread.join()

                    for test_log_saving_thread in test_log_saving_threads:
                        test_log_saving_thread.join()

                    for logcat_saving_thread in logcat_saving_threads:
                        logcat_saving_thread.join()

                    test_threads.clear()
                    logcat_threads.clear()
                    test_log_saving_threads.clear()
                    logcat_saving_threads.clear()

                if len(test_recording_saving_threads) > 0 and len(
                        logcat_threads) == 0:
                    if all(
                            len(t.recordings) == 0
                            for t in test_recording_saving_threads):
                        for recording_thread in test_recording_saving_threads:
                            recording_thread.kill_processes()
                            recording_thread.join()

                        test_recording_saving_threads.clear()

                threads_finished = len(logcat_threads) == 0 and len(
                    test_threads) == 0 and len(
                        test_log_saving_threads) == 0 and len(
                            logcat_saving_threads) == 0 and len(
                                test_recording_saving_threads) == 0 and len(
                                    test_cmd_templates) == 0
        except Exception as e:
            message = "Error has occurred during test session: \n" + str(e)
            raise LauncherFlowInterruptedException(self.TAG, message)
        finally:
            if len(test_threads) > 0:
                for test_thread in test_threads:
                    test_thread.kill_processes()
                    test_thread.join()

            if len(logcat_threads) > 0:
                for logcat_thread in logcat_threads:
                    logcat_thread.kill_processes()
                    logcat_thread.join()

            if len(test_log_saving_threads) > 0:
                for test_log_saving_thread in test_log_saving_threads:
                    test_log_saving_thread.join()

            if len(logcat_saving_threads) > 0:
                for logcat_saving_thread in logcat_saving_threads:
                    logcat_saving_thread.join()

            if len(test_recording_saving_threads) > 0:
                for recording_thread in test_recording_saving_threads:
                    recording_thread.kill_processes()
                    recording_thread.join()

            test_threads.clear()
            logcat_threads.clear()
            test_log_saving_threads.clear()
            logcat_saving_threads.clear()
            test_recording_saving_threads.clear()
示例#21
0
def _copy_styles():
    generator_styles_dir = FileUtils.clean_folder_only_dir(
        GlobalConfig.LOG_GENERATOR_DIR + GENERATOR_STYLES_DIR)
    FileUtils.copy(generator_styles_dir, GlobalConfig.OUTPUT_STYLES_FOLDER_DIR)
    def __init__(self, manifest_dir):
        self.launch_manifest_source = FileUtils.load_json(manifest_dir)
        self.launch_plan_dict = dict()

        for launch_plan in self.launch_manifest_source["launch_plan_list"]:
            self.launch_plan_dict.update({launch_plan["plan_name"]: LaunchPlan(launch_plan)})