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_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_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_c4_datalog_e2e(self): # ------------------------------------------------------------------ # # create IR instance saveDB = os.getcwd() + "/IR_test_dedalus_to_c4_datalog_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") # file for storing table strs table_save = os.path.abspath( __file__ + "/../../../testfiles/simplelog_v0_tables.data") # file for storing output the c4 datalog directly corresponding to the raw dedalus output_olg = os.path.abspath(__file__ + "/../../../testfiles/e2e_test.olg") # file storing the expected c4 datalog expected_olg = os.path.abspath( __file__ + "/../../../testfiles/simpleLog_v0_to_c4_expected.olg") expected_olg_molly = os.path.abspath( __file__ + "/../../../testfiles/expected_c4_prog_molly.olg") # 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 } # ------------------------------------------------------------------ # # translate and save to output file dedt.runTranslator(cursor, input_ded, argDict, table_save, output_olg, "c4") # compare test file translation with expected file translation self.assertTrue(e2e_tools.cmpDatalogFiles_c4(output_olg, expected_olg)) #self.assertTrue( e2e_tools.cmpDatalogFiles_c4( output_olg, expected_olg_molly ) ) # close database instance dedt.cleanUp(IRDB, saveDB)
def test_runTranslator_dedt(self): #testing set up. runTranslator has dependency #on createDedalusIRTables so that's #tested first above. testDB = testPath + "/IR.db" IRDB = sqlite3.connect(testDB) cursor = IRDB.cursor() tableList = testPath + "/testfiles/tableListStr.data" datalogProg = testPath + "/testfiles/c4program.olg" #dependency dedt.createDedalusIRTables(cursor) inputfile = testPath + "/testfiles/testFullProgram.ded" inputArg = { 'prov_diagrams': False, 'use_symmetry': False, 'crashes': 0, 'solver': None, 'disable_dot_rendering': False, 'negative_support': False, 'strategy': None, 'file': testPath + "/testfiles/testFullProgram.ded", 'EOT': 3, 'find_all_counterexamples': False, 'nodes': ['a', 'b', 'c', 'd'], 'EFF': 2, 'evaluator': 'c4' } #runs through function to make sure it finishes without error outputResult = None evaluator = "c4" with self.assertRaises(SystemExit): dedt.runTranslator(cursor, inputfile, inputArg, tableList, None, evaluator) outpaths = dedt.runTranslator(cursor, inputfile, inputArg, tableList, datalogProg, evaluator) if not outpaths is None: tables = outpaths[0] c4file = outpaths[1] #clean up testing IRDB.close() os.remove(testDB) if tables is not None: os.remove(tables) if c4file is not None: os.remove(c4file)
def test_example5(self): # --------------------------------------------------------------- # #testing set up. dedToIR has dependency #on createDedalusIRTables so that's #tested first above. testDB = "./IR.db" IRDB = sqlite3.connect(testDB) cursor = IRDB.cursor() # --------------------------------------------------------------- # #dependency dedt.createDedalusIRTables(cursor) # --------------------------------------------------------------- # #runs through function to make sure it finishes with expected error # specify input file path inputfile = "./testFiles/example5.ded" # get argDict argDict = self.getArgDict(inputfile) # run translator try: programData = dedt.translateDedalus(argDict, cursor) # portray actual output program lines as a single string actual_results = self.getActualResults(programData[0][0]) # something broke. save output as a single string except: actual_results = self.getError(sys.exc_info()) # grab expected output results as a string expected_results_path = "./testFiles/example5_error.txt" expected_results = None with open(expected_results_path, 'r') as expectedFile: expected_results = expectedFile.read() print "actual_results :" + repr(actual_results) print "expected_results:" + repr(expected_results) self.assertEqual(actual_results, expected_results) # --------------------------------------------------------------- # #clean up testing IRDB.close() os.remove(testDB)
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 test_createDedalusIRTables_dedt(self): #testing set up testDB = testPath + "/IR.db" IRDB = sqlite3.connect(testDB) cursor = IRDB.cursor() #checks if it runs through function without error self.assertTrue(dedt.createDedalusIRTables(cursor) == None) #checks if the tables are actually created self.assertFalse( cursor.execute( "SELECT name FROM sqlite_master WHERE type='table' AND name='Fact'" ).fetchone() == None) self.assertFalse( cursor.execute( "SELECT name FROM sqlite_master WHERE type='table' AND name='FactAtt'" ).fetchone() == None) self.assertFalse( cursor.execute( "SELECT name FROM sqlite_master WHERE type='table' AND name='Rule'" ).fetchone() == None) self.assertFalse( cursor.execute( "SELECT name FROM sqlite_master WHERE type='table' AND name='GoalAtt'" ).fetchone() == None) self.assertFalse( cursor.execute( "SELECT name FROM sqlite_master WHERE type='table' AND name='Subgoals'" ).fetchone() == None) self.assertFalse( cursor.execute( "SELECT name FROM sqlite_master WHERE type='table' AND name='SubgoalAtt'" ).fetchone() == None) self.assertFalse( cursor.execute( "SELECT name FROM sqlite_master WHERE type='table' AND name='SubgoalAddArgs'" ).fetchone() == None) self.assertFalse( cursor.execute( "SELECT name FROM sqlite_master WHERE type='table' AND name='Equation'" ).fetchone() == None) self.assertFalse( cursor.execute( "SELECT name FROM sqlite_master WHERE type='table' AND name='Clock'" ).fetchone() == None) self.assertFalse( cursor.execute( "SELECT name FROM sqlite_master WHERE type='table' AND name='Crash'" ).fetchone() == None) #clean up testing IRDB.close() os.remove(testDB)
def test_dedalus_to_cnf_rewrite_e2e(self): # ------------------------------------------------------------------ # # create IR instance saveDB = os.getcwd() + "/IR_test_dedalus_to_c4_datalog_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") # file for storing table strs table_save = os.path.abspath( __file__ + "/../../../testfiles/simplelog_v0_tables.data") # file for storing output the c4 datalog directly corresponding to the raw dedalus output_olg = os.path.abspath(__file__ + "/../../../testfiles/e2e_test.olg") # file storing the expected provTreeComplete expected_cnf_fmla_save = os.path.abspath( __file__ + "/../../../testfiles/expected_cnf_fmla_save.txt") # c4 evaluation results save path c4_results_save = os.path.abspath( __file__ + "/../../../testfiles/simpleLog_c4_results.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 } # ------------------------------------------------------------------ # # translate and save to output file dedt.runTranslator(cursor, input_ded, argDict, table_save, output_olg, "c4") # create and LDFICore insatnce and run evaluator only coreInstance = LDFICore.LDFICore(c4_results_save, table_save, output_olg, argDict, cursor) resultsPath = coreInstance.evaluate("C4_WRAPPER", coreInstance.table_list_path, coreInstance.datalog_prog_path, coreInstance.c4_dump_savepath) parsedResults = tools.getEvalResults_file_c4( resultsPath) # assumes C4 results stored in dump # build test proof/provenance/derivation tree fault_id = 0 provTreeComplete = coreInstance.buildProvTree( parsedResults, coreInstance.argDict["EOT"], fault_id, coreInstance.cursor) # generate formula from test provTree_fmla = EncodedProvTree_CNF.EncodedProvTree_CNF( provTreeComplete) cnf_fmla = provTree_fmla.cnfformula # load expected CNF formula fo = open(expected_cnf_fmla_save, "r") expected_cnf_fmla = fo.readline() fo.close() # compare test file translation with expected file translation self.assertTrue(cnf_fmla, expected_cnf_fmla) # close database instance dedt.cleanUp(IRDB, saveDB)
def run_workflow(self, test_id, argDict, input_file, eval_type, RUN_EVAL=True): # --------------------------------------------------------------- # # check if dedalus if input_file.endswith(".ded"): IS_DED = True elif input_file.endswith(".olg"): IS_DED = False else: raise Exception( "INVALID FILE TYPE : make sure the input file is either .ded or .olg" ) # --------------------------------------------------------------- # # make sure data dir exists if not os.path.exists(argDict["data_save_path"]): self.make_data_dir(argDict["data_save_path"], test_id) # --------------------------------------------------------------- # if not IS_DED: # extract program string program = self.extract_program_array(input_file) table_list = self.extract_table_list(program) program_data = [program, table_list] # run program with c4 wrapper if RUN_EVAL: eval_results_dict = self.run_program_c4(program_data, argDict) else: eval_results_dict = [] # --------------------------------------------------------------- # else: # --------------------------------------------------------------- # # set up IR data test_db = argDict["data_save_path"] + "/IR_" + test_id + ".db" if os.path.exists(test_db): os.remove(test_db) IRDB = sqlite3.connect(test_db) cursor = IRDB.cursor() dedt.createDedalusIRTables(cursor) dedt.globalCounterReset() # --------------------------------------------------------------- # # run translator # grab only the program lines and table list. program_data = dedt.translateDedalus(argDict, cursor)[0] # run program in c4 if RUN_EVAL: eval_results_dict = self.run_program_c4(program_data, argDict) else: eval_results_dict = [] # --------------------------------------------------------------- # # run analysis analysis_results_dict = self.run_analysis(program_data, eval_results_dict, IS_DED) print print "======================================" print "========== ANALYSIS RESULTS for " + eval_type + " ==========" print for res in analysis_results_dict: print res + " => " + str(analysis_results_dict[res]) print print "======================================" print # --------------------------------------------------------------- # # save analysis data to file self.save_analysis_data_to_file(analysis_results_dict, test_id, argDict) return eval_results_dict
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
def test_async_1(self): test_id = "pycosat_async_1" test_input_file_name = "async_1_driver" test_db = "./IR_" + test_id + ".db" logging.debug(">> RUNNING TEST '" + test_id + "' <<<") # --------------------------------------------------------------- # # set up test if os.path.exists(test_db): os.remove(test_db) IRDB = sqlite3.connect(test_db) cursor = IRDB.cursor() dedt.createDedalusIRTables(cursor) dedt.globalCounterReset() # --------------------------------------------------------------- # # specify input file paths inputfile = "./dedalus_drivers/" + test_input_file_name + ".ded" # --------------------------------------------------------------- # # get argDict argDict = self.get_arg_dict(inputfile) argDict["nodes"] = ["Node1", "Node2", "Server"] argDict["EOT"] = 3 argDict["EFF"] = 0 argDict[ 'settings'] = "./settings_files/settings_dm_allow_not_clocks.ini" if not os.path.exists(argDict["data_save_path"]): cmd = "mkdir " + argDict["data_save_path"] logging.debug(" TEST " + test_id.upper() + " : running cmd = " + cmd) os.system(cmd) # --------------------------------------------------------------- # # generate orik rgg orik_rgg = self.get_orik_rgg( argDict, \ inputfile, \ cursor, \ test_id ) # --------------------------------------------------------------- # # generate fault hypotheses pycosat_solver = PYCOSAT_Solver.PYCOSAT_Solver(argDict, orik_rgg) logging.debug(" TEST " + test_id.upper() + " : cnf_fmla_list :") for f in pycosat_solver.cnf_fmla_list: logging.debug(f) # get all the solns for all the fmlas for the provenance tree all_solns = self.get_all_solns(pycosat_solver) if self.PRINT_STOP: print "PRINTING ALL SOLNS:" print all_solns sys.exit("hit print stop.") expected_all_solns = [] self.assertEqual(all_solns, expected_all_solns) # --------------------------------------------------------------- # # clean up yo mess if os.path.exists(test_db): os.remove(test_db)
def test_simplog(self): test_id = "simplog" test_db = "./IR_" + test_id + ".db" logging.debug(">> RUNNING TEST '" + test_id + "' <<<") # --------------------------------------------------------------- # # set up test if os.path.exists(test_db): os.remove(test_db) IRDB = sqlite3.connect(test_db) cursor = IRDB.cursor() dedt.createDedalusIRTables(cursor) dedt.globalCounterReset() # --------------------------------------------------------------- # # specify input file paths inputfile = "./dedalus_drivers/" + test_id + "_driver.ded" # --------------------------------------------------------------- # # get argDict argDict = self.get_arg_dict(inputfile) argDict["nodes"] = ["a", "b", "c"] argDict["EOT"] = 4 argDict["EFF"] = 2 if not os.path.exists(argDict["data_save_path"]): cmd = "mkdir " + argDict["data_save_path"] logging.debug(" TEST SIMPLOG : running cmd = " + cmd) os.system(cmd) # --------------------------------------------------------------- # # generate orik rgg orik_rgg = self.get_orik_rgg( argDict, \ inputfile, \ cursor, \ test_id ) # --------------------------------------------------------------- # # generate fault hypotheses pycosat_solver = PYCOSAT_Solver.PYCOSAT_Solver(argDict, orik_rgg) logging.debug(" SIMPLOG : cnf_fmla_list :") for f in pycosat_solver.cnf_fmla_list: logging.debug(f) # get all the solns for all the fmlas for the provenance tree all_solns = self.get_all_solns(pycosat_solver) if self.PRINT_STOP: print all_solns sys.exit("hit print stop.") expected_all_solns = [["clock(['a','b','1','2'])"], ["clock(['a','c','1','2'])"]] self.assertEqual(all_solns, expected_all_solns) # --------------------------------------------------------------- # # clean up yo mess if os.path.exists(test_db): os.remove(test_db)