def test_dedToIR_dedt(self): #testing set up. dedToIR has dependency #on createDedalusIRTables so that's #tested first above. testDB = testPath + "/IR.db" IRDB = sqlite3.connect(testDB) cursor = IRDB.cursor() #dependency dedt.createDedalusIRTables(cursor) #throws error for nonexistent file inputfile = "./nonexistentfile.ded" with self.assertRaises(SystemExit) as cm: dedt.dedToIR(inputfile, cursor) self.assertIn("ERROR", cm.exception.code) #runs through function to make sure it finishes without error inputfile = testPath + "/testfiles/testFullProgram.ded" outputResult = None self.assertFalse(dedt.dedToIR(inputfile, cursor) == outputResult) #clean up testing IRDB.close() os.remove(testDB)
def test_initClockRelation_clockRelation(self): #testing setup. initClockRelation has dependency #on createDedalusIRTables and dedToIR so that's #tested first above. testDB = testPath + "/IR.db" IRDB = sqlite3.connect(testDB) cursor = IRDB.cursor() inputfile = testPath + "/testfiles/testFullProgram.ded" #Dependencies dedt.createDedalusIRTables(cursor) dedt.dedToIR(inputfile, cursor) #for saving the program clock output #to be used in comparison below clockRelation.CLOCKRELATION_DEBUG = True originalStdout = sys.stdout cmdResult = StringIO() fileResult = StringIO() #run through using cmdline topology option to make sure it doesn't #throw up an error sys.stdout = cmdResult inputArg = { 'file': testPath + "/testfiles/testFullProgram.ded", 'EOT': 3, 'nodes': ['a', 'b', 'c', 'd'] } outputResult = None self.assertTrue( clockRelation.initClockRelation(cursor, inputArg) == outputResult) #run through using node topology from inputfile option to make sure it #doesn't throw up an error sys.stdout = fileResult inputArg = { 'file': testPath + "/testfiles/testFullProgram.ded", 'EOT': 3, 'nodes': [] } self.assertTrue( clockRelation.initClockRelation(cursor, inputArg) == outputResult) #check to make sure that the outputs from both options are the same # where "options" := grabbing node topology from file OR # grabbing node topology from the cmdline sys.stdout = originalStdout #return stdout to original cmdOutput = cmdResult.getvalue()[cmdResult.getvalue().find('\n') + 1:] fileOutput = fileResult.getvalue()[fileResult.getvalue().find('\n') + 1:] self.assertEqual(cmdOutput, fileOutput) #clean up testing IRDB.close() os.remove(testDB)
def test_dedalus_to_dedalus_ir_rewrite_e2e(self): # ------------------------------------------------------------------ # # create IR instance saveDB = os.getcwd() + "/IR_test_dedalus_to_dedalus_ir_rewrite_e2e.db" os.system("rm saveDB") # delete db if it already exists. IRDB = sqlite3.connect( saveDB) # database for storing IR, stored in running script dir cursor = IRDB.cursor() dedt.createDedalusIRTables(cursor) # raw dedalus input_ded = os.path.abspath(__file__ + "/../../../testfiles/simpleLog_v0.ded") # path to test IR dump test_dump_save = os.getcwd() + "/test_dump.txt" os.system("rm test_dump_save") # remove if file already exists # path to expected IR dump expected_dump_save = os.path.abspath( __file__ + "/../../../testfiles/expected_IR_dump_test_dedalus_to_dedalus_ir_rewrite_e2e.txt" ) # dictionary of commandline args for executing the run argDict = { 'prov_diagrams' : False, \ 'use_symmetry' : False, \ 'crashes': 0, 'solver' : None, \ 'disable_dot_rendering' : False, \ 'negative_support' : False, \ 'strategy' : None, \ 'file' : input_ded, \ 'EOT' : 4, \ 'find_all_counterexamples' : False, \ 'nodes' : ['a', 'b', 'c'], \ 'evaluator' : 'c4', \ 'EFF' : 2 } # ------------------------------------------------------------------ # # populate the initial IR meta = dedt.dedToIR(input_ded, cursor) # generate the first clock dedt.starterClock(cursor, argDict) # perform the dedalus rewrite dedalusRewriter.rewriteDedalus(cursor) # dump contents of IR db to a save file dumpers_c4.dumpIR(cursor, test_dump_save) # compare test IR results with expected IR results by comparing save file dumps self.assertTrue( e2e_tools.cmpDatalogFiles_c4(test_dump_save, expected_dump_save)) # close database instance dedt.cleanUp(IRDB, saveDB)
def test_rewriteInductive_dedalusRewriter(self): #testing set up. Dependencies listed below. testDB = testPath + "/IR.db" IRDB = sqlite3.connect(testDB) cursor = IRDB.cursor() inputfile = testPath + "/testfiles/testFullProgram.ded" #dependency dedt.createDedalusIRTables(cursor) dedt.dedToIR(inputfile, cursor) #runs through function to make sure it finishes without error self.assertTrue(dedalusRewriter.rewriteInductive(cursor) == None) #clean up testing IRDB.close() os.remove(testDB)
def dedalus_to_datalog(starterFile, cursor): logging.debug(" DEDALUS TO DATALOG : running process...") argDict = {} argDict["settings"] = "./settings.ini" argDict["EOT"] = 4 argDict["nodes"] = ["a", "b", "c", "d"] # ----------------------------------------------------------------- # # create tables dedt.createDedalusIRTables(cursor) logging.debug(" DEDALUS TO DATALOG : created IR tables") # ----------------------------------------------------------------- # # get all input files fileList = tools.get_all_include_file_paths(starterFile) logging.debug(" DEDALUS TO DATALOG : fileList = " + str(fileList)) allProgramData = [] # TO DO : concat all lines into a single file, then translate for fileName in fileList: logging.debug(" DEDALUS TO DATALOG : running process...") #logging.warning( " RUN TRANSLATOR : WARNING : need to fix file includes to run translator once. need to know all program lines to derive data types for program." ) # ----------------------------------------------------------------- # # PARSE # ----------------------------------------------------------------- # meta = dedt.dedToIR(fileName, cursor) factMeta = meta[0] ruleMeta = meta[1] logging.debug(" DEDALUS TO DATALOG: len( ruleMeta ) = " + str(len(ruleMeta))) # ------------------------------------------------------------- # # generate the first clock logging.debug(" RUN TRANSLATOR : building starter clock...") dedt.starterClock(cursor, argDict) logging.debug(" RUN TRANSLATOR : ...done building starter clock.") # ----------------------------------------------------------------- # # REWRITE # ----------------------------------------------------------------- # # ----------------------------------------------------------------------------- # # dedalus rewrite # logging.debug( " REWRITE : calling dedalus rewrites..." ) # # allMeta = dedalusRewriter.rewriteDedalus( factMeta, ruleMeta, cursor ) # factMeta = allMeta[0] # ruleMeta = allMeta[1] # # # be sure to fill in all the type info for the new rule definitions # setTypes( cursor ) # # # ----------------------------------------------------------------------------- # # # provenance rewrites # # logging.debug( " REWRITE : calling provenance rewrites..." ) # # # add the provenance rules to the existing rule set # ruleMeta.extend( provenanceRewriter.rewriteProvenance( ruleMeta, cursor ) ) # # # be sure to fill in all the type info for the new rule definitions # setTypes( cursor ) # # # ----------------------------------------------------------------------------- # # # logging.debug( " REWRITE : ...done." ) # ------------------------------------------------------------- # # translate IR into datalog logging.debug(" DEDALUS TO DATALOG : launching c4 translation ...") allProgramData.extend(c4_translator.c4datalog(argDict, cursor)) logging.debug(" DEDALUS TO DATALOG : ...done with c4 translation.") # ------------------------------------------------------------- # return allProgramData