Esempio n. 1
0
    def test_create_dev_image(self) -> None:
        """Test VaRA install inside container."""
        vara_cfg()["vara"]["llvm_source_dir"] = "tools_src/vara-llvm-project"
        vara_cfg()["vara"]["llvm_install_dir"] = "tools/VaRA"
        vara_cfg()["container"]["from_source"] = False
        bb_cfg()["container"]["from_source"] = False

        with TemporaryDirectory() as tmpdir:
            research_tool = get_research_tool("vara")
            image_context = BaseImageCreationContext(ImageBase.DEBIAN_10,
                                                     Path(tmpdir))
            _create_dev_image_layers(image_context, research_tool)

        layers = image_context.layers

        # check that varats will be installed properly
        varats_install_layer = self.check_layer_type(layers[10], RunLayer)
        self.assertEqual("pip3", varats_install_layer.command)
        self.assertTupleEqual(
            ("install", '--ignore-installed', "varats-core", "varats"),
            varats_install_layer.args)
        varats_copy_config_layer = self.check_layer_type(layers[12], CopyLayer)
        self.assertEqual("/varats_root/.varats.yaml",
                         varats_copy_config_layer.destination)

        # check that research tool dependencies will be installed
        vara_deps_layer = self.check_layer_type(layers[11], RunLayer)
        self.assertEqual("apt", vara_deps_layer.command)

        # check that correct entry point will be set
        entrypoint_layer = self.check_layer_type(layers[16], EntryPoint)
        self.assertEqual(("vara-buildsetup", ), entrypoint_layer.command)
    def test_prepare_slurm(self, mock_create, mock_export) -> None:
        runner = CliRunner()
        bb_root = str(vara_cfg()["benchbuild_root"])
        node_dir = "/tmp/foo"
        export_dir = "/tmp/containers/export"
        vara_cfg()["container"]["research_tool"] = None
        result = runner.invoke(driver_container.main, [
            "prepare-slurm", "-i", "DEBIAN_10", "-t", "vara", "--export-dir",
            export_dir, "--node-dir", node_dir
        ])
        self.assertEqual(0, result.exit_code, result.exception)

        # check vara config
        self.assertEqual("vara", str(vara_cfg()["container"]["research_tool"]))

        # check slurm config
        self.assertEqual(f"{bb_root}/slurm_container.sh.inc",
                         str(bb_cfg()["slurm"]["template"]))
        self.assertTrue(Path(f"{bb_root}/slurm_container.sh.inc").is_file())

        # check bb container config
        self.assertEqual(f"{node_dir}/containers/lib",
                         str(bb_cfg()["container"]["root"]))
        self.assertEqual(f"{node_dir}/containers/run",
                         str(bb_cfg()["container"]["runroot"]))
        self.assertEqual(export_dir, str(bb_cfg()["container"]["export"]))
        self.assertEqual(export_dir, str(bb_cfg()["container"]["import"]))
        self.assertTrue(Path(export_dir).is_dir())
    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_sample_only_code(self):
        """Check if vara-cs gen select_sample with --only-code-commits only
        selects revisions that contain code."""
        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', '10',
                '--start', '68f1b90ad0d204907beb58304d0bd06391001a4d', '--end',
                'f4153a09f87cbb9c826d8fc12c74642bb2d879ea',
                '--only-code-commits', '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)
