def setUp(self): self._report = CCReportHelper('localhost', int(os.environ['CC_TEST_SERVER_PORT']), '/')
def main(): # handle argument parsing parseArgs() #--- main part ------------------------------------------------------------- reportTimeList = [] getTimeList = [] with CCReportHelper(args.address, args.check_port) as ccReporter, \ CCViewerHelper(args.address, args.view_port, '/') as ccViewer, \ open(args.output, 'r+') as outFile: outFile.truncate() for runCount in range(runNumber): before = datetime.datetime.now() run_id = ccReporter.addCheckerRun( 'command', 'name_' + str(runCount) + '_' + str(uuid4()), 'version', False) report_ids = [] for fileCount in range(fileNumber): print('\nrun: ' + str(runCount + 1) + '/' + str(runNumber) + '\nfile: ' + str(fileCount + 1) + '/' + str(fileNumber)) file_id = ccReporter.needFileContent(run_id, 'file_' + str(fileCount)).fileId ccReporter.addFileContent(file_id, fileContent) build_action_id = ccReporter.addBuildAction( run_id, 'build_cmd_' + str(fileCount), 'check_cmd_' + str(fileCount), 'target_' + str(fileCount)) ccReporter.finishBuildAction(build_action_id, '') for bugCount in range(bugPerFile): bug_pathes = [] bug_events = [] for bugElementCount in range(bugLength): line = bugCount * bugLength + bugElementCount + 1 bug_pathes.append( BugPathPos(line, 1, line, 10, file_id)) bug_events.append( BugPathEvent(line, 1, line, 10, 'event_msg', file_id)) report_id = ccReporter.addReport( build_action_id, file_id, 'hash_' + str(run_id) + '_' + str(fileCount) + '_' + str(bugCount), 1, 'checker_message', bug_pathes, bug_events, 'checker_name', 'checker_cat', 'bug_type', 1) report_ids.append(report_id) #ccReporter.moduleToReport(run_id, 'module_id', report_ids) ccReporter.finishCheckerRun(run_id) after = datetime.datetime.now() time = (after - before).total_seconds() reportTimeList.append(time) before = datetime.datetime.now() runIDs = [rundata.runId for rundata in ccViewer.getRunData()] after = datetime.datetime.now() time = (after - before).total_seconds() getTimeList.append(time) before = datetime.datetime.now() res = ccViewer.getAllRunResults(runIDs[-1]) after = datetime.datetime.now() time = (after - before).total_seconds() getTimeList.append(time) before = datetime.datetime.now() reportData = ccViewer.getReportDetails(res[-1].reportId) after = datetime.datetime.now() time = (after - before).total_seconds() getTimeList.append(time) s = str(runCount) + ';' + str(reportTimeList[-1]) + ';' + str( getTimeList[-3]) + ';' + str(getTimeList[-2]) + ';' + str( getTimeList[-1]) print(s) outFile.write(s + '\n')
class HashClash(unittest.TestCase): """Unit test for testing hash clash handling.""" def _create_run(self, name): """Creates a new run using an unique id.""" return self._report.addCheckerRun(name, name + str(uuid4()), 'v', False) def _create_file(self, run_id, name, cols=10, lines=10): """Creates a new file with random content.""" path = name + "_" + str(uuid4()) need = self._report.needFileContent(run_id, path) self.assertTrue(need.needed) content = _generate_content(cols, lines) success = self._report.addFileContent(need.fileId, content) self.assertTrue(success) return need.fileId def _create_build_action(self, run_id, name): """Creates a new build action.""" return self._report.addBuildAction(run_id, name, name) def _create_simple_report(self, file_id, build_action_id, bug_hash, position): """Creates a new report with one bug path position and event.""" bug_path = [BugPathPos(position[0][0], position[0][1], position[1][0], position[1][1], file_id)] bug_evt = [BugPathEvent(position[0][0], position[0][1], position[1][0], position[1][1], 'evt', file_id)] return self._report.addReport(build_action_id, file_id, bug_hash, 'test', bug_path, bug_evt, 'test_id', 'test_cat', 'test_type', Severity.UNSPECIFIED, False) @contextmanager def _init_new_test(self, name): """Creates a new run, file, and build action. Use it in a 'with' statement. At the end of the 'with' statement it calls the finish methods for the run and the build action. Example: with self._init_new_test('test') as ids: # do stuff """ run_id = self._create_run(name) file_id = self._create_file(run_id, name) build_action_id = self._create_build_action(run_id, name) yield (run_id, file_id, build_action_id) self._report.finishBuildAction(build_action_id, 'OK') self._report.finishCheckerRun(run_id) def setUp(self): self._report = CCReportHelper('localhost', int(os.environ['CC_TEST_SERVER_PORT']), '/') def test(self): """Runs the following tests: - Duplicates. - Hash clash in same file. - Hash clash in different files. - Hash clash in different build actions. """ with self._init_new_test('test1') as ids1, \ self._init_new_test('test2') as ids2: _, file_id1, build_action_id1 = ids1 run_id2, file_id2, build_action_id2 = ids2 rep_id1 = self._create_simple_report(file_id1, build_action_id1, 'XXX', ((1, 1), (1, 2))) rep_id2 = self._create_simple_report(file_id1, build_action_id1, 'XXX', ((1, 1), (1, 2))) # Same file, same hash and position self.assertEqual(rep_id1, rep_id2) rep_id3 = self._create_simple_report(file_id1, build_action_id1, 'XXX', ((2, 1), (2, 2))) # Same file, same hash and different position self.assertNotEqual(rep_id1, rep_id3) rep_id4 = self._create_simple_report(file_id2, build_action_id2, 'XXX', ((1, 1), (1, 2))) rep_id5 = self._create_simple_report(file_id2, build_action_id2, 'YYY', ((1, 1), (1, 2))) # Different file, same hash, and position self.assertNotEqual(rep_id1, rep_id4) # Different file, same hash and different position self.assertNotEqual(rep_id3, rep_id4) # Same file and position, different hash self.assertNotEqual(rep_id4, rep_id5) build_action_id2_2 = self._create_build_action(run_id2, 'test2_2') try: rep_id6 = self._create_simple_report(file_id2, build_action_id2_2, 'XXX', ((1, 1), (1, 2))) # Same run, file, hash, and position, but different build action self.assertEqual(rep_id4, rep_id6) finally: self._report.finishBuildAction(build_action_id2_2, 'OK') rep_id7 = self._create_simple_report(file_id1, build_action_id2, 'XXX', ((1, 1), (1, 2))) # build_action_id1 and build_action_id2 is in different runs self.assertNotEqual(rep_id1, rep_id7)