Beispiel #1
0
 def __enter__(self) -> "HammerToolHooksTestContext":
     """Initialize context by creating the temp_dir, driver, and loading mocksynth."""
     self.test.assertTrue(
         hammer_vlsi.HammerVLSISettings.
         set_hammer_vlsi_path_from_environment(),
         "hammer_vlsi_path must exist")
     temp_dir = tempfile.mkdtemp()
     json_path = os.path.join(temp_dir, "project.json")
     with open(json_path, "w") as f:
         f.write(
             json.dumps(
                 {
                     "vlsi.core.synthesis_tool": "mocksynth",
                     "vlsi.core.technology": "nop",
                     "synthesis.inputs.top_module": "dummy",
                     "synthesis.inputs.input_files": ("/dev/null", ),
                     "synthesis.mocksynth.temp_folder": temp_dir
                 },
                 indent=4))
     options = hammer_vlsi.HammerDriverOptions(environment_configs=[],
                                               project_configs=[json_path],
                                               log_file=os.path.join(
                                                   temp_dir, "log.txt"),
                                               obj_dir=temp_dir)
     self.temp_dir = temp_dir
     self._driver = hammer_vlsi.HammerDriver(options)
     self.test.assertTrue(self.driver.load_synthesis_tool())
     return self
Beispiel #2
0
    def __enter__(self) -> "HammerSignoffToolTestContext":
        """Initialize context by creating the temp_dir, driver, and loading the signoff tool."""
        self.test.assertTrue(
            hammer_vlsi.HammerVLSISettings.
            set_hammer_vlsi_path_from_environment(),
            "hammer_vlsi_path must exist")
        temp_dir = tempfile.mkdtemp()
        json_path = os.path.join(temp_dir, "project.json")
        json_content = {
            "vlsi.core.technology": "nop",
            "vlsi.core.%s_tool" % self._tool_type: "mock%s" % self._tool_type,
            "%s.inputs.top_module" % self._tool_type: "dummy",
            "%s.inputs.layout_file" % self._tool_type: "/dev/null",
            "%s.temp_folder" % self._tool_type: temp_dir,
            "%s.submit.command" % self._tool_type: "local"
        }  # type: Dict[str, Any]
        if self._tool_type is "lvs":
            json_content.update({
                "lvs.inputs.schematic_files": ["/dev/null"],
                "lvs.inputs.power_nets": ["VDD"],
                "lvs.inputs.ground_nets": ["VSS"],
                "lvs.inputs.hcells_list": []
            })

        with open(json_path, "w") as f:
            f.write(json.dumps(json_content, indent=4))

        options = hammer_vlsi.HammerDriverOptions(environment_configs=[],
                                                  project_configs=[json_path],
                                                  log_file=os.path.join(
                                                      temp_dir, "log.txt"),
                                                  obj_dir=temp_dir)
        self._driver = hammer_vlsi.HammerDriver(options)
        self.temp_dir = temp_dir
        return self
Beispiel #3
0
    def __enter__(self) -> "HammerSubmitCommandTestContext":
        """Initialize context by creating the temp_dir, driver, and loading mocksynth."""
        self.test.assertTrue(
            hammer_vlsi.HammerVLSISettings.
            set_hammer_vlsi_path_from_environment(),
            "hammer_vlsi_path must exist")
        temp_dir = tempfile.mkdtemp()
        json_path = os.path.join(temp_dir, "project.json")
        json_content = {
            "vlsi.core.synthesis_tool": "mocksynth",
            "vlsi.core.technology": "nop",
            "synthesis.inputs.top_module": "dummy",
            "synthesis.inputs.input_files": ("/dev/null", ),
            "synthesis.mocksynth.temp_folder": temp_dir,
            "synthesis.submit.command": self._cmd_type
        }
        if self._cmd_type is "lsf":
            json_content.update({
                "synthesis.submit.settings": [{
                    "lsf": {
                        "queue":
                        "myqueue",
                        "num_cpus":
                        4,
                        "log_file":
                        "test_log.log",
                        "bsub_binary":
                        os.path.join(
                            os.path.dirname(os.path.abspath(__file__)), "..",
                            "test", "mock_bsub.sh"),
                        "extra_args": ("-R", "myresources")
                    }
                }],
                "synthesis.submit.settings_meta":
                "lazyappend",
                "vlsi.submit.settings": [{
                    "lsf": {
                        "num_cpus": 8
                    }
                }],
                "vlsi.submit.settings_meta":
                "lazyappend"
            })

        with open(json_path, "w") as f:
            f.write(json.dumps(json_content, indent=4))

        options = hammer_vlsi.HammerDriverOptions(environment_configs=[],
                                                  project_configs=[json_path],
                                                  log_file=os.path.join(
                                                      temp_dir, "log.txt"),
                                                  obj_dir=temp_dir)
        self.temp_dir = temp_dir
        self._driver = hammer_vlsi.HammerDriver(options)
        self._submit_command = hammer_vlsi.HammerSubmitCommand.get(
            "synthesis", self.database)
        return self
Beispiel #4
0
    def test_bad_export_config_outputs(self) -> None:
        """
        Test that a plugin that fails to call super().export_config_outputs()
        is caught.
        """
        self.assertTrue(
            hammer_vlsi.HammerVLSISettings.
            set_hammer_vlsi_path_from_environment(),
            "hammer_vlsi_path must exist")
        tmpdir = tempfile.mkdtemp()
        proj_config = os.path.join(tmpdir, "config.json")

        with open(proj_config, "w") as f:
            f.write(
                json.dumps(
                    {
                        "vlsi.core.technology": "nop",
                        "vlsi.core.synthesis_tool": "nop",
                        "vlsi.core.par_tool": "nop",
                        "synthesis.inputs.top_module": "dummy",
                        "synthesis.inputs.input_files": ("/dev/null", )
                    },
                    indent=4))

        class BadExportTool(hammer_vlsi.HammerSynthesisTool, DummyTool):
            def export_config_outputs(self) -> Dict[str, Any]:
                # Deliberately forget to call super().export_config_outputs
                return {'extra': 'value'}

            def fill_outputs(self) -> bool:
                self.output_files = deeplist(self.input_files)
                return True

        driver = hammer_vlsi.HammerDriver(
            hammer_vlsi.HammerDriver.get_default_driver_options()._replace(
                project_configs=[proj_config]))

        syn_tool = BadExportTool()
        syn_tool.tool_dir = tmpdir
        driver.set_up_synthesis_tool(syn_tool, "bad_tool", run_dir=tmpdir)
        with HammerLoggingCaptureContext() as c:
            driver.run_synthesis()
        self.assertTrue(
            c.log_contains("did not call super().export_config_outputs()"))

        # Cleanup
        shutil.rmtree(tmpdir)