Esempio n. 5
0
    def gen(self) -> None:
        """Generate the case study using the selected strategy, project and
        strategy specific arguments."""
        cmap = create_lazy_commit_map_loader(self.selected_project, None,
                                             'HEAD', None)()
        version = self.cs_version.value()
        case_study = CaseStudy(self.revision_list_project, version)
        paper_config = vara_cfg()["paper_config"]["current_config"].value
        path = Path(vara_cfg()["paper_config"]["folder"].value) / (
            paper_config +
            f"/{self.revision_list_project}_{version}.case_study")

        if self.strategie_forms.currentIndex(
        ) == GenerationStrategie.SAMPLE.value:
            sampling_method = NormalSamplingMethod.get_sampling_method_type(
                self.sampling_method.currentText())
            extend_with_distrib_sampling(case_study, cmap, sampling_method(),
                                         0, self.num_revs.value(), True,
                                         self.code_commits.clicked)
        elif self.strategie_forms.currentIndex(
        ) == GenerationStrategie.SELECT_REVISION.value:
            selected_rows = self.revision_list.selectionModel().selectedRows(0)
            selected_commits = [row.data() for row in selected_rows]
            extend_with_extra_revs(case_study, cmap, selected_commits, 0)
            self.revision_list.clearSelection()
            self.revision_list.update()
        elif self.strategie_forms.currentIndex(
        ) == GenerationStrategie.REVS_PER_YEAR.value:
            extend_with_revs_per_year(
                case_study, cmap, 0, True,
                get_local_project_git_path(self.selected_project),
                self.revs_per_year.value(), self.seperate.checkState())
        store_case_study(case_study, path)
 def test_vara_cs_cleanup_error(self):
     """Test vara-cs cleanup error."""
     runner = CliRunner()
     vara_cfg()["paper_config"]["current_config"] = "test_cleanup_error"
     save_config()
     load_paper_config()
     importlib.reload(driver_casestudy)
     result = runner.invoke(
         driver_casestudy.main, ['cleanup', 'all', '--error']
     )
     self.assertEqual(0, result.exit_code, result.stdout)
     self.assertFalse(
         Path(
             vara_cfg()["result_dir"].value +
             "/brotli/CRE-CR-brotli-all-6c47009892_5d26c7ff-6d27-478f-bcd1"
             "-99e8e8e97f16_cerror.txt"
         ).exists()
     )
     self.assertFalse(
         Path(
             vara_cfg()["result_dir"].value +
             "/brotli/CRE-CR-brotli-all-aaa4424d9b_5d26c7ff-6d27-478f-bcd1-"
             "99e8e8e97f16_failed.txt"
         ).exists()
     )
     self.assertTrue(
         Path(
             vara_cfg()["result_dir"].value +
             "/brotli/CRE-CR-brotli-brotli-21ac39f7c8_34d4d1b5-7212-4244-"
             "9adc-b19bff599cf1_success.yaml"
         ).exists()
     )
Esempio n. 7
0
    def test_create_base_image_from_source(self) -> None:
        """Test varats install from source."""
        vara_cfg()["container"]["research_tool"] = None
        vara_cfg()["container"]["from_source"] = True
        vara_cfg()["container"]["varats_source"] = "varats_src"
        bb_cfg()["container"]["from_source"] = False
        bb_cfg()["jobs"] = 42

        with TemporaryDirectory() as tmpdir:
            image_context = BaseImageCreationContext(ImageBase.DEBIAN_10,
                                                     Path(tmpdir))
            _create_base_image_layers(image_context)

        layers = image_context.layers

        varats_install_layer = self.check_layer_type(layers[12], RunLayer)
        self.assertEqual("pip3", varats_install_layer.command)
        self.assertTupleEqual(("install", "--ignore-installed",
                               "/varats/varats-core", "/varats/varats"),
                              varats_install_layer.args)
        mounting_parameters = "type=bind,src=varats_src,target=/varats"
        if buildah_version() >= (1, 24, 0):
            mounting_parameters += ",rm"
        self.assertIn(("mount", mounting_parameters),
                      varats_install_layer.kwargs)
    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
        )
 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)
Esempio n. 10
0
def load_paper_config(config_path: tp.Optional[Path] = None) -> None:
    """
    Loads a paper config from a yaml file, initializes the paper config and sets
    it to the currently active paper config. If no config path is provided, the
    paper config set in the vara settings yaml is loaded.

    Note:
        Only one paper config can be active at a time

    Args:
        config_path: path to a paper config folder
    """
    if config_path is None:
        if vara_cfg()["paper_config"]["folder"].value is None or \
                vara_cfg()["paper_config"][
                    "current_config"].value is None:
            raise ConfigurationLookupError(
                f"No paper config was set in VaRA config file "
                f"{vara_cfg()['config_file']}")
        config_path = Path(
            str(vara_cfg()["paper_config"]["folder"]) + "/" +
            str(vara_cfg()["paper_config"]["current_config"]))

    global _G_PAPER_CONFIG  # pylint: disable=global-statement
    _G_PAPER_CONFIG = PaperConfig(config_path)
