def test_vara_cs_gen_specific(self):
     """Test for vara-cs gen select_specific."""
     runner = CliRunner()
     Path(vara_cfg()["paper_config"]["folder"].value + "/" +
          "test_gen").mkdir()
     vara_cfg()["paper_config"]["current_config"] = "test_gen"
     result = runner.invoke(
         driver_casestudy.main, [
             'gen', '-p', 'gravity', 'select_specific',
             '8820d0e08d1b389fc1e4ac2a17ad9f5418b21dfc',
             'f9e95a41c18ed995f2c7cee7498c1a2313427c08'
         ]
     )
     self.assertEqual(0, result.exit_code, result.exception)
     case_study_path = Path(
         vara_cfg()["paper_config"]["folder"].value +
         "/test_gen/gravity_0.case_study"
     )
     self.assertTrue(case_study_path.exists())
     case_study = load_case_study_from_file(case_study_path)
     self.assertTrue(
         case_study.revisions.__contains__(
             FullCommitHash('8820d0e08d1b389fc1e4ac2a17ad9f5418b21dfc')
         )
     )
     self.assertTrue(
         case_study.revisions.__contains__(
             FullCommitHash('f9e95a41c18ed995f2c7cee7498c1a2313427c08')
         )
     )
     self.assertEqual(len(case_study.revisions), 2)
    def test_increase_interaction_amount(self) -> None:
        """Checks if interactions where the amount increased between reports are
        shown."""
        diff = BlameReportDiff(self.reports[1], self.reports[0])
        changed_func = diff.get_blame_result_function_entry('bool_exec')

        # Check if deleted function is correctly added to diff
        self.assertEqual(changed_func.name, 'bool_exec')
        self.assertEqual(changed_func.demangled_name, 'bool_exec')
        self.assertEqual(len(changed_func.interactions), 2)

        # Check second interaction, that was increased
        self.assertEqual(
            changed_func.interactions[1].base_taint.commit.commit_hash,
            FullCommitHash('48f8ed5347aeb9d54e7ea041b1f8d67ffe74db33'))
        self.assertEqual(len(changed_func.interactions[1].interacting_taints),
                         2)
        self.assertEqual(
            changed_func.interactions[1].interacting_taints[0].commit.
            commit_hash,
            FullCommitHash('a387695a1a2e52dcb1c5b21e73d2fd5a6aadbaf9'))
        self.assertEqual(
            changed_func.interactions[1].interacting_taints[1].commit.
            commit_hash,
            FullCommitHash('e8999a84efbd9c3e739bff7af39500d14e61bfbc'))
        self.assertEqual(changed_func.interactions[1].amount, 2)
    def test_remove_function_between_reports(self) -> None:
        """Checks if the diff containts functions that where removed between
        reports."""
        diff = BlameReportDiff(self.reports[2], self.reports[0])
        del_func = diff.get_blame_result_function_entry('bool_exec')

        # Check if deleted function is correctly added to diff
        self.assertEqual(del_func.name, 'bool_exec')
        self.assertEqual(del_func.demangled_name, 'bool_exec')
        self.assertEqual(len(del_func.interactions), 2)
        # Check first interaction
        self.assertEqual(
            del_func.interactions[0].base_taint.commit.commit_hash,
            FullCommitHash('48f8ed5347aeb9d54e7ea041b1f8d67ffe74db33'))
        self.assertEqual(len(del_func.interactions[0].interacting_taints), 1)
        self.assertEqual(
            del_func.interactions[0].interacting_taints[0].commit.commit_hash,
            FullCommitHash('a387695a1a2e52dcb1c5b21e73d2fd5a6aadbaf9'))
        self.assertEqual(del_func.interactions[0].amount, 22)

        # Check second interaction
        self.assertEqual(
            del_func.interactions[1].base_taint.commit.commit_hash,
            FullCommitHash('48f8ed5347aeb9d54e7ea041b1f8d67ffe74db33'))
        self.assertEqual(len(del_func.interactions[1].interacting_taints), 2)
        self.assertEqual(
            del_func.interactions[1].interacting_taints[0].commit.commit_hash,
            FullCommitHash('a387695a1a2e52dcb1c5b21e73d2fd5a6aadbaf9'))
        self.assertEqual(
            del_func.interactions[1].interacting_taints[1].commit.commit_hash,
            FullCommitHash('e8999a84efbd9c3e739bff7af39500d14e61bfbc'))
        self.assertEqual(del_func.interactions[1].amount, 5)
    def test_vara_cs_gen_sample_start_end_timestamp(self):
        """Check if vara-cs gen select_sample with start and end timestamps
        selects the right revisiosn."""
        runner = CliRunner()
        Path(vara_cfg()["paper_config"]["folder"].value + "/" +
             "test_gen").mkdir()
        vara_cfg()["paper_config"]["current_config"] = "test_gen"
        result = runner.invoke(
            driver_casestudy.main, [
                'gen', '-p', 'brotli', 'select_sample', '--num-rev', '6',
                '--start', '2021-08-17', '--end', '2021-09-09',
                'UniformSamplingMethod'
            ]
        )

        self.assertEqual(0, result.exit_code, result.exception)
        case_study_path = Path(
            vara_cfg()["paper_config"]["folder"].value +
            "/test_gen/brotli_0.case_study"
        )
        self.assertTrue(case_study_path.exists())

        case_study = load_case_study_from_file(case_study_path)
        self.assertEqual(len(case_study.revisions), 5)
        self.assertTrue(
            FullCommitHash('68f1b90ad0d204907beb58304d0bd06391001a4d') in
            case_study.revisions
        )
        self.assertTrue(
            FullCommitHash('62662f87cdd96deda90ac817de94e3c4af75226a') in
            case_study.revisions
        )
 def test_vara_cs_gen_to_extend_new_stage(self):
     """Test the extend-functionality of vara-cs gen."""
     runner = CliRunner()
     vara_cfg()["paper_config"]["current_config"] = "test_ext"
     save_config()
     load_paper_config()
     old_commit = 'ef364d3abc5647111c5424ea0d83a567e184a23b'
     new_commit = '6c6da57ae2aa962aabde6892442227063d87e88c'
     result = runner.invoke(
         driver_casestudy.main, [
             'gen', '-p', 'xz', '--new-stage', '--merge-stage', 'test',
             'select_specific', new_commit
         ]
     )
     self.assertEqual(0, result.exit_code, result.exception)
     case_study_path = Path(
         vara_cfg()["paper_config"]["folder"].value +
         "/test_ext/xz_0.case_study"
     )
     self.assertTrue(case_study_path.exists())
     case_study = load_case_study_from_file(case_study_path)
     self.assertTrue(
         case_study.revisions.__contains__(FullCommitHash(old_commit))
     )
     self.assertTrue(
         case_study.revisions.__contains__(FullCommitHash(new_commit))
     )
     self.assertEqual(2, case_study.num_stages)
     self.assertEqual('test', case_study.stages[1].name)
    def test_get_interacting_commits_for_commit(self) -> None:
        """Test if retrieving of interacting commits works."""
        report = self.reports[1]  # YAML_DOC_BR_6
        commit = CommitRepoPair(
            FullCommitHash("e64923e69eab82332c1bed7fe1e80e14c2c5cb7f"),
            "Elementalist")

        expected_in = {
            CommitRepoPair(
                FullCommitHash("5e030723d70f4894c21881e32dba4decec815c7e"),
                "Elementalist"),
            CommitRepoPair(
                FullCommitHash("bd693d7bc2e4ae5be93e300506ba1efea149e5b7"),
                "Elementalist")
        }
        expected_out = {
            CommitRepoPair(
                FullCommitHash("5e030723d70f4894c21881e32dba4decec815c7e"),
                "Elementalist"),
            CommitRepoPair(
                FullCommitHash("97c573ee98a1c2143b6876433697e363c9eca98b"),
                "Elementalist")
        }

        actual_in, actual_out = get_interacting_commits_for_commit(
            report, commit)

        self.assertSetEqual(expected_in, actual_in)
        self.assertSetEqual(expected_out, actual_out)
