示例#1
0
    def test_bmc_setup(self):
        # pre conditions not satisfied
        # model must be loaded
        with self.assertRaises(NuSMVNeedBooleanModelError):
            bmcglob.bmc_setup()

        # vars need to be encoded
        load(self.model())
        with self.assertRaises(NuSMVNeedBooleanModelError):
            bmcglob.bmc_setup()

        # boolean model must be compiled out of the sexp
        flatten_hierarchy()
        with self.assertRaises(NuSMVNeedBooleanModelError):
            bmcglob.bmc_setup()

        # hierarchy must be flattened (actually, this is a requirement for the
        # boolean model too)
        encode_variables()
        with self.assertRaises(NuSMVNeedBooleanModelError):
            bmcglob.bmc_setup()

        # may not be called 2 times
        build_boolean_model()
        with self.assertRaises(NuSMVBmcAlreadyInitializedError):
            bmcglob.bmc_setup()
            bmcglob.bmc_setup()

        # even if the force flag is on (that's COI related)
        with self.assertRaises(NuSMVBmcAlreadyInitializedError):
            bmcglob.bmc_setup(force=True)

        bmcglob.bmc_exit()
示例#2
0
def process(path_to, model, formula=None, depths=range(10), flags=IDLE):
    '''
    Initializes PyNuSMV and loads the model, then proceeds to the bulk of the
    analysis. See `analyze_one` and `analyze_all` for further details about 
    what is done.
    
    By default, this analysis generates no output. However the following flags 
    can be customized to generate derived artifacts.
    
        + 'dimacs = True' will produce a *.cnf file containing the dimacs
           representation of the problem
        + 'structure = True' will produce a *.png file visually representing the 
           variable graph.
        + 'clouds = True' will produce a wordcloud (*.png file) per analyzed
           community to show the semantic information that occurs the most often
           in that community.
        + 'stats  = True' will produce a csv file containing all the raw 
           statistical data alongside with two charts plotting the evolution of
           the #communities and modulatity over time
    '''

    with init_nusmv():
        load(core.merge_model_text(path_to, model + ".smv"))

        with BmcSupport():
            analyze_all(model, formula, depths, flags)
示例#3
0
    def test_bmc_setup(self):
        # pre conditions not satisfied
        # model must be loaded
        with self.assertRaises(NuSMVNeedBooleanModelError):
            bmcglob.bmc_setup()
        
        # vars need to be encoded
        load(self.model())
        with self.assertRaises(NuSMVNeedBooleanModelError):
            bmcglob.bmc_setup()
        
        # boolean model must be compiled out of the sexp
        flatten_hierarchy()
        with self.assertRaises(NuSMVNeedBooleanModelError):
            bmcglob.bmc_setup()

        # hierarchy must be flattened (actually, this is a requirement for the
        # boolean model too)
        encode_variables()
        with self.assertRaises(NuSMVNeedBooleanModelError):
            bmcglob.bmc_setup()
        
        # may not be called 2 times
        build_boolean_model()
        with self.assertRaises(NuSMVBmcAlreadyInitializedError):
            bmcglob.bmc_setup()
            bmcglob.bmc_setup()
            
        # even if the force flag is on (that's COI related)
        with self.assertRaises(NuSMVBmcAlreadyInitializedError):
            bmcglob.bmc_setup(force=True)
            
        bmcglob.bmc_exit()
示例#4
0
文件: testMC.py 项目: yyaan/pynusmv
    def test_mc_ltl_true(self):
        # Initialize the model
        glob.load("tests/pynusmv/models/admin.smv")
        glob.compute_model()
        fsm = glob.prop_database().master.bddFsm

        spec = prop.Spec(parser.parse_ltl_spec("G admin = none"))
        self.assertEqual(mc.check_ltl_spec(spec), False)
示例#5
0
 def test_load_from_string(self):
     main = """
     MODULE main
         VAR state : boolean;
         INIT state
         TRANS next(state) = !state
     """
     glob.load(main)
示例#6
0
 def setUp(self):
     init_nusmv()
     glob.load(
         tests.current_directory(__file__) +
         "/models/flipflops_explicit_relation.smv")
     go_bmc()
     self._fsm = BeFsm.global_master_instance()
     self._manager = self._fsm.encoding.manager
