summaryrefslogtreecommitdiffstats
path: root/scripts/automation
diff options
context:
space:
mode:
authorHanoh Haim <hhaim@cisco.com>2016-02-03 11:36:58 +0200
committerHanoh Haim <hhaim@cisco.com>2016-02-03 11:36:58 +0200
commitdda9b08e2b57f785b71bccf4dab57ef4b2fb1dc3 (patch)
tree62eb7cb4d3c1ae8c7f38b0d48f4a0ca5f683e76e /scripts/automation
parent2e8a6255330ae7babdd0ace9889fa89796ac3687 (diff)
sanity check for var does not exists
Diffstat (limited to 'scripts/automation')
-rw-r--r--scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py24
-rw-r--r--scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py22
2 files changed, 43 insertions, 3 deletions
diff --git a/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py b/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py
index ee80e6d8..9c1b04fe 100644
--- a/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py
+++ b/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py
@@ -163,6 +163,30 @@ class CTRexPktBuilderSanitySCapy_Test(pkt_bld_general_test.CGeneralPktBld_Test):
d= pkt_builder.get_vm_data()
assert_equal(d['instructions'][1]['pkt_offset'],17)
+ def test_simple_vm3(self):
+ try:
+ raw1 = CTRexScRaw( [ CTRexVmDescFlowVar(name="my_valn",min_val=0,max_val=10,init_val=2,size=1,op="inc"),
+ CTRexVmDescWrFlowVar (fv_name="my_valn_err",pkt_offset= "802|1Q.vlan" ,offset_fixup=3) # fix the offset as valn is bitfield and not supported right now
+ ]
+ );
+
+ pkt_builder = CScapyTRexPktBuilder();
+
+ py='5'*128
+ pkt=Ether()/ \
+ Dot1Q(vlan=12)/ \
+ IP(src="16.0.0.1",dst="48.0.0.1")/ \
+ UDP(dport=12,sport=1025)/IP()/py
+
+ # set packet
+ pkt_builder.set_packet(pkt);
+ pkt_builder.add_command ( raw1 )
+ pkt_builder.compile();
+
+
+ d= pkt_builder.get_vm_data()
+ except CTRexPacketBuildException as e:
+ assert_equal(str(e), "[errcode:-11] 'variable my_valn_err does not exists '")
def tearDown(self):
diff --git a/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py b/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py
index fda77cf7..79616ad7 100644
--- a/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py
+++ b/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py
@@ -441,6 +441,12 @@ class CTRexVmDescBase(object):
print yaml.dump(self.get_json(), default_flow_style=False)
+ def get_var_ref (self):
+ '''
+ virtual function return a ref var name
+ '''
+ return None
+
def get_var_name(self):
'''
virtual function return the varible name if exists
@@ -520,6 +526,9 @@ class CTRexVmDescWrFlowVar(CTRexVmDescBase):
self.is_big =is_big;
assert(type(is_big)==bool);
+ def get_var_ref (self):
+ return self.name
+
def get_obj (self):
return CTRexVmInsWrFlowVar(self.name,self.pkt_offset+self.offset_fixup,self.add_val,self.is_big)
@@ -622,15 +631,22 @@ class CScapyTRexPktBuilder(object):
# make sure we have varibles once
vars={};
+
+ # add it add var to dit
for desc in obj.commands:
- print desc.__dict__
var_name = desc.get_var_name()
- print var_name
if var_name :
if vars.has_key(var_name):
- raise CTRexPacketBuildException(-11,("varible %s define twice ") % (var_name) );
+ raise CTRexPacketBuildException(-11,("variable %s define twice ") % (var_name) );
else:
vars[var_name]=1
+
+ # check that all write exits
+ for desc in obj.commands:
+ var_name = desc.get_var_ref()
+ if var_name :
+ if not vars.has_key(var_name):
+ raise CTRexPacketBuildException(-11,("variable %s does not exists ") % (var_name) );
desc.compile(self);
for desc in obj.commands: