Ejemplo n.º 1
0
 def test_load_test_and_options(self):
     input_unit = InputUnit([0,1,2,3,4])
     cmd_line_options = {}
     test_cases, options = loadTestsAndOptions([DummyTestCase],
             cmd_line_options)
     self.assertEqual(test_cases[0][1], 'test_b')
     self.assertEqual(test_cases[1][1], 'test_a')
Ejemplo n.º 2
0
    def test_with_post_processing(self):
        def done(result):
            report = oreporter.dummy_report
            self.assertEqual(len(report), 6)
            for entry in report:
                if entry['test_name'] == 'summary':
                    self.assertEqual(entry['report'], {'antani': 'sblinda'})

        input_unit = InputUnit([None])
        cmd_line_options = {'collector': None}

        oreporter = DummyReporter(cmd_line_options)
        oreporter.dummy_report = []

        test_cases, options = loadTestsAndOptions([DummyTestCasePP],
                cmd_line_options)

        d = runTestCasesWithInputUnit(test_cases, input_unit, oreporter, oreporter)
        d.addBoth(done)
        return d
Ejemplo n.º 3
0
    def test_run_testcase_with_input_unit(self):
        def done(result):
            report = oreporter.dummy_report
            self.assertEqual(len(report), 10*2)
            # XXX debug why this is failing
            # for idx, entry in enumerate(oreporter.dummy_report):
            #     if idx % 2 == 0:
            #         self.assertEqual(entry['report']['foo'], 'foo')
            #     else:
            #         self.assertEqual(entry['report']['bar'], 'bar')

        input_unit = InputUnit([0,1,2,3,4])
        cmd_line_options = {'collector': None}

        oreporter = DummyReporter(cmd_line_options)
        oreporter.dummy_report = []

        test_cases, options = loadTestsAndOptions([DummyTestCase],
                cmd_line_options)

        d = runTestCasesWithInputUnit(test_cases, input_unit, oreporter, oreporter)
        d.addBoth(done)
        return d
Ejemplo n.º 4
0
    if cmd_line_options['reportfile']:
        yamloo_filename = cmd_line_options['reportfile']
        pcap_filename = yamloo_filename + ".pcap"

    if os.path.exists(yamloo_filename):
        print "Report already exists with filename %s" % yamloo_filename
        print "Renaming it to %s" % yamloo_filename + '.old'
        os.rename(yamloo_filename, yamloo_filename + '.old')
    if os.path.exists(pcap_filename):
        print "Report PCAP already exists with filename %s" % pcap_filename
        print "Renaming it to %s" % pcap_filename + '.old'
        os.rename(pcap_filename, pcap_filename + '.old')

    classes = runner.findTestClassesFromConfig(cmd_line_options)
    test_cases, options = runner.loadTestsAndOptions(classes, cmd_line_options)
    if config.privacy.includepcap:
        try:
            checkForRoot()
        except NotRootError:
            print "[!] Includepcap options requires root priviledges to run"
            print "    you should run ooniprobe as root or disable the options in ooniprobe.conf"
            sys.exit(1)
        print "Starting sniffer"
        net.capturePackets(pcap_filename)

    log.start(cmd_line_options['logfile'])

    tests_d = runner.runTestCases(test_cases, options, cmd_line_options,
                                  yamloo_filename)
    tests_d.addBoth(testsEnded)
Ejemplo n.º 5
0
    if cmd_line_options['reportfile']:
        yamloo_filename = cmd_line_options['reportfile']
        pcap_filename = yamloo_filename+".pcap"

    if os.path.exists(yamloo_filename):
        log.msg("Report already exists with filename %s" % yamloo_filename)
        log.msg("Renaming it to %s" % yamloo_filename+'.old')
        os.rename(yamloo_filename, yamloo_filename+'.old')
    if os.path.exists(pcap_filename):
        log.msg("Report already exists with filename %s" % pcap_filename)
        log.msg("Renaming it to %s" % pcap_filename+'.old')
        os.rename(pcap_filename, pcap_filename+'.old')

    log.start(cmd_line_options['logfile'])
    classes = runner.findTestClassesFromConfig(cmd_line_options)
    test_cases, options = runner.loadTestsAndOptions(classes, cmd_line_options)
    if config.privacy.includepcap:
        try:
            checkForRoot()
        except NotRootError:
            log.err("includepcap options requires root priviledges to run")
            log.err("you should run ooniprobe as root or disable the options in ooniprobe.conf")
            sys.exit(1)
        log.debug("Starting sniffer")
        sniffer_d = net.capturePackets(pcap_filename)

    tests_d = runner.runTestCases(test_cases, options,
            cmd_line_options, yamloo_filename)
    tests_d.addBoth(testsEnded)

    reactor.run()
Ejemplo n.º 6
0
            self["test"] = args[0]

            self["subArgs"] = args[1:]
        except:
            raise usage.UsageError("No test filename specified!")

    def postOptions(self):
        self["reporter"] = reporter.OONIReporter


def run():
    log.start()

    if len(sys.argv) == 1:
        sys.argv.append("--help")
    config = Options()
    try:
        config.parseOptions()
    except usage.error, ue:
        raise SystemExit, "%s: %s" % (sys.argv[0], ue)

    if config["debug-stacktraces"]:
        defer.setDebugging(True)

    classes = runner.findTestClassesFromConfig(config)
    casesList, options = runner.loadTestsAndOptions(classes, config)

    for idx, cases in enumerate(casesList):
        orunner = runner.ORunner(cases, options[idx], config)
        orunner.run()