summaryrefslogtreecommitdiffstats
path: root/scripts/automation/regression/functional_tests/stl_basic_tests.py
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-03-23 10:43:40 +0200
committerimarom <imarom@cisco.com>2016-03-23 13:01:10 +0200
commit89a2be8247936e2d3d8323c0e51a86c198a879a2 (patch)
tree3433141e9eb84d35816c938308347686608ae6a3 /scripts/automation/regression/functional_tests/stl_basic_tests.py
parenta380bf1055c6cb4432b1c928f73a3ca3ada52d9d (diff)
yes...again Python3....
Diffstat (limited to 'scripts/automation/regression/functional_tests/stl_basic_tests.py')
-rw-r--r--scripts/automation/regression/functional_tests/stl_basic_tests.py123
1 files changed, 61 insertions, 62 deletions
diff --git a/scripts/automation/regression/functional_tests/stl_basic_tests.py b/scripts/automation/regression/functional_tests/stl_basic_tests.py
index ea515401..6467c128 100644
--- a/scripts/automation/regression/functional_tests/stl_basic_tests.py
+++ b/scripts/automation/regression/functional_tests/stl_basic_tests.py
@@ -7,9 +7,9 @@ from nose.tools import assert_not_equal
from nose.tools import nottest
from nose.plugins.attrib import attr
from trex import CTRexScenario
-from dpkt import pcap
from trex_stl_lib import trex_stl_sim
from trex_stl_lib.trex_stl_streams import STLProfile
+from trex_stl_lib.trex_stl_packet_builder_scapy import RawPcapReader, RawPcapWriter
import sys
import os
import subprocess
@@ -36,7 +36,7 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
self.profiles['random_size_9k'] = os.path.join(self.profiles_path, "../udp_rand_len_9k.py")
self.profiles['imix_tuple_gen'] = os.path.join(self.profiles_path, "imix_1pkt_tuple_gen.yaml")
- for k, v in self.profiles.iteritems():
+ for k, v in self.profiles.items():
self.verify_exists(v)
self.valgrind_profiles = [ self.profiles['imix_3pkt_vm'],
@@ -65,23 +65,19 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
def compare_caps (self, cap1, cap2, max_diff_sec = 0.01):
- with open(cap1, 'r') as f1:
- reader1 = pcap.Reader(f1)
- pkts1 = reader1.readpkts()
-
- with open(cap2, 'r') as f2:
- reader2 = pcap.Reader(f2)
- pkts2 = reader2.readpkts()
+ pkts1 = list(RawPcapReader(cap1))
+ pkts2 = list(RawPcapReader(cap2))
assert_equal(len(pkts1), len(pkts2))
- for pkt1, pkt2, i in zip(pkts1, pkts2, xrange(1, len(pkts1))):
- ts1 = pkt1[0]
- ts2 = pkt2[0]
+ for pkt1, pkt2, i in zip(pkts1, pkts2, range(1, len(pkts1))):
+ ts1 = float(pkt1[1][0]) + (float(pkt1[1][1]) / 1e6)
+ ts2 = float(pkt2[1][0]) + (float(pkt2[1][1]) / 1e6)
+
if abs(ts1-ts2) > 0.000005: # 5 nsec
raise AssertionError("TS error: cap files '{0}', '{1}' differ in cap #{2} - '{3}' vs. '{4}'".format(cap1, cap2, i, ts1, ts2))
- if pkt1[1] != pkt2[1]:
+ if pkt1[0] != pkt2[0]:
raise AssertionError("RAW error: cap files '{0}', '{1}' differ in cap #{2}".format(cap1, cap2, i))
@@ -121,6 +117,7 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
finally:
if not do_no_remove:
os.unlink(output_cap)
+
if test_generated:
try:
generated_filename = input_file.replace('.py', '_GENERATED.py').replace('.yaml', '_GENERATED.py')
@@ -128,15 +125,18 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
profile = STLProfile.load_py(input_file)
elif input_file.endswith('.yaml'):
profile = STLProfile.load_yaml(input_file)
- profile.dump_to_code(generated_filename)
+ profile.dump_to_code(generated_filename)
+
rc = self.run_sim(generated_filename, output_cap, options, silent)
assert_equal(rc, True)
if compare:
self.compare_caps(output_cap, golden_file)
+
except Exception as e:
- print e
+ print(e)
+
finally:
if not do_no_remove_generated:
os.unlink(generated_filename)
@@ -148,52 +148,52 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
def test_stl_profiles (self):
p = [
- ["udp_1pkt_1mac_override.py","-m 1 -l 50",True],
- ["syn_attack.py","-m 1 -l 50",True], # can't compare random now
- ["udp_1pkt_1mac.py","-m 1 -l 50",True],
- ["udp_1pkt_mac.py","-m 1 -l 50",True],
- ["udp_1pkt.py","-m 1 -l 50",True],
- ["udp_1pkt_tuple_gen.py","-m 1 -l 50",True],
- ["udp_rand_len_9k.py","-m 1 -l 50",True], # can't do the compare
- ["udp_1pkt_mpls.py","-m 1 -l 50",True],
- ["udp_1pkt_mpls_vm.py","-m 1 ",True],
- ["imix.py","-m 1 -l 100",True],
- ["udp_inc_len_9k.py","-m 1 -l 100",True],
- ["udp_1pkt_range_clients.py","-m 1 -l 100",True],
- ["multi_burst_2st_1000pkt.py","-m 1 -l 100",True],
- ["pcap.py", "-m 1", True],
- ["pcap_with_vm.py", "-m 1", True],
+ ["udp_1pkt_1mac_override.py","-m 1 -l 50",True],
+ ["syn_attack.py","-m 1 -l 50",True], # can't compare random now
+ ["udp_1pkt_1mac.py","-m 1 -l 50",True],
+ ["udp_1pkt_mac.py","-m 1 -l 50",True],
+ ["udp_1pkt.py","-m 1 -l 50",True],
+ ["udp_1pkt_tuple_gen.py","-m 1 -l 50",True],
+ ["udp_rand_len_9k.py","-m 1 -l 50",True], # can't do the compare
+ ["udp_1pkt_mpls.py","-m 1 -l 50",True],
+ ["udp_1pkt_mpls_vm.py","-m 1 ",True],
+ ["imix.py","-m 1 -l 100",True],
+ ["udp_inc_len_9k.py","-m 1 -l 100",True],
+ ["udp_1pkt_range_clients.py","-m 1 -l 100",True],
+ ["multi_burst_2st_1000pkt.py","-m 1 -l 100",True],
+ ["pcap.py", "-m 1", True],
+ ["pcap_with_vm.py", "-m 1", True],
# YAML test
- ["yaml/burst_1000_pkt.yaml","-m 1 -l 100",True],
- ["yaml/burst_1pkt_1burst.yaml","-m 1 -l 100",True],
- ["yaml/burst_1pkt_vm.yaml","-m 1 -l 100",True],
- ["yaml/imix_1pkt.yaml","-m 1 -l 100",True],
- ["yaml/imix_1pkt_2.yaml","-m 1 -l 100",True],
- ["yaml/imix_1pkt_tuple_gen.yaml","-m 1 -l 100",True],
- ["yaml/imix_1pkt_vm.yaml","-m 1 -l 100",True],
- ["udp_1pkt_pcap.py","-m 1 -l 10",True],
- ["udp_3pkt_pcap.py","-m 1 -l 10",True],
- #["udp_1pkt_simple.py","-m 1 -l 3",True],
- ["udp_1pkt_pcap_relative_path.py","-m 1 -l 3",True],
- ["udp_1pkt_tuple_gen_split.py","-m 1 -c 2 -l 100",True],
- ["udp_1pkt_range_clients_split.py","-m 1 -c 2 -l 100",True],
- ["udp_1pkt_vxlan.py","-m 1 -c 1 -l 17",True, False], # can't generate: no VXLAN in Scapy, only in profile
- ["udp_1pkt_ipv6_in_ipv4.py","-m 1 -c 1 -l 17",True],
- ["yaml/imix_3pkt.yaml","-m 50kpps --limit 20 --cores 2",True],
- ["yaml/imix_3pkt_vm.yaml","-m 50kpps --limit 20 --cores 2",True],
- ["udp_1pkt_simple_mac_dst.py","-m 1 -l 1 ",True],
- ["udp_1pkt_simple_mac_src.py","-m 1 -l 1 ",True],
- ["udp_1pkt_simple_mac_dst_src.py","-m 1 -l 1 ",True],
- ["burst_3st_loop_x_times.py","-m 1 -l 20 ",True],
- ["udp_1pkt_mac_step.py","-m 1 -l 20 ",True],
- ["udp_1pkt_mac_mask1.py","-m 1 -l 20 ",True] ,
- ["udp_1pkt_mac_mask2.py","-m 1 -l 20 ",True],
- ["udp_1pkt_mac_mask3.py","-m 1 -l 20 ",True],
- ["udp_1pkt_simple_test2.py","-m 1 -l 10 ",True], # test split of packet with ip option
- ["udp_1pkt_simple_test.py","-m 1 -l 10 ",True],
- ["udp_1pkt_mac_mask5.py","-m 1 -l 30 ",True],
- ["udp_1pkt_range_clients_split_garp.py","-m 1 -l 50",True]
+ ["yaml/burst_1000_pkt.yaml","-m 1 -l 100",True],
+ ["yaml/burst_1pkt_1burst.yaml","-m 1 -l 100",True],
+ ["yaml/burst_1pkt_vm.yaml","-m 1 -l 100",True],
+ ["yaml/imix_1pkt.yaml","-m 1 -l 100",True],
+ ["yaml/imix_1pkt_2.yaml","-m 1 -l 100",True],
+ ["yaml/imix_1pkt_tuple_gen.yaml","-m 1 -l 100",True],
+ ["yaml/imix_1pkt_vm.yaml","-m 1 -l 100",True],
+ ["udp_1pkt_pcap.py","-m 1 -l 10",True],
+ ["udp_3pkt_pcap.py","-m 1 -l 10",True],
+ #["udp_1pkt_simple.py","-m 1 -l 3",True],
+ ["udp_1pkt_pcap_relative_path.py","-m 1 -l 3",True],
+ ["udp_1pkt_tuple_gen_split.py","-m 1 -c 2 -l 100",True],
+ ["udp_1pkt_range_clients_split.py","-m 1 -c 2 -l 100",True],
+ ["udp_1pkt_vxlan.py","-m 1 -c 1 -l 17",True, False], # can't generate: no VXLAN in Scapy, only in profile
+ ["udp_1pkt_ipv6_in_ipv4.py","-m 1 -c 1 -l 17",True],
+ ["yaml/imix_3pkt.yaml","-m 50kpps --limit 20 --cores 2",True],
+ ["yaml/imix_3pkt_vm.yaml","-m 50kpps --limit 20 --cores 2",True],
+ ["udp_1pkt_simple_mac_dst.py","-m 1 -l 1 ",True],
+ ["udp_1pkt_simple_mac_src.py","-m 1 -l 1 ",True],
+ ["udp_1pkt_simple_mac_dst_src.py","-m 1 -l 1 ",True],
+ ["burst_3st_loop_x_times.py","-m 1 -l 20 ",True],
+ ["udp_1pkt_mac_step.py","-m 1 -l 20 ",True],
+ ["udp_1pkt_mac_mask1.py","-m 1 -l 20 ",True] ,
+ ["udp_1pkt_mac_mask2.py","-m 1 -l 20 ",True],
+ ["udp_1pkt_mac_mask3.py","-m 1 -l 20 ",True],
+ ["udp_1pkt_simple_test2.py","-m 1 -l 10 ",True], # test split of packet with ip option
+ ["udp_1pkt_simple_test.py","-m 1 -l 10 ",True],
+ ["udp_1pkt_mac_mask5.py","-m 1 -l 30 ",True],
+ ["udp_1pkt_range_clients_split_garp.py","-m 1 -l 50",True]
];
@@ -240,11 +240,10 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
# valgrind tests - this runs in multi thread as it safe (no output)
def test_valgrind_various_profiles (self):
-
- print "\n"
+ print("\n")
threads = []
for profile in self.valgrind_profiles:
- print "\n*** VALGRIND: testing profile '{0}' ***\n".format(profile)
+ print("\n*** VALGRIND: testing profile '{0}' ***\n".format(profile))
obj = {'t': None, 'rc': None}
t = Thread(target = self.run_sim,
kwargs = {'obj': obj, 'yaml': profile, 'output':None, 'options': "--cores 8 --limit 20 --valgrind", 'silent': True})