Пример #1
0
def compute_diff_coverage_for_given_commit(path_to_concerned_module,
                                           path_to_concerned_module_other,
                                           commit_json, commits, key_commit,
                                           prefix_result):
    output_path = toolbox.get_absolute_path(
        toolbox.prefix_result + project + "/" +
        toolbox.get_output_folder_for_commit(commit_json, commits) + "/" +
        prefix_result + "_" +
        toolbox.name_of_csv_with_list_of_test_that_execute_the_changes +
        ".csv")
    toolbox.set_output_log_path(
        toolbox.get_absolute_path(
            toolbox.prefix_result + project + "/" +
            toolbox.get_output_folder_for_commit(commit_json, commits) + "/" +
            prefix_result + "_" +
            toolbox.name_of_csv_with_list_of_test_that_execute_the_changes +
            ".log"))
    concerned_module = commit_json["concernedModule"]
    cmd = [
        toolbox.maven_home + "mvn", "clean",
        "eu.stamp-project:diff-test-selection:0.5-SNAPSHOT:list",
        "-DpathToDiff=patch.diff",
        "-DpathToOtherVersion=" + path_to_concerned_module_other,
        "-Dmodule=" + concerned_module, "-DoutputPath=" + output_path
    ]
    toolbox.print_and_call_in_a_file(" ".join(cmd),
                                     cwd=path_to_concerned_module)
Пример #2
0
def run_for_configuration(configuration, prefix_folder_result, commit):
    folder_result = prefix_folder_result + "/" + configuration + "/"
    if os.path.isdir(folder_result):
        for file in os.listdir(folder_result):
            if os.path.isdir(folder_result + file):
                toolbox.set_output_log_path(
                    toolbox.get_absolute_path(folder_result +
                                              "behavioral_encoding_check.log"))
                path_to_concerned_module = toolbox.get_absolute_path(
                    toolbox.prefix_current_dataset + project + "/" +
                    commit["concernedModule"])
                print path_to_concerned_module
                path_concerned_pom = path_to_concerned_module + "/pom.xml"
                test_suite_switcher.switch(folder_result, path_concerned_pom)
                junit_enforcer.enforce(path_concerned_pom)
                toolbox.print_and_call(
                    [
                        "mvn", "clean", "install", "-DskipTests", "--quiet",
                        "-Dcheckstyle.skip=true", "-Denforcer.skip=true",
                        "-Dxwiki.clirr.skip=true"
                    ],
                    cwd=toolbox.get_absolute_path(
                        toolbox.prefix_current_dataset + project + "/"))
                toolbox.print_and_call(["mvn", "clean", "test"],
                                       cwd=path_to_concerned_module)
                path_to_surefire_report = path_to_concerned_module + suffix_target_surefire_reports
                for report in os.listdir(path_to_surefire_report):
                    if report.startswith("TEST-") and report.endswith(".xml"):
                        return containsFailureOrError(path_to_surefire_report +
                                                      "/" + report)
    return None
Пример #3
0
def run(project, indices, amplifiers):
    path_to_project_json = toolbox.prefix_current_dataset + project + ".json"
    project_json = toolbox.get_json_file(path_to_project_json)
    path_to_project_root = toolbox.prefix_dataset + project
    commits = project_json["commits"]

    # for each commits.
    for index in indices:
        commit = commits[index]
        output_path = toolbox.get_absolute_path(
            toolbox.prefix_result + project + "/" +
            toolbox.get_output_folder_for_commit(commit, commits))
        if amplifiers:
            output_path = output_path + "/input_amplification"
        else:
            output_path = output_path + "/assert_amplification"
        toolbox.create(output_path)
        toolbox.set_output_log_path(output_path + "/commit_set.log")
        #  1) set up both version of the program
        commit_setter.set_commit(path_to_project_root, project,
                                 commits.index(commit))
        toolbox.set_output_log_path(output_path + "/amplification.log")
        path_to_concerned_module = toolbox.get_absolute_path(
            toolbox.prefix_dataset + project + "/" + commit["concernedModule"])
        path_to_concerned_module_parent = toolbox.get_absolute_path(
            toolbox.prefix_dataset + project + toolbox.suffix_parent + "/" +
            commit["concernedModule"])
        path_to_test_that_executes_the_changes = toolbox.get_path_to_csv_file(
            project, commit, commits)
        preparation.prepare(project)
        # run now dspot with maven plugin
        cmd = [
            toolbox.maven_home + "mvn",
            "eu.stamp-project:dspot-maven:1.1.1-SNAPSHOT:amplify-unit-tests",
            "-Dpath-to-test-list-csv=" +
            path_to_test_that_executes_the_changes, "-Dverbose=true",
            "-Dtest-criterion=ChangeDetectorSelector",
            "-Doutput-path=" + output_path,
            "-Dpath-to-second-version=" + path_to_concerned_module,
            "-Dgenerate-new-test-class=true", "-Dclean=true", "-X"
        ]
        if amplifiers:
            cmd.append(
                "-Damplifiers=TestDataMutator,MethodAdd,MethodRemove,MethodGeneratorAmplifier,ReturnValueAmplifier,NullifierAmplifier"
            )
            cmd.append("-Diteration=3")
            cmd.append("-Dbudgetizer=SimpleBudgetizer")
        cmd = preparation.add_needed_options(cmd, project)
        toolbox.print_and_call_in_a_file(" ".join(cmd),
                                         cwd=path_to_concerned_module_parent)
