示例#1
0
    def test_startsCurrentPeriod_endsCurrentPeriod_psiNotSatisfiable(self):
        """ Testing exit label 4 """
        chk1 = check(self.system.port) < 100
        chk2 = check(self.system.secondPort) == 5
        formula = tctl.EU(chk1, chk2)
        formula.interval > 2
        formula.interval < 6  # interval is completely in the period

        # prepare mocks
        mc = ModelChecker(self.ss)
        original_check = mc.check  # copy reference, so we can now safely mock the potentially recursive call
        mc.is_satisfiable = mock.MagicMock(name="is_satisfiable",
                                           return_value=False)
        self.ss.successors = mock.MagicMock(return_value=[
            mock.sentinel.successor, mock.sentinel.othersuccessor,
            mock.sentinel.thirdsuccessor
        ])
        mc.check = mock.MagicMock(name="check",
                                  side_effect=[False, [13, 22], False])

        # action
        result_trace = original_check(formula)

        # assert
        self.assertFalse(
            result_trace,
            "We correctly exited with False, since psi is not reachable and the interval ends before maxdt"
        )
        mc.check.assert_not_called()
示例#2
0
    def test_startsCurrentPeriod_endsFuturePeriod_phiNotValid(self):
        """ Testing exit label 5 """
        chk1 = check(self.system.port) < 100
        chk2 = check(self.system.secondPort) == 5
        formula = tctl.EU(chk1, chk2)
        formula.interval > 2
        formula.interval < 23  # interval ends after this period

        # prepare mocks
        mc = ModelChecker(self.ss)
        original_check = mc.check  # copy reference, so we can now safely mock the potentially recursive call
        mc.is_satisfiable = mock.MagicMock(name="is_satisfiable",
                                           return_value=False)
        mc.is_valid = mock.MagicMock(name="is_valid", return_value=False)
        mc.check = mock.MagicMock(name="check")

        # action (on original check)
        result_trace = original_check(formula)

        # assert that the return value was correct
        self.assertFalse(
            result_trace,
            "Assert that if the first formula is invalid in this period, the result is False"
        )

        # assert that is_valid was called with the correct values
        mc.is_valid.assert_called_once()
        (formula,
         systemstate), kwargs = mc.is_valid.call_args  # get the last callargs
        self.assertEqual(
            formula.interval.end, 7,
            "The subformula validity check was called with the correct interval end"
        )
        self.assertEqual(
            systemstate, self.ss.graph["root"],
            "The subformula validity check was called on the correct state")

        # assert that the check was not called (we exited early)
        mc.check.assert_not_called()
示例#3
0
    def test_startsCurrentPeriod_endsFuturePeriod_secondSuccessorSatisfiable_doesNotCallThird(
            self):
        """ Testing exit label 6) """
        chk1 = check(self.system.port) < 100
        chk2 = check(self.system.secondPort) == 5
        formula = tctl.EU(chk1, chk2)
        formula.interval > 2
        formula.interval < 23  # interval ends after this period

        # prepare mocks
        self.ss.successors = mock.MagicMock(return_value=[
            mock.sentinel.successor, mock.sentinel.othersuccessor,
            mock.sentinel.thirdsuccessor
        ])
        mc = ModelChecker(self.ss)
        original_check = mc.check  # copy reference, so we can now safely mock the potentially recursive call
        mc.is_satisfiable = mock.MagicMock(name="is_satisfiable",
                                           return_value=False)
        mc.is_valid = mock.MagicMock(return_value=True)
        mc.check = mock.MagicMock(side_effect=[False, [13, 22], False])

        # action
        result_trace = original_check(formula)

        # assert that the resulting trace is correct
        self.assertEqual(
            result_trace, [7, 13, 22],
            "Assert that if the first formula is invalid in this period, the result is False"
        )

        # assert that is valid was called on the formula
        mc.is_valid.assert_called_once()
        (formula,
         systemstate), kwargs = mc.is_valid.call_args  # get the last callargs
        self.assertEqual(
            formula.interval.end, 7,
            "The subformula validity check was called with the correct interval end"
        )
        self.assertEqual(
            systemstate, self.ss.graph["root"],
            "The subformula validity check was called on the correct state")

        # assert that a modified version of the formula (-= maxdt) was called on each successor
        self.assertEqual(
            mc.check.call_count, 2,
            "Check recursed on each of the successors, because both returned False"
        )

        (formula, systemstate
         ), kwargs = mc.check.call_args_list[0]  # get the last callargs
        self.assertEqual(
            formula.interval.start, -5,
            "The recursion check was called with the correct interval start")
        self.assertEqual(
            formula.interval.end, 16,
            "The recursion check was called with the correct interval end")
        self.assertEqual(
            systemstate, mock.sentinel.successor,
            "The recursion check was called on the correct state")

        (formula, systemstate
         ), kwargs = mc.check.call_args_list[1]  # get the last callargs
        self.assertEqual(
            formula.interval.start, -5,
            "The recursion check was called with the correct interval start")
        self.assertEqual(
            formula.interval.end, 16,
            "The recursion check was called with the correct interval end")
        self.assertEqual(
            systemstate, mock.sentinel.othersuccessor,
            "The recursion check was called on the correct state")