Ejemplo n.º 1
0
def test():
    g = Graph()
    print "Initialized graph."
    rtx_graph.BuildGraphStructure(g)

    #empty config
    impl = RtxImplem()
    if Algos.identity_match(g, "LKM::Context", impl) is None:
        print "[1] Found multiple matches for an identity match."
        return False

    # config with only one variable
    impl = RtxImplem()
    impl.addConstraint("LKM::os",       "==",   "Linux")
    if Algos.identity_match(g, "LKM::Context", impl) is None:
        print "[2] Found multiple matches for an identity match."
        return False

    # config with multiple variables
    impl = RtxImplem()
    impl.addConstraint("LKM::os",       "==",   "Windows")
    impl.addConstraint("LKM::version",  ">=",   "7")
    if Algos.identity_match(g, "LKM::Context", impl) is None:
        print "[3] Found multiple matches for an identity match."
        return False


    # config with multiple conditions on one variable
    # First on a no-other-configs tpl
    impl = RtxImplem()
    impl.addConstraint("LKM::os",       "==",   "FreeBSD")
    impl.addConstraint("LKM::version",  ">=",    "4")
    impl.addConstraint("LKM::version",  "<=",    "7")
    if Algos.identity_match(g, "LKM::Write(LKM::Context, Builtin::Buffer)",
                            impl) is None:
        print "[4] Found multiple matches for an identity match."
        return False

    # Then on a tpl with multiple configs
    impl = RtxImplem()
    impl.addConstraint("LKM::os",       "==",   "Windows")
    impl.addConstraint("LKM::version",  "<=",   "7")
    impl.addConstraint("LKM::version",  ">=",    "4")
    if Algos.identity_match(g, "LKM::Context", impl) is None:
        print "[5] Found multiple matches for an identity match."
        return False
Ejemplo n.º 2
0
def generate_template_implem(g, tpl, tpl_node, implem):
    result = None
    impl_node = None

    impl_node = Algos.identity_match(g, tpl.signature(), implem)

    if impl_node is None:
        impl_node = g.implems.create(
            source_file=tpl.signature() + "_{}.blt".format(implem.id()),
            ast_file=tpl.signature() + "_{}.ast".format(implem.id()),
        )
        g.implements.create(tpl_node, impl_node)
        for sign in implem.constraints():
            for val, op in implem.constraints()[sign]:
                var_node = check_unique(g.variables.index.lookup(signature=sign), "Variable", sign, True)
                g.selects.create(impl_node, var_node, value=val, constraint=op)
                if dbg:
                    print "Created constraint %s %s on %s" % (op, val, sign)
        if dbg:
            print "Created impl for tpl %s" % (tpl.signature())