Exemple #1
0
    def test_get_undershoot(self):
        """Test get_undershoot"""

        A = [0, 0, 0, 1, 1, 1, 1, 1]
        B = [2, 2, 2, 2, 2, 2, 2, 2]

        trace = trappy.BareTrace()
        df = pd.DataFrame({"A": A, "B": B})
        trace.add_parsed_event("event", df)

        s = SignalCompare(trace, "event:A", "event:B")
        expected = (4.0 / 14.0, 1.0)
        self.assertEqual(s.get_undershoot(method="rect"), expected)

        A = [3, 3, 3, 3, 3, 3, 3, 3]
        B = [2, 2, 2, 2, 2, 2, 1, 1]

        df = pd.DataFrame({"A": A, "B": B})
        trace.event.data_frame = df
        s = SignalCompare(trace, "event:A", "event:B")

        expected = (float("nan"), 0.0)
        result = s.get_undershoot(method="rect")
        self.assertTrue(np.isnan(result[0]))
        self.assertEqual(result[1], expected[1])
Exemple #2
0
    def test_barplot_trace(self):
        """BarPlot plots traces without exploding"""
        trace = trappy.BareTrace()
        trace.add_parsed_event("event", self.dfr)

        trappy.BarPlot(trace, signals=["event:foo",
                                       "event:bar"]).view(test=True)
Exemple #3
0
    def setUp(self):
        trace = trappy.BareTrace()
        data = {
            "identifier": [
                0,
                0,
                0,
                1,
                1,
                1,
            ],
            "result": [
                "fire",
                "blank",
                "fire",
                "blank",
                "fire",
                "blank",
            ],
        }

        index = pd.Series([0.1, 0.2, 0.3, 0.4, 0.5, 0.6], name="Time")
        data_frame = pd.DataFrame(data, index=index)
        trace.add_parsed_event("aim_and_fire", data_frame)
        self._trace = trace
        self.topology = Topology(clusters=[[0], [1]])
 def test_exp_ops(self):
     """Test exponentiation: Numeric"""
     parser = Parser(trappy.BareTrace())
     eqn = "3**3 * 2**4"
     self.assertEqual(parser.solve(eqn), 432)
     eqn = "3**(4/2)"
     self.assertEqual(parser.solve(eqn), 9)
Exemple #5
0
    def test_bare_trace_get_duration(self):
        """BareTrace.get_duration() works for a simple case"""

        trace = trappy.BareTrace()
        trace.add_parsed_event("pmu_counter", self.dfr[0])
        trace.add_parsed_event("load_event", self.dfr[1])

        self.assertEquals(trace.get_duration(), self.dfr[1].index[-1])
    def test_sum_operator(self):
        """Test Addition And Subtraction: Numeric"""

        parser = Parser(trappy.BareTrace())
        # Simple equation
        eqn = "10 + 2 - 3"
        self.assertEqual(parser.solve(eqn), 9)
        # Equation with bracket and unary ops
        eqn = "(10 + 2) - (-3 + 2)"
        self.assertEqual(parser.solve(eqn), 13)
Exemple #7
0
    def test_bare_trace_can_add_parsed_event(self):
        """The BareTrace() class can add parsed events to its collection of trace events"""
        trace = trappy.BareTrace()
        trace.add_parsed_event("pmu_counters", self.dfr[0])

        self.assertEquals(len(trace.pmu_counters.data_frame), 3)
        self.assertEquals(trace.pmu_counters.data_frame["l1_misses"].iloc[0],
                          24)

        trace.add_parsed_event("pivoted_counters", self.dfr[0], pivot="cpu")
        self.assertEquals(trace.pivoted_counters.pivot, "cpu")
Exemple #8
0
    def test_assert_statement_bool(self):
        """Check that asssertStatement() works with a simple boolean case"""

        rolls_dfr = pd.DataFrame({"results": [1, 3, 2, 6, 2, 4]})
        trace = trappy.BareTrace()
        trace.add_parsed_event("dice_rolls", rolls_dfr)
        config = {"MAX_DICE_NUMBER": 6}

        t = Analyzer(trace, config)
        statement = "numpy.max(dice_rolls:results) <= MAX_DICE_NUMBER"
        self.assertTrue(t.assertStatement(statement, select=0))
    def test_mul_ops(self):
        """Test Mult and Division: Numeric"""

        parser = Parser(trappy.BareTrace())
        eqn = "(10 * 2 / 10)"
        self.assertEqual(parser.solve(eqn), 2)
        eqn = "-2 * 2 + 2 * 10 / 10"
        self.assertEqual(parser.solve(eqn), -2)
        eqn = "3.5 // 2"
        self.assertEqual(parser.solve(eqn), 1)
        eqn = "5 % 2"
        self.assertEqual(parser.solve(eqn), 1)