Beispiel #7
0
def as_raw_bug(pygit_bug: PygitBug) -> RawBug:
    """Converts a ``PygitBug`` to a ``RawBug``."""
    introducing_commits: tp.Set[FullCommitHash] = set()
    for intro_commit in pygit_bug.introducing_commits:
        introducing_commits.add(FullCommitHash.from_pygit_commit(intro_commit))
    return RawBug(FullCommitHash.from_pygit_commit(pygit_bug.fixing_commit),
                  introducing_commits, pygit_bug.issue_id,
                  pygit_bug.creation_date, pygit_bug.resolution_date)
    def test_less_repo(self):
        """Tests that a smaller repo is less, if the commits are equal."""
        cr_pair_1 = CommitRepoPair(
            FullCommitHash("4200000000000000000000000000000000000000"),
            "foo_repo")
        cr_pair_2 = CommitRepoPair(
            FullCommitHash("4200000000000000000000000000000000000000"),
            "boo_repo")

        self.assertFalse(cr_pair_1 < cr_pair_2)
    def test_less_commit(self):
        """Tests that a smaller commit is less."""
        cr_pair_1 = CommitRepoPair(
            FullCommitHash("4100000000000000000000000000000000000000"),
            "foo_repo")
        cr_pair_2 = CommitRepoPair(
            FullCommitHash("4200000000000000000000000000000000000000"),
            "foo_repo")

        self.assertTrue(cr_pair_1 < cr_pair_2)