Esempio n. 11
0
    def test_vara_install(self, mock_install_exists) -> None:
        """Test VaRA install inside container."""
        mock_install_exists.return_value = True
        vara_cfg()["container"]["research_tool"] = "vara"
        vara_cfg()["vara"]["llvm_source_dir"] = "tools_src/vara-llvm-project"
        vara_cfg()["vara"]["llvm_install_dir"] = "tools/VaRA"
        vara_cfg()["container"]["from_source"] = False
        bb_cfg()["container"]["from_source"] = False

        with TemporaryDirectory() as tmpdir:
            image_context = BaseImageCreationContext(ImageBase.DEBIAN_10,
                                                     Path(tmpdir))
            _create_base_image_layers(image_context)

        layers = image_context.layers
        vara_deps_layer = self.check_layer_type(layers[11], RunLayer)
        self.assertEqual("apt", vara_deps_layer.command)

        vara_copy_layer = self.check_layer_type(layers[12], CopyLayer)
        self.assertEqual("/varats_root/tools/VaRA_DEBIAN_10",
                         vara_copy_layer.destination)
        self.assertTupleEqual(("tools/VaRA_DEBIAN_10", ),
                              vara_copy_layer.sources)

        bb_config_layer = self.check_layer_type(layers[15], UpdateEnv)
        self.assertTupleEqual(
            ("BB_ENV", "{PATH: [/varats_root/tools/VaRA_DEBIAN_10/bin]}"),
            bb_config_layer.env[3])
 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)
Esempio n. 13
0
    def test_get_newest_result_files_for_case_study_fail(self) -> None:
        """Check that when we have two files, the newes one get's selected."""
        vara_cfg()['paper_config']['current_config'] = "test_revision_lookup"
        load_paper_config()

        bad_file = ReportFilename(
            'CRE-CR-brotli-brotli-21ac39f7c8_'
            '34d4d1b5-7212-4244-9adc-b19bff599cf1_success.yaml')

        now = datetime.now().timestamp()
        file_path = Path(str(
            vara_cfg()['result_dir'])) / 'brotli' / bad_file.filename
        os.utime(file_path, (now, now))

        newest_res_files = MCS.get_newest_result_files_for_case_study(
            get_paper_config().get_case_studies('brotli')[0],
            Path(vara_cfg()['result_dir'].value), CR)

        # remove unnecessary files
        filtered_newest_res_files = list(
            filter(
                lambda res_file: res_file.commit_hash == bad_file.commit_hash,
                map(lambda res_file: ReportFilename(res_file),
                    newest_res_files)))

        self.assertFalse(filtered_newest_res_files[0].uuid.endswith('42'))
Esempio n. 14
0
    def test_bb_run_slurm_and_container(self, mock_sbatch,
                                        mock_build_images) -> None:
        runner = CliRunner()
        vara_cfg()['paper_config']['current_config'] = "test_revision_lookup"
        # needed so we see the paper config
        load_paper_config()
        # needed so benchbuild sees the paper config
        save_config()

        bb_cfg()["slurm"]["template"] = str(
            Path(str(vara_cfg()["benchbuild_root"])) /
            "slurm_container.sh.inc")
        save_bb_config()

        # Easiest way to configure slurm + container is 'vara-container'
        # As a side-effect, this command is now even more tested :)
        prepare_result = runner.invoke(driver_container.main,
                                       ["prepare-slurm"])
        self.assertEqual(0, prepare_result.exit_code, prepare_result.exception)
        self.assertTrue(Path(str(bb_cfg()["slurm"]["template"])).exists())

        result = runner.invoke(driver_run.main,
                               ["--slurm", "--container", "-E", "JustCompile"])
        self.assertEqual(0, result.exit_code, result.exception)
        self.assertTrue((Path(str(vara_cfg()["benchbuild_root"])) /
                         "JustCompile-slurm.sh").exists())