Пример #4
0
def run(project):
    path_to_root_project = toolbox.get_absolute_path(
        toolbox.prefix_current_dataset + project + "/")
    project_json = toolbox.get_json_file(
        toolbox.get_absolute_path(toolbox.prefix_current_dataset + project))
    commits = project_json['commits']
    for commit in commits:
        commit_setter.set_commit(path_to_root_project, project,
                                 commits.index(commit))
        toolbox.print_and_call_no_redirection(
            [toolbox.maven_home + "mvn", "clean", "test"],
            cwd=path_to_root_project)
        commit['nb_test_per_commit'] = count_tests(path_to_root_project)
    with open(
            toolbox.get_absolute_path(toolbox.prefix_current_dataset + project)
            + '.json', 'w') as outfile:
        json.dump(project_json, outfile)
Пример #5
0
def create_diff(commit_id, cwd):
    toolbox.delete_if_exists(
        cwd + "/patch.diff"
    )
    cmd = [
        "git", "diff",
        commit_id,
        ">", toolbox.get_absolute_path(cwd + "/patch.diff")
    ]
    toolbox.print_and_call_in_a_file_no_redirection(cmd, cwd=cwd)
Пример #6
0
def run(project, index_commit):
    project_json = toolbox.get_json_file(
        toolbox.get_absolute_path(toolbox.prefix_current_dataset + project))
    beg = 0 if index_commit == -1 else index_commit
    end = index_commit if index_commit == -1 else index_commit + 1
    output_path_to_json = toolbox.get_absolute_path(
        toolbox.prefix_result + project + "/behavioral-encoding-check.json")
    if os.path.isfile(output_path_to_json):
        data = toolbox.get_json_file(
            toolbox.get_absolute_path(output_path_to_json))
    else:
        data = {project: {}}
    data_project = data[project]
    commits = project_json["commits"]
    for commit in commits:
        if not commits.index(commit) in data_project:
            commit_setter.set_commit(
                toolbox.get_absolute_path(toolbox.prefix_current_dataset +
                                          project), project,
                commits.index(commit))
            prefix_folder_result = toolbox.get_absolute_path(
                toolbox.prefix_result + project + "/" +
                toolbox.get_output_folder_for_commit(commit, commits) + "/")
            key_commit = str(commits.index(commit)) + "_" + str(
                commit["sha"][0:7])
            for configuration in [
                    "assert_amplification", "input_amplification"
            ]:
                value = run_for_configuration(configuration,
                                              prefix_folder_result, commit)
                if not value is None:
                    if not key_commit in data_project:
                        data_project[key_commit] = {}
                    data_project[key_commit][configuration] = value
    with open(output_path_to_json, 'w') as outfile:
        json.dump(data, outfile)
Пример #7
0
def set_commit(path_to_project_root, project, index_commit):
    cmd = [
        "java",
        "-cp",
        toolbox.get_absolute_path(toolbox.path_to_jar),
        toolbox.full_qualified_name_repositories_setter,
        "--path-to-repository",
        path_to_project_root,
        "--project",
        project,
        "--folder-with-json",
        toolbox.prefix_current_dataset,
        "--commit-index",
        str(index_commit),
    ]
    toolbox.print_and_call(cmd)
