def execute(self, toVersionizeList, rawPredicateContentDict, sqlTableInfo,
                originalRawPredList):
        smartList = list(
        )  # analogous to toVersionizeList, format : [ [x], ..., [y, y+1], ..., [z, z+1] ]
        sqlFileStr = self.generateBooleanVcPlsqlFileString(
            toVersionizeList, rawPredicateContentDict, originalRawPredList,
            smartList)

        file = open('mc/boolean_vc_plsql_file.sql', "w")
        file.write(sqlFileStr)
        file.close()

        input = FileStream('mc/boolean_vc_plsql_file.sql')
        lexer = PlSqlLexer(input)
        stream = CommonTokenStream(lexer)
        parser = PlSqlParser(stream)
        tree = parser.sql_script()

        cfg = MyCFG()
        self.cfg = cfg
        helper = MyHelper(parser)
        self.helper = helper

        self.helper.updateTableDict(sqlTableInfo)
        utility = MyUtility(self.helper)
        v = MyVisitor(parser, self.cfg, utility)
        v.visit(tree)

        res = MyRawCfgToGraph(v.rawCFG, self.cfg)
        res.execute()
        utility.generateDomSet(self.cfg)
        utility.generateSDomSet(self.cfg)
        utility.generatIDom(self.cfg)
        utility.generateDFSet(self.cfg)
        utility.insertPhiNode(self.cfg)

        utility.initialiseVersinosedPhiNode(self.cfg)
        utility.versioniseVariable(self.cfg)
        utility.phiDestruction(self.cfg)

        ssaStringObj = MySsaStringGenerator(self.cfg, parser)
        ssaStringObj.execute()

        # print('{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{')
        # for nodeId in self.cfg.nodes:
        #     self.cfg.nodes[nodeId].printPretty()
        # print('{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{')

        versionizedPredicateList = self.processSmartList(
            smartList, rawPredicateContentDict, toVersionizeList)
        # last element of smartList will be versionized ConsequentList node ids
        nodeList = smartList[len(smartList) - 1]
        versionizedConsequentList = list()
        for i in nodeList:
            tempCond = self.getEquivalentPredicateForANode(i).strip()
            versionizedConsequentList.append(tempCond)
        return versionizedPredicateList, self.variablesForZ3, versionizedConsequentList
示例#2
0
 def copyCfg(self, cfg):
     res = MyCFG()
     for nodeId in cfg.nodes:
         res.addNode(self.copyNode(cfg.nodes[nodeId]))
     return res
示例#3
0
 def reverseDictOrder(self, reverseCnfCfg):
     temp = list(reverseCnfCfg.nodes.keys())
     res = MyCFG()
     for i in range(len(temp)-1, -1, -1):
         res.addNode(reverseCnfCfg.nodes[temp[i]])
     return res
示例#4
0
 def ssaToCnf(self, iCnfCfg):        # iCnfCfg -> intermediate cnfCfg
     branchingAncestor = []
     res = MyCFG()
     self.explore(iCnfCfg, iCnfCfg.nodes[0].id, branchingAncestor, res)
     return res
示例#5
0
 def topologicalSort(self, iCnfCfg):
     res = MyCFG()
     self.counter = 1
     self.traverse(iCnfCfg, iCnfCfg.nodes[0].id, res)
     return res
