Example #1
0
 def testPacketMatchFail(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode10', ['stest'], TestFrameworkTests.opt_nocompile)
     self.assertIn('1 passed, 1 failed, 2 pending', xio.contents)
     self.assertRegex(xio.contents, 
         re.compile('an\s+exact\s+match\s+failed', re.M | re.I))
Example #2
0
 def testDryRun(self):
     with self.assertLogs(level='INFO') as cm:
         main_test('ucode1.py', ['stest'], TestFrameworkTests.opt_dryrun)
     self.assertIn('Imported your code successfully', cm.output[0])
     with self.assertLogs(level='INFO') as cm:
         main_test('ucode1', ['stest'], TestFrameworkTests.opt_dryrun)
     self.assertIn('Imported your code successfully', cm.output[0])
Example #3
0
 def testShutdownSignal(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode6', ['stest'],
                       TestFrameworkTests.opt_nocompile)
     self.assertIn('4 passed, 0 failed, 0 pending', xio.contents)
     self.assertIn('All tests passed', xio.contents)
Example #4
0
 def testScenarioTimeoutHandledCorrectly(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode5', ['stest'],
                       TestFrameworkTests.opt_nocompile)
     self.assertIn('4 passed, 0 failed, 0 pending', xio.contents)
     self.assertIn('All tests passed', xio.contents)
Example #5
0
 def testEmptyUserProgram(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode1', ['stest'],
                       TestFrameworkTests.opt_nocompile)
     self.assertIn('0 passed, 1 failed, 3 pending', xio.contents)
     self.assertNotIn('All tests passed', xio.contents)
Example #6
0
 def testOneRecvCall(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode2', ['stest'], TestFrameworkTests.opt_nocompile)
     self.assertIn('1 passed, 1 failed, 2 pending', xio.contents)
     self.assertRegex(xio.contents, re.compile('Passed:\s*1\s*Incoming ARP request', re.M))
     self.assertRegex(xio.contents, re.compile('Failed:\s*Outgoing ARP reply',re.M))
Example #7
0
 def testDeviceMatchFail(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode9', ['stest'], TestFrameworkTests.opt_nocompile)
     self.assertIn('1 passed, 1 failed, 2 pending', xio.contents)
     self.assertRegex(xio.contents, 
         re.compile('output\s+on\s+device\s+router-eth2\s+unexpected', re.M))
Example #8
0
 def testDryRun(self):
     with self.assertLogs(level='INFO') as cm:
         main_test('ucode1.py', ['stest'], TestFrameworkTests.opt_dryrun)
     self.assertIn('Imported your code successfully', cm.output[0])
     with self.assertLogs(level='INFO') as cm:
         main_test('ucode1', ['stest'], TestFrameworkTests.opt_dryrun)
     self.assertIn('Imported your code successfully', cm.output[0])
Example #9
0
 def testEpicFail(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode8', ['stest'], TestFrameworkTests.opt_nocompile)
     self.assertNotIn('All tests passed', xio.contents)
     self.assertIn('0 passed, 1 failed, 3 pending', xio.contents)
     self.assertRegex(xio.contents, 
         re.compile('Your\s+code\s+crashed', re.M))
Example #10
0
 def testTwoRecvCalls(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode3', ['stest'], TestFrameworkTests.opt_nocompile)
     self.assertIn('1 passed, 1 failed, 2 pending', xio.contents)
     self.assertRegex(xio.contents, re.compile('Passed:\s*1\s*Incoming ARP request', re.M))
     self.assertRegex(xio.contents, re.compile('Failed:\s*Outgoing ARP reply',re.M))
     self.assertRegex(xio.contents, re.compile('recv_packet\s+called,\s+but\s+I\s+was\s+expecting\s+send_packet', re.M))
Example #11
0
 def testTooManySends(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode7', ['stest'], TestFrameworkTests.opt_nocompile)
     self.assertIn('4 passed, 0 failed, 0 pending', xio.contents)
     self.assertRegex(xio.contents, 
         re.compile('Your\s+code\s+didn\'t\s+crash,\s+but\s+something\s+unexpected\s+happened.', re.M))
     self.assertNotIn('All tests passed', xio.contents)
Example #12
0
 def testPacketMatchFail(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode10', ['stest'],
                       TestFrameworkTests.opt_nocompile)
     self.assertIn('1 passed, 1 failed, 2 pending', xio.contents)
     self.assertRegex(
         xio.contents, re.compile('an\s+exact\s+match\s+failed',
                                  re.M | re.I))
Example #13
0
 def testEpicFail(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode8', ['stest'],
                       TestFrameworkTests.opt_nocompile)
     self.assertNotIn('All tests passed', xio.contents)
     self.assertIn('0 passed, 1 failed, 3 pending', xio.contents)
     self.assertRegex(xio.contents, re.compile('Your\s+code\s+crashed',
                                               re.M))
Example #14
0
 def testDeviceMatchFail(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode9', ['stest'],
                       TestFrameworkTests.opt_nocompile)
     self.assertIn('1 passed, 1 failed, 2 pending', xio.contents)
     self.assertRegex(
         xio.contents,
         re.compile('output\s+on\s+device\s+router-eth2\s+unexpected',
                    re.M))
Example #15
0
 def testOneRecvCall(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode2', ['stest'],
                       TestFrameworkTests.opt_nocompile)
     self.assertIn('1 passed, 1 failed, 2 pending', xio.contents)
     self.assertRegex(
         xio.contents, re.compile('Passed:\s*1\s*Incoming ARP request',
                                  re.M))
     self.assertRegex(xio.contents,
                      re.compile('Failed:\s*Outgoing ARP reply', re.M))
Example #16
0
 def testTooManySends(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode7', ['stest'],
                       TestFrameworkTests.opt_nocompile)
     self.assertIn('4 passed, 0 failed, 0 pending', xio.contents)
     self.assertRegex(
         xio.contents,
         re.compile(
             'Your\s+code\s+didn\'t\s+crash,\s+but\s+something\s+unexpected\s+happened.',
             re.M))
     self.assertNotIn('All tests passed', xio.contents)
Example #17
0
 def testTwoRecvCalls(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode3', ['stest'],
                       TestFrameworkTests.opt_nocompile)
     self.assertIn('1 passed, 1 failed, 2 pending', xio.contents)
     self.assertRegex(
         xio.contents, re.compile('Passed:\s*1\s*Incoming ARP request',
                                  re.M))
     self.assertRegex(xio.contents,
                      re.compile('Failed:\s*Outgoing ARP reply', re.M))
     self.assertRegex(
         xio.contents,
         re.compile(
             'recv_packet\s+called,\s+but\s+I\s+was\s+expecting\s+send_packet',
             re.M))
Example #18
0
 def testNoScenario(self):
     with self.assertLogs(level='ERROR') as cm:
         main_test('ucode1', [], TestFrameworkTests.opt_compile)
     self.assertIn('no scenarios', cm.output[0])
Example #19
0
 def testShutdownSignal(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode6', ['stest'], TestFrameworkTests.opt_nocompile)
     self.assertIn('4 passed, 0 failed, 0 pending', xio.contents)
     self.assertIn('All tests passed', xio.contents)
Example #20
0
 def testScenarioTimeoutHandledCorrectly(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode5', ['stest'], TestFrameworkTests.opt_nocompile)
     self.assertIn('4 passed, 0 failed, 0 pending', xio.contents)
     self.assertIn('All tests passed', xio.contents)
Example #21
0
 def testEmptyUserProgram(self):
     with redirectio() as xio:
         with self.assertLogs(level='INFO') as cm:
             main_test('ucode1', ['stest'], TestFrameworkTests.opt_nocompile)
     self.assertIn('0 passed, 1 failed, 3 pending', xio.contents)
     self.assertNotIn('All tests passed', xio.contents)
Example #22
0
 def testCompileOutput(self):
     with self.assertLogs(level='INFO') as cm:
         main_test('ucode1', ['stest'], TestFrameworkTests.opt_compile)
     self.assertIn('Compiling', cm.output[0])
     self.assertIsNotNone(os.stat('stest.srpy'))
Example #23
0
 def testNoScenario(self):
     with self.assertLogs(level='ERROR') as cm:
         main_test('ucode1', [], TestFrameworkTests.opt_compile)
     self.assertIn('no scenarios', cm.output[0])
Example #24
0
        sys.exit()

    waiters = 1
    if args.app:
        waiters = 2
    barrier = Barrier(waiters)

    if args.app:
        ApplicationLayer.init()
        _appt = Thread(target=start_app, args=(args.app,barrier))
        _appt.start()

    if args.testmode:
        if args.usercode and args.compile:
            log_info("You specified user code to run with compile flag, but I'm just doing compile.")
        main_test(args.usercode, args.scenario, args)
    else:
        if sys.platform != 'win32' and os.geteuid() != 0:
            log_warn("You're running in real mode, but not as root.  "
                "You should expect errors, but I'm going to "
                "continue anyway.")
        if args.exclude is None:
            args.exclude = []
        if args.intf is None:
            args.intf = []

        if args.app:
            args.fwconfig = []
        elif args.fwconfig is None:
            args.fwconfig = ('all',)
Example #25
0
 def testCompileOutput(self):
     with self.assertLogs(level='INFO') as cm:
         main_test('ucode1', ['stest'], TestFrameworkTests.opt_compile)
     self.assertIn('Compiling', cm.output[0])
     self.assertIsNotNone(os.stat('stest.srpy'))