Esempio n. 15
0
def _pc_create(paper_config: str) -> None:
    """paper_config:
            Path to the new paper config.
             Relative paths are interpreted relative to the current
             `paper_config/folder`."""
    pc_path: Path = Path(paper_config)
    if not pc_path.is_absolute():
        current_folder = vara_cfg()["paper_config"]["folder"].value
        if current_folder is None:
            pc_path = Path(vara_cfg()["config_file"].value
                           ).parent / "paper_configs" / pc_path
        else:
            pc_path = Path(current_folder) / pc_path

    if pc_path.exists():
        LOG.error(f"Cannot create paper config at: {pc_path} "
                  "(Path already exists).")
        return

    folder = pc_path.parent
    current_config = pc_path.name

    LOG.info(
        f"Creating new paper config {current_config} at location {folder}.")
    pc_path.mkdir(parents=True)

    vara_cfg()["paper_config"]["folder"] = str(folder)
    vara_cfg()["paper_config"]["current_config"] = str(current_config)
    save_config()
Esempio n. 16
0
    def sample(cls,
               prj_cls: tp.Type[Project]) -> tp.List[source.VariantContext]:
        """
        Adapt version sampling process if needed, otherwise fallback to default
        implementation.

        Args:
            prj_cls: project class

        Returns:
            list of sampled versions
        """
        variants = list(source.product(*prj_cls.SOURCE))

        if bool(vara_cfg()["experiment"]["random_order"]):
            random.shuffle(variants)

        fs_blacklist = vara_cfg()["experiment"]["file_status_blacklist"].value
        fs_whitelist = vara_cfg()["experiment"]["file_status_whitelist"].value

        if fs_blacklist or fs_whitelist:
            fs_good = set(FileStatusExtension) if not fs_whitelist else set()

            fs_good -= {
                FileStatusExtension.get_file_status_from_str(x)
                for x in fs_blacklist
            }
            fs_good |= {
                FileStatusExtension.get_file_status_from_str(x)
                for x in fs_whitelist
            }

            report_specific_bad_revs = []
            for report_type in cls.report_spec():
                report_specific_bad_revs.append({
                    revision.hash for revision, file_status in
                    get_tagged_experiment_specific_revisions(
                        prj_cls, report_type, experiment_type=cls
                    ) if file_status not in fs_good
                })

            bad_revisions = report_specific_bad_revs[0].intersection(
                *report_specific_bad_revs[1:]
            )

            variants = list(
                filter(lambda var: str(var[0]) not in bad_revisions, variants)
            )

        if not variants:
            print("Could not find any unprocessed variants.")
            return []

        variants = cls._sample_num_versions(variants)

        if bool(bb_cfg()["versions"]["full"]):
            return [source.context(*var) for var in variants]

        return [source.context(*variants[0])]
Esempio n. 17
0
 def test_vara_config_set(self):
     runner = CliRunner()
     vara_cfg()["artefacts"]["artefacts_dir"] = "test"
     save_config()
     runner.invoke(driver_config.main,
                   ["set", "artefacts/artefacts_dir=artefacts"])
     self.assertEqual("artefacts",
                      vara_cfg()["artefacts"]["artefacts_dir"].value)
Esempio n. 18
0
 def test_gen_bbconfig(self):
     """basic tests for the `gen-bbconfig` command."""
     runner = CliRunner()
     Path(vara_cfg()["benchbuild_root"].value + "/.benchbuild.yml").unlink()
     runner.invoke(driver_gen_benchbuild_config.main, [])
     self.assertTrue(
         Path(vara_cfg()["benchbuild_root"].value +
              "/.benchbuild.yml").exists())
 def test_vara_pc_create(self):
     """Test the vara-pc create subcommand."""
     runner = CliRunner()
     runner.invoke(driver_paper_config.main, ["create", "foo"])
     paper_config = Path(vara_cfg()["paper_config"]["folder"].value + "/" +
                         "foo")
     self.assertTrue(paper_config.exists())
     self.assertEqual("foo",
                      vara_cfg()["paper_config"]["current_config"].value)