示例#6
0
def execute(tableInfo, predicates, rawPredicateContent, predicateVarSet,
            resultString, dataFileName, specFileName):
    file = open('mc/upper_input.sql', "w")
    file.write(resultString)
    file.close()

    # recording startTime1
    startTime1 = datetime.datetime.now()

    input = FileStream('mc/upper_input.sql')
    lexer = PlSqlLexer(input)
    stream = CommonTokenStream(lexer)
    parser = PlSqlParser(stream)
    tree = parser.sql_script()

    cfg = MyCFG()
    helper = MyHelper(parser)
    helper.updateTableDict(tableInfo)
    utility = MyUtility(helper)
    v = MyVisitor(parser, cfg, utility)
    v.visit(tree)

    # print("\n--- Raw CFG >>>\t", v.rawCFG, "\n")

    res = MyRawCfgToGraph(v.rawCFG, cfg)
    res.execute()

    mcCfg = MyCFG()
    for nodeId in cfg.nodes:
        tempNode = copyNode(cfg.nodes[nodeId])
        mcCfg.nodes[nodeId] = tempNode

    utility.generateVariableSet(mcCfg)
    ssaString = MySsaStringGenerator(mcCfg, parser)
    wpcObj = WpcGenerator(mcCfg, helper, ssaString)
    mcUtility = McUtility(mcCfg, wpcObj, predicateVarSet)
    # print("mc graph------------->")
    # for nodeId in mcCfg.nodes:
    #     mcCfg.nodes[nodeId].printPretty()

    for i in mcCfg.nodes:
        if mcCfg.nodes[i].ctx is not None:
            print(i, mcCfg.nodes[i].ctx.getText())
        else:
            print(i, "ctx = None")
    # print("\n++++++++++++++++++++++\tPredicates Given in SPEC file:")
    # for i in predicates:
    #     print(i)
    # print("++++++++++++++++++++++\n")
    # mcCfg.dotToPng(cfg.dotGraph, "mc/raw_graph")

    mcExecutor = McExecutor()

    # recording endTime1
    endTime1 = datetime.datetime.now()

    pwd = os.getcwd()
    pwd = pwd + "/"
    sePathsInfoForMc = SePathsInfoForMc()
    sePathList, seSatInfoList = sePathsInfoForMc.execute(
        dataFileName, specFileName, pwd)
    pathCount = len(sePathList)
    predicateCount = len(predicates)

    print("sePathList", sePathList)
    print("seSatInfoList", seSatInfoList)
    paths = []
    mcExecutor.getAllPaths(mcCfg, 0, [], paths)
    print("mcPaths", paths)

    # recording startTime2
    startTime2 = datetime.datetime.now()
    print(
        "********CDCDCDCDCDCDCDCD******** Entered into McExcuter ********CDCDCDCDCDCDCDCD********"
    )
    spuriousCount, refinementCount = mcExecutor.execute(
        mcUtility, predicates, rawPredicateContent, sePathList, seSatInfoList,
        tableInfo)
    print(
        "********CDCDCDCDCDCDCDCD******** Exited from McExcuter ********CDCDCDCDCDCDCDCD********\n"
    )
    # recording endTime2
    endTime2 = datetime.datetime.now()

    timeForMcExcludingSe = ((endTime1 - startTime1) +
                            (endTime2 - startTime2)).total_seconds()

    return timeForMcExcludingSe, pathCount, predicateCount, spuriousCount, refinementCount