Beispiel #10
0
    def test_less_equal(self):
        """Tests that two equal pairs are not less."""
        cr_pair_1 = CommitRepoPair(
            FullCommitHash("4200000000000000000000000000000000000000"),
            "foo_repo")
        cr_pair_2 = CommitRepoPair(
            FullCommitHash("4200000000000000000000000000000000000000"),
            "foo_repo")

        self.assertFalse(cr_pair_1 < cr_pair_2)
Beispiel #11
0
    def test_equal_equal(self):
        """Tests that two equal pairs are equal."""
        cr_pair_1 = CommitRepoPair(
            FullCommitHash("4200000000000000000000000000000000000000"),
            "foo_repo")
        cr_pair_2 = CommitRepoPair(
            FullCommitHash("4200000000000000000000000000000000000000"),
            "foo_repo")

        self.assertTrue(cr_pair_1 == cr_pair_2)
Beispiel #12
0
    def test_equal_repo(self):
        """Tests that two different commits are not equal."""
        cr_pair_1 = CommitRepoPair(
            FullCommitHash("4200000000000000000000000000000000000000"),
            "bar_repo")
        cr_pair_2 = CommitRepoPair(
            FullCommitHash("4200000000000000000000000000000000000000"),
            "foo_repo")

        self.assertFalse(cr_pair_1 == cr_pair_2)
Beispiel #13
0
    def test_id_hash_mapping(self) -> None:
        """Test if id -> hash mappings are correct."""
        self.assertEqual(
            self.r_mappings["8ac1b3f73baceb4a16e99504807d23d38e5123b1"].hash,
            FullCommitHash("8ac1b3f73baceb4a16e99504807d23d38e5123b1")
        )

        self.assertEqual(
            self.r_mappings["38f87b03c2763bb2af05ae98905b0ac8ba55b3eb"].hash,
            FullCommitHash("38f87b03c2763bb2af05ae98905b0ac8ba55b3eb")
        )