Esempio n. 20
0
def _pc_set(paper_config: tp.Optional[Path]) -> None:
    if not paper_config:
        pc_folder_path = Path(
            get_value_or_default(vara_cfg()["paper_config"], "folder",
                                 str(get_varats_base_folder())))
        if not (pc_folder_path.exists() and pc_folder_path.is_dir()):
            LOG.error(f"Paper config folder not set: {pc_folder_path} "
                      "(Path does not exist or is no directory).")
            return

        paper_configs = _get_paper_configs(pc_folder_path)
        if not paper_configs:
            LOG.error(f"Could not find paper configs in: {pc_folder_path}")
            return

        raw_pc_path = None

        def set_pc_path(choice: str) -> None:
            nonlocal raw_pc_path
            raw_pc_path = choice

        current_config = None
        try:
            current_config = get_paper_config().path.name
        except ConfigurationLookupError:
            # No paper config specified in the varats config file
            pass

        try:
            cli_list_choice(
                "Choose a number to select a paper config", paper_configs,
                lambda x: f"{x} *"
                if current_config and x == current_config else x, set_pc_path)
        except EOFError:
            return
        if raw_pc_path is None:
            raise AssertionError("Choice should always return a value")
        paper_config = Path(raw_pc_path)

    paper_config = Path(paper_config)
    if not paper_config.is_absolute():
        paper_config = Path(
            vara_cfg()["paper_config"]["folder"].value) / paper_config

    if not (paper_config.exists() and paper_config.is_dir()):
        LOG.error(f"Not a paper config: {paper_config} "
                  "(Path does not exist or is no directory).")
        return

    folder = paper_config.parent
    current_config = paper_config.name

    LOG.info(
        f"Current paper config is now {current_config} at location {folder}.")
    vara_cfg()["paper_config"]["folder"] = str(folder)
    vara_cfg()["paper_config"]["current_config"] = str(current_config)
    save_config()
 def test_vara_cs_gen_release(self):
     """Test gen select_release."""
     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_release', 'major']
     )
     self.assertEqual(0, result.exit_code, result.exception)
Esempio n. 22
0
    def test_get_newest_result_files_for_case_study_with_empty_res_dir(
            self) -> None:
        """Check that we correctly handle the edge case where no result dir
        exists."""
        vara_cfg()['paper_config']['current_config'] = "test_revision_lookup"
        load_paper_config()

        self.assertListEqual(
            MCS.get_newest_result_files_for_case_study(
                get_paper_config().get_case_studies('brotli')[0],
                Path(vara_cfg()['result_dir'].value), CR), [])
Esempio n. 23
0
 def test_research_tool_accessor_default(self, _):
     """Checks if the source_location of a ``ResearchTool`` is set to the
     correct default."""
     with test_environment() as tmp_path:
         vara_cfg()["config_file"] = tmp_path / "dummy.yml"
         vara_cfg()["vara"]["llvm_source_dir"] = tmp_path / "tools_src"
         vara = get_research_tool("vara")
         self.assertTrue(vara.has_source_location())
         self.assertEqual(
             vara.source_location().relative_to(Path(tmp_path)),
             Path("tools_src"))
