1#!/usr/bin/python
2# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Configuration for cell emulator tests."""
7import copy, unittest
8
9CELLS = {}
10
11# TODO(rochberg):  Need some way to subset this list for long/short tests
12
13LTE_TECHNOLOGIES = ['LTE']
14GENERIC_GSM_TECHNOLOGIES = ['GPRS', 'EGPRS', 'WCDMA', 'HSDPA', 'HSUPA',
15                            'HSDUPA', 'HSPA_PLUS']
16
17ICERA_TECHNOLOGIES = GENERIC_GSM_TECHNOLOGIES[:]
18ICERA_TECHNOLOGIES.remove('HSPA_PLUS')
19
20GOBI_3000_TECHNOLOGIES = GENERIC_GSM_TECHNOLOGIES + ['CDMA_2000', 'EVDO_1X']
21
22GOBI_2000_TECHNOLOGIES = GOBI_3000_TECHNOLOGIES[:]
23GOBI_2000_TECHNOLOGIES.remove('HSPA_PLUS')
24
25# TODO(thieule): Make HSPA_PLUS work with autotest (crosbug.com/32621).
26GENERIC_GSM_TECHNOLOGIES.remove('HSPA_PLUS')
27GOBI_3000_TECHNOLOGIES.remove('HSPA_PLUS')
28
29def combine_trees(a_original, b):
30    """Combines two dict-of-dict trees, favoring the second."""
31    try:
32        a = copy.copy(a_original)
33        for (key_b, value_b) in b.iteritems():
34            a[key_b] = combine_trees(a.get(key_b, None), value_b)
35    except AttributeError:  # one argument wasn't a dict.  B wins.
36        return b
37    return a
38
39
40def MakeDefaultCallBoxConfig(specifics):
41    base = {
42            "type": "8960-prologix",
43            # IP addresses and netmask for the air-side of the
44            # basestation network.
45            "bs_addresses": [
46                "192.168.2.2",
47                "192.168.2.3"
48                ],
49            "bs_netmask": "255.255.0.0",
50
51            "gpib_adapter": {
52                "gpib_address": 14,
53                "ip_port": 1234
54                },
55            # DNS addresses for the UE.  You do not need a
56            # working DNS server at this address, but you must
57            # have a machine there to send ICMP Port
58            # Unreachable messages, so the DNS lookups will
59            # fail quickly)
60            "ue_dns_addresses": [
61                "192.168.2.254",
62                "192.168.2.254"
63                ],
64            "ue_rf_addresses": [
65                "192.168.2.4",
66                "192.168.2.5"
67                ]
68            }
69    return combine_trees(base, specifics)
70
71def MakeDefaultPerfServer(specifics):
72    rf_address = "192.168.2.254"
73    base = {
74        "rf_address": rf_address,
75        "upload_url": "http://%s/upload" % (rf_address),
76        "download_url_format_string": ("http://%s/download?size=%%(size)s" %
77                                       rf_address),
78        }
79    return combine_trees(base, specifics)
80
81
82CELLS['cam'] = {
83    "basestations": [
84        MakeDefaultCallBoxConfig({
85            "gpib_adapter": {
86                "address": "172.31.206.171",
87                },
88            })
89        ],
90    "duts": [
91        {
92            "address": "172.31.206.145",
93            "name": "ad-hoc-usb",
94            "technologies": GOBI_2000_TECHNOLOGIES,
95            "rf_switch_port": 3,
96            },
97        {
98            "address": "172.31.206.146",
99            "name": "y3300",
100            "technologies": GENERIC_GSM_TECHNOLOGIES,
101            "rf_switch_port": 0,
102            }
103        ],
104
105    "perfserver": MakeDefaultPerfServer({
106        "name": "perfserver-cam",
107        "address": "172.31.206.153",
108        "ethernet_mac": "e8:11:32:cb:bb:95 ",
109        }),
110
111    "http_connectivity": {
112        # "url" should point to a URL that fetches a page small enough
113        # to be comfortably kept in memory.  If
114        # "url_required_contents" is present, it points to a string
115        # that must be present in the the fetched data.
116
117        "url": "http://192.168.2.254/connectivity/index.html",
118        "url_required_contents": "Chromium",
119        },
120    "rf_switch": {
121        "type": "ether_io",
122        "address":  "172.31.206.172",
123        "ethernet_mac": "00:11:ba:02:12:83",
124        }
125    }
126
127CELLS['mtv'] = {
128    "basestations": [
129        MakeDefaultCallBoxConfig({
130            "gpib_adapter": {
131              "type":'8960',
132              "address": "172.22.50.118",
133              "ethernet_mac": "00:21:69:01:06:46",
134              }
135            }),
136        MakeDefaultCallBoxConfig({
137          "type":'pxt',
138          "gpib_adapter": {
139              "address": "172.22.50.244",
140              "ethernet_mac": "00:21:69:01:0a:11",
141              # ddns-hostname "chromeos1-rack1-pxt-gpib";
142            }
143        })
144        ],
145
146
147#chromeos1-rack1-pxt / 172.22.50.243
148#chromeos1-rack2-rfswitch2 / 172.22.50.229
149#pixel 172.22.50.86 chromeos1-rack2-host6
150
151    "duts": [
152         {
153             "address": "172.22.50.86",
154             "ethernet_mac": "00:0e:c6:89:9d:18",
155             "name": "link-lte",
156             "technologies": LTE_TECHNOLOGIES,
157             "location": "rack2-host6",
158             "rf_switch_port": 1,
159             },
160        {
161            "address": "172.22.50.187",
162            "ethernet_mac": "00:00:00:00:08:4b",
163            "name": "alex-gobi-2000",
164            "technologies": GOBI_2000_TECHNOLOGIES,
165            "location": "rack2-host0",
166            "rf_switch_port": 0,
167            },
168        {
169            "address": "172.22.50.85",
170            "ethernet_mac": "00:00:00:00:00:c8",
171            "name": "alex-gobi-3000",
172            "technologies": GOBI_3000_TECHNOLOGIES,
173            "location": "rack2-host4",
174            "rf_switch_port": 1,
175            },
176        {
177            "address": "172.22.50.191",
178            "ethernet_mac": "c0:c1:c0:4b:d7:4f",
179            "name": "alex-y3300",
180            "technologies": ICERA_TECHNOLOGIES,
181            "location": "rack2-host1",
182            "rf_switch_port": 3,
183            },
184        {
185            "address": "172.22.50.89",
186            "ethernet_mac": "58:6d:8f:50:ae:55",
187            "name": "alex-y3400",
188            "technologies": ICERA_TECHNOLOGIES,
189            "location": "rack2-host5",
190            "rf_switch_port": 2,
191            },
192        ],
193
194    "perfserver": MakeDefaultPerfServer({
195        "name": "perfserver-mtv",
196        "address": "172.22.50.246",
197        "ethernet_mac": "c4:54:44:2a:1a:8b",
198        }),
199
200    # Used for tests that check web connectivity
201    "http_connectivity": {
202        "url": "http://192.168.2.254/connectivity/index.html",
203        "url_required_contents": "Chromium",
204        },
205    "rf_switch": {
206        "type": "ether_io",
207        "name": "rf-switch-1-mtv",
208        "ethernet_mac": "00:11:BA:02:12:82",
209        "address":  "172.22.50.88",
210        }
211    }
212
213
214class TestCombineTrees(unittest.TestCase):
215    def test_simple(self):
216        self.assertEqual({1:2, 3:4, 5:6},
217                         combine_trees({1:2, 3:4}, {5:6}))
218
219    def test_override_simple(self):
220        self.assertEqual({1:3},
221                         combine_trees({1:2},{1:3}))
222
223    def test_join_nested(self):
224        self.assertEqual({1:{2:3, 3:4}},
225                         combine_trees({1:{2:3}},{1:{3:4}}))
226
227    def test_override_in_nested(self):
228        self.assertEqual({1:{2:4}},
229                         combine_trees({1:{2:3}},{1:{2:4}}))
230
231    def test_override_different_types(self):
232        self.assertEqual({1:{2:4}},
233                         combine_trees({1:'rhinoceros'},{1:{2:4}}))
234        self.assertEqual({1:'rhinoceros'},
235                         combine_trees({1:{2:4}},{1:'rhinoceros'}))
236
237    def test_two_level(self):
238        self.assertEqual({1:{2:{3:4, 5:6}}},
239                         combine_trees({1:{2:{3:4}}},{1:{2:{5:6}}}))
240
241    def test_none(self):
242        self.assertEqual({1:None},
243                         combine_trees({1:2}, {1:None}))
244        self.assertEqual({1:None},
245                         combine_trees({1:None}, {}))
246        self.assertEqual({1:2},
247                         combine_trees({1:None}, {1:2}))
248
249
250if __name__ == '__main__':
251    unittest.main()
252