validation do not require the target attribute in yml
This commit is contained in:
parent
fc3a064ad4
commit
cdb954756f
@ -5,6 +5,12 @@ from mpTcptraceData import *
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
# to get a REPL:
|
||||||
|
#import code
|
||||||
|
#code.interact(local=locals())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# A checker runs tests, and a test is made of multiple validations
|
# A checker runs tests, and a test is made of multiple validations
|
||||||
|
|
||||||
|
|
||||||
@ -13,7 +19,10 @@ import numpy as np
|
|||||||
# as argument a value from which to extract the value to compare or the value itself
|
# as argument a value from which to extract the value to compare or the value itself
|
||||||
class Validation:
|
class Validation:
|
||||||
def __init__(self, yml):
|
def __init__(self, yml):
|
||||||
|
if "target" in yml:
|
||||||
self.compared=yml["target"]
|
self.compared=yml["target"]
|
||||||
|
else:
|
||||||
|
self.compared=None
|
||||||
def name(self):
|
def name(self):
|
||||||
return self.__class__.__name__
|
return self.__class__.__name__
|
||||||
def validate(self,value):
|
def validate(self,value):
|
||||||
@ -38,9 +47,11 @@ class ExactValueValidation(Validation):
|
|||||||
self.value = value
|
self.value = value
|
||||||
return self.compared==value
|
return self.compared==value
|
||||||
|
|
||||||
# individual flow validation (specific)
|
# individual flow validations (used with FlowsTest)
|
||||||
# gets flow_spec = (index, flows) where index is the index of the flow to validate, and flows is the array of flows
|
###################################################
|
||||||
|
|
||||||
class MinDelayValidation(Validation):
|
class MinDelayValidation(Validation):
|
||||||
|
# receives flow_spec = (index, flows) where index is the index of the flow to validate, and flows is the array of flows
|
||||||
def validate(self, flow_spec):
|
def validate(self, flow_spec):
|
||||||
(yml,trace) = flow_spec
|
(yml,trace) = flow_spec
|
||||||
index=yml["index"]
|
index=yml["index"]
|
||||||
@ -48,12 +59,11 @@ class MinDelayValidation(Validation):
|
|||||||
self.value = val
|
self.value = val
|
||||||
return self.compared<=val
|
return self.compared<=val
|
||||||
|
|
||||||
# individual flow validation (specific)
|
class MinDelayBetweenValidation(Validation):
|
||||||
# gets flow_spec = ( [ index0, index1] , flows) where:
|
# gets flow_spec = ( [ index0, index1] , flows) where:
|
||||||
# - index0 is the index of the flow taken as reference for timing
|
# - index0 is the index of the flow taken as reference for timing
|
||||||
# - index1 is the flow for which we want to validate the timing
|
# - index1 is the flow for which we want to validate the timing
|
||||||
# - flows is the array of flows
|
# - flows is the array of flows
|
||||||
class MinDelayBetweenValidation(Validation):
|
|
||||||
def validate(self, flow_spec):
|
def validate(self, flow_spec):
|
||||||
(yml ,trace) = flow_spec
|
(yml ,trace) = flow_spec
|
||||||
[index0, index1] = yml["index"]
|
[index0, index1] = yml["index"]
|
||||||
@ -93,17 +103,23 @@ class AttributeMaximumRatioValidation(AttributeValidation):
|
|||||||
self.value = float(self.val1)/float(self.val0)
|
self.value = float(self.val1)/float(self.val0)
|
||||||
return self.compared>=self.value
|
return self.compared>=self.value
|
||||||
|
|
||||||
|
# mptcptrace csv validations
|
||||||
|
############################
|
||||||
|
|
||||||
|
# validates all values passed have increasing values
|
||||||
|
# it is the Tester's get_tested_value method that does the work
|
||||||
|
# to extract the values list from the trace.
|
||||||
class IncreasingValueValidation(AttributeValidation):
|
class IncreasingValueValidation(AttributeValidation):
|
||||||
def validate(self, values):
|
def validate(self, values):
|
||||||
previous = 0
|
previous = 0
|
||||||
for i,v in enumerate(values):
|
for i,v in enumerate(values):
|
||||||
#print i, "{:10.6f}".format(previous), "{:10.6f}".format(v)
|
#print i, "{:10.6f}".format(previous), "{:10.6f}".format(v)
|
||||||
if v<previous:
|
if v<previous:
|
||||||
self.value=i # index of error row
|
self.value= "row " + str(i) # index of error row
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
previous=v
|
previous=v
|
||||||
return self.compared>=self.value
|
return True
|
||||||
|
|
||||||
|
|
||||||
class Tester:
|
class Tester:
|
||||||
@ -119,11 +135,16 @@ class Tester:
|
|||||||
klass_name=val["name"].title().replace("_","")+"Validation"
|
klass_name=val["name"].title().replace("_","")+"Validation"
|
||||||
tester_klass=globals()[klass_name]
|
tester_klass=globals()[klass_name]
|
||||||
tester = tester_klass(val)
|
tester = tester_klass(val)
|
||||||
|
if "target" in val:
|
||||||
|
target=val["target"]
|
||||||
|
else:
|
||||||
|
target=None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if tester.validate(tested_value):
|
if tester.validate(tested_value):
|
||||||
self.logs=self.logs+ " " + " OK :" + val["desc"] +" - " + tester.name()+ " value : " + str(tester.value) +" vs " + str(val["target"]) + "\n"
|
self.logs=self.logs+ " " + " OK :" + val["desc"] +" - " + tester.name()+ " value : " + str(tester.value) + ("" if target==None else " vs target " + str(val["target"])) + "\n"
|
||||||
else:
|
else:
|
||||||
self.logs=self.logs+ " " + " FAIL:" + val["desc"] +" - " + tester.name()+ " value : " + str(tester.value) +" vs " + str(val["target"]) + "\n"
|
self.logs=self.logs+ " " + " FAIL:" + val["desc"] +" - " + tester.name()+ " value : " + str(tester.value) + ("" if target==None else " vs target " + str(val["target"])) + "\n"
|
||||||
is_ok = False
|
is_ok = False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logs=self.logs+ ("" if self.logs=="" else "\n ")+ " EXCP:" + val["desc"] +" - " + tester.name()+ " " + str(e) + "\n"
|
self.logs=self.logs+ ("" if self.logs=="" else "\n ")+ " EXCP:" + val["desc"] +" - " + tester.name()+ " " + str(e) + "\n"
|
||||||
@ -160,12 +181,10 @@ class FlowsTest(TcptraceTest):
|
|||||||
class MptcptraceTest(Tester):
|
class MptcptraceTest(Tester):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
import code
|
|
||||||
# get_tested_value returns the number of flows
|
# get_tested_value returns the number of flows
|
||||||
class ColumnValuesTest(TcptraceTest):
|
class ColumnValuesTest(TcptraceTest):
|
||||||
def get_tested_value(self, yml):
|
def get_tested_value(self, yml):
|
||||||
a = self.trace.get(yml["csv"])
|
a = self.trace.get(yml["csv"])
|
||||||
code.interact(local=locals())
|
|
||||||
return a[:,yml["column"]]
|
return a[:,yml["column"]]
|
||||||
|
|
||||||
class Checker:
|
class Checker:
|
||||||
|
@ -4,7 +4,6 @@ mptcptrace:
|
|||||||
- name: "increasing_value"
|
- name: "increasing_value"
|
||||||
csv: "c2s_seq_1"
|
csv: "c2s_seq_1"
|
||||||
column: 2
|
column: 2
|
||||||
target: irrelevant
|
|
||||||
desc: "dummy: check sequence numbers grow"
|
desc: "dummy: check sequence numbers grow"
|
||||||
tcptrace:
|
tcptrace:
|
||||||
- test: "number_of_flows"
|
- test: "number_of_flows"
|
||||||
@ -52,6 +51,6 @@ tcptrace:
|
|||||||
index:
|
index:
|
||||||
- 0
|
- 0
|
||||||
- 1
|
- 1
|
||||||
# 5%
|
# flows[1].packets_a2b/flows[2].packets_a2b < 5%
|
||||||
target: 0.05
|
target: 0.05
|
||||||
desc: "a->b packet ration flow 2 compard to flow1"
|
desc: "a->b packet ration flow 2 compard to flow1"
|
||||||
|
Loading…
Reference in New Issue
Block a user