Exemplo n.º 1
0
class GraphParserDriver(BaseTraceTaskDriver):
    """
    Task driver that generates a cheriplot graph from a trace file.

    Available parameters are:

    * :class:`BaseTraceTaskDriver` parameters
    * threads: the number of threads to use (default 1)
    * outfile: the output trace file (default <trace_file_name>_graph.gt
    """
    description = """
    Trace parse tool.
    This tool generates a cheriplot graph from a CHERI trace.
    """

    threads = Option(
        type=int,
        default=1,
        help="Run the tool with the given number of workers (experimental)")
    outfile = Option(default=None,
                     type=file_path_validator,
                     help="Output graph file name")
    display_name = Option(default=None,
                          help="User-readable name of the dataset")
    cheri_cap_size = Option(default="256",
                            choices=("128", "256"),
                            help="Cheri capability size")

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        default_outfile = "{}_graph.gt".format(self.config.trace)
        outfile = self.config.outfile or default_outfile
        if self.config.cheri_cap_size == "128":
            cap_size = 16
        elif self.config.cheri_cap_size == "256":
            cap_size = 32
        else:
            raise ValueError("Invalid capability size {}".format(
                self.config.cheri_cap_size))

        self.pgm = ProvenanceGraphManager(outfile)
        """Graph manager."""

        self._parser = CheriMipsModelParser(self.pgm,
                                            capability_size=cap_size,
                                            trace_path=self.config.trace,
                                            threads=self.config.threads)
        """Graph parser strategy, depends on the architecture."""

    def run(self):
        self._parser.parse()
        # get the parsed provenance graph model
        self.pgm.save(name=self.config.display_name)
        # force free the parser to reclaim memory
        del self._parser
Exemplo n.º 2
0
def test_nodegen_errors(pgm, trace, exc_type, threads):
    """
    Test expected failure conditions where 
    the parser should throw an error.
    """

    with tempfile.NamedTemporaryFile() as tmp:
        # setup the mock trace
        w = ProvenanceTraceWriter(tmp.name)
        w.write_trace(trace, pc=0x1000)

        # get parsed graph
        parser = CheriMipsModelParser(pgm, trace_path=tmp.name, threads=threads)
        with pytest.raises(exc_type) as excinfo:
            parser.parse()
Exemplo n.º 3
0
def test_nodegen_simple(pgm, trace, threads):
    """Test provenance parser with the simplest trace possible."""

    with tempfile.NamedTemporaryFile() as tmp:
        # setup the mock trace
        w = ProvenanceTraceWriter(tmp.name)
        # multipart traces can be given so that common initialization
        # parts are not repeated
        w.write_trace(trace[0], pc=0x1000)
        for t in trace[1:]:
            w.write_trace(t)

        # get parsed graph
        parser = CheriMipsModelParser(pgm, trace_path=tmp.name, threads=threads)
        parser.parse()
        assert_graph_equal(w.pgm.graph, pgm.graph)
Exemplo n.º 4
0
def test_callgen_errors(pgm, test_data, threads):
    """Test provenance parser with the simplest trace possible."""

    with tempfile.NamedTemporaryFile() as tmp:
        # setup the mock trace
        w = ProvenanceTraceWriter(tmp.name)
        traces, error = test_data
        for base, model in traces:
            w.write_trace(model, pc=base)

        # get parsed graph
        parser = CheriMipsModelParser(pgm,
                                      trace_path=tmp.name,
                                      threads=threads)
        with pytest.raises(error):
            parser.parse()
Exemplo n.º 5
0
def test_callgen(pgm, traces, threads):
    """Test provenance parser with the simplest trace possible."""

    with tempfile.NamedTemporaryFile() as tmp:
        # setup the mock trace
        w = ProvenanceTraceWriter(tmp.name)
        for base, model in traces:
            w.write_trace(model, pc=base)

        # get parsed graph
        parser = CheriMipsModelParser(pgm,
                                      trace_path=tmp.name,
                                      threads=threads)
        parser.parse()
        # check the provenance graph model
        assert_graph_equal(w.pgm.graph, pgm.graph)
Exemplo n.º 6
0
def test_mem_errors(pgm, trace, exc_type, threads):
    """
    Test expected failure conditions where 
    the parser should throw an error.
    """

    with tempfile.NamedTemporaryFile() as tmp:
        # setup the mock trace
        w = ProvenanceTraceWriter(tmp.name)
        # multipart traces can be given so that common initialization
        # parts are not repeated
        w.write_trace(trace[0], pc=0x1000)
        for t in trace[1:]:
            w.write_trace(t)

        # get parsed graph
        parser = CheriMipsModelParser(pgm, trace_path=tmp.name, threads=threads)
        with pytest.raises(exc_type) as excinfo:
            parser.parse()