def reeval_test_result(pargs, logger=None): race_suspect = None with db_interface.get_connection(pargs.host, pargs.user, pargs.pwd, pargs.database) as db_con: test_suspect = db_interface.get_suspect_id_of_test(db_con, pargs.testid, logger) race_suspect = db_interface.retrieve_race_suspect(db_con, test_suspect, logger) xdebugTriplets = db_interface.get_test_xdebugs(db_con, pargs.testid) suspectFingerprint = XdebugFingerprint(race_suspect._refXdebug[0], PaQu(race_suspect._refpaqu)) fingerprints = list() for element in xdebugTriplets: xdebug = Xdebug.XdebugTrace(element[2]) fingerprints.append(XdebugFingerprint(xdebug, PaQu(element[1]))) if pargs.relaxed_check: count = count_equalp_fingerprints_relaxed(suspectFingerprint, race_suspect._query, fingerprints, race_suspect._projname, race_suspect._session, race_suspect._user, pargs.host, pargs.user, pargs.pwd, pargs.database, pargs.expid, logger=logger) else: count = count_equalp_fingerprints(suspectFingerprint, fingerprints, race_suspect._projname, race_suspect._session, race_suspect._user, pargs.host, pargs.user, pargs.pwd, pargs.database, pargs.expid, logger=logger) logger.info("overall {} hits".format(count))
def get_litmus_test_results(experiment_id, db_host, db_user, db_pwd, db_name, firebases, testcase, xpath, target, root_user, root_password, vm_name, vm_state, logger=None, sequentialp=True, do_not_run_tests=False): with db_interface.get_connection(db_host, db_user, db_pwd, db_name) as db_con: zipNameTriples, count = db_interface.get_litmus_test_results(db_con, experiment_id, sequentialp) if len(zipNameTriples) == 0: if do_not_run_tests: raise Exception("No {} litmustest found but running test forbidden".format("sequential" if sequentialp else "parallel")) logger.info("no stored {} litmus test results for experiment {} found. Generating them now.".format( "sequential" if sequentialp else "parallel", experiment_id)) with RunningVirtualMachine(vm_name, vm_state, target, root_user, root_password, _CONST_TARGET_FOLDERS, logger=logger): set_query(root_user, target, root_password, "SELECT nothing FROM fake", logger) zipNameTriples, count = run_litmus_test(testcase, target, firebases, root_user, root_password, xpath, logger=logger, sequentialp=sequentialp) db_interface.enter_litmus_test_results(db_con, experiment_id, count, zipNameTriples, sequentialp) else: logger.info("found {} litmus test results for experiment {}".format("sequential" if sequentialp else "parallel", experiment_id)) xdebugFingerprints = list() for element in zipNameTriples: xdebug = Xdebug.XdebugTrace(element[2]) # print xdebug xdebugFingerprints.append(XdebugFingerprint(xdebug, PaQu(element[1]))) return xdebugFingerprints, count
def get_all_used_php_files(args): with open(args.file) as file: xdebug = xdebugparser.XdebugTrace(file) for php_file in xdebug.get_all_used_source_files(): if args.relative: print "/{}".format(drop_until_htdoc(php_file)) else: print "{}".format(php_file)
def retrieve_race_suspect(db_con, suspect_id, logger): suspect_query = """SELECT id, chg_expid, chg_selcmdctr, chg_httpreqctr, chg_query FROM RaceSuspectsView WHERE id = %(id)s;""" xdebug_query = """SELECT content, name FROM xdebugDumpsRacoonView WHERE expid = %(expid)s AND selcmdctr = %(selcmdctr)s AND httpreqctr = %(httpreqctr)s;""" request_query = """SELECT url FROM httprequestsview WHERE ctr = %(httpreqctr)s AND expid = %(expid)s AND selcmdctr = %(selcmdctr)s;""" experiment_query = """SELECT projname, session, operation, username FROM experimentsview WHERE id = %(expid)s;""" with db_con.cursor() as cur: valuedict = {"id": suspect_id} cur.execute(suspect_query, valuedict) suspect_result = cur.fetchone() valuedict = {"expid": suspect_result[1], "selcmdctr": suspect_result[2], "httpreqctr": suspect_result[3]} logger.debug("valuedic xdebug query {}".format(valuedict)) logger.debug("query {}".format(xdebug_query)) cur.execute(xdebug_query, valuedict) xdebug_result = cur.fetchone() stream = StringIO.StringIO(zlib.decompress(xdebug_result[0])) x = xdebug.XdebugTrace(stream) cur.execute(request_query, valuedict) url_result = cur.fetchone() paqu = "/" + "/".join(url_result[0].split("/")[3:]) cur.execute(experiment_query, valuedict) experiment_result = cur.fetchone() if len(x.get_sql_queries()) == 0: raise Exception("the retrieved race suspect reference xdebug does not contain any queries") return race_suspect_short(suspect_result[0], suspect_result[1], (x, xdebug_result[1]), # I do not remember why I am doing a xtrace and paqu string pair here - legacy mb? suspect_result[4], paqu, experiment_result[0], "{}-{}".format(experiment_result[2], experiment_result[1]), experiment_result[3])
def copy_all_used_php_files(args): if exists(args.target): if args.force: rmtree(args.target) makedirs(args.target) else: raise Exception("target folder already exists") else: makedirs(args.target) with open(args.file) as file: xdebug = xdebugparser.XdebugTrace(file) for php_file in xdebug.get_all_used_source_files(): php_file = "{}/{}".format(args.source, drop_until_htdoc(php_file)) final = copy_file_with_path_structure(php_file, args.target) print "copy {} to {}".format(php_file, final)
def get_all_sql_queries_of(expid, host, user, pwd, database, logger): with psql.connect(host=host, user=user, password=pwd, database=database) as con: with con.cursor() as cur: query = """SELECT expid,selcmdctr,httpreqctr,content FROM XdebugDumpsView WHERE expid = %s ORDER BY expid, selcmdctr, httpreqctr ASC;""" cur.execute(query, (expid,)) queries = [] # logger.debug("I have currently {} queries in storage".format(len(queries))) for xdebug in cur.fetchall(): logger.info("extracting query from expid {} selcmdctr {} httpreqctr {}".format( expid, xdebug[1], xdebug[2])) try: stream = None stream = StringIO.StringIO(zlib.decompress(xdebug[3])) trace = None trace = xpar.XdebugTrace(stream) stream.close() quers = [] quers, offsets = trace.get_sql_queries(keep_all_queries=True, logger=None) logger.debug("raw queries: {}".format(quers)) counter = 0 for query, offset in zip(quers, offsets): try: time = trace._time + datetime.timedelta(seconds=float(offset)) queries.append(Query(sanitize_query(query), Request(xdebug[0], xdebug[1], xdebug[2]), counter, time)) counter += 1 except Exception as err: logger.error("related query: {}".format(sanitize_query(query))) logger.error("{}".format(err)) with open("/home/simkoc/tmp/xdebug_offender.xt", 'w') as f: f.write(zlib.decompress(xdebug[3])) logger.error( "dumped violating xdebug into ~/tmp/xdebug_offender.xt") raise finally: stream.close() return queries
def show_litmus_queries(pargs, logger=None): with db_interface.get_connection(pargs.host, pargs.user, pargs.pwd, pargs.database) as con: data = db_interface.get_xdebug_queries(con, pargs.expid) for selcmd in data: print "Queries for SELCMD " + str(selcmd[0]) + " and HTTPREQ " + str(selcmd[1]) + ":" try: stream = StringIO.StringIO(zlib.decompress(selcmd[2])) trace = Xdebug.XdebugTrace(stream) stream.close() queries = trace.get_sql_queries(keep_all_queries=True, logger=None) for element in queries: for subelement in element: if type(pargs.search_query) is str: if subelement.find(pargs.search_query) != -1: print subelement else: print subelement finally: stream.close()
def run_simple_interleaving(tc, target, firebases, root, pwd, xpath, refXdebug, refpaqu, refQuery, projname, session, user, logger, db_host, db_user, db_pwd, db_name, expid, hit_function=STRICT_CHECK): """ assumptions: 1. vm is already running 2. vm is set up with interceptor 3. interceptor is already configured 4. firebases are already started """ start_time_testing = time.time() successfull_runs = HQ_sub(tc, target, firebases, logger=logger) end_time_testing = time.time() xdebugtriples = get_xdebugs(root, target, pwd, xpath, logger=logger) refFingerprints = list() for triple in xdebugtriples: try: x = Xdebug.XdebugTrace(triple[2]) except IndexError: logger.error( "Encountered an XDEBUG that is broken dumped at {}".format( _ERROR_XDEBUG_DUMP)) with open(_ERROR_XDEBUG_DUMP, 'w') as f: f.write(zlib.decompress(triple[0]), file=f) raise fingerprint = XdebugFingerprint(x, PaQu(triple[1], logger=logger)) refFingerprints.append(fingerprint) logger.info("extracted {} xdebugs".format(len(refFingerprints))) for ref in refFingerprints: logger.debug(ref) fingerprint = XdebugFingerprint(refXdebug, PaQu(refpaqu, logger=logger)) start_time_eval = time.time() if hit_function == STRICT_CHECK: matches = count_equalp_fingerprints(fingerprint, refFingerprints, projname, session, user, db_host, db_user, db_pwd, db_name, expid, logger=logger) elif hit_function == RELAXED_CHECK: matches = count_equalp_fingerprints_relaxed(fingerprint, refQuery, refFingerprints, projname, session, user, db_host, db_user, db_pwd, db_name, expid, logger=logger) end_time_eval = time.time() return matches, xdebugtriples, successfull_runs, [ start_time_testing, end_time_testing, start_time_eval, end_time_eval ]