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))
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])
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)
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)
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)
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))
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))
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))
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))
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)
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))
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))
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))
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)
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))
def testNoScenario(self): with self.assertLogs(level='ERROR') as cm: main_test('ucode1', [], TestFrameworkTests.opt_compile) self.assertIn('no scenarios', cm.output[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'))
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',)