Beispiel #14
0
    def get_release_revisions(
            cls, release_type: ReleaseType
    ) -> tp.List[tp.Tuple[FullCommitHash, str]]:
        major_release_regex = "^v[0-9]+\\.[0-9]+$"
        minor_release_regex = "^v[0-9]+\\.[0-9]+(\\.[0-9]+)?$"

        tagged_commits = get_tagged_commits(cls.NAME)
        if release_type == ReleaseType.MAJOR:
            return [(FullCommitHash(h), tag) for h, tag in tagged_commits
                    if re.match(major_release_regex, tag)]
        return [(FullCommitHash(h), tag) for h, tag in tagged_commits
                if re.match(minor_release_regex, tag)]
 def test_get_config_ids_for_rev_in_stage(self) -> None:
     """Checks if the correct config IDs are fetched for the different
     revisions."""
     self.assertEqual(
         self.case_study.get_config_ids_for_revision_in_stage(
             FullCommitHash('7620b817357d6f14356afd004ace2da426cf8c36'), 0
         ), [2]
     )
     self.assertEqual(
         self.case_study.get_config_ids_for_revision_in_stage(
             FullCommitHash('7620b817357d6f14356afd004ace2da426cf8c36'), 1
         ), [-1]
     )
 def test_get_config_ids_for_rev(self) -> None:
     """Checks if the correct config IDs are fetched for the different
     revisions."""
     self.assertEqual(
         self.case_study.get_config_ids_for_revision(
             FullCommitHash('b8b25e7f1593f6dcc20660ff9fb1ed59ede15b7a')
         ), [0, 1]
     )
     self.assertEqual(
         self.case_study.get_config_ids_for_revision(
             FullCommitHash('8798d5c4fd520dcf91f36ebfa60bc5f3dca550d9')
         ), [-1]
     )
Beispiel #17
0
 def test_gen_interactions_nodes(self) -> None:
     """Test generation of interaction node."""
     nodes = generate_interactions(self.commit_report, self.cmap)[0]
     self.assertEqual(
         nodes.at[0, 'hash'],
         FullCommitHash('38f87b03c2763bb2af05ae98905b0ac8ba55b3eb')
     )
     self.assertEqual(nodes.at[0, 'id'], 12)
     self.assertEqual(
         nodes.at[3, 'hash'],
         FullCommitHash('95ace546d3f6c5909a636017f141784105f9dab2')
     )
     self.assertEqual(nodes.at[3, 'id'], 9)
Beispiel #18
0
    def test_get_submodule_head(self):
        """Check if correct submodule commit is retrieved."""
        repo_path = get_local_project_git_path("grep")
        old_head = get_head_commit(repo_path)
        repo_head = FullCommitHash("cb15dfa4b2d7fba0d50e87b49f979c7f996b8ebc")
        checkout_branch_or_commit(repo_path, repo_head)

        try:
            submodule_head = get_submodule_head("grep", "gnulib", repo_head)
            self.assertEqual(
                submodule_head,
                FullCommitHash("f44eb378f7239eadac38d02463019a8a6b935525"))
        finally:
            checkout_branch_or_commit(repo_path, old_head)