示例#7
0
def main(argv):
    name = "gen/data/"+argv[1]
    file = open(name, "r")
    content = file.read().upper()
    file.close()
    file = open('upper_input.sql', "w")
    file.write(content)
    file.close()

    input = FileStream('upper_input.sql')
    lexer = PlSqlLexer(input)
    stream = CommonTokenStream(lexer)
    parser = PlSqlParser(stream)
    tree = parser.sql_script()
    #ast = tree.toStringTree(recog=parser)
    #print(ast)
    # print(str(MyPlSqlVisitor(parser).getRuleName(tree)))
    # print("\n\n", signature(tree.toStringTree), "\n")

    cfg = MyCFG()
    helper = MyHelper(parser)
    utility = MyUtility(helper)
    v = MyVisitor(parser, cfg, utility)
    v.visit(tree)


    print(v.rawCFG)

    for key in v.cfg.nodes:
        if v.cfg.nodes[key].ctx != None:
            print(key, " --> ", v.cfg.nodes[key].ctx.getText())


    res = MyRawCfgToGraph(v.rawCFG, cfg)
    res.execute()
    cfg.printPretty()
    cfg.dotToPng(cfg.dotGraph, "raw_graph.dot")
    utility.generateDomSet(cfg)
    print("Dominator set ended----------->\n\n")
    utility.generateSDomSet(cfg)
    print("Strictly Dominator set ended ----------->\n\n")
    utility.generatIDom(cfg)
    print("Immediate Dominator ended ----------->\n\n")
    utility.generateDFSet(cfg)
    utility.insertPhiNode(cfg)


    utility.initialiseVersinosedPhiNode(cfg)
    utility.versioniseVariable(cfg)
    utility.phiDestruction(cfg)


    ssaString = MySsaStringGenerator(cfg, parser)
    ssaString.execute()
    
    
    
    
    utility.dfs(cfg.nodes[0].id, cfg)
    
    #start = cfg.nodes[0].id
    
    for nodeId in cfg.nodes:
        last_node = cfg.nodes[nodeId].id


    
    list_of_path = list(utility.dfs_path(cfg.nodes[0].id, last_node, cfg))
    #print(list_of_path)
    #print(start)
    #print(last_node)
    
    vcs = SymbolicVcGeneration(cfg, parser)
    #vcs.SymbolicVcCalculation(cfg, start, last_node)
    
    list_of_vcs = []
    for path in list_of_path:
        print("\n Path %d --->", path)
        vc=vcs.SymbolicVc(path)
        #list_of_vcs.append(vc)
        print(vc)
    #file = open("dbvcs.txt","w")
    #for ele in list_of_vcs:
       # file.write("%s\n" % ele)
        #print (ele+"\n")
    #file.close()
            
    z3fr = z3formulaofvcs(cfg, parser)
    for path in list_of_path:
        z3fr.z3VariableDeclarationSet(path)
    
    #print(list_of_path)
    
    #for path in list_of_path:
        #print(path)
    
    
    #print(cfg.nodes[0].id)

    # utility.generateFinalDotGraph(cfg)   
   
    #for nodeId in cfg.nodes:
        #cfg.nodes[nodeId].printPretty()

    #
    #hello = utility.generateFinalDotGraph(cfg)
    #print(hello)
    #cfg.dotToPng(hello, "versioned_graph.dot")

    #hello2 = utility.generateVersionedDotFile(cfg)
    #print(hello2)
    #cfg.dotToPng(hello2, "versioned_graph.dot")

    #hello3 = utility.generateVersionedPhiNodeWalaDotFile(cfg)
    #print(hello3)
    #cfg.dotToPng(hello3, "versioned_phi_node_wala_graph.dot")
    
    hello4 = utility.generateDestructedPhiNodeWalaDotFile(cfg)
    #print(hello4)
    cfg.dotToPng(hello4, "destructed_phi_node_wala_graph.dot")
