Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change bmv2 test runner to run bmv2 model and CLI from build tree if … #362

Merged
merged 1 commit into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions backends/bmv2/bmv2stf.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ class Local(object):
# object to hold local vars accessable to nested functions
pass

def FindExe(dirname, exe):
dir = os.getcwd()
while len(dir) > 1:
if os.path.isdir(os.path.join(dir, dirname)):
rv = None
rv_time = 0
for dName, sdName, fList in os.walk(os.path.join(dir, dirname)):
if exe in fList:
n=os.path.join(dName, exe)
if os.path.isfile(n) and os.access(n, os.X_OK):
n_time = os.path.getmtime(n)
if n_time > rv_time:
rv = n
rv_time = n_time
if rv is not None:
return rv
dir = os.path.dirname(dir)
return exe

def run_timeout(options, args, timeout, stderr):
if options.verbose:
print("Executing ", " ".join(args))
Expand Down Expand Up @@ -473,7 +492,8 @@ def run(self):
thriftPort = str(9090 + rand)

try:
runswitch = ["simple_switch", "--log-file", self.switchLogFile, "--log-flush",
runswitch = [FindExe("behavioral-model", "simple_switch"),
"--log-file", self.switchLogFile, "--log-flush",
"--use-files", str(wait), "--thrift-port", thriftPort,
"--device-id", str(rand)] + self.interfaceArgs() + ["../" + self.jsonfile]
if self.options.verbose:
Expand All @@ -499,7 +519,7 @@ def run(self):
# need to wait if there are none
time.sleep(0.5)

runcli = ["simple_switch_CLI", "--thrift-port", thriftPort]
runcli = [FindExe("behavioral-model", "simple_switch_CLI"), "--thrift-port", thriftPort]
if self.options.verbose:
print("Running", " ".join(runcli))
cli = subprocess.Popen(runcli, cwd=self.folder, stdin=subprocess.PIPE)
Expand Down
94 changes: 0 additions & 94 deletions backends/bmv2/run-bmv2-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,6 @@ def usage(options):
print(" -f: replace reference outputs with newly generated ones")
print(" -observation-log <file>: save packet output to <file>")

def ByteToHex(byteStr):
return ''.join( [ "%02X " % ord( x ) for x in byteStr ] ).strip()

def HexToByte(hexStr):
bytes = []
hexStr = ''.join( hexStr.split(" ") )
for i in range(0, len(hexStr), 2):
bytes.append( chr( int (hexStr[i:i+2], 16 ) ) )
return ''.join( bytes )

def isError(p4filename):
# True if the filename represents a p4 program that should fail
return "_errors" in p4filename
Expand Down Expand Up @@ -160,84 +150,6 @@ def target():

timeout = 10 * 60

def compare_files(options, produced, expected):
if options.replace:
if options.verbose:
print("Saving new version of ", expected)
shutil.copy2(produced, expected)
return SUCCESS

if options.verbose:
print("Comparing", produced, "and", expected)
diff = difflib.Differ().compare(open(produced).readlines(), open(expected).readlines())
result = SUCCESS

marker = re.compile("\?[ \t\+]*");
ignoreNextMarker = False
message = ""
for l in diff:
if l.startswith("- #include") or l.startswith("+ #include"):
# These can differ because the paths change
ignoreNextMarker = True
continue
if ignoreNextMarker:
ignoreNextMarker = False
if marker.match(l):
continue
if l[0] == ' ': continue
result = FAILURE
message += l

if message is not "":
print("Files ", produced, " and ", expected, " differ:", file=sys.stderr)
print(message, file=sys.stderr)

return result

class ConcurrentInteger(object):
# Generates exclusive integers in a range 0-max
# in a way which is safe across multiple processes.
# It uses a simple form of locking using folder names.
# This is necessary because this script may be invoked
# concurrently many times by make, and we need the many simulator instances
# to use different port numbers.
def __init__(self, folder, max):
self.folder = folder
self.max = max
def lockName(self, value):
return "lock_" + str(value)
def release(self, value):
os.rmdir(self.lockName(value))
def generate(self):
# try 10 times
for i in range(0, 10):
index = random.randint(0, self.max)
file = self.lockName(index)
try:
os.makedirs(file)
return index
except:
time.sleep(1)
continue
return None

def check_generated_files(options, tmpdir, expecteddir):
files = os.listdir(tmpdir)
for file in files:
if options.verbose:
print("Checking", file)
produced = tmpdir + "/" + file
expected = expecteddir + "/" + file
if not os.path.isfile(expected):
if options.verbose:
print("Expected file does not exist; creating", expected)
shutil.copy2(produced, expected)
else:
result = compare_files(options, produced, expected)
if result != SUCCESS:
return result
return SUCCESS

def run_model(options, tmpdir, jsonfile):
if not options.hasBMv2:
return SUCCESS
Expand Down Expand Up @@ -310,12 +222,6 @@ def process_file(options, argv):
shutil.rmtree(tmpdir)
return result

def isdir(path):
try:
return stat.S_ISDIR(os.stat(path).st_mode)
except OSError:
return False;

######################### main

def main(argv):
Expand Down