trex_cfg_creator_test.py revision 45135430
1#!/usr/bin/python
2
3import sys
4import copy
5from collections import OrderedDict
6from trex import CTRexScenario
7sys.path.append(CTRexScenario.scripts_path)
8from dpdk_setup_ports import ConfigCreator, DpdkSetup
9sys.path.remove(CTRexScenario.scripts_path)
10from nose.tools import assert_raises
11import yaml
12
13class CompareLinesDiff(Exception): pass
14class CompareLinesNumDiff(Exception): pass
15class CompareTypeErr(Exception): pass
16
17def compare_lines(golden, output):
18    if type(golden) is not str:
19        raise CompareTypeErr('Type of golden should be str, got: %s' % type(golden))
20    if type(output) is not str:
21        raise CompareTypeErr('Type of output should be str, got: %s' % type(output))
22    golden_lines = golden.strip().splitlines()
23    output_lines = output.strip().splitlines()
24    if len(golden_lines) != len(output_lines):
25        raise CompareLinesNumDiff('Number of lines on golden is: %s, in output: %s\nGolden:\n%s\nGenerated:\n%s\n' % (len(golden_lines), len(output_lines), golden, output))
26    for line_num, (golden_line, output_line) in enumerate(zip(golden_lines, output_lines)):
27        if golden_line != output_line:
28            raise CompareLinesDiff('Produced YAML differs from golden at line %s.Golden: %s <-> Output: %s' % (line_num + 1, golden_line, output_line))
29
30def create_config(cpu_topology, interfaces, *args, **kwargs):
31    config = ConfigCreator(cpu_topology, interfaces, *args, **kwargs)
32    return config.create_config()
33
34def verify_master_core0(output):
35    output_yaml = yaml.safe_load(output)
36    assert type(output_yaml) is list, 'Generated YAML should be list'
37    assert len(output_yaml) is 1, 'Generated YAML should be list with 1 element'
38    output_yaml = output_yaml[0]
39    assert 'platform' in output_yaml, 'Generated YAML has no platform section:\n%s' % output
40    assert 'master_thread_id' in output_yaml['platform'], 'Generated YAML does not specify master thread id:\n%s' % output
41    assert output_yaml['platform']['master_thread_id'] is 0, 'Master thread id should be 0 in generated YAML, got:%s' % output_yaml['platform']['master_thread_id']
42
43class TRexCfgCreator_Test:
44
45    def test_vm_cfg(self):
46        cpu_topology = {0: OrderedDict([i, [i]] for i in range(5))}
47        interfaces = [{'Active': '',
48  'Class': '0200',
49  'Class_str': 'Ethernet controller',
50  'Device': 1968,
51  'Device_str': 'VMXNET3 Ethernet Controller',
52  'Driver_str': 'vmxnet3',
53  'Interface': 'ens192',
54  'Interface_argv': '0b:00.0',
55  'Module_str': 'igb_uio,vfio-pci,uio_pci_generic',
56  'NUMA': -1,
57  'PhySlot': '192',
58  'PhySlot_str': '192',
59  'ProgIf': '01',
60  'Rev': '01',
61  'Rev_str': '01',
62  'SDevice': '07b0',
63  'SDevice_str': 'VMXNET3 Ethernet Controller',
64  'SVendor': '15ad',
65  'SVendor_str': 'VMware',
66  'Slot': '0000:0b:00.0',
67  'Slot_str': '0b:00.0',
68  'Vendor': 5549,
69  'Vendor_str': 'VMware',
70  'dest_mac': '00:0c:29:92:f1:ca',
71  'src_mac': '00:0c:29:92:f1:d4',
72  'loopback_dest': True},
73 {'Active': '',
74  'Class': '0200',
75  'Class_str': 'Ethernet controller',
76  'Device': 1968,
77  'Device_str': 'VMXNET3 Ethernet Controller',
78  'Driver_str': 'vmxnet3',
79  'Interface': 'ens160',
80  'Interface_argv': '03:00.0',
81  'Module_str': 'igb_uio,vfio-pci,uio_pci_generic',
82  'NUMA': -1,
83  'PhySlot': '160',
84  'PhySlot_str': '160',
85  'ProgIf': '01',
86  'Rev': '01',
87  'Rev_str': '01',
88  'SDevice': '07b0',
89  'SDevice_str': 'VMXNET3 Ethernet Controller',
90  'SVendor': '15ad',
91  'SVendor_str': 'VMware',
92  'Slot': '0000:03:00.0',
93  'Slot_str': '03:00.0',
94  'Vendor': 5549,
95  'Vendor_str': 'VMware',
96  'dest_mac': '00:0c:29:92:f1:d4',
97  'src_mac': '00:0c:29:92:f1:ca'}]
98        golden = '''
99### Config file generated by dpdk_setup_ports.py ###
100
101- port_limit: 2
102  version: 2
103  interfaces: ['0b:00.0', '03:00.0']
104  port_info:
105      - dest_mac: 00:0c:29:92:f1:ca # MAC OF LOOPBACK TO IT'S DUAL INTERFACE
106        src_mac:  00:0c:29:92:f1:d4
107      - dest_mac: 00:0c:29:92:f1:d4
108        src_mac:  00:0c:29:92:f1:ca
109
110  platform:
111      master_thread_id: 0
112      latency_thread_id: 1
113      dual_if:
114        - socket: 0
115          threads: [2]
116'''
117        output = create_config(cpu_topology, interfaces)
118        verify_master_core0(output)
119        compare_lines(golden, output)
120        with assert_raises(CompareLinesNumDiff):
121            compare_lines('1' + golden, output)
122        output = create_config(cpu_topology, interfaces, exclude_lcores = [0])
123        with assert_raises(AssertionError):
124            verify_master_core0(output)
125        output = create_config(cpu_topology, interfaces, include_lcores = [1,2,3,4])
126        with assert_raises(AssertionError):
127            verify_master_core0(output)
128        output = create_config(cpu_topology, interfaces, include_lcores = [0,2,3,4])
129        verify_master_core0(output)
130        output = create_config(cpu_topology, interfaces, include_lcores = [0,2,3,4], exclude_lcores = [0])
131        with assert_raises(AssertionError):
132            verify_master_core0(output)
133
134    def test_trex08_cfg(self):
135        cpu_topology = OrderedDict([(0, OrderedDict([(0, [0, 16]), (1, [1, 17]), (2, [2, 18]), (3, [3, 19]), (4, [4, 20]), (5, [5, 21]), (6, [6, 22]), (7, [7, 23])])), (1, OrderedDict([(0, [8, 24]), (1, [9, 25]), (2, [10, 26]), (3, [11, 27]), (4, [12, 28]), (5, [13, 29]), (6, [14, 30]), (7, [15, 31])]))])
136        interfaces = [{'Active': '',
137  'Class': '0200',
138  'Class_str': 'Ethernet controller',
139  'Device': 5507,
140  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
141  'Driver_str': 'igb_uio',
142  'Interface': '',
143  'Interface_argv': '0000:02:00.0',
144  'Module_str': 'vfio-pci,uio_pci_generic',
145  'NUMA': 0,
146  'PhySlot': '0-1',
147  'PhySlot_str': '0-1',
148  'ProgIf': '01',
149  'Rev': '01',
150  'Rev_str': '01',
151  'SDevice': '0002',
152  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
153  'SVendor': '8086',
154  'SVendor_str': 'Intel Corporation',
155  'Slot': '0000:02:00.0',
156  'Slot_str': '02:00.0',
157  'Vendor': 32902,
158  'Vendor_str': 'Intel Corporation',
159  'dest_mac': '02:00:02:00:00:00',
160  'src_mac': '01:00:01:00:00:00'},
161 {'Active': '',
162  'Class': '0200',
163  'Class_str': 'Ethernet controller',
164  'Device': 5507,
165  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
166  'Driver_str': 'igb_uio',
167  'Interface': '',
168  'Interface_argv': '0000:02:00.1',
169  'Module_str': 'vfio-pci,uio_pci_generic',
170  'NUMA': 0,
171  'PhySlot': '0-1',
172  'PhySlot_str': '0-1',
173  'ProgIf': '01',
174  'Rev': '01',
175  'Rev_str': '01',
176  'SDevice': '0000',
177  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
178  'SVendor': '8086',
179  'SVendor_str': 'Intel Corporation',
180  'Slot': '0000:02:00.1',
181  'Slot_str': '02:00.1',
182  'Vendor': 32902,
183  'Vendor_str': 'Intel Corporation',
184  'dest_mac': '01:00:01:00:00:00',
185  'src_mac': '02:00:02:00:00:00'},
186 {'Active': '',
187  'Class': '0200',
188  'Class_str': 'Ethernet controller',
189  'Device': 5507,
190  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
191  'Driver_str': 'igb_uio',
192  'Interface': '',
193  'Interface_argv': '0000:84:00.0',
194  'Module_str': 'vfio-pci,uio_pci_generic',
195  'NUMA': 1,
196  'PhySlot': '0-8',
197  'PhySlot_str': '0-8',
198  'ProgIf': '20',
199  'Rev': '01',
200  'Rev_str': '01',
201  'SDevice': '0002',
202  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
203  'SVendor': '8086',
204  'SVendor_str': 'Intel Corporation',
205  'Slot': '0000:84:00.0',
206  'Slot_str': '84:00.0',
207  'Vendor': 32902,
208  'Vendor_str': 'Intel Corporation',
209  'dest_mac': '04:00:04:00:00:00',
210  'src_mac': '03:00:03:00:00:00'},
211 {'Active': '',
212  'Class': '0200',
213  'Class_str': 'Ethernet controller',
214  'Device': 5507,
215  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
216  'Driver_str': 'igb_uio',
217  'Interface': '',
218  'Interface_argv': '0000:84:00.1',
219  'Module_str': 'vfio-pci,uio_pci_generic',
220  'NUMA': 1,
221  'PhySlot': '0-8',
222  'PhySlot_str': '0-8',
223  'ProgIf': '20',
224  'Rev': '01',
225  'Rev_str': '01',
226  'SDevice': '0000',
227  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
228  'SVendor': '8086',
229  'SVendor_str': 'Intel Corporation',
230  'Slot': '0000:84:00.1',
231  'Slot_str': '84:00.1',
232  'Vendor': 32902,
233  'Vendor_str': 'Intel Corporation',
234  'dest_mac': '03:00:03:00:00:00',
235  'src_mac': '04:00:04:00:00:00'},
236 {'Active': '',
237  'Class': '0200',
238  'Class_str': 'Ethernet controller',
239  'Device': 5507,
240  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
241  'Driver_str': 'igb_uio',
242  'Interface': '',
243  'Interface_argv': '05:00.0',
244  'Module_str': 'vfio-pci,uio_pci_generic',
245  'NUMA': 0,
246  'PhySlot': '0-3',
247  'PhySlot_str': '0-3',
248  'ProgIf': '01',
249  'Rev': '02',
250  'Rev_str': '02',
251  'SDevice': '0000',
252  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
253  'SVendor': '8086',
254  'SVendor_str': 'Intel Corporation',
255  'Slot': '0000:05:00.0',
256  'Slot_str': '05:00.0',
257  'Vendor': 32902,
258  'Vendor_str': 'Intel Corporation',
259  'dest_mac': '06:00:06:00:00:00',
260  'src_mac': '05:00:05:00:00:00'},
261 {'Active': '',
262  'Class': '0200',
263  'Class_str': 'Ethernet controller',
264  'Device': 5507,
265  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
266  'Driver_str': 'igb_uio',
267  'Interface': '',
268  'Interface_argv': '05:00.1',
269  'Module_str': 'vfio-pci,uio_pci_generic',
270  'NUMA': 0,
271  'PhySlot': '0-3',
272  'PhySlot_str': '0-3',
273  'ProgIf': '01',
274  'Rev': '02',
275  'Rev_str': '02',
276  'SDevice': '0000',
277  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
278  'SVendor': '8086',
279  'SVendor_str': 'Intel Corporation',
280  'Slot': '0000:05:00.1',
281  'Slot_str': '05:00.1',
282  'Vendor': 32902,
283  'Vendor_str': 'Intel Corporation',
284  'dest_mac': '05:00:05:00:00:00',
285  'src_mac': '06:00:06:00:00:00'}]
286        golden = '''
287### Config file generated by dpdk_setup_ports.py ###
288
289- port_limit: 6
290  version: 2
291  interfaces: ['02:00.0', '02:00.1', '84:00.0', '84:00.1', '05:00.0', '05:00.1']
292  port_bandwidth_gb: 40
293  port_info:
294      - dest_mac: 02:00:02:00:00:00
295        src_mac:  01:00:01:00:00:00
296      - dest_mac: 01:00:01:00:00:00
297        src_mac:  02:00:02:00:00:00
298
299      - dest_mac: 04:00:04:00:00:00
300        src_mac:  03:00:03:00:00:00
301      - dest_mac: 03:00:03:00:00:00
302        src_mac:  04:00:04:00:00:00
303
304      - dest_mac: 06:00:06:00:00:00
305        src_mac:  05:00:05:00:00:00
306      - dest_mac: 05:00:05:00:00:00
307        src_mac:  06:00:06:00:00:00
308
309  platform:
310      master_thread_id: 0
311      latency_thread_id: 16
312      dual_if:
313        - socket: 0
314          threads: [1,17,2,18,3,19,4]
315
316        - socket: 1
317          threads: [8,24,9,25,10,26,11]
318
319        - socket: 0
320          threads: [20,5,21,6,22,7,23]
321'''
322        output = create_config(cpu_topology, interfaces)
323        verify_master_core0(output)
324        compare_lines(golden, output)
325
326        interfaces = [{'Active': '',
327  'Class': '0200',
328  'Class_str': 'Ethernet controller',
329  'Device': 5507,
330  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
331  'Driver_str': 'igb_uio',
332  'Interface': '',
333  'Interface_argv': '0000:02:00.0',
334  'Module_str': 'vfio-pci,uio_pci_generic',
335  'NUMA': 0,
336  'PhySlot': '0-1',
337  'PhySlot_str': '0-1',
338  'ProgIf': '01',
339  'Rev': '01',
340  'Rev_str': '01',
341  'SDevice': '0002',
342  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
343  'SVendor': '8086',
344  'SVendor_str': 'Intel Corporation',
345  'Slot': '0000:02:00.0',
346  'Slot_str': '02:00.0',
347  'Vendor': 32902,
348  'Vendor_str': 'Intel Corporation',
349  'dest_mac': '02:00:02:00:00:00',
350  'src_mac': '01:00:01:00:00:00'},
351 {'Active': '',
352  'Class': '0200',
353  'Class_str': 'Ethernet controller',
354  'Device': 5507,
355  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
356  'Driver_str': 'igb_uio',
357  'Interface': '',
358  'Interface_argv': '0000:02:00.1',
359  'Module_str': 'vfio-pci,uio_pci_generic',
360  'NUMA': 0,
361  'PhySlot': '0-1',
362  'PhySlot_str': '0-1',
363  'ProgIf': '01',
364  'Rev': '01',
365  'Rev_str': '01',
366  'SDevice': '0000',
367  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
368  'SVendor': '8086',
369  'SVendor_str': 'Intel Corporation',
370  'Slot': '0000:02:00.1',
371  'Slot_str': '02:00.1',
372  'Vendor': 32902,
373  'Vendor_str': 'Intel Corporation',
374  'dest_mac': '01:00:01:00:00:00',
375  'src_mac': '02:00:02:00:00:00'},
376 {'Active': '',
377  'Class': '0200',
378  'Class_str': 'Ethernet controller',
379  'Device': 5507,
380  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
381  'Driver_str': 'igb_uio',
382  'Interface': '',
383  'Interface_argv': '0000:84:00.0',
384  'Module_str': 'vfio-pci,uio_pci_generic',
385  'NUMA': 1,
386  'PhySlot': '0-8',
387  'PhySlot_str': '0-8',
388  'ProgIf': '20',
389  'Rev': '01',
390  'Rev_str': '01',
391  'SDevice': '0002',
392  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
393  'SVendor': '8086',
394  'SVendor_str': 'Intel Corporation',
395  'Slot': '0000:84:00.0',
396  'Slot_str': '84:00.0',
397  'Vendor': 32902,
398  'Vendor_str': 'Intel Corporation',
399  'dest_mac': '04:00:04:00:00:00',
400  'src_mac': '03:00:03:00:00:00'},
401 {'Active': '',
402  'Class': '0200',
403  'Class_str': 'Ethernet controller',
404  'Device': 5507,
405  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
406  'Driver_str': 'igb_uio',
407  'Interface': '',
408  'Interface_argv': '0000:84:00.1',
409  'Module_str': 'vfio-pci,uio_pci_generic',
410  'NUMA': 1,
411  'PhySlot': '0-8',
412  'PhySlot_str': '0-8',
413  'ProgIf': '20',
414  'Rev': '01',
415  'Rev_str': '01',
416  'SDevice': '0000',
417  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
418  'SVendor': '8086',
419  'SVendor_str': 'Intel Corporation',
420  'Slot': '0000:84:00.1',
421  'Slot_str': '84:00.1',
422  'Vendor': 32902,
423  'Vendor_str': 'Intel Corporation',
424  'dest_mac': '03:00:03:00:00:00',
425  'src_mac': '04:00:04:00:00:00'}]
426        golden = '''
427### Config file generated by dpdk_setup_ports.py ###
428
429- port_limit: 4
430  version: 2
431  interfaces: ['02:00.0', '02:00.1', '84:00.0', '84:00.1']
432  port_bandwidth_gb: 40
433  port_info:
434      - dest_mac: 02:00:02:00:00:00
435        src_mac:  01:00:01:00:00:00
436      - dest_mac: 01:00:01:00:00:00
437        src_mac:  02:00:02:00:00:00
438
439      - dest_mac: 04:00:04:00:00:00
440        src_mac:  03:00:03:00:00:00
441      - dest_mac: 03:00:03:00:00:00
442        src_mac:  04:00:04:00:00:00
443
444  platform:
445      master_thread_id: 0
446      latency_thread_id: 31
447      dual_if:
448        - socket: 0
449          threads: [1,17,2,18,3,19,4,20,5,21,6,22,7,23,16]
450
451        - socket: 1
452          threads: [8,24,9,25,10,26,11,27,12,28,13,29,14,30,15]
453'''
454        output = create_config(cpu_topology, interfaces)
455        verify_master_core0(output)
456        compare_lines(golden, output)
457
458        interfaces = [{'Active': '',
459  'Class': '0200',
460  'Class_str': 'Ethernet controller',
461  'Device': 5507,
462  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
463  'Driver_str': 'igb_uio',
464  'Interface': '',
465  'Interface_argv': '0000:02:00.0',
466  'Module_str': 'vfio-pci,uio_pci_generic',
467  'NUMA': 0,
468  'PhySlot': '0-1',
469  'PhySlot_str': '0-1',
470  'ProgIf': '01',
471  'Rev': '01',
472  'Rev_str': '01',
473  'SDevice': '0002',
474  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
475  'SVendor': '8086',
476  'SVendor_str': 'Intel Corporation',
477  'Slot': '0000:02:00.0',
478  'Slot_str': '02:00.0',
479  'Vendor': 32902,
480  'Vendor_str': 'Intel Corporation',
481  'dest_mac': '02:00:02:00:00:00',
482  'src_mac': '01:00:01:00:00:00'},
483 {'Active': '',
484  'Class': '0200',
485  'Class_str': 'Ethernet controller',
486  'Device': 5507,
487  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
488  'Driver_str': 'igb_uio',
489  'Interface': '',
490  'Interface_argv': '0000:02:00.1',
491  'Module_str': 'vfio-pci,uio_pci_generic',
492  'NUMA': 0,
493  'PhySlot': '0-1',
494  'PhySlot_str': '0-1',
495  'ProgIf': '01',
496  'Rev': '01',
497  'Rev_str': '01',
498  'SDevice': '0000',
499  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
500  'SVendor': '8086',
501  'SVendor_str': 'Intel Corporation',
502  'Slot': '0000:02:00.1',
503  'Slot_str': '02:00.1',
504  'Vendor': 32902,
505  'Vendor_str': 'Intel Corporation',
506  'dest_mac': '01:00:01:00:00:00',
507  'src_mac': '02:00:02:00:00:00'},
508 {'Active': '',
509  'Class': '0200',
510  'Class_str': 'Ethernet controller',
511  'Device': 5507,
512  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
513  'Driver_str': 'igb_uio',
514  'Interface': '',
515  'Interface_argv': '05:00.0',
516  'Module_str': 'vfio-pci,uio_pci_generic',
517  'NUMA': 0,
518  'PhySlot': '0-3',
519  'PhySlot_str': '0-3',
520  'ProgIf': '01',
521  'Rev': '02',
522  'Rev_str': '02',
523  'SDevice': '0000',
524  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
525  'SVendor': '8086',
526  'SVendor_str': 'Intel Corporation',
527  'Slot': '0000:05:00.0',
528  'Slot_str': '05:00.0',
529  'Vendor': 32902,
530  'Vendor_str': 'Intel Corporation',
531  'dest_mac': '04:00:04:00:00:00',
532  'src_mac': '03:00:03:00:00:00'},
533 {'Active': '',
534  'Class': '0200',
535  'Class_str': 'Ethernet controller',
536  'Device': 5507,
537  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
538  'Driver_str': 'igb_uio',
539  'Interface': '',
540  'Interface_argv': '05:00.1',
541  'Module_str': 'vfio-pci,uio_pci_generic',
542  'NUMA': 0,
543  'PhySlot': '0-3',
544  'PhySlot_str': '0-3',
545  'ProgIf': '01',
546  'Rev': '02',
547  'Rev_str': '02',
548  'SDevice': '0000',
549  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
550  'SVendor': '8086',
551  'SVendor_str': 'Intel Corporation',
552  'Slot': '0000:05:00.1',
553  'Slot_str': '05:00.1',
554  'Vendor': 32902,
555  'Vendor_str': 'Intel Corporation',
556  'dest_mac': '03:00:03:00:00:00',
557  'src_mac': '04:00:04:00:00:00'}]
558        golden = '''
559### Config file generated by dpdk_setup_ports.py ###
560
561- port_limit: 4
562  version: 2
563  interfaces: ['02:00.0', '02:00.1', '05:00.0', '05:00.1']
564  port_bandwidth_gb: 40
565  port_info:
566      - dest_mac: 02:00:02:00:00:00
567        src_mac:  01:00:01:00:00:00
568      - dest_mac: 01:00:01:00:00:00
569        src_mac:  02:00:02:00:00:00
570
571      - dest_mac: 04:00:04:00:00:00
572        src_mac:  03:00:03:00:00:00
573      - dest_mac: 03:00:03:00:00:00
574        src_mac:  04:00:04:00:00:00
575
576  platform:
577      master_thread_id: 0
578      latency_thread_id: 16
579      dual_if:
580        - socket: 0
581          threads: [1,17,2,18,3,19,4]
582
583        - socket: 0
584          threads: [20,5,21,6,22,7,23]
585'''
586        output = create_config(cpu_topology, interfaces)
587        verify_master_core0(output)
588        compare_lines(golden, output)
589
590    def test_cfg_negative(self):
591        cpu_topology = OrderedDict([(0, OrderedDict([(0, [0, 16]), (1, [1, 17]), (2, [2, 18]), (3, [3, 19]), (4, [4, 20]), (5, [5, 21]), (6, [6, 22]), (7, [7, 23])])), (1, OrderedDict([(0, [8, 24]), (1, [9, 25]), (2, [10, 26]), (3, [11, 27]), (4, [12, 28]), (5, [13, 29]), (6, [14, 30]), (7, [15, 31])]))])
592        interfaces = [{'Active': '',
593  'Class': '0200',
594  'Class_str': 'Ethernet controller',
595  'Device': 5507,
596  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
597  'Driver_str': 'igb_uio',
598  'Interface': '',
599  'Interface_argv': '0000:02:00.0',
600  'Module_str': 'vfio-pci,uio_pci_generic',
601  'NUMA': 0,
602  'PhySlot': '0-1',
603  'PhySlot_str': '0-1',
604  'ProgIf': '01',
605  'Rev': '01',
606  'Rev_str': '01',
607  'SDevice': '0002',
608  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
609  'SVendor': '8086',
610  'SVendor_str': 'Intel Corporation',
611  'Slot': '0000:02:00.0',
612  'Slot_str': '02:00.0',
613  'Vendor': 32902,
614  'Vendor_str': 'Intel Corporation',
615  'dest_mac': '02:00:02:00:00:00',
616  'src_mac': '01:00:01:00:00:00'},
617 {'Active': '',
618  'Class': '0200',
619  'Class_str': 'Ethernet controller',
620  'Device': 5507,
621  'Device_str': 'Ethernet Controller XL710 for 40GbE QSFP+',
622  'Driver_str': 'igb_uio',
623  'Interface': '',
624  'Interface_argv': '0000:02:00.1',
625  'Module_str': 'vfio-pci,uio_pci_generic',
626  'NUMA': 0,
627  'PhySlot': '0-1',
628  'PhySlot_str': '0-1',
629  'ProgIf': '01',
630  'Rev': '01',
631  'Rev_str': '01',
632  'SDevice': '0000',
633  'SDevice_str': 'Ethernet Converged Network Adapter XL710-Q2',
634  'SVendor': '8086',
635  'SVendor_str': 'Intel Corporation',
636  'Slot': '0000:02:00.1',
637  'Slot_str': '02:00.1',
638  'Vendor': 32902,
639  'Vendor_str': 'Intel Corporation',
640  'dest_mac': '01:00:01:00:00:00',
641  'src_mac': '02:00:02:00:00:00'}]
642        # types errors
643        with assert_raises(AssertionError):
644            create_config(None, None)
645        with assert_raises(AssertionError):
646            create_config(cpu_topology, None)
647        with assert_raises(AssertionError):
648            create_config(None, interfaces)
649        with assert_raises(AssertionError):
650            create_config(cpu_topology, [])
651        with assert_raises(AssertionError):
652            create_config({}, interfaces)
653        with assert_raises(AssertionError):
654            create_config({}, [])
655        # not enough cores at NUMA 0
656        with assert_raises(DpdkSetup):
657            create_config({0:{0:[]}, 1:{0:[1,2,3,4,5,6,7]}}, interfaces)
658        with assert_raises(DpdkSetup):
659            create_config({0:{0:[1]}, 1:{0:[3]}}, interfaces)
660        with assert_raises(DpdkSetup):
661            create_config({0:{0:[1,2]}}, interfaces)
662        # no NUMA 0 info, NICs at NUMA 0
663        cpu_topo1 = copy.deepcopy(cpu_topology)
664        del cpu_topo1[0]
665        with assert_raises(KeyError):
666            create_config(cpu_topo1, interfaces)
667        int1 = copy.deepcopy(interfaces)
668        for interface in int1:
669            interface['NUMA'] = 1
670        # now should work, as interfaces use NUMA 1
671        create_config(cpu_topo1, int1)
672        int2 = copy.deepcopy(interfaces)
673        int2[1]['NUMA'] = 1
674        # interfaces on different NUMAs
675        with assert_raises(DpdkSetup):
676            create_config(cpu_topology, int2)
677
678
679    def test_inner_comparator(self):
680        compare_lines('', '')
681        compare_lines('one\ntwo', 'one\ntwo')
682        with assert_raises(CompareLinesNumDiff):
683            compare_lines('one\ntwo', 'one\ntwo\nthree')
684        with assert_raises(CompareLinesDiff):
685            compare_lines('one\ntwo', 'one\ntwo1')
686        with assert_raises(CompareLinesDiff):
687            compare_lines('one\ntwo', 'one\nthree')
688        with assert_raises(CompareTypeErr):
689            compare_lines(None, 'one\nthree')
690        with assert_raises(CompareTypeErr):
691            compare_lines('one\ntwo', None)
692        with assert_raises(CompareTypeErr):
693            compare_lines(None, None)
694
695    @classmethod
696    def tearDownClass(cls):
697        sys.path.remove(CTRexScenario.scripts_path)
698        del sys.modules['dpdk_setup_ports']
699