Пример #8
0
def run(project, index_begin, index_end, amplifiers):
    path_to_project_json = toolbox.prefix_current_dataset + project + ".json"
    project_json = toolbox.get_json_file(path_to_project_json)
    path_to_project_root = toolbox.prefix_dataset + project
    commits = project_json["commits"]

    # for each commits.
    for commit in commits[index_begin:index_end]:
        log_path = toolbox.get_absolute_path(toolbox.prefix_result + project + "/commits_" + str(commits.index(commit)))
        if amplifiers:
            log_path = log_path + "_amplifiers"
        log_path = log_path + ".log"

        toolbox.set_output_log_path(log_path)
        #  1) set up both version of the program
        commit_setter.set_commit(path_to_project_root, project, commits.index(commit))

        path_to_concerned_module = toolbox.get_absolute_path(
            toolbox.prefix_dataset + project + "/" + commit["concernedModule"])
        path_to_concerned_module_parent = toolbox.get_absolute_path(
            toolbox.prefix_dataset + project + toolbox.suffix_parent + "/" + commit["concernedModule"])
        create_diff(commit["parent"], path_to_concerned_module)

        path_to_test_that_executes_the_changes = toolbox.get_path_to_csv_file(project, str(commits.index(commit)))
        preparation.prepare(project)

        # if the list does not exists, then compute it
        if not os.path.isfile(path_to_test_that_executes_the_changes):
            # must build all the project, i.e. installing the version
            cmd = [toolbox.maven_home + "mvn", "clean", "install", "-DskipTests"]
            toolbox.print_and_call_in_a_file(" ".join(cmd), cwd=path_to_project_root)

            get_list_of_tests_that_execute_changes(commit["concernedModule"],
                                                   path_to_concerned_module,
                                                   path_to_concerned_module_parent,
                                                   path_to_test_that_executes_the_changes)

        output_path = toolbox.get_absolute_path(toolbox.prefix_result + project + "/commit_" + str(commits.index(commit)))
        if amplifiers:
            output_path = output_path + "_amplifiers"

        # run now dspot with maven plugin
        cmd = [
            toolbox.maven_home + "mvn",
            "eu.stamp-project:dspot-maven:1.1.1-SNAPSHOT:amplify-unit-tests",
            "-Dpath-to-test-list-csv=" + path_to_test_that_executes_the_changes,
            "-Dverbose=True",
            "-Dtest-criterion=ChangeDetectorSelector",
            "-Doutput-path=" + output_path,
            "-Dpath-to-second-version=" + path_to_concerned_module_parent,
            "-Dgenerate-new-test-class=true",
            "-Dclean=true"
        ]

        if amplifiers:
            cmd.append("-Damplifiers=AllLiteralAmplifiers,MethodAdd,MethodRemove,MethodGeneratorAmplifier,ReturnValueAmplifier,NullifierAmplifier")
            cmd.append("-Diteration=3")
            cmd.append("-Dbudgetizer=SimpleBudgetizer")

        cmd = preparation.add_needed_options(cmd, project)
        toolbox.print_and_call_in_a_file(" ".join(cmd), cwd=path_to_concerned_module)
Пример #9
0
def diff_coverage(project):
    project_json = toolbox.get_json_file(
        toolbox.get_absolute_path(toolbox.prefix_current_dataset + project))
    commits = project_json["commits"]
    for commit_json in commits:
        concerned_module = commit_json["concernedModule"]
        commit_setter.set_commit(
            toolbox.get_absolute_path(toolbox.prefix_current_dataset +
                                      project), project,
            commits.index(commit_json))
        path_to_concerned_module_parent = toolbox.get_absolute_path(
            toolbox.prefix_current_dataset + project + "_parent/" +
            concerned_module)
        path_to_concerned_module = toolbox.get_absolute_path(
            toolbox.prefix_current_dataset + project + "/" + concerned_module)
        if not concerned_module == "":
            toolbox.set_output_log_path(
                "trash.log")  # we don't care about the log of the installation
            path_to_project_root = toolbox.get_absolute_path(
                toolbox.prefix_current_dataset + project + "/")
            cmd = [
                toolbox.maven_home + "mvn", "clean", "install", "-DskipTests",
                "-Dmaven.compiler.source=1.8", "-Dmaven.compiler.target=1.8",
                "-Dmaven.compile.source=1.8", "-Dmaven.compile.target=1.8",
                "-Dcheckstyle.skip=true", "-Denforcer.skip=true",
                "-Dxwiki.clirr.skip=true"
            ]
            toolbox.print_and_call_in_a_file(" ".join(cmd),
                                             cwd=path_to_project_root)
        run.create_diff(
            commit_json["sha"],
            path_to_concerned_module_parent,
        )
        run.create_diff(
            commit_json["parent"],
            path_to_concerned_module,
        )
        shutil.copy(
            toolbox.get_absolute_path(path_to_concerned_module +
                                      "/patch.diff"),
            toolbox.get_absolute_path(
                toolbox.prefix_result + project + "/" +
                toolbox.get_output_folder_for_commit(commit_json, commits) +
                "/commit_coverage_patch.diff"))
        shutil.copy(
            toolbox.get_absolute_path(path_to_concerned_module_parent +
                                      "/patch.diff"),
            toolbox.get_absolute_path(
                toolbox.prefix_result + project + "/" +
                toolbox.get_output_folder_for_commit(commit_json, commits) +
                "/parent_coverage_patch.diff"))

        preparation.prepare(project)
        '''
        compute_diff_coverage_for_given_commit(path_to_concerned_module_parent,
                                               path_to_concerned_module,
                                               commit_json,
                                               commits,
                                               "sha",
                                               "parent_coverage"
                                               )
        '''
        compute_diff_coverage_for_given_commit(
            path_to_concerned_module, path_to_concerned_module_parent,
            commit_json, commits, "parent", "commit_coverage")