示例#7
0
文件: testMC.py 项目: yyaan/pynusmv
    def test_ex(self):
        glob.load("tests/pynusmv/models/admin.smv")
        glob.compute_model()
        fsm = glob.prop_database().master.bddFsm

        alice = mc.eval_simple_expression(fsm, "admin = alice")
        spec = prop.Spec(parser.parse_ctl_spec("EX admin = alice"))
        exalice = mc.eval_ctl_spec(fsm, spec)
        self.assertEqual(mc.ex(fsm, alice), exalice)
示例#8
0
 def test_load_from_string_syntax_errors(self):
     main = """
     MODULE main
         VAR state : boolean
         INIT state
         TRANS next(state) = !state
     """
     with self.assertRaises(NuSMVParsingError):
         glob.load(main)
示例#9
0
    def test_build_master_be_fsm(self):
        load(self.model())
        flatten_hierarchy()
        encode_variables()
        build_boolean_model()
        bmcglob.bmc_setup()
        # may not provoke C assert failures
        bmcglob.build_master_be_fsm()

        bmcglob.bmc_exit()
示例#10
0
 def test_force_reordering(self):
     glob.load("tests/pynusmv/models/admin.smv")
     glob.compute_model(variables_ordering="tests/pynusmv/models/admin.ord")
     fsm = glob.prop_database().master.bddFsm
     
     self.assertTupleEqual(("admin", "state"),
                           fsm.bddEnc.get_variables_ordering())
     reorder(fsm.bddEnc.DDmanager)
     self.assertTupleEqual(("state", "admin"),
                           fsm.bddEnc.get_variables_ordering())
示例#11
0
    def setUp(self):
        init_nusmv()
        glob.load(self.model())
        glob.flatten_hierarchy()
        glob.encode_variables()  # does it for BDD
        self.go_bmc()

        pd = _prop.PropPkg_get_prop_database()
        fsm = _prop.PropDb_master_get_be_fsm(pd)
        self._TEST = _be.BeFsm_get_fairness_list(fsm)
示例#12
0
文件: testBDD.py 项目: yyaan/pynusmv
    def test_force_reordering(self):
        glob.load("tests/pynusmv/models/admin.smv")
        glob.compute_model(variables_ordering="tests/pynusmv/models/admin.ord")
        fsm = glob.prop_database().master.bddFsm

        self.assertTupleEqual(("admin", "state"),
                              fsm.bddEnc.get_variables_ordering())
        reorder(fsm.bddEnc.DDmanager)
        self.assertTupleEqual(("state", "admin"),
                              fsm.bddEnc.get_variables_ordering())
示例#13
0
 def test_master_be_fsm(self):
     load(self.model())
     flatten_hierarchy()
     encode_variables()
     build_boolean_model()
     bmcglob.bmc_setup()
     # may not provoke C assert failures
     bmcglob.build_master_be_fsm()
     self.assertEqual(bmcglob.master_be_fsm(), BeFsm.global_master_instance())
     bmcglob.bmc_exit()
示例#14
0
 def setUp(self):
     init_nusmv()
     glob.load(self.model())
     glob.flatten_hierarchy()
     glob.encode_variables()  # does it for BDD
     self.go_bmc()
     
     pd = _prop.PropPkg_get_prop_database()
     fsm= _prop.PropDb_master_get_be_fsm(pd)
     self._TEST = _be.BeFsm_get_fairness_list(fsm)
示例#15
0
 def test_build_master_be_fsm(self):
     load(self.model())
     flatten_hierarchy()
     encode_variables()
     build_boolean_model()
     bmcglob.bmc_setup()
     # may not provoke C assert failures
     bmcglob.build_master_be_fsm()
     
     bmcglob.bmc_exit()
示例#16
0
 def test_master_be_fsm(self):
     load(self.model())
     flatten_hierarchy()
     encode_variables()
     build_boolean_model()
     bmcglob.bmc_setup()
     # may not provoke C assert failures
     bmcglob.build_master_be_fsm()
     self.assertEqual(bmcglob.master_be_fsm(),
                      BeFsm.global_master_instance())
     bmcglob.bmc_exit()
