small test cleanup, can isolate to a singular core test fixture

This commit is contained in:
Blake J. Harnden 2017-07-25 10:16:18 -07:00
parent 45a11f7586
commit f767c32643
8 changed files with 67 additions and 79 deletions

3
.gitignore vendored
View file

@ -23,3 +23,6 @@ stamp-h1
# sonarqube sonar-scanner # sonarqube sonar-scanner
.scannerwork .scannerwork
# ignore test coverage files
coverage.xml

View file

@ -528,13 +528,16 @@ class BasicRangeModel(WirelessModel):
with self.wlan._linked_lock: with self.wlan._linked_lock:
linked = self.wlan.linked(a, b) linked = self.wlan.linked(a, b)
logger.info("checking if link distance is out of range: %s > %s", d, self.range) logger.info("checking range netif1(%s) netif2(%s): linked(%s) actual(%s) > config(%s)",
a.name, b.name, linked, d, self.range)
if d > self.range: if d > self.range:
if linked: if linked:
logger.info("was linked, unlinking")
self.wlan.unlink(a, b) self.wlan.unlink(a, b)
self.sendlinkmsg(a, b, unlink=True) self.sendlinkmsg(a, b, unlink=True)
else: else:
if not linked: if not linked:
logger.info("was not linked, linking")
self.wlan.link(a, b) self.wlan.link(a, b)
self.sendlinkmsg(a, b) self.sendlinkmsg(a, b)
except KeyError: except KeyError:

View file

@ -6,3 +6,4 @@ sphinx==1.4.8
sphinx_rtd_theme==0.1.9 sphinx_rtd_theme==0.1.9
pytest==3.0.7 pytest==3.0.7
pytest-runner==2.11.1 pytest-runner==2.11.1
pytest-cov==2.5.1

View file

