From ff43615ab17b4747052de6d6237783fb9903d271 Mon Sep 17 00:00:00 2001 From: Brandon Heller <brandonh@stanford.edu> Date: Fri, 18 Dec 2009 01:59:41 -0800 Subject: [PATCH] Add example unit tests and Makefile target --- Makefile | 5 ++++- mininet/mininet.py | 2 ++ mininet/test/test_nets.py | 42 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 mininet/test/test_nets.py diff --git a/Makefile b/Makefile index 82a5d374..829736b1 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,5 @@ clean: - rm -rf build dist build *.egg-info *.pyc \ No newline at end of file + rm -rf build dist build *.egg-info *.pyc + +test: mininet/*.py mininet/test/*.py + mininet/test/test_nets.py \ No newline at end of file diff --git a/mininet/mininet.py b/mininet/mininet.py index f46b8259..b0d8baa7 100755 --- a/mininet/mininet.py +++ b/mininet/mininet.py @@ -73,6 +73,8 @@ flush = sys.stdout.flush from resource import setrlimit, RLIMIT_NPROC, RLIMIT_NOFILE +DATAPATHS = ['user', 'kernel'] + # Utility routines to make it easier to run commands def run( cmd ): diff --git a/mininet/test/test_nets.py b/mininet/test/test_nets.py new file mode 100755 index 00000000..87dca058 --- /dev/null +++ b/mininet/test/test_nets.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +'''@package mininet + +Test creation and all-pairs ping for each included mininet topo type. +''' + +from time import sleep +import unittest + +from mininet.mininet import init, TreeNet, pingTest, DATAPATHS + +class testMinimal(unittest.TestCase): + '''For each datapath type, test ping with a minimal topology. + + Each topology has two hosts and one switch. + ''' + + def testMinimal(self): + '''Ping test with user-space datapath on minimal topology''' + init() + for datapath in DATAPATHS: + k = datapath == 'kernel' + network = TreeNet(depth = 1, fanout = 2, kernel = k) + dropped = network.run(pingTest) + self.assertEqual(dropped, 0) + + +class testTree(unittest.TestCase): + '''For each datapath type, test all-pairs ping with TreeNet.''' + + def testTree16(self): + '''Ping test with user-space datapath on minimal topology''' + init() + for datapath in DATAPATHS: + k = datapath == 'kernel' + network = TreeNet(depth = 2, fanout = 4, kernel = k) + dropped = network.run(pingTest) + self.assertEqual(dropped, 0) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file -- GitLab