示例#17
0
文件: testMC.py 项目: yyaan/pynusmv
    def test_mc_explain_ltl_true(self):
        # Initialize the model
        glob.load("tests/pynusmv/models/admin.smv")
        glob.compute_model()

        spec = prop.Spec(
            parser.parse_ltl_spec("(F admin = alice) | (F admin = bob)"))

        result, explanation = mc.check_explain_ltl_spec(spec)
        self.assertTrue(result)
        self.assertIsNone(explanation)
示例#18
0
    def test_bmcSupport(self):
        # model MUST be loaded
        with self.assertRaises(NuSMVNoReadModelError):
            with bmcglob.BmcSupport():
                # may not provoke any error
                pass

        load(self.model())
        with bmcglob.BmcSupport():
            # may not provoke any error
            pass
示例#19
0
文件: testMC.py 项目: yyaan/pynusmv
    def test_au(self):
        glob.load("tests/pynusmv/models/admin.smv")
        glob.compute_model()
        fsm = glob.prop_database().master.bddFsm

        none = mc.eval_simple_expression(fsm, "admin = none")
        alice = mc.eval_simple_expression(fsm, "admin = alice")
        spec = prop.Spec(
            parser.parse_ctl_spec("A[admin = none U admin = alice]"))
        aunonealice = mc.eval_ctl_spec(fsm, spec)
        self.assertEqual(mc.au(fsm, none, alice), aunonealice)
示例#20
0
 def test_bmcSupport(self):
     # model MUST be loaded
     with self.assertRaises(NuSMVNoReadModelError):
         with bmcglob.BmcSupport():
             # may not provoke any error
             pass
         
     load(self.model())
     with bmcglob.BmcSupport():
         # may not provoke any error
         pass
示例#21
0
文件: testMC.py 项目: yyaan/pynusmv
    def test_eg(self):
        glob.load("tests/pynusmv/models/admin.smv")
        glob.compute_model()
        fsm = glob.prop_database().master.bddFsm

        alice = mc.eval_simple_expression(fsm, "admin = alice")
        spec = prop.Spec(parser.parse_ctl_spec("EG admin = alice"))
        egalice = mc.eval_ctl_spec(fsm, spec)
        self.assertEqual(mc.eg(fsm, alice), egalice)

        self.assertEqual(
            egalice,
            fixpoint(lambda Z: alice & fsm.pre(Z), BDD.true())
            & fsm.reachable_states)
示例#22
0
    def test_change_trans_of_flat(self):
        glob.load(*self.counters())
        glob.flatten_hierarchy()
        flat = glob.flat_hierarchy()
        self.assertIsNotNone(flat)

        trans = flat.trans

        choose_run = node.Expression.from_string("run = rc1")
        flat.trans = flat.trans & choose_run

        glob.compute_model()
        fsm = glob.prop_database().master.bddFsm

        self.assertEqual(fsm.count_states(fsm.reachable_states), 3)
示例#23
0
 def test_change_trans_of_flat(self):
     glob.load(*self.counters())
     glob.flatten_hierarchy()
     flat = glob.flat_hierarchy()
     self.assertIsNotNone(flat)
     
     trans = flat.trans
     
     choose_run = node.Expression.from_string("run = rc1")
     flat.trans = flat.trans & choose_run
     
     glob.compute_model()
     fsm = glob.prop_database().master.bddFsm
     
     self.assertEqual(fsm.count_states(fsm.reachable_states), 3)
示例#24
0
def main():
    args = arguments()

    with init_nusmv():
        load(args.model)
        if args.verbose:
            with open(args.model) as f:
                print(f.read())

        with BmcSupport():
            if args.spec is not None:
                check(args.spec, args)
            else:
                print("Enter LTL properties, one per line:")
                for line in sys.stdin:
                    check(line, args)
示例#25
0
 def test_go_bmc(self):
     # pre conditions not satisfied
     # model must be loaded
     with self.assertRaises(NuSMVNoReadModelError):
         bmcglob.go_bmc()
     
     # vars need to be encoded
     load(self.model())
     
     # it doesn't hurt to call it more than once
     bmcglob.go_bmc()
     bmcglob.go_bmc()
     
     # unless the force flag is on
     bmcglob.go_bmc(force=True)
         
     bmcglob.bmc_exit()
