示例#1
0
    def analyze(self, program_file_path: str, config: Config) -> None:
        """
        Runs e2e analyses on the given program
        :param program_file_path: **absolute** path to the program to analyze
        :param config: config object for user-defined configuration
        """
        input_sizes: List[int] = config.get_input_sizes()

        # creates all required dockerfiles and stores paths in a dict of <input_size, dockerfile path>
        debug("Creating dockerfiles for each input size")
        dockerfiles: Dict[int, str] = \
            {size: self._build_dockerfile_for_input(program_file_path, size, config) for size in input_sizes}

        # builds all the dockerfiles into images and stores the image names in a dict of <input_size, image name>
        debug("Building docker images for each input size")
        images: Dict[int, str] = \
            {size: build_docker_image(dockerfile) for size, dockerfile in dockerfiles.items()}

        # execute the test runs
        for input_size, image in images.items():
            debug("Analyzing for input size {}".format(input_size))
            individual_results: List[TestResult] = self._run_test_container(
                image, self.RUNS_PER_INPUT_SIZE)
            computed_results: InputSizeResult = self._compute_average(
                individual_results)
            self.results[input_size] = computed_results

        debug("End-to-end analysis complete!")
        debug("Doing some clean-up!")
        try:
            delete_all_docker_images(exceptions=["python"], force=True)
            debug("All cleaned-up here.")
        except:
            debug("Cleanup failed. Please cleanup Docker manually")
示例#2
0
def test_sample_config_complete():
    config_path = path.join(PATH_TO_SAMPLE_CONFIGS,
                            "sample_config_complete.json")
    config = Config(config_path)
    assert config.get_input_sizes() == [1, 2, 10, 20, 30, 100, 2000]
    assert config.get_args_for(1) == ["-n", "51", "-f", "/some/file"]
    assert config.get_args_for(2) == ["-n", "52", "-f", "/some/file"]
    assert config.get_args_for(10) == ["-n", "60", "-f", "/some/file"]
    assert config.get_args_for(20) == ["-n", "70", "-f", "/some/file"]
    assert config.get_args_for(30) == ["-n", "80", "-f", "/some/file"]
    assert config.get_args_for(100) == ["-n", "150", "-f", "/some/file"]
    assert config.get_args_for(2000) == ["-n", "2050", "-f", "/some/file"]
示例#3
0
 def _build_dockerfile_for_input(self, program_file_path: str,
                                 input_size: int, config: Config) -> str:
     """
     Builds a dockerfile to run the program for the given input size and returns the path to the dockerfile
     :param program_file_path: path to python program to test
     :param input_size: input size on which to test program
     :param config: user provided config
     :return: path to generated dockerfile
     """
     return build_python_dockerfile(program_file_path,
                                    config.get_args_for(input_size))
示例#4
0
def test_config_non_file_path():
    with pytest.raises(Exception):
        config_path = PATH_TO_SAMPLE_CONFIGS
        Config(config_path)
示例#5
0
def test_config_file_does_not_exist():
    with pytest.raises(Exception):
        config_path = "/non/existent/path"
        Config(config_path)
示例#6
0
def test_sample_config_non_numeric_sizes():
    with pytest.raises(Exception):
        config_path = path.join(PATH_TO_SAMPLE_CONFIGS,
                                "sample_config_non_numeric_sizes.json")
        Config(config_path)
示例#7
0
def test_sample_config_missing_arg_property():
    with pytest.raises(Exception):
        config_path = path.join(PATH_TO_SAMPLE_CONFIGS,
                                "sample_config_missing_arg_property.json")
        Config(config_path)