summaryrefslogtreecommitdiff
path: root/validation/test/test_spc300.py
blob: 18f1e62f3026a962a71fe2bd2e56c6627d54fc4a (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# -*- coding: utf-8 -*-

import random
import validlib.power_strip as power_strip
import validlib.link as link
import validlib.spc300 as spc300
from validlib.spc300 import role, r_ping

def test():
    print
    print "Executing", __file__, "..."

#    The OK or NOK in the comments below refer to the results obtained with av-1.2.1

#    test_shape()
#    test_kill()
#    test_split()
#    test_merge()
#    test_split_merge()
#    test_coexist()

def test_shape():
    test_shape_an_avln_cco_3_sta() # OK, except that everybody is UCCO

def test_kill():
    test_kill_cco_in_cco_2_sta() # OK, but the roles are not checked

def test_split():
    test_split_cco_1_sta_in_2_avlns_ucco() # OK, but the roles are not checked
    test_split_cco_3_sta_in_2_avlns_cco_1_sta() # (#2869) NOK, it happens that avln_2 cannot be shaped 

def test_merge():
    test_merge_ucco_with_ucco() # OK, but the roles are not checked
    test_merge_cco_1_sta_with_ucco_scenario_1() # OK, but the roles are not checked
    test_merge_cco_1_sta_with_ucco_scenario_2() # (#2535) NOK, it happens that avln_1 cannot be shaped
    test_merge_cco_1_sta_with_cco_1_sta() # (#2243) NOK, the final AVLN can never be shaped

def test_split_merge():
    test_replace_cco_in_cco_1_sta() # OK, but the roles are not checked
    test_split_merge_split_cco_3_sta_in_2_avlns_cco_1_sta() # (#2543) To be done, when the split will work

def test_coexist():
    test_coexist_cco_1_sta_with_cco_1_sta_scenario_1() # (#2713) NOK
    test_coexist_cco_1_sta_with_cco_1_sta_scenario_2() # (#2713) NOK

def test_shape_an_avln_cco_3_sta():
    setup("attach")
    title("Test shape an AVLN CCO + 3 STA...")
    avln = [(1, 1), (1, 2), (2, 1), (2, 2)]
    change_nmk(avln)
    switch_on(avln)
    check_networks(avln, [])

def test_kill_cco_in_cco_2_sta():
    setup("attach")
    title("Test kill CCO in CCO + 2 STA...")
    avln = [(1, 1), (1, 2), (2, 1)]
    switch_on(avln)
    check_networks(avln, [])
    power_strip.switch("off", (1, 1))
    check_networks([(1, 2), (2, 1)], [])

def test_split_cco_1_sta_in_2_avlns_ucco():
    setup("attach")
    title("Test split CCO + 1 STA in 2 AVLNs UCCOs...")
    avln = [(1, 1), (2, 1)]
    switch_on(avln)
    check_networks(avln, [])
    link.detach(1)
    check_networks([(1, 1)], [(2, 1)])

def test_split_cco_3_sta_in_2_avlns_cco_1_sta():
    setup("attach")
    title("Test split CCO + 3 STA in 2 AVLNs CCO + 1 STA...")
    avln = [(1, 1), (1, 2), (2, 1), (2, 2)]
    switch_on(avln)
    check_networks(avln, [])
    link.detach(1)
    check_networks([(1, 1), (1, 2)], [(2, 1), (2, 2)])

def test_merge_ucco_with_ucco():
    setup("detach")
    title("Test merge UCCO with UCCO...")
    switch_on([(1, 1), (2, 1)])
    check_networks([(1, 1)], [(2, 1)])
    link.attach(1)
    check_networks([(1, 1), (2, 1)], [])

def test_merge_cco_1_sta_with_ucco_scenario_1():
    setup("detach")
    title("Test merge CCO + 1 STA with UCCO...")
    switch_on([(1, 1), (1, 2)])
    check_networks([(1, 1), (1, 2)], [])
    switch_on((2, 1))
    check_networks([(1, 1), (1, 2)], [(2, 1)])
    link.attach(1)
    check_networks([(1, 1), (1, 2), (2, 1)], [])

def test_merge_cco_1_sta_with_ucco_scenario_2():
    setup("detach")
    title("Test merge CCO + 1 STA with UCCO...")
    switch_on([(1, 1), (2, 1)])
    check_networks([(1, 1)], [(2, 1)])
    switch_on((1, 2))
    check_networks([(1, 1), (1, 2)], [(2, 1)])
    link.attach(1)
    check_networks([(1, 1), (1, 2), (2, 1)], [])

def test_merge_cco_1_sta_with_cco_1_sta():
    setup("detach")
    title("Test merge CCO + 1 STA with CCO + 1 STA...")
    avln_1 = [(1, 1), (1, 2)]
    avln_2 = [(2, 1), (2, 2)]
    switch_on(avln_1 + avln_2)
    check_networks(avln_1, avln_2)
    link.attach(1)
    check_networks(avln_1 + avln_2, [])

def test_replace_cco_in_cco_1_sta():
    setup("attach")
    title("Test replace CCO in CCO + 1 STA...")
    switch_on([(1, 1), (1, 2)])
    check_networks([(1, 1), (1, 2)], [])
    power_strip.switch("off", (1, 1))
    switch_on((2, 1))
    check_networks([(1, 2), (2, 1)], [])

def test_coexist_cco_1_sta_with_cco_1_sta_scenario_1():
   setup("detach")
   title("Test coexistence of 2 (CCO + 1 STA) with a different NMK...")
   avln_1 = [(1, 1), (1, 2)]
   avln_2 = [(2, 1), (2, 2)]
   change_nmk(avln_1)
   switch_on(avln_1 + avln_2)
   check_networks(avln_1, avln_2)
   link.attach(1)
   check_networks(avln_1, avln_2)

def test_coexist_cco_1_sta_with_cco_1_sta_scenario_2():
    setup("attach")
    title("Test coexistence of 2 (CCO + 1 STA) with a different NMK...")
    avln_1 = [(1, 1), (1, 2)]
    avln_2 = [(2, 1), (2, 2)]
    change_nmk(avln_1)
    switch_on(avln_1 + avln_2)
    check_networks(avln_1, avln_2)

def setup(action):
    title("Initialize the test bench...")
    power_strip.switch_off_all()
    if action == "detach": link.detach(1)
    if action == "attach": link.attach(1)

def get_cco(avln):
    for key in avln:
        if role(key) == "CCO": return key
    assert false

def title(String):
    print "+++++++++++++++++++++++++++"
    print "+", String
    print "+++++++++++++++++++++++++++"    
    
def check_networks(avln_1, avln_2):
    print "Checking the networks", avln_1, "and", avln_2, "...{"
    check_intra_network(avln_1)
    check_intra_network(avln_2)
    check_inter_networks(avln_1, avln_2)
    print"OK: the networks are as expected"
    print "}"

def check_intra_network(avln):
    for key_1 in avln:
        for key_2 in avln:
            assert r_ping(key_1, key_2) == "pong", (key_1, key_2)
    if len(avln) > 1:
        roles = [ role(key) for key in avln ]
        roles.sort()
        #assert roles[0] == "CCO", roles
        #assert roles.count("STA") == len(avln) - 1, (roles, avln)

def check_inter_networks(avln_1, avln_2):
    for key_1 in avln_1:
        for key_2 in avln_2:
            assert r_ping(key_1, key_2) == "pang", (key_1, key_2)

def change_nmk(keys):
    new_nmk = str(random.random())
    for key in keys:
        switch_on(key)
        spc300.change_nmk(key, new_nmk)
        power_strip.switch("off", key)

def switch_on(keys):
    if type(keys) != list:
        keys = [keys]
    for key in keys:
        spc300.switch_on(key)