示例#26
0
文件: testMC.py 项目: yyaan/pynusmv
    def test_mc_explain_ltl_false(self):
        # Initialize the model
        glob.load("tests/pynusmv/models/admin.smv")
        glob.compute_model()

        spec = prop.Spec(parser.parse_ltl_spec("G admin = none"))

        result, explanation = mc.check_explain_ltl_spec(spec)
        self.assertFalse(result)
        self.assertIsNotNone(explanation)

        #print(explanation[0])
        #for inputs, state in zip(explanation[1::2], explanation[2::2]):
        #    print(inputs)
        #    print(state)
        self.assertTrue(
            any(state["admin"] != "none" for state in explanation[::2]))
示例#27
0
    def test_go_bmc(self):
        # pre conditions not satisfied
        # model must be loaded
        with self.assertRaises(NuSMVNoReadModelError):
            bmcglob.go_bmc()

        # vars need to be encoded
        load(self.model())

        # it doesn't hurt to call it more than once
        bmcglob.go_bmc()
        bmcglob.go_bmc()

        # unless the force flag is on
        bmcglob.go_bmc(force=True)

        bmcglob.bmc_exit()
示例#28
0
    def test_access_flat_hierarchy(self):
        glob.load(*self.counters())
        glob.compute_model()

        flat = glob.flat_hierarchy()
        symb_table = glob.symb_table()

        self.assertIsNotNone(flat.init)
        self.assertIsNotNone(flat.trans)
        self.assertIsNone(flat.invar)
        self.assertIsNone(flat.justice)
        self.assertIsNone(flat.compassion)

        variables = flat.variables
        for variable in variables:
            var_type = symb_table.get_variable_type(variable)
            self.assertEqual(nssymb_table.SymbType_get_tag(var_type),
                             nssymb_table.SYMB_TYPE_ENUM)
示例#29
0
 def test_access_flat_hierarchy(self):
     glob.load(*self.counters())
     glob.compute_model()
     
     flat = glob.flat_hierarchy()
     symb_table = glob.symb_table()
     
     self.assertIsNotNone(flat.init)
     self.assertIsNotNone(flat.trans)
     self.assertIsNone(flat.invar)
     self.assertIsNone(flat.justice)
     self.assertIsNone(flat.compassion)
     
     variables = flat.variables
     for variable in variables:
         var_type = symb_table.get_variable_type(variable)
         self.assertEqual(nssymb_table.SymbType_get_tag(var_type),
                          nssymb_table.SYMB_TYPE_ENUM)
示例#30
0
def proceed(args):
    """Actually proceeds to the verification"""
    with init_nusmv():
        load(args.model)
        with BmcSupport():

            observable = mk_observable_names(args)

            if not args.quiet:
                with open(args.model) as m:
                    model = m.read()
                print_greeting(model, observable)

            if args.spec is not None:
                check(args, args.spec, observable)
            else:
                print("*"*80)
                print("* DIAGNOSABILITY TESTS")
                print("*"*80)
                print("Enter diagnosability condition, one per line in the format: 'c1 ; c2'")
                for line in sys.stdin:
                    check(args, line,  observable)
示例#31
0
def proceed(args):
    """Actually proceeds to the verification"""
    with init_nusmv():
        load(args.model)
        with BmcSupport():

            observable = mk_observable_names(args)

            if not args.quiet:
                with open(args.model) as m:
                    model = m.read()
                print_greeting(model, observable)

            if args.spec is not None:
                check(args, args.spec, observable)
            else:
                print("*" * 80)
                print("* DIAGNOSABILITY TESTS")
                print("*" * 80)
                print("Enter diagnosability condition, one per line in the format: 'c1 ; c2'")
                for line in sys.stdin:
                    check(args, line, observable)
示例#32
0
 def setUp(self):
     init_nusmv()
     glob.load(tests.current_directory(__file__) + "/models/flipflops_explicit_relation.smv")
     go_bmc()
     self._fsm = BeFsm.global_master_instance()
     self._manager = self._fsm.encoding.manager
示例#33
0
 def setUp(self):
     init_nusmv()
     load(self.model())