@ -27,8 +27,13 @@ setup(name="core-python",
install_requires=[ install_requires=[
"enum34" "enum34"
], ],
setup_requires=["pytest-runner"], setup_requires=[
tests_require=["pytest"], "pytest-runner"
],
tests_require=[
"pytest",
"pytest-cov"
],
description="Python components of CORE", description="Python components of CORE",
url="http://www.nrl.navy.mil/itd/ncs/products/core", url="http://www.nrl.navy.mil/itd/ncs/products/core",
author="Boeing Research & Technology", author="Boeing Research & Technology",

View file

@ -131,23 +131,6 @@ def session():
session_fixture = Session(1, persistent=True) session_fixture = Session(1, persistent=True)
session_fixture.master = True session_fixture.master = True
assert os.path.exists(session_fixture.session_dir) assert os.path.exists(session_fixture.session_dir)
yield session_fixture
# cleanup
print "shutting down session"
session_fixture.shutdown()
assert not os.path.exists(session_fixture.session_dir)
@pytest.fixture()
def session_emane():
# configure default nodes
node_map = nodemaps.CLASSIC_NODES
nodeutils.set_node_map(node_map)
# create and return session
session_fixture = Session(1, persistent=True)
assert os.path.exists(session_fixture.session_dir)
# load emane services # load emane services
quagga.load_services() quagga.load_services()
@ -178,8 +161,3 @@ def ip_prefix():
@pytest.fixture() @pytest.fixture()
def core(session, ip_prefix): def core(session, ip_prefix):
return Core(session, ip_prefix) return Core(session, ip_prefix)
@pytest.fixture()
def core_emane(session_emane, ip_prefix):
return Core(session_emane, ip_prefix)

View file

@ -139,8 +139,8 @@ class TestCore:
wlan_node.setmodel(BasicRangeModel, values) wlan_node.setmodel(BasicRangeModel, values)
# create nodes # create nodes
core.create_node("n1", services=EMANE_SERVICES, model="mdr") core.create_node("n1", position=(0, 0), services=EMANE_SERVICES, model="mdr")
core.create_node("n2", services=EMANE_SERVICES, model="mdr") core.create_node("n2", position=(0, 0), services=EMANE_SERVICES, model="mdr")
# add interfaces # add interfaces
interface_one = core.add_interface(wlan_node, "n1") interface_one = core.add_interface(wlan_node, "n1")
@ -149,10 +149,6 @@ class TestCore:
# link nodes in wlan # link nodes in wlan
core.link(wlan_node, interface_one, interface_two) core.link(wlan_node, interface_one, interface_two)
# mark node position as together
core.get_node("n1").setposition(0, 0)
core.get_node("n2").setposition(0, 0)
# instantiate session # instantiate session
core.session.instantiate() core.session.instantiate()
@ -176,8 +172,8 @@ class TestCore:
wlan_node.setmodel(BasicRangeModel, values) wlan_node.setmodel(BasicRangeModel, values)
# create nodes # create nodes
core.create_node("n1", services=EMANE_SERVICES, model="mdr") core.create_node("n1", position=(0, 0), services=EMANE_SERVICES, model="mdr")
core.create_node("n2", services=EMANE_SERVICES, model="mdr") core.create_node("n2", position=(0, 0), services=EMANE_SERVICES, model="mdr")
# add interfaces # add interfaces
interface_one = core.add_interface(wlan_node, "n1") interface_one = core.add_interface(wlan_node, "n1")
@ -196,8 +192,8 @@ class TestCore:
# assert node directories created # assert node directories created
core.assert_nodes() core.assert_nodes()
# ping n2 from n1 and assert failure # ping n2 from n1 and assert failure )
time.sleep(1) time.sleep(3)
status = core.ping("n1", "n2") status = core.ping("n1", "n2")
assert status assert status
@ -261,7 +257,7 @@ class TestCore:
stdout = core.iperf("n1", "n2") stdout = core.iperf("n1", "n2")
assert stdout assert stdout
value = float(stdout.split(',')[loss_index]) value = float(stdout.split(',')[loss_index])
assert 45 <= value <= 55 assert 40 <= value <= 60
def test_link_delay(self, core): def test_link_delay(self, core):
""" """

View file

@ -12,7 +12,7 @@ from core.emane.rfpipe import EmaneRfPipeModel
class TestGui: class TestGui:
def test_80211(self, core_emane): def test_80211(self, core):
""" """
Test emane 80211 model. Test emane 80211 model.
@ -20,31 +20,31 @@ class TestGui:
""" """
# create emane node for networking the core nodes # create emane node for networking the core nodes
emane_node = core_emane.session.add_object(name="emane", cls=EmaneNode) emane_node = core.session.add_object(name="emane", cls=EmaneNode)
emane_node.setposition(x=80, y=50) emane_node.setposition(x=80, y=50)
# set the emane model # set the emane model
core_emane.set_emane_model(emane_node, EmaneIeee80211abgModel) core.set_emane_model(emane_node, EmaneIeee80211abgModel)
# create nodes # create nodes
core_emane.create_node("n1", objid=1, position=(150, 150), services=EMANE_SERVICES, model="mdr") core.create_node("n1", objid=1, position=(150, 150), services=EMANE_SERVICES, model="mdr")
core_emane.create_node("n2", objid=2, position=(300, 150), services=EMANE_SERVICES, model="mdr") core.create_node("n2", objid=2, position=(300, 150), services=EMANE_SERVICES, model="mdr")
# add interfaces to nodes # add interfaces to nodes
core_emane.add_interface(emane_node, "n1") core.add_interface(emane_node, "n1")
core_emane.add_interface(emane_node, "n2") core.add_interface(emane_node, "n2")
# instantiate session # instantiate session
core_emane.session.instantiate() core.session.instantiate()
# assert node directories created # assert node directories created
core_emane.assert_nodes() core.assert_nodes()
# ping n2 from n1 and assert success # ping n2 from n1 and assert success
status = core_emane.ping("n1", "n2") status = core.ping("n1", "n2")
assert not status assert not status
def test_rfpipe(self, core_emane): def test_rfpipe(self, core):
""" """
Test emane 80211 model. Test emane 80211 model.
@ -52,31 +52,31 @@ class TestGui:
""" """
# create emane node for networking the core nodes # create emane node for networking the core nodes
emane_node = core_emane.session.add_object(name="emane", cls=EmaneNode) emane_node = core.session.add_object(name="emane", cls=EmaneNode)
emane_node.setposition(x=80, y=50) emane_node.setposition(x=80, y=50)
# set the emane model # set the emane model
core_emane.set_emane_model(emane_node, EmaneRfPipeModel) core.set_emane_model(emane_node, EmaneRfPipeModel)
# create nodes # create nodes
core_emane.create_node("n1", objid=1, position=(150, 150), services=EMANE_SERVICES, model="mdr") core.create_node("n1", objid=1, position=(150, 150), services=EMANE_SERVICES, model="mdr")
core_emane.create_node("n2", objid=2, position=(300, 150), services=EMANE_SERVICES, model="mdr") core.create_node("n2", objid=2, position=(300, 150), services=EMANE_SERVICES, model="mdr")
# add interfaces to nodes # add interfaces to nodes
core_emane.add_interface(emane_node, "n1") core.add_interface(emane_node, "n1")
core_emane.add_interface(emane_node, "n2") core.add_interface(emane_node, "n2")
# instantiate session # instantiate session
core_emane.session.instantiate() core.session.instantiate()
# assert node directories created # assert node directories created
core_emane.assert_nodes() core.assert_nodes()
# ping n2 from n1 and assert success # ping n2 from n1 and assert success
status = core_emane.ping("n1", "n2") status = core.ping("n1", "n2")
assert not status assert not status
def test_commeffect(self, core_emane): def test_commeffect(self, core):
""" """
Test emane 80211 model. Test emane 80211 model.
@ -84,11 +84,11 @@ class TestGui:
""" """
# create emane node for networking the core nodes # create emane node for networking the core nodes
emane_node = core_emane.session.add_object(name="emane", cls=EmaneNode) emane_node = core.session.add_object(name="emane", cls=EmaneNode)
emane_node.setposition(x=80, y=50) emane_node.setposition(x=80, y=50)
# set the emane model # set the emane model
core_emane.set_emane_model(emane_node, EmaneCommEffectModel) core.set_emane_model(emane_node, EmaneCommEffectModel)
# configure emane to enable default connectivity # configure emane to enable default connectivity
config_data = ConfigData( config_data = ConfigData(
@ -98,27 +98,27 @@ class TestGui:
data_types=(11,), data_types=(11,),
data_values="defaultconnectivitymode=1" data_values="defaultconnectivitymode=1"
) )
EmaneCommEffectModel.configure_emane(core_emane.session, config_data) EmaneCommEffectModel.configure_emane(core.session, config_data)
# create nodes # create nodes
core_emane.create_node("n1", objid=1, position=(150, 150), services=EMANE_SERVICES, model="mdr") core.create_node("n1", objid=1, position=(150, 150), services=EMANE_SERVICES, model="mdr")
core_emane.create_node("n2", objid=2, position=(300, 150), services=EMANE_SERVICES, model="mdr") core.create_node("n2", objid=2, position=(300, 150), services=EMANE_SERVICES, model="mdr")
# add interfaces to nodes # add interfaces to nodes
core_emane.add_interface(emane_node, "n1") core.add_interface(emane_node, "n1")
core_emane.add_interface(emane_node, "n2") core.add_interface(emane_node, "n2")
# instantiate session # instantiate session
core_emane.session.instantiate() core.session.instantiate()
# assert node directories created # assert node directories created
core_emane.assert_nodes() core.assert_nodes()
# ping n2 from n1 and assert success # ping n2 from n1 and assert success
status = core_emane.ping("n1", "n2") status = core.ping("n1", "n2")
assert not status assert not status
def test_bypass(self, core_emane): def test_bypass(self, core):
""" """
Test emane 80211 model. Test emane 80211 model.
@ -126,26 +126,26 @@ class TestGui:
""" """
# create emane node for networking the core nodes # create emane node for networking the core nodes
emane_node = core_emane.session.add_object(name="emane", cls=EmaneNode) emane_node = core.session.add_object(name="emane", cls=EmaneNode)
emane_node.setposition(x=80, y=50) emane_node.setposition(x=80, y=50)
# set the emane model # set the emane model
core_emane.set_emane_model(emane_node, EmaneBypassModel) core.set_emane_model(emane_node, EmaneBypassModel)
# create nodes # create nodes
core_emane.create_node("n1", objid=1, position=(150, 150), services=EMANE_SERVICES, model="mdr") core.create_node("n1", objid=1, position=(150, 150), services=EMANE_SERVICES, model="mdr")
core_emane.create_node("n2", objid=2, position=(300, 150), services=EMANE_SERVICES, model="mdr") core.create_node("n2", objid=2, position=(300, 150), services=EMANE_SERVICES, model="mdr")
# add interfaces to nodes # add interfaces to nodes
core_emane.add_interface(emane_node, "n1") core.add_interface(emane_node, "n1")
core_emane.add_interface(emane_node, "n2") core.add_interface(emane_node, "n2")
# instantiate session # instantiate session
core_emane.session.instantiate() core.session.instantiate()
# assert node directories created # assert node directories created
core_emane.assert_nodes() core.assert_nodes()
# ping n2 from n1 and assert success # ping n2 from n1 and assert success
status = core_emane.ping("n1", "n2") status = core.ping("n1", "n2")
assert not status assert not status

View file

@ -16,6 +16,8 @@ sonar.sourceEncoding=UTF-8
sonar.scm.provider=git sonar.scm.provider=git
# python adapter library # python adapter library
PythonLibrary.sonar.projectBaseDir=daemon/core PythonLibrary.sonar.projectBaseDir=daemon
PythonLibrary.sonar.language=py PythonLibrary.sonar.language=py
PythonLibrary.sonar.sources=./ PythonLibrary.sonar.sources=./core
PythonLibrary.sonar.tests=./tests
PythonLibrary.sonar.python.coverage.reportPath=coverage.xml