Beispiel #19
0
    def test_commit_range(self):
        """Check if we get the correct code churn for commit range."""

        repo_path = get_local_project_git_path("brotli")

        files_changed, insertions, deletions = calc_code_churn(
            repo_path,
            FullCommitHash("36ac0feaf9654855ee090b1f042363ecfb256f31"),
            FullCommitHash("924b2b2b9dc54005edbcd85a1b872330948cdd9e"),
            ChurnConfig.create_c_style_languages_config())

        self.assertEqual(files_changed, 3)
        self.assertEqual(insertions, 49)
        self.assertEqual(deletions, 11)
    def test_found_interactions(self) -> None:
        """Test if all interactions were found."""
        c_interaction_list = self.func_entry_c.interactions
        self.assertEqual(len(c_interaction_list), 2)
        self.assertEqual(
            c_interaction_list[0].base_taint.commit.commit_hash,
            FullCommitHash('48f8ed5347aeb9d54e7ea041b1f8d67ffe74db33'))
        self.assertEqual(c_interaction_list[0].amount, 22)
        self.assertEqual(
            c_interaction_list[1].base_taint.commit.commit_hash,
            FullCommitHash('48f8ed5347aeb9d54e7ea041b1f8d67ffe74db33'))
        self.assertEqual(c_interaction_list[1].amount, 5)

        cxx_interaction_list = self.func_entry_cxx.interactions
        self.assertEqual(cxx_interaction_list, [])
    def test_base_hash(self) -> None:
        """Test if base_hash is loaded correctly."""
        self.assertEqual(
            self.blame_interaction_1.base_taint.commit.commit_hash,
            FullCommitHash('48f8ed5347aeb9d54e7ea041b1f8d67ffe74db33'))
        self.assertEqual(
            self.blame_interaction_1.base_taint.commit.repository_name,
            'Unknown')

        self.assertEqual(
            self.blame_interaction_2.base_taint.commit.commit_hash,
            FullCommitHash('48f8ed5347aeb9d54e7ea041b1f8d67ffe74db33'))
        self.assertEqual(
            self.blame_interaction_2.base_taint.commit.repository_name,
            'Unknown')
    def test_gen_filter(self) -> None:
        """Check if the project generates a revision filter."""
        revision_filter = self.case_study.get_revision_filter()
        self.assertTrue(
            revision_filter(
                FullCommitHash("b8b25e7f1593f6dcc20660ff9fb1ed59ede15b7a")
            )
        )
        self.assertTrue(revision_filter(ShortCommitHash("b8b25e7f15")))

        self.assertFalse(
            revision_filter(
                FullCommitHash("42b25e7f1593f6dcc20660ff9fb1ed59ede15b7a")
            )
        )
Beispiel #23
0
    def test_get_all_revisions_between_full(self):
        """Check if the correct all revisions are correctly found."""
        repo_path = get_local_project_git_path("brotli")
        revs = get_all_revisions_between(
            '5692e422da6af1e991f9182345d58df87866bc5e',
            '2f9277ff2f2d0b4113b1ffd9753cc0f6973d354a', FullCommitHash,
            repo_path)

        self.assertSetEqual(
            set(revs), {
                FullCommitHash("5692e422da6af1e991f9182345d58df87866bc5e"),
                FullCommitHash("2f9277ff2f2d0b4113b1ffd9753cc0f6973d354a"),
                FullCommitHash("63be8a99401992075c23e99f7c84de1c653e39e2"),
                FullCommitHash("2a51a85aa86abb4c294c65fab57f3d9c69f10080")
            })
Beispiel #24
0
    def test_start_with_initial_commit(self):
        """Check if the initial commit is handled correctly."""

        repo_path = get_local_project_git_path("brotli")

        churn = calc_code_churn_range(
            repo_path, ChurnConfig.create_c_style_languages_config(),
            FullCommitHash("8f30907d0f2ef354c2b31bdee340c2b11dda0fb0"),
            FullCommitHash("8f30907d0f2ef354c2b31bdee340c2b11dda0fb0"))

        files_changed, insertions, deletions = churn[FullCommitHash(
            "8f30907d0f2ef354c2b31bdee340c2b11dda0fb0")]
        self.assertEqual(files_changed, 11)
        self.assertEqual(insertions, 1730)
        self.assertEqual(deletions, 0)
