merge with tip

This commit is contained in:
Tom Henderson
2008-09-15 06:11:38 -07:00
4 changed files with 81 additions and 25 deletions

View File

@@ -47,14 +47,14 @@ def main(argv):
#
# Explicitly create the nodes required by the topology(shown above).
#
print "Create nodes."
#print "Create nodes."
terminals = ns3.NodeContainer()
terminals.Create(4)
csmaSwitch = ns3.NodeContainer()
csmaSwitch.Create(1)
print "Build Topology"
#print "Build Topology"
csma = ns3.CsmaHelper()
csma.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(5000000)))
csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)))
@@ -83,7 +83,7 @@ def main(argv):
# We've got the "hardware" in place. Now we need to add IP addresses.
#
print "Assign IP Addresses."
#print "Assign IP Addresses."
ipv4 = ns3.Ipv4AddressHelper()
ipv4.SetBase(ns3.Ipv4Address("10.1.1.0"), ns3.Ipv4Mask("255.255.255.0"))
ipv4.Assign(terminalDevices)
@@ -91,7 +91,7 @@ def main(argv):
#
# Create an OnOff application to send UDP datagrams from node zero to node 1.
#
print "Create Applications."
#print "Create Applications."
port = 9 # Discard port(RFC 863)
onoff = ns3.OnOffHelper("ns3::UdpSocketFactory",
@@ -142,10 +142,10 @@ def main(argv):
#
# Now, do the actual simulation.
#
print "Run Simulation."
#print "Run Simulation."
ns3.Simulator.Run()
ns3.Simulator.Destroy()
print "Done."
#print "Done."

View File

@@ -0,0 +1,16 @@
#! /usr/bin/env python
"""Generic trace-comparison-type regression test."""
import os
import sys
import tracediff
def run(verbose, generate, refDirName):
"""Execute a test."""
if tracediff.env['ENABLE_PYTHON_BINDINGS']:
return tracediff.run_test(verbose, generate, refDirName,
"csma-bridge", pyscript=os.path.join('examples', 'csma-bridge.py'))
else:
print >> sys.stderr, "Skipping csma-bridge: Python bindings not available."
raise NotImplementedError

View File

@@ -9,4 +9,4 @@ import tracediff
def run(verbose, generate, refDirName):
"""Execute a test."""
return tracediff.run_test(verbose, generate, refDirName, "wifi-wired-bridging", "--SendIp=0")
return tracediff.run_test(verbose, generate, refDirName, "wifi-wired-bridging", ["--SendIp=0"])

76
wscript
View File

@@ -820,7 +820,26 @@ class Regression(object):
self.testdir = testdir
self.env = Params.g_build.env_of_name('default')
def run_test(self, verbose, generate, refDirName, testName, *arguments):
def run_test(self, verbose, generate, refDirName, testName, arguments=[], pyscript=None):
"""
@param verbose: enable verbose execution
@param generate: generate new traces instead of comparing with the reference
@param refDirName: name of the base directory containing reference traces
@param testName: name of the test
@arguments: list of extra parameters to pass to the program to be tested
@pyscript: if not None, the test is written in Python and this
parameter contains the path to the python script, relative to
the project root dir
"""
if not isinstance(arguments, list):
raise TypeError
refTestDirName = os.path.join(refDirName, (testName + ".ref"))
if not os.path.exists(refDirName):
@@ -832,12 +851,20 @@ class Regression(object):
print "creating new " + refTestDirName
os.mkdir(refTestDirName)
Params.g_options.cwd_launch = refTestDirName
tmpl = "%s"
for arg in arguments:
tmpl = tmpl + " " + arg
run_program(testName, tmpl)
if pyscript is None:
Params.g_options.cwd_launch = refTestDirName
tmpl = "%s"
for arg in arguments:
tmpl = tmpl + " " + arg
run_program(testName, tmpl)
else:
argv = [self.env['PYTHON'], os.path.join('..', '..', '..', *os.path.split(pyscript))] + arguments
before = os.getcwd()
os.chdir(refTestDirName)
try:
_run_argv(argv)
finally:
os.chdir(before)
print "Remember to commit " + refTestDirName
return 0
else:
@@ -850,13 +877,23 @@ class Regression(object):
#os.system("./waf --cwd regression/traces --run " +
# testName + " > /dev/null 2>&1")
Params.g_options.cwd_launch = "traces"
run_program(testName, command_template=get_command_template(*arguments))
if pyscript is None:
Params.g_options.cwd_launch = "traces"
run_program(testName, command_template=get_command_template(*arguments))
else:
argv = [self.env['PYTHON'], os.path.join('..', '..', *os.path.split(pyscript))] + arguments
before = os.getcwd()
os.chdir("traces")
try:
_run_argv(argv)
finally:
os.chdir(before)
if verbose:
#diffCmd = "diff traces " + refTestDirName + " | head"
diffCmd = subprocess.Popen([self.env['DIFF'], "traces", refTestDirName],
stdout=dev_null())
stdout=subprocess.PIPE)
headCmd = subprocess.Popen("head", stdin=diffCmd.stdout)
rc2 = headCmd.wait()
diffCmd.stdout.close()
@@ -943,15 +980,18 @@ def run_regression():
bad = []
for test in tests:
result = _run_regression_test(test)
if result == 0:
if Params.g_options.regression_generate:
print "GENERATE " + test
try:
result = _run_regression_test(test)
if result == 0:
if Params.g_options.regression_generate:
print "GENERATE " + test
else:
print "PASS " + test
else:
print "PASS " + test
else:
bad.append(test)
print "FAIL " + test
bad.append(test)
print "FAIL " + test
except NotImplementedError:
print "SKIP " + test
return len(bad) > 0