示例#34
0
文件: pytlq.py 项目: sbusard/PyTLQ
def cli(model_path, query, order):
    """Solve QUERY that belongs to fragment CTLQx for model in MODEL_PATH."""
    try:
        # Parse `query` and transform it in NNF.
        ast = negation_normal_form(parse_ctlq(query))

        # Check that `query` belongs to fragment CTLQx.
        if not check_ctlqx(ast):
            click.echo('Error: {query} does not belong to CTLQx'
                       .format(query=query))
            # Quit PyTLQ.
            sys.exit()

        # Initialize NuSMV.
        with init_nusmv():
            # Load model from `model_path`.
            load(model_path)
            # Enable dynamic reordering of the variables.
            enable_dynamic_reordering()
            # Check if an order file is given.
            if order:
                # Build model with pre-calculated variable ordering.
                compute_model(variables_ordering=order)
            else:
                # Build model.
                compute_model()
            # Retrieve FSM of the model.
            fsm = prop_database().master.bddFsm

            # Solve `query` in `fsm`.
            solution = solve_ctlqx(fsm, ast)

            # Display solution.
            click.echo('Solution states:')
            if not solution:
                click.echo('No solution')
                # Quit PyTLQ.
                sys.exit()
            elif solution.is_false():
                click.echo('False')
                # Quit PyTLQ.
                sys.exit()
            else:
                size = fsm.count_states(solution)
                if size > 100:
                    if click.confirm('The number of states is too large'
                                     ' ({size}). Do you still want to print'
                                     ' them?'.format(size=size)):
                        pprint(bdd_to_set(fsm, solution))
                else:
                    pprint(bdd_to_set(fsm, solution))

            # Ask for further manipulations.
            while True:
                command = click.prompt('\nWhat do you want to do?'
                                       '\n  1. Project the solution on a'
                                       ' subset of the variables'
                                       '\n  2. Simplify the solution according'
                                       ' to Chan\'s approximate conjunctive'
                                       ' decomposition'
                                       '\n  3. Quit PyTLQ'
                                       '\nYour choice',
                                       type=click.IntRange(1, 3), default=3)

                # Check if solution must be projected or simplified.
                if command == 1 or command == 2:

                    # Gather more information.
                    click.echo('')
                    if command == 2:
                        maximum = click.prompt('Please enter the maximum'
                                               ' number of variables that must'
                                               ' appear in the conjuncts of'
                                               ' the simplification', type=int,
                                               default=1)
                    variables = click.prompt('Please enter the list of'
                                             ' variables of interest,'
                                             ' separated by commas', type=str,
                                             default='all the variables')
                    # Format `variables`.
                    if variables == 'all the variables':
                        variables = None
                    else:
                        variables = variables.replace(" ", "").split(',')

                    if command == 1:
                        # Project solution and display projection.
                        click.echo('\nProjection:')
                        click.echo(project(fsm, solution, variables))
                    else:
                        # Simplify solution and display simplification.
                        click.echo('\nApproximate conjunctive decomposition:')
                        click.echo(simplify(fsm, solution, maximum, variables))

                # No further manipulations are needed.
                else:
                    break

    except Exception as error:
        click.echo('Error: {msg}'.format(msg=error))
示例#35
0
 def setUp(self):
     init_nusmv()
     glob.load(self.model())
     go_bmc()
     self.enc = master_be_fsm().encoding
示例#36
0
 def test_cdr(self):
     glob.load(*self.counters())
     glob.compute_model()
     spec = node.Node.from_ptr(parse_ctl_spec("A [x U y]"))
     self.assertEqual(type(spec.cdr), node.Atom)
     self.assertEqual(str(spec.cdr), "y")
示例#37
0
 def setUp(self):
     init_nusmv()
     load(self.model())
示例#38
0
 def load_admin_model(self):
     glob.load("tests/pynusmv/models/admin.smv")
     glob.compute_model()
示例#39
0
 def setUp(self):
     init_nusmv()
     load(self.model())
     go_bmc()
     self.fsm = BeFsm.global_master_instance()
示例#40
0
 def setUp(self):
     init_nusmv()
     load(self.model())
     go_bmc()
     self.fsm = BeFsm.global_master_instance()
