summaryrefslogtreecommitdiff
path: root/maximus/python/test
diff options
context:
space:
mode:
authorburet2007-11-30 16:34:27 +0000
committerburet2007-11-30 16:34:27 +0000
commit211781985a3a98d028900ec6504c8dd626d945a3 (patch)
treea7a1aa6047e3fab5a8517f5f83c6a320c8de7cda /maximus/python/test
parentcc1ff1a4e14b7779d9cc90f4260d0335be32d5d2 (diff)
Maximus V2: development of the first step of the MACFrame reception feature.
- implement the Python 'MACFrame.sendnrecv' function - implement the Python general 'recv' function - update C++ code - update Pyhton and C++ unitary tests - write a system TX/RX test - still some work to have a more user-friendly interface... git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1079 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'maximus/python/test')
-rw-r--r--maximus/python/test/test_interface.py67
-rw-r--r--maximus/python/test/test_macframe.py44
-rw-r--r--maximus/python/test/test_simu.py91
3 files changed, 146 insertions, 56 deletions
diff --git a/maximus/python/test/test_interface.py b/maximus/python/test/test_interface.py
index ca746eb20b..491039a18d 100644
--- a/maximus/python/test/test_interface.py
+++ b/maximus/python/test/test_interface.py
@@ -6,6 +6,7 @@ import startup
import interface
from interface import *
+from maximus.macframe import *
from string import *
from struct import *
@@ -23,7 +24,7 @@ import unittest
m = Maximus()
# Initialize Maximus with command line arguments
-argv = ['test_interface.py', '-e', '/home/buret/workspace/maximus/maximus/stationtest/obj/stationtest.elf']
+argv = ['test_interface.py', '-e', '/home/buret/workspace/maximus/maximus/stationtest/obj/stationtest.elf', '-l', '0']
m.init(argv)
def cb1(msg):
@@ -92,58 +93,42 @@ class TestInterfaceFunctions(unittest.TestCase):
# Create a probe message
probe = self.m.create_probe()
-
- def test_send_phy(self):
-
- # Define an empty MPDU structure for Maximus
- class MPDU:
- pass
+
+ def test_send_macframe(self):
fcall1 = self.m.create_fcall('set_tonemask')
fcall1.send(self.station)
fcall2 = self.m.create_fcall('prepare_rx')
fcall2.send(self.station)
- # Create an MPDU, configure it and send it synchronously
- mpdu = MPDU()
- mpdu.fc_10 = 123
- mpdu.fc_av = 1, 123, 456, 789
- mpdu.payload = 'This is the MPDU payload'
- mpdu.fc_mode = 4
- mpdu.short_ppdu = 0
- mpdu.mod = 4
- self.m.send_phy(mpdu)
-
- def test_send_phy_async(self):
-
- # Define an empty MPDU structure for Maximus
- class MPDU:
+ # Create a MAC Frame, configure it and send it asynchronously
+ frame = macframe.MACFrame()
+ frame.mpdu.fc_10 = 123
+ frame.mpdu.fc_av = 1, 123, 456, 789
+ frame.mpdu.payload = 'This is the MPDU payload'
+ frame.mpdu.fc_mode = 4
+ frame.mpdu.short_ppdu = 0
+ frame.mpdu.mod = 4
+ self.m.send_macframe(frame)
+
+ def test_set_macframe_rx(self):
+ def cb(macframe):
pass
+ def create_fc():
+ pass
+ self.m.set_macframe_rx(cb, create_fc)
- fcall1 = self.m.create_fcall('set_tonemask')
- fcall1.send(self.station)
- fcall2 = self.m.create_fcall('prepare_rx')
- fcall2.send(self.station)
-
- # Create an MPDU, configure it and send it synchronously
- mpdu = MPDU()
- mpdu.fc_10 = 123
- mpdu.fc_av = 1, 123, 456, 789
- mpdu.payload = 'This is the MPDU payload'
- mpdu.fc_mode = 4
- mpdu.short_ppdu = 0
- mpdu.mod = 4
- self.m.send_phy_async(mpdu)
-
- def test_send_ether(self):
+ def test_send_msdu(self):
class MSDU:
pass
- self.m.send_ether(MSDU())
+ self.m.send_msdu(MSDU())
- def test_send_ether_async(self):
- class MSDU:
+ def test_set_msdu_rx(self):
+ def cb(macframe):
+ pass
+ def create_fc():
pass
- self.m.send_ether_async(MSDU())
+ self.m.set_macframe_rx(cb, create_fc)
def test_wait(self):
self.m.wait()
diff --git a/maximus/python/test/test_macframe.py b/maximus/python/test/test_macframe.py
index 39da1f8abe..b27f2a85e1 100644
--- a/maximus/python/test/test_macframe.py
+++ b/maximus/python/test/test_macframe.py
@@ -9,15 +9,16 @@ from maximus.mme import *
from interface import *
from struct import *
+
+# MPDU TEST
+
# Create a Maximus instance
m = Maximus()
# Initialize Maximus with command line arguments
-argv = ['test_macframe.py', '-e', '/home/buret/workspace/maximus/maximus/stationtest/obj/stationtest.elf']
+argv = ['test_macframe.py', '-e', '/home/buret/workspace/maximus/maximus/stationtest/obj/stationtest.elf', '-l', '0']
m.init(argv)
-# MPDU TEST
-
# Create a MAC Frame
macFrame1 = macframe.MACFrame(FC_10 = fc_10.FC_10(), FC_AV = fc_av.FC_AV())
@@ -49,15 +50,10 @@ fcall2 = m.create_fcall('prepare_rx')
fcall2.send(station)
rsp = macFrame4.sendnrecv(m)
-macFrame4.add(mme.MME())
-
# Send the MAC Frame asynchronously
fcall2.send(station)
macFrame4.send(m)
-# Receive a MAC Frame
-macFrame1.recv()
-
# Create a MAC Frame containing an MME
macFrame5 = macframe.MACFrame(msdu=mme.MME())
fcall2.send(station)
@@ -187,7 +183,19 @@ class TestMACFrameFunctions(unittest.TestCase):
def setUp(self):
print "setUp"
+
self.macframe = macframe.MACFrame()
+ self.assertNotEqual(self.macframe.mpdu, None)
+ self.assertEqual(self.macframe.get_fc_10(), None)
+ self.assertNotEqual(self.macframe.get_fc_av(), None)
+ self.assertNotEqual(self.macframe.get_macframeheader(), None)
+ self.assertEqual(self.macframe.get_ats(), None)
+ self.assertEqual(self.macframe.get_confounder(), None)
+ self.assertEqual(self.macframe.get_icv(), None)
+ self.assertEqual(self.macframe.get_msdu(), None)
+ self.assertEqual(self.macframe.get_iv(), 3*4*'0')
+ self.assertEqual(self.macframe.get_nek(), 4*4*'0')
+
self.m = m
self.sta = self.m.create_sta()
fcall = self.m.create_fcall('set_tonemask')
@@ -225,6 +233,11 @@ class TestMACFrameFunctions(unittest.TestCase):
self.macframe.set_fc_av(fcav)
self.assertEqual(self.macframe.get_fc_av(),fcav)
self.assertEqual(self.macframe.mpdu.fc_av,unpack('IIII',fcav))
+ # Test with a tuple of 4 Python longs
+ fcav = (0, 1, 2, 3)
+ self.macframe.set_fc_av(fcav)
+ self.assertEqual(self.macframe.get_fc_av(),fcav)
+ self.assertEqual(self.macframe.mpdu.fc_av,fcav)
def test_set_macframeheader(self):
# Test with a MAC Frame Header object
@@ -303,6 +316,17 @@ class TestMACFrameFunctions(unittest.TestCase):
self.macframe.set_nek(nek)
self.assertEqual(self.macframe.get_nek(),nek)
+ def test_set_macframe_attr(self):
+ fc10 = 10
+ fcav = (0, 1, 2, 3)
+ payload = 'ABCDEFGHIJKL'
+ self.macframe.set_macframe_attr(fc10, fcav, payload)
+ self.assertEqual(self.macframe.get_fc_10(), fc10)
+ self.assertEqual(self.macframe.get_fc_av(), fcav)
+ self.assertEqual(self.macframe.get_macframeheader(), 'AB')
+ self.assertEqual(self.macframe.get_msdu(), 'CDEFGH')
+ self.assertEqual(self.macframe.get_icv(), 'IJKL')
+
def test_sendnrecv(self):
rx1 = self.m.create_fcall('prepare_rx')
rx1.send(self.sta)
@@ -319,8 +343,8 @@ class TestMACFrameFunctions(unittest.TestCase):
self.macframe.set_msdu('This is the MPDU payload')
self.macframe.send(self.m)
- def test_recv(self):
- self.macframe.recv()
+ def test_create_macframe(self):
+ self.assertNotEqual(create.create_macframe(), None)
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestMACFrameFunctions))
diff --git a/maximus/python/test/test_simu.py b/maximus/python/test/test_simu.py
index 8377829964..f17a0d42c4 100644
--- a/maximus/python/test/test_simu.py
+++ b/maximus/python/test/test_simu.py
@@ -5,22 +5,32 @@ print __name__
import startup
from maximus.simu import *
+from interface import *
# SIMU TEST
+# Create a Maximus instance
+m = Maximus()
+
+# Initialize Maximus with command line arguments
+argv = ['test_simu.py', '-e', '/home/buret/workspace/maximus/maximus/stationtest/obj/stationtest.elf', '-l', '0']
+m.init(argv)
+
# Transmission
rsp = send.sendnrecv(file='data', timeout=5000)
send.send(file='data')
+# Define a filter function
+def my_filter(rx_macframe):
+ print "=> my_filter"
+ return True
+
# Reception
-rsp = receive.recv(filter=filter.Filter('type RSP'), count=2, timeout=10000)
+rsp = receive.recv(maximus=m, timeout=10000, filter=my_filter, count=0)
#rsp1 = rsp[1]
#rsp2 = rsp[2]
-# Define a filter
-my_filter=filter.Filter('name CC_ACCESS_NEW and type RSP')
-
# Get the current date
t = date.get_date()
@@ -37,7 +47,76 @@ doctest.testmod(send)
# UNIT TEST
import unittest
-suite = unittest.TestSuite()
+
+class TestRxFunctions(unittest.TestCase):
+
+ def setUp(self):
+ print "setUp"
+ self.rx = receive.Rx(m)
+
+ def tearDown(self):
+ print "tearDown"
+
+ def test_init(self):
+ rx = receive.Rx(maximus=m, filter_fc=my_filter)
+
+ def test_cb(self):
+ rx = receive.Rx(maximus=m, filter_fc=my_filter, counter=1)
+ class MACFrame:
+ pass
+ macframe = MACFrame()
+ rx.cb(macframe)
+
+ def test_recv(self):
+ rx = receive.Rx(maximus=m, filter_fc=my_filter, counter=2)
+ class MACFrame:
+ pass
+ macframe1 = MACFrame()
+ macframe2 = MACFrame()
+ rx.cb(macframe1)
+ rx.cb(macframe2)
+ self.assertEqual(rx.recv(), [macframe1, macframe2])
+
+ def test_add_frame(self):
+ class MACFrame:
+ pass
+ macframe1 = MACFrame()
+ macframe2 = MACFrame()
+ self.rx.add_frame(macframe1)
+ self.assertEqual(len(self.rx.get_frame_list()), 1)
+ self.assertEqual(self.rx.get_frame_list()[0], macframe1)
+ self.rx.add_frame(macframe2)
+ self.assertEqual(len(self.rx.get_frame_list()), 2)
+ self.assertEqual(self.rx.get_frame_list()[0], macframe1)
+ self.assertEqual(self.rx.get_frame_list()[1], macframe2)
+
+ def test_set_counter(self):
+ counter = 10
+ self.rx.set_counter(counter)
+ self.assertEqual(self.rx.get_counter(), counter)
+
+ def test_decr_counter(self):
+ self.rx.decr_counter()
+ self.assertEqual(self.rx.get_counter(), 0)
+ counter = 10
+ self.rx.set_counter(counter)
+ self.rx.decr_counter()
+ self.assertEqual(self.rx.get_counter(), counter-1)
+
+ def test_call_filter_fc(self):
+ def filter_fc(macframe):
+ print "=> filter_fc"
+ self.rx.set_filter_fc(filter_fc)
+ class MACFrame:
+ pass
+ macframe = MACFrame()
+ self.rx.call_filter_fc(macframe)
+
+ def test_recv(self):
+ self.assertEqual(receive.recv(maximus=m, timeout=None, filter=None, count=0), None)
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestRxFunctions)
+
try:
suite.addTest(doctest.DocTestSuite(date))
suite.addTest(doctest.DocTestSuite(filter))
@@ -46,3 +125,5 @@ try:
except ValueError:
print "has no tests"
+if __name__ == '__main__':
+ testResult = unittest.TextTestRunner(verbosity=2).run(suite)