diff --git a/.gitignore b/.gitignore index 7caac1d1..448f711a 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ stamp-h1 # sonarqube sonar-scanner .scannerwork + +# ignore test coverage files +coverage.xml diff --git a/daemon/core/mobility.py b/daemon/core/mobility.py index 6cb7f74e..1bad3617 100644 --- a/daemon/core/mobility.py +++ b/daemon/core/mobility.py @@ -528,13 +528,16 @@ class BasicRangeModel(WirelessModel): with self.wlan._linked_lock: 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 linked: + logger.info("was linked, unlinking") self.wlan.unlink(a, b) self.sendlinkmsg(a, b, unlink=True) else: if not linked: + logger.info("was not linked, linking") self.wlan.link(a, b) self.sendlinkmsg(a, b) except KeyError: diff --git a/daemon/requirements.txt b/daemon/requirements.txt index 897df186..9aa8fc3c 100644 --- a/daemon/requirements.txt +++ b/daemon/requirements.txt @@ -6,3 +6,4 @@ sphinx==1.4.8 sphinx_rtd_theme==0.1.9 pytest==3.0.7 pytest-runner==2.11.1 +pytest-cov==2.5.1 diff --git a/daemon/setup.py b/daemon/setup.py index e610ab86..fdaaf62b 100644 --- a/daemon/setup.py +++ b/daemon/setup.py @@ -27,8 +27,13 @@ setup(name="core-python", install_requires=[ "enum34" ], - setup_requires=["pytest-runner"], - tests_require=["pytest"], + setup_requires=[ + "pytest-runner" + ], + tests_require=[ + "pytest", + "pytest-cov" + ], description="Python components of CORE", url="http://www.nrl.navy.mil/itd/ncs/products/core", author="Boeing Research & Technology", diff --git a/daemon/tests/conftest.py b/daemon/tests/conftest.py index 4c268ce5..bc8350e3 100644 --- a/daemon/tests/conftest.py +++ b/daemon/tests/conftest.py @@ -131,23 +131,6 @@ def session(): session_fixture = Session(1, persistent=True) session_fixture.master = True 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 quagga.load_services() @@ -178,8 +161,3 @@ def ip_prefix(): @pytest.fixture() def core(session, ip_prefix): return Core(session, ip_prefix) - - -@pytest.fixture() -def core_emane(session_emane, ip_prefix): - return Core(session_emane, ip_prefix) diff --git a/daemon/tests/test_core.py b/daemon/tests/test_core.py index 99ef587d..dce645d7 100644 --- a/daemon/tests/test_core.py +++ b/daemon/tests/test_core.py @@ -139,8 +139,8 @@ class TestCore: wlan_node.setmodel(BasicRangeModel, values) # create nodes - core.create_node("n1", services=EMANE_SERVICES, model="mdr") - core.create_node("n2", services=EMANE_SERVICES, model="mdr") + core.create_node("n1", position=(0, 0), services=EMANE_SERVICES, model="mdr") + core.create_node("n2", position=(0, 0), services=EMANE_SERVICES, model="mdr") # add interfaces interface_one = core.add_interface(wlan_node, "n1") @@ -149,10 +149,6 @@ class TestCore: # link nodes in wlan 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 core.session.instantiate() @@ -176,8 +172,8 @@ class TestCore: wlan_node.setmodel(BasicRangeModel, values) # create nodes - core.create_node("n1", services=EMANE_SERVICES, model="mdr") - core.create_node("n2", services=EMANE_SERVICES, model="mdr") + core.create_node("n1", position=(0, 0), services=EMANE_SERVICES, model="mdr") + core.create_node("n2", position=(0, 0), services=EMANE_SERVICES, model="mdr") # add interfaces interface_one = core.add_interface(wlan_node, "n1") @@ -196,8 +192,8 @@ class TestCore: # assert node directories created core.assert_nodes() - # ping n2 from n1 and assert failure - time.sleep(1) + # ping n2 from n1 and assert failure ) + time.sleep(3) status = core.ping("n1", "n2") assert status @@ -261,7 +257,7 @@ class TestCore: stdout = core.iperf("n1", "n2") assert stdout value = float(stdout.split(',')[loss_index]) - assert 45 <= value <= 55 + assert 40 <= value <= 60 def test_link_delay(self, core): """ diff --git a/daemon/tests/test_emane.py b/daemon/tests/test_emane.py index 819c05d3..6ec826b6 100644 --- a/daemon/tests/test_emane.py +++ b/daemon/tests/test_emane.py @@ -12,7 +12,7 @@ from core.emane.rfpipe import EmaneRfPipeModel class TestGui: - def test_80211(self, core_emane): + def test_80211(self, core): """ Test emane 80211 model. @@ -20,31 +20,31 @@ class TestGui: """ # 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) # set the emane model - core_emane.set_emane_model(emane_node, EmaneIeee80211abgModel) + core.set_emane_model(emane_node, EmaneIeee80211abgModel) # create nodes - core_emane.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("n1", objid=1, position=(150, 150), services=EMANE_SERVICES, model="mdr") + core.create_node("n2", objid=2, position=(300, 150), services=EMANE_SERVICES, model="mdr") # add interfaces to nodes - core_emane.add_interface(emane_node, "n1") - core_emane.add_interface(emane_node, "n2") + core.add_interface(emane_node, "n1") + core.add_interface(emane_node, "n2") # instantiate session - core_emane.session.instantiate() + core.session.instantiate() # assert node directories created - core_emane.assert_nodes() + core.assert_nodes() # ping n2 from n1 and assert success - status = core_emane.ping("n1", "n2") + status = core.ping("n1", "n2") assert not status - def test_rfpipe(self, core_emane): + def test_rfpipe(self, core): """ Test emane 80211 model. @@ -52,31 +52,31 @@ class TestGui: """ # 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) # set the emane model - core_emane.set_emane_model(emane_node, EmaneRfPipeModel) + core.set_emane_model(emane_node, EmaneRfPipeModel) # create nodes - core_emane.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("n1", objid=1, position=(150, 150), services=EMANE_SERVICES, model="mdr") + core.create_node("n2", objid=2, position=(300, 150), services=EMANE_SERVICES, model="mdr") # add interfaces to nodes - core_emane.add_interface(emane_node, "n1") - core_emane.add_interface(emane_node, "n2") + core.add_interface(emane_node, "n1") + core.add_interface(emane_node, "n2") # instantiate session - core_emane.session.instantiate() + core.session.instantiate() # assert node directories created - core_emane.assert_nodes() + core.assert_nodes() # ping n2 from n1 and assert success - status = core_emane.ping("n1", "n2") + status = core.ping("n1", "n2") assert not status - def test_commeffect(self, core_emane): + def test_commeffect(self, core): """ Test emane 80211 model. @@ -84,11 +84,11 @@ class TestGui: """ # 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) # 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 config_data = ConfigData( @@ -98,27 +98,27 @@ class TestGui: data_types=(11,), data_values="defaultconnectivitymode=1" ) - EmaneCommEffectModel.configure_emane(core_emane.session, config_data) + EmaneCommEffectModel.configure_emane(core.session, config_data) # create nodes - core_emane.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("n1", objid=1, position=(150, 150), services=EMANE_SERVICES, model="mdr") + core.create_node("n2", objid=2, position=(300, 150), services=EMANE_SERVICES, model="mdr") # add interfaces to nodes - core_emane.add_interface(emane_node, "n1") - core_emane.add_interface(emane_node, "n2") + core.add_interface(emane_node, "n1") + core.add_interface(emane_node, "n2") # instantiate session - core_emane.session.instantiate() + core.session.instantiate() # assert node directories created - core_emane.assert_nodes() + core.assert_nodes() # ping n2 from n1 and assert success - status = core_emane.ping("n1", "n2") + status = core.ping("n1", "n2") assert not status - def test_bypass(self, core_emane): + def test_bypass(self, core): """ Test emane 80211 model. @@ -126,26 +126,26 @@ class TestGui: """ # 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) # set the emane model - core_emane.set_emane_model(emane_node, EmaneBypassModel) + core.set_emane_model(emane_node, EmaneBypassModel) # create nodes - core_emane.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("n1", objid=1, position=(150, 150), services=EMANE_SERVICES, model="mdr") + core.create_node("n2", objid=2, position=(300, 150), services=EMANE_SERVICES, model="mdr") # add interfaces to nodes - core_emane.add_interface(emane_node, "n1") - core_emane.add_interface(emane_node, "n2") + core.add_interface(emane_node, "n1") + core.add_interface(emane_node, "n2") # instantiate session - core_emane.session.instantiate() + core.session.instantiate() # assert node directories created - core_emane.assert_nodes() + core.assert_nodes() # ping n2 from n1 and assert success - status = core_emane.ping("n1", "n2") + status = core.ping("n1", "n2") assert not status diff --git a/sonar-project.properties b/sonar-project.properties index d2e0867e..d579815b 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -16,6 +16,8 @@ sonar.sourceEncoding=UTF-8 sonar.scm.provider=git # python adapter library -PythonLibrary.sonar.projectBaseDir=daemon/core +PythonLibrary.sonar.projectBaseDir=daemon PythonLibrary.sonar.language=py -PythonLibrary.sonar.sources=./ +PythonLibrary.sonar.sources=./core +PythonLibrary.sonar.tests=./tests +PythonLibrary.sonar.python.coverage.reportPath=coverage.xml