summaryrefslogtreecommitdiff
path: root/cesar/maximus/python/test/test_channel.py
blob: cc8a23d3948a97d6cad17a70f2c54a0c8d4971ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! usr/bin/env python

print "\n*** " + __file__ + " ***\n"

import sys, startup

from maximus.channel import *
from maximus.station import *
from interface import *


# CHANNEL TEST

# Create a Maximus instance
m = Maximus()

# Initialize Maximus with command line arguments
m.init(sys.argv)

# Enable channel perturbation
m.disturb_channel()

# Create an SNR description file
f = open('test/channel_settings.txt', 'w+')
for i in range(0, 7):
	f.write(str((i+1)*5000) + "\t")
f.write("# End times (in ticks) of each interval of the beacon period\n")
for i in range (0, 1155):
	f.write(str(i+1+0.1) + "\t" + str(i+1+0.2) + "\t" + str(i+1+0.3) + "\t" + str(i+1+0.4) + "\t" + str(i+1+0.5) + "\t" + str(i+1+0.6) + "\t" + str(i+1+0.7) + "\t" + str(i+1+0.8) + "\t" + "# SNR values (in dB) for carrier number " + str(i+1) + "\n")
f.close()

# Set the SNR
staA = STA(m)
staB = STA(m)
set_snr(m, value=15)
set_snr(m, file='test/channel_settings.txt')
set_snr(m, value=10, src=staA)
set_snr(m, file='test/channel_settings.txt', src=staA)
set_snr(m, value=12, dst=staB)
set_snr(m, file='test/channel_settings.txt', dst=staB)
set_snr(m, value=12, src=staA, dst=staB)
set_snr(m, file='test/channel_settings.txt', src=staA, dst=staB)
staC = STA(m)
set_snr(m, value=10, src=staA)
set_snr(m, file='test/channel_settings.txt', src=staC, both_directions=True)
set_snr(m, value=12, dst=staC)
set_snr(m, file='test/channel_settings.txt', dst=staC, both_directions=True)
set_snr(m, value=12, src=staA, dst=staC, both_directions=True)
set_snr(m, file='test/channel_settings.txt', src=staA, dst=staC, both_directions=True)
staD = m.create_sta()
set_snr(m, value=12, src=staD)

# Remove stations
m.create_fcall("uninit_ether").send(staA.get())
staA.remove()
m.create_fcall("uninit_ether").send(staB.get())
staB.remove()
m.create_fcall("uninit_ether").send(staC.get())
staC.remove()
m.create_fcall("uninit_ether").send(staD)
staD.remove()


# DOC TEST

import doctest
doctest.testmod(snr)


# UNIT TEST

import unittest
suite = unittest.TestSuite()
try:
	suite.addTest(doctest.DocTestSuite(snr))
except ValueError:
	print "has no tests"

if __name__ == '__main__':
	testResult = unittest.TextTestRunner(verbosity=2).run(suite)