示例#8
0
def executeSinglePlSqlFile(data, spec):
    f = open(data, 'r')
    linesOfCode = len(f.readlines())
    f.close()

    processor = PreProcessor(spec, data)
    tableInfo, assumeConstraint, assertConstraint, resultString = processor.start(
    )

    file = open('cnf/upper_input.sql', "w")
    file.write(resultString)
    file.close()

    # recording startTime
    startTime = datetime.datetime.now()

    input = FileStream('cnf/upper_input.sql')
    lexer = PlSqlLexer(input)
    stream = CommonTokenStream(lexer)
    parser = PlSqlParser(stream)
    tree = parser.sql_script()
    # ast = tree.toStringTree(recog=parser)
    # print(str(MyPlSqlVisitor(parser).getRuleName(tree)))
    # print("\n\n", signature(tree.toStringTree), "\n")

    cfg = MyCFG()
    helper = MyHelper(parser)
    helper.updateTableDict(tableInfo)
    utility = MyUtility(helper)
    v = MyVisitor(parser, cfg, utility)
    v.visit(tree)

    print("\nRaw CFG : ", v.rawCFG)

    # for key in v.cfg.nodes:
    #     if v.cfg.nodes[key].ctx != None:
    #         print(key, " --> ", v.cfg.nodes[key].ctx.getText())

    res = MyRawCfgToGraph(v.rawCFG, cfg)
    res.execute()
    # cfg.printPretty()
    # cfg.dotToPng(cfg.dotGraph, "cnf/raw_graph")  # TODO: make dot file in cnf form
    utility.generateDomSet(cfg)
    # print("Dominator set ended----------->\n\n")
    utility.generateSDomSet(cfg)
    # print("Strictly Dominator set ended ----------->\n\n")
    utility.generatIDom(cfg)
    # print("Immediate Dominator ended ----------->\n\n")
    utility.generateDFSet(cfg)
    utility.insertPhiNode(cfg)

    utility.initialiseVersinosedPhiNode(cfg)
    utility.versioniseVariable(cfg)
    utility.phiDestruction(cfg)

    ssaString = MySsaStringGenerator(cfg, parser)
    ssaString.execute()

    # utility.generateFinalDotGraph(cfg)
    # for nodeId in cfg.nodes:
    #     cfg.nodes[nodeId].printPretty()

    # cfg.dotToPng(cfg.dotGraph, "cnf/raw_graph")
    #
    # hello1 = utility.generateBeforeVersioningDotFile(cfg)
    # cfg.dotToPng(hello1, "cnf/before_versioning_graph")
    #
    # hello4 = utility.generateDestructedPhiNodeWalaDotFile(cfg)
    # cfg.dotToPng(hello4, "cnf/destructed_phi_node_wala_graph")

    cnfUtility = CnfUtility(helper)
    iCnfCfg = cnfUtility.copyCfg(cfg)
    reverseCnfCfg = cnfUtility.topologicalSort(iCnfCfg)
    cnfUtility.unvisit(iCnfCfg)
    cnfUtility.setParentBranching(iCnfCfg)

    cnfCfg = cnfUtility.reverseDictOrder(reverseCnfCfg)
    cnfUtility.copyParentBranching(cnfCfg, iCnfCfg)
    # print("\n\n\n\n\n\t\t\tThe intermediate CNF form is ------------------------------>\n\n\n\n")

    # for nodeId in iCnfCfg.nodes:
    #     iCnfCfg.nodes[nodeId].printPretty()

    # print("\n\n\n\n\n\t\t\tThe CNF form is ------------------------------>\n\n\n\n")

    cnfVcGenerator = CnfVcGenerator(cnfCfg, parser)

    cnfPath = []

    for nodeId in cnfCfg.nodes:
        cnfPath.append(nodeId)

    cnfVcGenerator.generateCnfVc(cnfPath)

    # print("\n\n\n\n\t\t\tThe CNF VCs are : ------------------------------->\n\n\n")
    # print(cnfVcs)

    # for nodeId in cnfCfg.nodes:
    #     cnfCfg.nodes[nodeId].printPretty()

    # cnfVc = cnfUtility.cnfVc(cnfCfg)
    #
    # print("\n\n\t\tThe CNF VCs are ----------------->\n\n\n")
    #
    # for str in cnfVc:
    #     print(str)

    varSet, z3Str = cnfUtility.iZ3format(cnfCfg)

    # print("\n\n*******************\n\n", z3Str, "\n\n--------------\n\n")
    # print(varSet)
    #
    # print("\n\n")
    z3Str = z3Str.replace("  ", " ")
    z3Str = z3Str.replace(" == ", " = ")
    z3Str = z3Str.replace(" = ", " == ")

    print("\n**** Final CNF VC in Well_Bracketted_Format:\n\n", z3Str, "\n")

    z3StringConvertor = WpcStringConverter(z3Str)
    z3StringConvertor.execute()

    # print("\n**** Final CNF VC in Z3 Format:\n", z3StringConvertor.convertedWpc, "\n")

    z3FileString = "# This file was generated at runtime on " + str(
        datetime.datetime.now()) + "\n"
    z3FileString = z3FileString + "from z3 import *\n\n"
    z3FileString = z3FileString + "class Z3RuntimeCnfFile():\n"
    z3FileString = z3FileString + "\t" + "def __init__(self):\n"
    z3FileString = z3FileString + "\t\t" + "self.finalFormula = \"\"\n"
    z3FileString = z3FileString + "\t\t" + "self.satisfiability = \"\"\n"
    z3FileString = z3FileString + "\t\t" + "self.modelForViolation = \"\"\n\n"

    z3FileString = z3FileString + "\t" + "def execute(self):\n"
    for i in varSet:
        z3FileString = z3FileString + "\t\t" + i + " = Real(\'" + i + "\')\n"
    z3FileString = z3FileString + "\n\t\ts = Solver()\n"

    if len(z3StringConvertor.implies_p) > 0:
        for i in range(len(z3StringConvertor.implies_p)):
            z3FileString = z3FileString + "\t\t" + "s.add(" + z3StringConvertor.implies_p[
                i] + ")\n"
            if not z3StringConvertor.convertedWpc == z3StringConvertor.implies_p_q[
                    i]:
                z3FileString = z3FileString + "\t\t" + "s.add(" + z3StringConvertor.implies_p_q[
                    i] + ")\n"
    #     if z3StringConvertor.convertedWpc not in z3StringConvertor.implies_p_q:
    #         z3FileString = z3FileString + "\t\t" + "s.add(" + z3StringConvertor.convertedWpc + ")\n"
    # else:
    #     z3FileString = z3FileString + "\t\t" + "s.add(" + z3StringConvertor.convertedWpc + ")\n"
    z3FileString = z3FileString + "\t\t" + "s.add( Not( " + z3StringConvertor.convertedWpc + " ) )\n"

    # z3FileString = z3FileString + "\n\t\t" + "print()"
    # z3FileString = z3FileString + "\n\t\t" + "print(\"%%%%%%%%%% Aggregate Formula %%%%%%%%%%\\n\", s)"
    z3FileString = z3FileString + "\n\t\t" + "self.finalFormula = str(s)"
    # z3FileString = z3FileString + "\n\t\t" + "print()"
    # z3FileString = z3FileString + "\n\t\t" + "print(\"%%%%%%%%%% Satisfiability %%%%%%%%%%\")\n"
    z3FileString = z3FileString + "\n\t\t" + "self.satisfiability = str(s.check())"

    z3FileString = z3FileString + "\n\t\t" + "if self.satisfiability == \"sat\":"
    # z3FileString = z3FileString + "\n\t\t\t" + "print()"
    # z3FileString = z3FileString + "\n\t\t\t" + "print(\"-------->> Violation Occurred...\")"
    z3FileString = z3FileString + "\n\t\t\t" + "self.satisfiability = \"violation\""
    # z3FileString = z3FileString + "\n\t\t\t" + "print()"
    # z3FileString = z3FileString + "\n\t\t\t" + "print(\"%%%%%%%%%% An Instance for which Violation Occurred %%%%%%%%%%\\n\", s.model())"
    z3FileString = z3FileString + "\n\t\t\t" + "self.modelForViolation = str(s.model())"

    z3FileString = z3FileString + "\n\t\t" + "elif self.satisfiability == \"unsat\":"
    # z3FileString = z3FileString + "\n\t\t\t" + "print()"
    # z3FileString = z3FileString + "\n\t\t\t" + "print(\"-------->> NO Violation Detected so far...\")"
    z3FileString = z3FileString + "\n\t\t\t" + "self.satisfiability = \"sat\""
    # z3FileString = z3FileString + "\n\t\t\t" + "print()"
    # z3FileString = z3FileString + "\n\t\t" + "print()\n"

    file = open('cnf/Z3RuntimeCnfFile.py', "w")
    file.write(z3FileString)
    file.close()

    import cnf.Z3RuntimeCnfFile
    from cnf.Z3RuntimeCnfFile import Z3RuntimeCnfFile
    # Reload after module's creation to avoid old module remain imported from disk...VVI...
    cnf.Z3RuntimeCnfFile = reload(cnf.Z3RuntimeCnfFile)

    z3Runtime = Z3RuntimeCnfFile()
    z3Runtime.execute()

    finishTime = datetime.datetime.now()
    timeDifference = (finishTime - startTime).total_seconds()

    return linesOfCode, timeDifference, z3StringConvertor.convertedWpc, z3Runtime.satisfiability, z3Runtime.modelForViolation
