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

Extend the wwan connection tests to support multiple cycle connection tests (new) #1534

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
23 changes: 13 additions & 10 deletions providers/base/bin/wwan_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def _ping_test(if_name):

class ThreeGppConnection:

def invoked(self):
def register_argument(self):
parser = argparse.ArgumentParser()
parser.add_argument(
"hw_id", type=str, help="The hardware ID of the modem"
Expand All @@ -353,22 +353,25 @@ def invoked(self):
default=30,
help="delay before ping test",
)
args = parser.parse_args(sys.argv[2:])
return parser.parse_args(sys.argv[2:])

mm = MMCLI()
mm_id = mm.equipment_id_to_mm_id(args.hw_id)
wwan_control_if = mm.get_primary_port(mm_id)
def invoked(self):

args = self.register_argument()

ret_code = 1
try:
_create_3gpp_connection(wwan_control_if, args.apn)
_wwan_radio_on()
time.sleep(args.wwan_setup_time)
ret_code = _ping_test(args.wwan_net_if)
with WWANTestCtx(args.hw_id, True, True) as ctx:
wwan_control_if = ctx.mm_obj.get_primary_port(
str(ctx.modem_idx)
)
_create_3gpp_connection(wwan_control_if, args.apn)
time.sleep(args.wwan_setup_time)
ret_code = _ping_test(args.wwan_net_if)
except subprocess.SubprocessError:
pass
_destroy_3gpp_connection()
_wwan_radio_off()

sys.exit(ret_code)


Expand Down
81 changes: 81 additions & 0 deletions providers/base/tests/test_wwan_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,84 @@ def test_invoked_call_error(self, mock_arg, mock_mmctx, mock_run):
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)


class TestThreeGppConnectionTest(unittest.TestCase):

def test_register_argument(self):

sys.argv = [
"wwan_tests.py",
"3gpp-connection",
"hw_id",
"wwan_net_if",
"apn",
"30",
]
obj_3gppscan = wwan_tests.ThreeGppConnection()
ret_args = obj_3gppscan.register_argument()
self.assertEqual(ret_args.hw_id, "hw_id")
self.assertEqual(ret_args.wwan_net_if, "wwan_net_if")
self.assertEqual(ret_args.apn, "apn")
self.assertEqual(ret_args.wwan_setup_time, 30)

@patch("wwan_tests._ping_test")
@patch("wwan_tests._destroy_3gpp_connection")
@patch("wwan_tests._create_3gpp_connection")
@patch("wwan_tests.WWANTestCtx")
@patch("wwan_tests.ThreeGppConnection.register_argument")
def test_invoked_successfully(
self, mock_arg, mock_mmctx, mock_create_conn, mock_rm_conn, mock_ping
):
mock_arg.return_value = argparse.Namespace(
hw_id="2", wwan_net_if="wwan0", apn="internet", wwan_setup_time=0.1
)
mock_get_primary_port = Mock()
mmcli_instance = Mock()
mmcli_instance.modem_idx = "0"
mmcli_instance.mm_obj = Mock(get_primary_port=mock_get_primary_port)
mock_mmctx.return_value.__enter__.return_value = mmcli_instance
mock_ping.return_value = 0

with redirect_stdout(StringIO()):
with self.assertRaises(SystemExit) as context:
obj_3gppscan = wwan_tests.ThreeGppConnection()
obj_3gppscan.invoked()

mock_mmctx.assert_called_with("2", True, True)
self.assertEqual(mock_arg.call_count, 1)
self.assertEqual(mock_get_primary_port.call_count, 1)
self.assertEqual(mock_ping.call_count, 1)
self.assertEqual(mock_create_conn.call_count, 1)
self.assertEqual(mock_rm_conn.call_count, 1)
self.assertEqual(context.exception.code, 0)

@patch("wwan_tests._ping_test")
@patch("wwan_tests._destroy_3gpp_connection")
@patch("wwan_tests._create_3gpp_connection")
@patch("wwan_tests.WWANTestCtx")
@patch("wwan_tests.ThreeGppConnection.register_argument")
def test_invoked_failed_exit_code(
self, mock_arg, mock_mmctx, mock_create_conn, mock_rm_conn, mock_ping
):
mock_arg.return_value = argparse.Namespace(
hw_id="2", wwan_net_if="wwan0", apn="internet", wwan_setup_time=0.1
)
mock_get_primary_port = Mock()
mmcli_instance = Mock()
mmcli_instance.modem_idx = "0"
mmcli_instance.mm_obj = Mock(get_primary_port=mock_get_primary_port)
mock_mmctx.return_value.__enter__.return_value = mmcli_instance
mock_ping.return_value = 1

with redirect_stdout(StringIO()):
with self.assertRaises(SystemExit) as context:
obj_3gppscan = wwan_tests.ThreeGppConnection()
obj_3gppscan.invoked()

mock_mmctx.assert_called_with("2", True, True)
self.assertEqual(mock_arg.call_count, 1)
self.assertEqual(mock_ping.call_count, 1)
self.assertEqual(mock_create_conn.call_count, 1)
self.assertEqual(mock_rm_conn.call_count, 1)
self.assertEqual(context.exception.code, 1)
11 changes: 9 additions & 2 deletions providers/base/units/wwan/jobs.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ template-unit: job
id: wwan/gsm-connection-{manufacturer}-{model}-{hw_id}-auto
template-id: wwan/gsm-connection-manufacturer-model-hw_id-auto
_summary: Verify a GSM broadband modem can create a data connection
_template-summary: Verify a GSM broadband modem can create a data connection multiple times
_purpose:
Any modems discovered by the resource job that list GSM support
will be tested to ensure a data connection can be made.
Any modems discovered by the resource job that list GSM support
will be tested to ensure a data connection can be made.
plugin: shell
command:
BEGIN_CONNECTION_TEST_TS=$(date '+%Y-%m-%d %H:%M:%S')
Expand All @@ -56,6 +57,12 @@ requires:
manifest.has_wwan_module == 'True'
manifest.has_sim_card == 'True'
snap.name == 'modem-manager' or package.name == 'modemmanager'
_siblings:
[{{
"id": "wwan/gsm-reconnection-{manufacturer}-{model}-{hw_id}-auto",
"_summary": "Verify a GSM broadband modem can recreate a data connection",
"depends": "wwan/gsm-connection-{manufacturer}-{model}-{hw_id}-auto"
}}]

unit: template
template-resource: wwan_resource
Expand Down
1 change: 1 addition & 0 deletions providers/base/units/wwan/test-plan.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ include:
wwan/detect certification-status=blocker
wwan/3gpp-scan-manufacturer-model-hw_id-auto
wwan/gsm-connection-.*-auto certification-status=blocker
wwan/gsm-reconnection-.*-auto certification-status=blocker
wwan/check-sim-present-.*-auto
bootstrap_include:
wwan_resource
Expand Down
Loading