示例#41
0
文件: pytlq.py 项目: sbusard/PyTLQ
def cli(model_path, query, order):
    """Solve QUERY that belongs to fragment CTLQx for model in MODEL_PATH."""
    try:
        # Parse `query` and transform it in NNF.
        ast = negation_normal_form(parse_ctlq(query))

        # Check that `query` belongs to fragment CTLQx.
        if not check_ctlqx(ast):
            click.echo("Error: {query} does not belong to CTLQx".format(query=query))
            # Quit PyTLQ.
            sys.exit()

        # Initialize NuSMV.
        with init_nusmv():
            # Load model from `model_path`.
            load(model_path)
            # Enable dynamic reordering of the variables.
            enable_dynamic_reordering()
            # Check if an order file is given.
            if order:
                # Build model with pre-calculated variable ordering.
                compute_model(variables_ordering=order)
            else:
                # Build model.
                compute_model()
            # Retrieve FSM of the model.
            fsm = prop_database().master.bddFsm

            # Solve `query` in `fsm`.
            solution = solve_ctlqx(fsm, ast)

            # Display solution.
            click.echo("Solution states:")
            if not solution:
                click.echo("No solution")
                # Quit PyTLQ.
                sys.exit()
            elif solution.is_false():
                click.echo("False")
                # Quit PyTLQ.
                sys.exit()
            else:
                size = fsm.count_states(solution)
                if size > 100:
                    if click.confirm(
                        "The number of states is too large"
                        " ({size}). Do you still want to print"
                        " them?".format(size=size)
                    ):
                        pprint(bdd_to_set(fsm, solution))
                else:
                    pprint(bdd_to_set(fsm, solution))

            # Ask for further manipulations.
            while True:
                command = click.prompt(
                    "\nWhat do you want to do?"
                    "\n  1. Project the solution on a"
                    " subset of the variables"
                    "\n  2. Simplify the solution according"
                    " to Chan's approximate conjunctive"
                    " decomposition"
                    "\n  3. Quit PyTLQ"
                    "\nYour choice",
                    type=click.IntRange(1, 3),
                    default=3,
                )

                # Check if solution must be projected or simplified.
                if command == 1 or command == 2:

                    # Gather more information.
                    click.echo("")
                    if command == 2:
                        maximum = click.prompt(
                            "Please enter the maximum"
                            " number of variables that must"
                            " appear in the conjuncts of"
                            " the simplification",
                            type=int,
                            default=1,
                        )
                    variables = click.prompt(
                        "Please enter the list of" " variables of interest," " separated by commas",
                        type=str,
                        default="all the variables",
                    )
                    # Format `variables`.
                    if variables == "all the variables":
                        variables = None
                    else:
                        variables = variables.replace(" ", "").split(",")

                    if command == 1:
                        # Project solution and display projection.
                        click.echo("\nProjection:")
                        click.echo(project(fsm, solution, variables))
                    else:
                        # Simplify solution and display simplification.
                        click.echo("\nApproximate conjunctive decomposition:")
                        click.echo(simplify(fsm, solution, maximum, variables))

                # No further manipulations are needed.
                else:
                    break

    except Exception as error:
        click.echo("Error: {msg}".format(msg=error))
示例#42
0
                print("-- No problem at length {}".format(i))
        else:
            print(" 'Problem {}' ; {}".format(i, end-start))

    return ("Ok", bound, None)

def check(formula, args):
    parsed_fml          = Node.from_ptr(parse_ltl_spec(formula.strip()))
    status,length,trace = check_ltl(parsed_fml, args.bound, args.dry_run)
    if status != 'Ok':
        print("-- {} for length {}".format(status, length))
        print(trace)


if __name__ == "__main__":
    args = arguments()

    with init_nusmv():
        load(args.model)
        if args.verbose:
            with open(args.model) as f:
                print(f.read())

        with BmcSupport():
            if args.spec is not None:
                check(args.spec, args)
            else:
                print("Enter LTL properties, one per line:")
                for line in sys.stdin:
                    check(line, args)
示例#43
0
 def test_cdr(self):
     glob.load(*self.counters())
     glob.compute_model()
     spec = node.Node.from_ptr(parse_ctl_spec("A [x U y]"))
     self.assertEqual(type(spec.cdr), node.Atom)
     self.assertEqual(str(spec.cdr), "y")