示例#9
0
def executeSinglePlSqlFile(data, spec):
    f = open(data, 'r')
    linesOfCode = len(f.readlines())
    f.close()

    processor = PreProcessor(spec, data)
    tableInfo, assumeConstraintList, assertConstraintList, resultString = processor.start(
    )

    file = open('wpc/upper_input.sql', "w")
    file.write(resultString)
    file.close()

    # recording startTime
    startTime1 = datetime.datetime.now()

    input = FileStream('wpc/upper_input.sql')
    lexer = PlSqlLexer(input)
    stream = CommonTokenStream(lexer)
    parser = PlSqlParser(stream)
    tree = parser.sql_script()

    cfg = MyCFG()
    helper = MyHelper(parser)
    helper.updateTableDict(tableInfo)
    utility = MyUtility(helper)
    v = MyVisitor(parser, cfg, utility)
    v.visit(tree)

    print("\nRaw CFG :", v.rawCFG, "\n")

    # for key in v.cfg.nodes:
    #     if v.cfg.nodes[key].ctx != None:
    #         print(key, " --> ", v.cfg.nodes[key].ctx.getText())
    # print("\n")

    res = MyRawCfgToGraph(v.rawCFG, cfg)
    res.execute()
    # cfg.printPretty()
    # print("\n")

    utility.generateVariableSet(cfg)

    # all properties of each node
    # for nodeId in cfg.nodes:
    #     cfg.nodes[nodeId].printPretty()

    ssaString = MySsaStringGenerator(cfg, parser)
    ssaString.execute(
    )  # only for generating DOT file for "before_versioning_graph"

    # recording finishTime
    finishTime1 = datetime.datetime.now()

    # cfg.dotToPng(cfg.dotGraph, "wpc/raw_graph")
    #
    # hello1 = utility.generateBeforeVersioningDotFile(cfg)
    # cfg.dotToPng(hello1, "wpc/before_versioning_graph")

    # recording startTime
    startTime2 = datetime.datetime.now()

    algo = WpcGenerator(cfg, helper, ssaString)
    algo.execute()
    algo.finalWpcString = algo.finalWpcString.replace("  ", " ")
    # done: replace " = " with " == " in algo.finalWpcString
    algo.finalWpcString = algo.finalWpcString.replace(" = ", " == ")

    print("\n**** Final WPC VC in Well_Bracketted_Format:\n\n",
          algo.finalWpcString, "\n")

    # print(algo.variablesForZ3)

    # algo.finalWpcString = "( ( z ) ^ ( ( ! ( y ) ) ==> ( ( ( 2 ) v ( x ) ) ==> ( y - 2 ) ) ) )"       # for testing! Don't UNCOMMENT...
    # algo.finalWpcString = "( ( ( z ) ==> ( u ) ) ^ ( ( ! ( y ) ) ==> ( ( ( true ) ) ==> ( y - 2 ) ) ) )"       # for testing! Don't UNCOMMENT...
    # algo.finalWpcString = "( ( ( z ) ==> ( u ) ) ^ ( ( ! ( y ) ) ==> ( true ) ) ^ ( ( a ) ==> ( b ) ) )"       # for testing! Don't UNCOMMENT...
    # algo.finalWpcString = "( ( ( ! ( y ) ) ==> ( true ) ) )"       # for testing! Don't UNCOMMENT...
    # algo.finalWpcString = "( ( ( ! ( y ) ) ^ ( true ) v ( g ) ) )"       # for testing! Don't UNCOMMENT...
    z3StringConvertor = WpcStringConverter(algo.finalWpcString)
    z3StringConvertor.execute()
    # z3StringConvertor.convertedWpc is the FINAL VC Generated...
    print("\n**** Final WPC VC in Z3 Format:\n\n",
          z3StringConvertor.convertedWpc, "\n")

    z3FileString = "# This file was generated at runtime on " + str(
        datetime.datetime.now()) + "\n"
    z3FileString = z3FileString + "from z3 import *\n\n"
    z3FileString = z3FileString + "class Z3RuntimeWpcFile():\n"
    z3FileString = z3FileString + "\t" + "def __init__(self):\n"
    z3FileString = z3FileString + "\t\t" + "self.finalFormula = \"\"\n"
    z3FileString = z3FileString + "\t\t" + "self.satisfiability = \"\"\n"
    z3FileString = z3FileString + "\t\t" + "self.modelForViolation = \"\"\n\n"

    z3FileString = z3FileString + "\t" + "def execute(self):\n"
    for i in algo.variablesForZ3:
        z3FileString = z3FileString + "\t\t" + i + " = Real(\'" + i + "\')\n"
    z3FileString = z3FileString + "\n\t\ts = Solver()\n"

    if len(z3StringConvertor.implies_p) > 0:
        for i in range(len(z3StringConvertor.implies_p)):
            z3FileString = z3FileString + "\t\t" + "s.add(" + z3StringConvertor.implies_p[
                i] + ")\n"
            if not z3StringConvertor.convertedWpc == z3StringConvertor.implies_p_q[
                    i]:
                z3FileString = z3FileString + "\t\t" + "s.add(" + z3StringConvertor.implies_p_q[
                    i] + ")\n"
    z3FileString = z3FileString + "\t\t" + "s.add( Not( " + z3StringConvertor.convertedWpc + " ) )\n"

    # z3FileString = z3FileString + "\n\t\t" + "print()"
    z3FileString = z3FileString + "\n\t\t" + "#print(\"\\n%%%%%%%%%% Aggregate Formula %%%%%%%%%%\\n\", s)"
    z3FileString = z3FileString + "\n\t\t" + "self.finalFormula = str(s)"
    # z3FileString = z3FileString + "\n\t\t" + "print()"
    z3FileString = z3FileString + "\n\t\t" + "#print(\"\\n%%%%%%%%%% Satisfiability %%%%%%%%%%\")\n"
    z3FileString = z3FileString + "\n\t\t" + "self.satisfiability = str(s.check())"

    z3FileString = z3FileString + "\n\t\t" + "if self.satisfiability == \"sat\":"
    # z3FileString = z3FileString + "\n\t\t\t" + "print()"
    z3FileString = z3FileString + "\n\t\t\t" + "#print(\"\\n-------->> Violation Occurred...\")"
    z3FileString = z3FileString + "\n\t\t\t" + "self.satisfiability = \"violation\""
    # z3FileString = z3FileString + "\n\t\t\t" + "print()"
    z3FileString = z3FileString + "\n\t\t\t" + "#print(\"\\n%%%%%%%%%% An Instance for which Violation Occurred %%%%%%%%%%\\n\", s.model())"
    z3FileString = z3FileString + "\n\t\t\t" + "self.modelForViolation = str(s.model())"

    z3FileString = z3FileString + "\n\t\t" + "elif self.satisfiability == \"unsat\":"
    # z3FileString = z3FileString + "\n\t\t\t" + "print()"
    z3FileString = z3FileString + "\n\t\t\t" + "#print(\"\\n-------->> NO Violation Detected so far...\\n\")"
    z3FileString = z3FileString + "\n\t\t\t" + "self.satisfiability = \"sat\""
    # z3FileString = z3FileString + "\n\t\t\t" + "print()"
    # z3FileString = z3FileString + "\n\t\t" + "print()\n"

    file = open('wpc/Z3RuntimeWpcFile.py', "w")
    file.write(z3FileString)
    file.close()

    # time.sleep(2)

    # import file created on Runtime...
    import wpc.Z3RuntimeWpcFile
    from wpc.Z3RuntimeWpcFile import Z3RuntimeWpcFile
    # Reload after module's creation to avoid old module remain imported from disk...VVI...
    wpc.Z3RuntimeWpcFile = reload(wpc.Z3RuntimeWpcFile)

    z3Runtime = Z3RuntimeWpcFile()
    z3Runtime.execute()
    # print(z3Runtime.finalFormula)
    # print(z3Runtime.satisfiability)
    # print(z3Runtime.modelForViolation)

    # recording finishTime
    finishTime2 = datetime.datetime.now()
    timeDifference = ((finishTime1 - startTime1) +
                      (finishTime2 - startTime2)).total_seconds()

    return linesOfCode, timeDifference, z3StringConvertor.convertedWpc, z3Runtime.satisfiability, z3Runtime.modelForViolation