Esempio n. 24
0
    def test_sample_limit(self):
        """Test if base_hash is loaded correctly."""
        self.prepare_vara_config(vara_cfg())
        self.assertEqual(vara_cfg()["experiment"]["sample_limit"].value, None)
        self.assertEqual(
            # pylint: disable=protected-access
            self.vers_expr._sample_num_versions(self.rev_list),
            self.rev_list)

        vara_cfg()["experiment"]["sample_limit"] = 3
        self.assertEqual(
            len(self.vers_expr._sample_num_versions(self.rev_list)), 3)
 def test_vara_pc_list(self):
     """Test the vara-pc list subcommand."""
     runner = CliRunner()
     paper_configs = ["foo", "bar", "baz"]
     pc_path = Path(vara_cfg()["paper_config"]["folder"].value)
     for pc in paper_configs:
         (pc_path / pc).mkdir()
     vara_cfg()["paper_config"]["current_config"] = "foo"
     load_paper_config()
     result = runner.invoke(driver_paper_config.main, ["list"])
     self.assertEqual(
         "Found the following paper_configs:\nbar\nbaz\nfoo *\n",
         result.output)
Esempio n. 26
0
def main() -> None:
    """
    Main function for working with paper configs.

    `vara-pc`
    """
    initialize_cli_tool()

    if vara_cfg()["paper_config"]["folder"].value is None:
        # Setup default paper config path when none exists
        vara_cfg()["paper_config"]["folder"] = str(
            Path('paper_configs').absolute())
        save_config()
Esempio n. 27
0
    def _create_benchbuild_config() -> None:
        if vara_cfg()["config_file"].value is None:
            LOG.warning("No VaRA config found, please initialize a "
                        "VaRA config first.")
            return

        if vara_cfg()["benchbuild_root"].value is None:
            vara_cfg()["benchbuild_root"] = path.dirname(
                str(vara_cfg()["config_file"])) + "/benchbuild"
        create_missing_folders()

        bb_cfg = create_new_bb_config(vara_cfg())
        save_bb_config(bb_cfg)
Esempio n. 28
0
    def _sample_num_versions(
        versions: tp.List[VersionType]
    ) -> tp.List[VersionType]:
        if vara_cfg()["experiment"]["sample_limit"].value is None:
            return versions

        sample_size = int(vara_cfg()["experiment"]["sample_limit"])
        versions = [
            versions[i] for i in sorted(
                random.
                sample(range(len(versions)), min(sample_size, len(versions)))
            )
        ]
        return versions
Esempio n. 29
0
    def test_only_whitelisting_one(self, mock_get_tagged_revisions):
        """Test if we can whitelist file status."""
        self.prepare_vara_config(vara_cfg())
        bb_cfg()["versions"]["full"] = True
        # Revision not in set
        mock_get_tagged_revisions.return_value = \
            self.generate_get_tagged_revisions_output()

        vara_cfg()["experiment"]["file_status_whitelist"] = ['success']

        sample_gen = self.vers_expr.sample(BBTestProject)

        self.assertEqual(sample_gen[0]["test_source"].version, "rev1000000")
        self.assertEqual(len(sample_gen), 1)
        mock_get_tagged_revisions.assert_called()
Esempio n. 30
0
def __quickfix_dev_branches(branch_name: str, sub_project: SubProject) -> str:
    """
    Fix vara branches names for checking out master or dev branches.

    Test:
    >>> import re
    >>> fixed_branch_name = __quickfix_dev_branches(\
        'vara-dev', SubProject(None, "vara-llvm-project", "", "", ""))
    >>> re.match(r'vara-\\d+-dev', fixed_branch_name) is not None
    True

    >>> fixed_branch_name = __quickfix_dev_branches(\
        'vara', SubProject(None, "vara-llvm-project", "", "", ""))
    >>> re.match(r'vara-\\d+', fixed_branch_name) is not None
    True

    >>> __quickfix_dev_branches(\
        "f-FooBar", SubProject(None, "vara-llvm-project", "", "", ""))
    'f-FooBar'

    >>> __quickfix_dev_branches(\
        "vara-dev", SubProject(None, "vara", "", "", ""))
    'vara-dev'
    """
    if sub_project.name == "vara-llvm-project":
        version = str(vara_cfg()['vara']['version'])
        if branch_name == 'vara-dev':
            return f"vara-{version}-dev"
        if branch_name == 'vara':
            return f"vara-{version}"

    return branch_name