예제 #1
0
def handle(device: Device, script_path: str, generation: int,
           individual_index: int, test_case_index: int,
           unique_crashes: Set[str]) -> bool:

    result_dir = RequiredFeature('result_dir').request()

    device_bugreport_path = "/mnt/sdcard/bugreport.crash"

    individual_suffix = f"{str(generation)}.{str(individual_index)}.{str(test_case_index)}"
    local_bugreport_path = f"{result_dir}/crashes/bugreport.{individual_suffix}"

    # save the crash report
    output, errors, result_code = adb.pull(device, device_bugreport_path,
                                           local_bugreport_path)
    if result_code != 0:
        return False

    # get content
    with open(local_bugreport_path) as bug_report_file:
        content = bug_report_file.read().split('\n')

    # delete remote file
    adb.shell_command(device, f"rm {device_bugreport_path}")

    # should not caused by android itself
    if content[0].startswith("// CRASH: com.android."):
        os.system(f"rm {local_bugreport_path}")

        # caught a crash, but it was Android related
        return True

    # drop first line
    content = content[1:]

    # filter duplicate crashes
    content_str = "".join(content)
    if content_str in unique_crashes:
        os.system(f"rm {local_bugreport_path}")

        # caught a crash, but it wasn't a new one
        return True

    unique_crashes.add(content_str)

    # save the script, indicating its ith gen
    if script_path != "":
        os.system(
            f"cp {script_path} {result_dir}/crashes/script.{individual_suffix}"
        )

    return True
예제 #2
0
    def retrieve_generated_test(self, device: Device,
                                destination_file_name: str) -> TestCase:
        output, errors, result_code = adb.pull(
            device,
            self.motifcore_script_path_in_devices,
            destination_file_name,
            timeout=settings.ADB_REGULAR_COMMAND_TIMEOUT)
        if result_code != 0:
            raise Exception(
                f"Failed to retrieve motifcore script from device: {device.name}"
            )

        # remove motifgenes from test case if they are disabled
        if not self.use_motifgene:
            os.system(f"sed -i \'/GUIGen/d\' {destination_file_name}")

        return self.get_test_case_from_file(destination_file_name)
예제 #3
0
    def get_coverage(
            self,
            device: Device,
            coverage_folder_local_path: str,
            accumulated_output: str,
            accumulated_errors: str,
    ) -> int:
        result_dir: str = RequiredFeature('result_dir').request()
        coverage_ec_local_path = f"{coverage_folder_local_path}/coverage.ec"

        # pull coverage.ec file from device
        jacoco_coverage_class_files_path = RequiredFeature('jacoco_coverage_class_files_path').request()
        output, errors, result_code = adb.pull(device,
                                               self.coverage_ec_device_backup_path,
                                               coverage_ec_local_path)
        accumulated_output += output
        accumulated_errors += errors
        if result_code != 0:
            adb.log_evaluation_result(device, result_dir, "pull-coverage", False)
            if self.verbose_level > 0:
                logger.log_progress(f"\n{accumulated_output}\n{accumulated_errors}")
            raise Exception(f"Unable to pull coverage for device: {device.name}")

        # process coverage.ec file
        app_path = RequiredFeature('app_path').request()
        jacoco_cmd = f"java -jar {settings.WORKING_DIR}lib/jacococli.jar " \
                   f"report coverage.ec " \
                   f"--classfiles {jacoco_coverage_class_files_path} " \
                   f"--sourcefiles {settings.WORKING_DIR}{app_path}/src " \
                   f"--xml jacoco_report.xml " \
                   f"--html jacoco_html_report"

        output, errors, result_code = run_cmd(jacoco_cmd, cwd=coverage_folder_local_path)
        accumulated_output += output
        accumulated_errors += errors
        if result_code != 0:
            adb.log_evaluation_result(device, result_dir, "process-coverage", False)
            if self.verbose_level > 0:
                logger.log_progress(f"\n{accumulated_output}\n{accumulated_errors}")
            raise Exception(f"Unable to process coverage.ec file fetched from device: {device.name}")

        # parse generated html to extract global line coverage
        html_path = f"{coverage_folder_local_path}/jacoco_html_report/index.html"
        return self.extract_coverage(html_path)
예제 #4
0
    def get_coverage(
            self,
            device: Device,
            coverage_folder_local_path: str,
            accumulated_output: str,
            accumulated_errors: str,
    ) -> int:
        result_dir: str = RequiredFeature('result_dir').request()
        coverage_ec_local_path = f"{coverage_folder_local_path}/coverage.ec"

        # pull coverage.ec file from device
        output, errors, result_code = adb.pull(device, self.coverage_ec_device_backup_path, coverage_ec_local_path)
        accumulated_output += output
        accumulated_errors += errors
        if result_code != 0:
            adb.log_evaluation_result(device, result_dir, "pull-coverage", False)
            if self.verbose_level > 0:
                logger.log_progress(f"\n{accumulated_output}\n{accumulated_errors}")
            raise Exception(f"Unable to pull coverage for device: {device.name}")

        # process coverage.ec file
        app_path = RequiredFeature('app_path').request()
        emma_cmd = f"java -cp {settings.WORKING_DIR}lib/emma.jar emma report -r html" \
                   f" -in coverage.em,coverage.ec -sp {settings.WORKING_DIR}{app_path}/src"
        output, errors, result_code = run_cmd(emma_cmd, cwd=coverage_folder_local_path)
        accumulated_output += output
        accumulated_errors += errors
        if result_code != 0:
            adb.log_evaluation_result(device, result_dir, "process-coverage", False)
            if self.verbose_level > 0:
                logger.log_progress(f"\n{accumulated_output}\n{accumulated_errors}")
            raise Exception(f"Unable to process coverage.ec file fetched from device: {device.name}")

        # parse generated html to extract global line coverage
        html_path = f"{coverage_folder_local_path}/coverage/index.html"
        coverage_str = self.extract_coverage(html_path)

        aux = coverage_str.split("%")
        coverage = int(aux[0])

        return coverage