Пример #10
0
def build_table(projects):
    print_header()
    gray = False
    for project in projects:
        project_json = toolbox.get_json_file(toolbox.get_absolute_path(toolbox.prefix_current_dataset + project))
        nb_commit = project_json["numberCommits"]  # DATA 1
        commits = project_json["commits"]
        nb_test_to_be_amplified = 0  # DATA 2
        nb_success = [0, 0]  # DATA 3
        nb_test_amplified = [0, 0]  # DATA 4
        time = [0, 0]
        coverage = []
        for commit_json in commits[0:10]:
            path_to_commit_folder = toolbox.get_absolute_path(
                toolbox.prefix_result + project + '/' + toolbox.get_output_folder_for_commit(commit_json, commits)
            ) + '/'
            nb_test_to_be_amplified = nb_test_to_be_amplified + get_nb_test_to_be_amplified(path_to_commit_folder)
            modes = ["assert_amplification", "input_amplification"]
            nb_test_amplified_mode = [0, 0]
            time_mode = [0, 0]
            success_mode = [0, 0]
            coverage_commit = get_diff_coverage_commit(path_to_commit_folder)
            coverage.append(coverage_commit)
            for mode in modes:
                path_to_mode_result = path_to_commit_folder + '/' + mode + '/'
                if os.path.isdir(path_to_mode_result):
                    if is_success(path_to_mode_result):
                        success_mode[modes.index(mode)] = success_mode[modes.index(mode)] + 1
                    nb_test_amplified_mode[modes.index(mode)] = nb_test_amplified_mode[
                                                                    modes.index(mode)] + get_nb_test_amplified(
                        path_to_mode_result)
                    if not commit_json['concernedModule'] == "":
                        time_mode[modes.index(mode)] = time_mode[modes.index(mode)] + get_time(path_to_mode_result,
                                                                                               commit_json[
                                                                                                   'concernedModule'].split(
                                                                                                   '/')[
                                                                                                   -2])
                    else:
                        time_mode[modes.index(mode)] = time_mode[modes.index(mode)] + get_time(path_to_mode_result,
                                                                                                project + toolbox.suffix_parent)
            '''
            if gray:
                print '\\rowcolor[HTML]{EFEFEF}'
            gray = not gray
            print_line(
                str(commit_json["sha"])[0:7],
                str(coverage_commit),
                get_nb_test_to_be_amplified(path_to_commit_folder),
                nb_test_amplified_mode[0],
                "\\cmark" if success_mode[0] == 1 else "\\xmark",
                convert_time(time_mode[0]),
                nb_test_amplified_mode[1],
                "\\cmark" if success_mode[1] == 1 else "\\xmark",
                convert_time(time_mode[1])
            )'''

            time[0] = time[0] + time_mode[0]
            time[1] = time[1] + time_mode[1]
            nb_test_amplified[0] = nb_test_amplified[0] + nb_test_amplified_mode[0]
            nb_test_amplified[1] = nb_test_amplified[1] + nb_test_amplified_mode[1]
            nb_success[0] = nb_success[0] + success_mode[0]
            nb_success[1] = nb_success[1] + success_mode[1]

        #percentage_success_aampl = compute_percentage(nb_commit, nb_success[0])
        #percentage_success_iampl = compute_percentage(nb_commit, nb_success[1])

        time[0] = convert_time(time[0])
        time[1] = convert_time(time[1])


        if gray:
            print '\\rowcolor[HTML]{EFEFEF}'
        gray = not gray
        print_line(
            '\\tiny{\\textsc{' + project + '}}',
            '\\tiny{' + str(round(avg(coverage), 2)) + '}',
            '\\tiny{' + str(nb_test_to_be_amplified) + '}',
            '\\tiny{' + str(nb_test_amplified[0]) + '}',
            '\\tiny{' + str(nb_success[0]) + '}',
            '\\tiny{' + str(time[0]) + '}',
            '\\tiny{' + str(nb_test_amplified[1]) + '}',
            '\\tiny{' + str(nb_success[1]) + '}',
            '\\tiny{' + str(time[1]) + '}'
        )
