From 14a5d11c4e02341dee8f72501f457eb68af43575 Mon Sep 17 00:00:00 2001 From: "Blake J. Harnden" Date: Thu, 27 Jul 2017 14:59:40 -0700 Subject: [PATCH] parameterized emane tests, added tdma test, although it is currently failing --- daemon/core/emane/emanemanager.py | 4 +- daemon/tests/test_core.py | 2 +- daemon/tests/test_emane.py | 146 ++++++++---------------------- 3 files changed, 40 insertions(+), 112 deletions(-) diff --git a/daemon/core/emane/emanemanager.py b/daemon/core/emane/emanemanager.py index 84a82d39..fc393b7e 100644 --- a/daemon/core/emane/emanemanager.py +++ b/daemon/core/emane/emanemanager.py @@ -16,6 +16,7 @@ from core.emane.commeffect import EmaneCommEffectModel from core.emane.emanemodel import EmaneModel from core.emane.ieee80211abg import EmaneIeee80211abgModel from core.emane.rfpipe import EmaneRfPipeModel +from core.emane.tdma import EmaneTdmaModel from core.enumerations import ConfigDataTypes, NodeTypes from core.enumerations import ConfigFlags from core.enumerations import ConfigTlvs @@ -48,7 +49,8 @@ EMANE_MODELS = [ EmaneRfPipeModel, EmaneIeee80211abgModel, EmaneCommEffectModel, - EmaneBypassModel + EmaneBypassModel, + EmaneTdmaModel ] diff --git a/daemon/tests/test_core.py b/daemon/tests/test_core.py index 7c455663..e35c6415 100644 --- a/daemon/tests/test_core.py +++ b/daemon/tests/test_core.py @@ -21,8 +21,8 @@ from core.xml import xmlsession _XML_VERSIONS = ["0.0", "1.0"] _NODE_CLASSES = [nodes.PtpNet, nodes.HubNode, nodes.SwitchNode] -class TestCore: +class TestCore: @pytest.mark.parametrize("cls", _NODE_CLASSES) def test_nodes(self, core, cls): """ diff --git a/daemon/tests/test_emane.py b/daemon/tests/test_emane.py index 6ec826b6..d9b67eeb 100644 --- a/daemon/tests/test_emane.py +++ b/daemon/tests/test_emane.py @@ -1,6 +1,9 @@ """ Unit tests for testing with a CORE switch. """ + +import pytest + from conftest import EMANE_SERVICES from core.data import ConfigData @@ -9,14 +12,39 @@ from core.emane.commeffect import EmaneCommEffectModel from core.emane.ieee80211abg import EmaneIeee80211abgModel from core.emane.nodes import EmaneNode from core.emane.rfpipe import EmaneRfPipeModel +from core.emane.tdma import EmaneTdmaModel -class TestGui: - def test_80211(self, core): +def setup_commeffect(session, emane_node): + # configure emane to enable default connectivity + config_data = ConfigData( + node=emane_node.objid, + object="emane_commeffect", + type=2, + data_types=(11,), + data_values="defaultconnectivitymode=1" + ) + EmaneCommEffectModel.configure_emane(session, config_data) + + +_EMANE_MODELS = [ + (EmaneIeee80211abgModel, None), + (EmaneRfPipeModel, None), + (EmaneBypassModel, None), + (EmaneCommEffectModel, setup_commeffect), + (EmaneTdmaModel, None), +] + + +class TestEmane: + @pytest.mark.parametrize("model,setup", _EMANE_MODELS) + def test_models(self, core, model, setup): """ - Test emane 80211 model. + Test emane models within a basic network. :param conftest.Core core: core fixture to test with + :param model: emane model to test + :param func setup: setup function to configure emane node """ # create emane node for networking the core nodes @@ -24,113 +52,11 @@ class TestGui: emane_node.setposition(x=80, y=50) # set the emane model - core.set_emane_model(emane_node, EmaneIeee80211abgModel) - - # create nodes - 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.add_interface(emane_node, "n1") - core.add_interface(emane_node, "n2") - - # instantiate session - core.session.instantiate() - - # assert node directories created - core.assert_nodes() - - # ping n2 from n1 and assert success - status = core.ping("n1", "n2") - assert not status - - def test_rfpipe(self, core): - """ - Test emane 80211 model. - - :param conftest.Core core: core fixture to test with - """ - - # create emane node for networking the core nodes - emane_node = core.session.add_object(name="emane", cls=EmaneNode) - emane_node.setposition(x=80, y=50) - - # set the emane model - core.set_emane_model(emane_node, EmaneRfPipeModel) - - # create nodes - 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.add_interface(emane_node, "n1") - core.add_interface(emane_node, "n2") - - # instantiate session - core.session.instantiate() - - # assert node directories created - core.assert_nodes() - - # ping n2 from n1 and assert success - status = core.ping("n1", "n2") - assert not status - - def test_commeffect(self, core): - """ - Test emane 80211 model. - - :param conftest.Core core: core fixture to test with - """ - - # create emane node for networking the core nodes - emane_node = core.session.add_object(name="emane", cls=EmaneNode) - emane_node.setposition(x=80, y=50) - - # set the emane model - core.set_emane_model(emane_node, EmaneCommEffectModel) - - # configure emane to enable default connectivity - config_data = ConfigData( - node=emane_node.objid, - object="emane_commeffect", - type=2, - data_types=(11,), - data_values="defaultconnectivitymode=1" - ) - EmaneCommEffectModel.configure_emane(core.session, config_data) - - # create nodes - 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.add_interface(emane_node, "n1") - core.add_interface(emane_node, "n2") - - # instantiate session - core.session.instantiate() - - # assert node directories created - core.assert_nodes() - - # ping n2 from n1 and assert success - status = core.ping("n1", "n2") - assert not status - - def test_bypass(self, core): - """ - Test emane 80211 model. - - :param conftest.Core core: core fixture to test with - """ - - # create emane node for networking the core nodes - emane_node = core.session.add_object(name="emane", cls=EmaneNode) - emane_node.setposition(x=80, y=50) - - # set the emane model - core.set_emane_model(emane_node, EmaneBypassModel) + core.set_emane_model(emane_node, model) + + # run setup method, if needed + if setup: + setup(core.session, emane_node) # create nodes core.create_node("n1", objid=1, position=(150, 150), services=EMANE_SERVICES, model="mdr")