示例#10
0
    def start(self):
        tableInfo, predicates = self.getSpec()

        magicString = "CREATE OR REPLACE PROCEDURE TEST(X IN VARCHAR)\nIS\nBEGIN\n"
        for predicate in predicates:
            magicString = magicString + "\tASSUME " + predicate + ";\n"
        magicString = magicString + "\nEND;"
        file = open('mc/magic_file.sql', "w")
        file.write(magicString)
        file.close()

        input = FileStream('mc/magic_file.sql')
        lexer = PlSqlLexer(input)
        stream = CommonTokenStream(lexer)
        parser = PlSqlParser(stream)
        tree = parser.sql_script()

        cfg = MyCFG()
        helper = MyHelper(parser)
        helper.updateTableDict(tableInfo)
        utility = MyUtility(helper)
        v = MyVisitor(parser, cfg, utility)
        v.visit(tree)

        res = MyRawCfgToGraph(v.rawCFG, cfg)
        res.execute()
        utility.generateVariableSet(cfg)

        ssaStringObj = MySsaStringGenerator(cfg, parser)
        wpcGeneratorObj = WpcGenerator(cfg, helper, ssaStringObj)

        newPredicates = []
        predicateVarSet = set()
        for nodeId in cfg.nodes:
            if helper.getRuleName(cfg.nodes[nodeId].ctx) == "assume_statement":
                assumeCondition = wpcGeneratorObj.getConditionalString(
                    cfg.nodes[nodeId].ctx.children[1])
                assumeCondition = assumeCondition.replace("  ", " ").strip()
                newPredicates.append(assumeCondition)
                predicateVarSet = predicateVarSet.union(
                    cfg.nodes[nodeId].variableSet)

        f = open(self.fileData, "r")
        content = f.read().upper()
        f.close()
        assumeConstraintString = "TO_CORRECT_PROBLEMS_IN_SE_API > 0"
        assertConstraintString = "TO_CORRECT_PROBLEMS_IN_SE_API > 0"
        temp = content.strip().split("BEGIN")
        result = ""
        result = result + temp[
            0] + "BEGIN\n\t" + "ASSUME " + assumeConstraintString + " ;\n" + temp[
                1]
        for i in range(2, len(temp)):
            result = result + "BEGIN" + temp[i]

        temp = result.strip().split("END")
        result = temp[0]
        for i in range(1, len(temp) - 1):
            result = result + "END" + temp[i]
        result = result + "ASSERT " + assertConstraintString + " ;\n\t" + "END" + temp[
            len(temp) - 1]

        return tableInfo, newPredicates, predicates, predicateVarSet, result  # newPredicates : in wpc format ; predicate : in plsql format