Beispiel #25
0
def generate_interactions(
        commit_report: CommitReport,
        c_map: CommitMap) -> tp.Tuple[pd.DataFrame, pd.DataFrame]:
    """
    Converts the commit analysis interaction data from a ``CommitReport`` into a
    pandas data frame for plotting.

    Args:
        commit_report: the report
        c_map: commit map for mapping commits to unique IDs
    """
    node_rows = []
    for item in commit_report.region_mappings.values():
        node_rows.append([item.hash, c_map.time_id(item.hash)])

    node_rows.sort(key=lambda row: int(tp.cast(int, row[1])), reverse=True)
    nodes = pd.DataFrame(node_rows, columns=['hash', 'id'])

    link_rows = []
    for func_g_edge in commit_report.graph_info.values():
        for cf_edge in func_g_edge.cf_edges:
            link_rows.append([
                cf_edge.edge_from, cf_edge.edge_to, 1,
                c_map.time_id(FullCommitHash(cf_edge.edge_from))
            ])

    links = pd.DataFrame(link_rows,
                         columns=['source', 'target', 'value', 'src_id'])
    return (nodes, links)
    def test_vara_cs_gen_sample_start_before_initial_commit(self):
        """Check if vara-cs gen select_sample with start timestamp before the
        initial commit selects the right revisiosn."""
        runner = CliRunner()
        Path(vara_cfg()["paper_config"]["folder"].value + "/" +
             "test_gen").mkdir()
        vara_cfg()["paper_config"]["current_config"] = "test_gen"
        result = runner.invoke(
            driver_casestudy.main, [
                'gen', '-p', 'brotli', '--allow-blocked', 'select_sample',
                '--num-rev', '6', '--start', '1991-01-01', '--end',
                '2013-10-20', 'UniformSamplingMethod'
            ]
        )

        self.assertEqual(0, result.exit_code, result.exception)
        case_study_path = Path(
            vara_cfg()["paper_config"]["folder"].value +
            "/test_gen/brotli_0.case_study"
        )
        self.assertTrue(case_study_path.exists())

        case_study = load_case_study_from_file(case_study_path)
        self.assertEqual(len(case_study.revisions), 1)
        self.assertTrue(
            FullCommitHash('e0346c826249368f0f4a68a2b95f4ab5cf1e235b') in
            case_study.revisions
        )
Beispiel #27
0
    def test_get_initial_commit_with_specified_path(self) -> None:
        """Check if we can correctly retrieve the inital commit of a repo."""
        inital_commit = get_initial_commit(
            get_local_project_git_path("FeaturePerfCSCollection"))

        self.assertEqual(
            FullCommitHash("4d84c8f80ec2db3aaa880d323f7666752c4be51d"),
            inital_commit)
Beispiel #28
0
 def create_taint_data(
         raw_taint_data: tp.Dict[str, tp.Any]) -> 'BlameTaintData':
     """Create a :class:`BlameTaintData` instance from from the corresponding
     yaml document section."""
     commit = CommitRepoPair(FullCommitHash(raw_taint_data["commit"]),
                             raw_taint_data["repository"])
     return BlameTaintData(commit, raw_taint_data.get("region"),
                           raw_taint_data.get("function"))
 def test_get_config_ids_for_multiple_revs(self) -> None:
     """Checks if the correct config IDs are fetched for the different
     revisions if a revisions is part of more than one stage."""
     self.assertEqual(
         self.case_study.get_config_ids_for_revision(
             FullCommitHash('7620b817357d6f14356afd004ace2da426cf8c36')
         ), [2]
     )
Beispiel #30
0
 def test_time_id(self) -> None:
     """Test time id look up."""
     self.assertEqual(
         self.cmap.time_id(
             FullCommitHash("ae332f2a5d2f6f3e0a23443f8a9bcb068c8af74d")
         ), 1
     )
     self.assertEqual(
         self.cmap.time_id(
             FullCommitHash("ef58a957a6c1887930cc70d6199ae7e48aa8d716")
         ), 0
     )
     self.assertEqual(
         self.cmap.time_id(
             FullCommitHash("20540be6186c159880dda3a49a5827722c1a0ac9")
         ), 32
     )