Exemple #10
0
    def test_bare_trace_get_duration_normalized(self):
        """BareTrace.get_duration() works if the trace has been normalized"""

        trace = trappy.BareTrace()
        trace.add_parsed_event("pmu_counter", self.dfr[0].copy())
        trace.add_parsed_event("load_event", self.dfr[1].copy())

        basetime = self.dfr[0].index[0]
        trace.normalize_time(basetime)

        expected_duration = self.dfr[1].index[-1] - basetime
        self.assertEquals(trace.get_duration(), expected_duration)
Exemple #11
0
    def test_assert_statement_dataframe(self):
        """assertStatement() works if the generated statement creates a pandas.DataFrame of bools"""

        rolls_dfr = pd.DataFrame({"results": [1, 3, 2, 6, 2, 4]})
        trace = trappy.BareTrace()
        trace.add_parsed_event("dice_rolls", rolls_dfr)
        config = {"MIN_DICE_NUMBER": 1, "MAX_DICE_NUMBER": 6}
        t = Analyzer(trace, config)

        statement = "(dice_rolls:results <= MAX_DICE_NUMBER) & (dice_rolls:results >= MIN_DICE_NUMBER)"
        self.assertTrue(t.assertStatement(statement))

        statement = "dice_rolls:results == 3"
        self.assertFalse(t.assertStatement(statement))
Exemple #12
0
    def test_bare_trace_normalize_time_accepts_basetime(self):
        """BareTrace().normalize_time() accepts an arbitrary basetime"""

        trace = trappy.BareTrace()
        trace.add_parsed_event("pmu_counter", self.dfr[0].copy())

        prev_first_time = trace.pmu_counter.data_frame.index[0]
        basetime = 3

        trace.normalize_time(basetime)

        self.assertEquals(trace.basetime, basetime)

        exp_first_time = prev_first_time - basetime
        self.assertEquals(
            round(trace.pmu_counter.data_frame.index[0] - exp_first_time, 7),
            0)
Exemple #13
0
    def test_conditional_compare(self):
        """Test conditional_compare"""

        # Refer to the example in
        # bart.common.signal.SignalCompare.conditional_compare
        # doc-strings which explains the calculation for the
        # data set below
        A = [0, 0, 0, 3, 3, 0, 0, 0]
        B = [0, 0, 2, 2, 2, 2, 1, 1]

        trace = trappy.BareTrace()
        df = pd.DataFrame({"A": A, "B": B})
        trace.add_parsed_event("event", df)

        s = SignalCompare(trace, "event:A", "event:B")
        expected = (1.5, 2.0 / 7)
        self.assertEqual(
            s.conditional_compare("event:A > event:B", method="rect"),
            expected)
Exemple #14
0
    def test_filter_prev_values(self):
        """Trigger works with a filter that depends on previous values of the same pivot"""

        # We generate an example in which we want a trigger whenever the
        # identifier is no longer 1 for blank

        class my_filter(object):
            def __init__(self, val_out):
                self.prev_val = 0
                self.val_out = val_out

            def __call__(self, val):
                ret = self.prev_val == self.val_out
                self.prev_val = val

                return ret

        trace = trappy.BareTrace()
        data = collections.OrderedDict([
            (0.1, ["blank", 1]),
            (0.2, ["fire", 1]),
            (0.3, ["blank", 0]),  # value is no longer 1, trigger
            (0.4, ["blank", 1]),
            (0.5, ["fire", 0]),  # This should NOT trigger
            (0.6, ["blank", 0]),  # value is no longer 1 for blank, trigger
        ])
        data_frame = pd.DataFrame.from_dict(
            data,
            orient="index",
        )
        data_frame.columns = ["result", "identifier"]
        trace.add_parsed_event("aim_and_fire", data_frame)

        trigger = Trigger(trace,
                          trace.aim_and_fire,
                          filters={"identifier": my_filter(1)},
                          value=-1,
                          pivot="result")

        expected = pd.Series([-1, -1], index=[0.3, 0.6])
        assert_series_equal(expected, trigger.generate("blank"))
Exemple #15
0
    def test_bare_trace_accepts_name(self):
        """The BareTrace() accepts a name parameter"""

        trace = trappy.BareTrace(name="foo")

        self.assertEquals(trace.name, "foo")