示例#11
0
def main(argv):
    datafile = "se/data/" + argv[1]
    specfile = "se/spec/" + argv[2]

    # file = open(datafile, "r")
    # content = file.read().upper()
    # file.close()

    processor = PreProcessor(specfile, datafile)
    tableInfo, assumeConstraintList, assertConstraintList, resultString = processor.start(
    )

    file = open('se/upper_input.sql', "w")
    file.write(resultString)
    file.close()

    input = FileStream('se/upper_input.sql')
    lexer = PlSqlLexer(input)
    stream = CommonTokenStream(lexer)
    parser = PlSqlParser(stream)
    tree = parser.sql_script()
    # ast = tree.toStringTree(recog=parser)
    # print(str(MyPlSqlVisitor(parser).getRuleName(tree)))
    # print("\n\n", signature(tree.toStringTree), "\n")

    cfg = MyCFG()
    helper = MyHelper(parser)
    helper.updateTableDict(tableInfo)
    utility = MyUtility(helper)
    v = MyVisitor(parser, cfg, utility)
    v.visit(tree)

    print("\n\t", v.rawCFG, "\n")

    # for key in v.cfg.nodes:
    #     if v.cfg.nodes[key].ctx != None:
    #         print(key, " --> ", v.cfg.nodes[key].ctx.getText())

    res = MyRawCfgToGraph(v.rawCFG, cfg)
    res.execute()
    # cfg.printPretty()
    cfg.dotToPng(cfg.dotGraph, "se/raw_graph")
    utility.generateDomSet(cfg)
    # print("Dominator set ended----------->\n\n")
    utility.generateSDomSet(cfg)
    # print("Strictly Dominator set ended ----------->\n\n")
    utility.generatIDom(cfg)
    # print("Immediate Dominator ended ----------->\n\n")
    utility.generateDFSet(cfg)
    utility.insertPhiNode(cfg)

    utility.initialiseVersinosedPhiNode(cfg)
    utility.versioniseVariable(cfg)
    utility.phiDestruction(cfg)

    ssaString = MySsaStringGenerator(cfg, parser)
    ssaString.execute()

    for nodeId in cfg.nodes:
        cfg.nodes[nodeId].printPretty()

    hello1 = utility.generateBeforeVersioningDotFile(cfg)
    # print(hello1)
    cfg.dotToPng(hello1, "se/before_versioning_graph")

    hello2 = utility.generateVersionedDotFile(cfg)
    #print(hello2)
    cfg.dotToPng(hello2, "se/versioned_graph")

    hello3 = utility.generateVersionedPhiNodeWalaDotFile(cfg)
    #print(hello3)
    cfg.dotToPng(hello3, "se/versioned_phi_node_wala_graph")

    hello4 = utility.generateDestructedPhiNodeWalaDotFile(cfg)
    #print(hello4)
    cfg.dotToPng(hello4, "se/destructed_phi_node_wala_graph")