Пример #11
0
def build_table(projects):
    print_header()
    gray = False
    for project in projects:
        project_json = toolbox.get_json_file(
            toolbox.get_absolute_path(toolbox.prefix_current_dataset +
                                      project))
        nb_commit = project_json["numberCommits"]  # DATA 1
        commits = project_json["commits"]
        nb_test_to_be_amplified = 0  # DATA 2
        nb_success = [0, 0]  # DATA 3
        nb_test_amplified = [[], []]  # DATA 4
        time = [[], []]
        coverage = []
        nb_test_total_project = []
        print '\multirow{11}{*}{\\rotvertical{' + project + '}}'
        for commit_json in commits[0:10]:
            path_to_commit_folder = toolbox.get_absolute_path(
                toolbox.prefix_result + project + '/' + toolbox.
                get_output_folder_for_commit(commit_json, commits)) + '/'
            coverage_commit = get_diff_coverage_commit(path_to_commit_folder)
            nb_test_total = commit_json['nb_test_per_commit']
            if coverage_commit == -1:
                continue
            coverage.append(round(coverage_commit, 2))
            nb_test_to_be_amplified = nb_test_to_be_amplified + get_nb_test_to_be_amplified(
                path_to_commit_folder)
            modes = ["assert_amplification", "input_amplification"]
            nb_test_amplified_mode = [0, 0]
            time_mode = [0, 0]
            success_mode = [0, 0]
            size_diff = diff_size.size(path_to_commit_folder +
                                       "commit_coverage_patch.diff")
            date = commit_json['date']
            nb_test_modified_commit = commit_json['nbModifiedTest']
            for mode in modes:
                path_to_mode_result = path_to_commit_folder + '/' + mode + '/'
                if os.path.isdir(path_to_mode_result):
                    if is_success(path_to_mode_result):
                        success_mode[modes.index(
                            mode)] = success_mode[modes.index(mode)] + 1
                    nb_test_amplified_mode[modes.index(
                        mode)] = nb_test_amplified_mode[modes.index(
                            mode)] + get_nb_test_amplified(path_to_mode_result)
                    if not commit_json['concernedModule'] == "":
                        time_mode[modes.index(
                            mode)] = time_mode[modes.index(mode)] + get_time(
                                path_to_mode_result,
                                commit_json['concernedModule'].split('/')[-2])
                    else:
                        time_mode[modes.index(
                            mode)] = time_mode[modes.index(mode)] + get_time(
                                path_to_mode_result,
                                project + toolbox.suffix_parent)
            print_line(
                str(commit_json["sha"])[0:7], convert_date(date),
                str(nb_test_modified_commit), str(nb_test_total),
                convert_diff_size(size_diff), str(round(coverage_commit, 2)),
                get_nb_test_to_be_amplified(path_to_commit_folder),
                '\\cmark(' + str(nb_test_amplified_mode[0]) +
                ')' if success_mode[0] == 1 else "0",
                convert_time(time_mode[0]),
                '\\cmark(' + str(nb_test_amplified_mode[1]) +
                ')' if success_mode[1] == 1 else "0",
                convert_time(time_mode[1]))

            time[0].append(convert_time(time_mode[0]))
            time[1].append(convert_time(time_mode[1]))
            nb_success[0] = nb_success[0] + success_mode[0]
            nb_success[1] = nb_success[1] + success_mode[1]
            nb_test_total_project.append(nb_test_total)
            nb_test_amplified[0].append(nb_test_amplified_mode[0])
            nb_test_amplified[1].append(nb_test_amplified_mode[1])

        # percentage_success_aampl = compute_percentage(nb_commit, nb_success[0])
        # percentage_success_iampl = compute_percentage(nb_commit, nb_success[1])

        # time[0] = convert_time(time[0])
        # time[1] = convert_time(time[1])

        print '\\hline'

        print '\\rowcolor[HTML]{EFEFEF}'
        print_line('total', '\\xspace{}', '\\xspace{}', '\\xspace{}',
                   '\\xspace{}', '\\xspace{}', nb_test_to_be_amplified,
                   avg(nb_test_amplified[0]), 'avg(' + str(avg(time[0])) + ')',
                   avg(nb_test_amplified[1]), 'avg(' + str(avg(time[1])) + ')')
        print '\\hline'