Skip to content

Commit

Permalink
add wwan reconnection test
Browse files Browse the repository at this point in the history
add wwan reconnection test
  • Loading branch information
stanley31huang committed Oct 8, 2024
1 parent d0fda12 commit afa8d64
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 16 deletions.
39 changes: 25 additions & 14 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 Expand Up @@ -453,25 +456,33 @@ def invoked(self):

class Resources:

def invoked(self):
def register_arguments(self):
parser = argparse.ArgumentParser()
parser.add_argument(
"--use-cli",
action="store_true",
help="Use mmcli for all calls rather than dbus",
)
args = parser.parse_args(sys.argv[2:])
return parser.parse_args(sys.argv[2:])

def invoked(self):
args = self.register_arguments()
if args.use_cli:
mm = MMCLI()
else:
mm = MMDbus()

for m in mm.get_modem_ids():
print("mm_id: {}".format(m))
print("hw_id: {}".format(mm.get_equipment_id(m)))
print("manufacturer: {}".format(mm.get_manufacturer(m)))
print("model: {}".format(mm.get_model_name(m)))
print("firmware_revision: {}".format(mm.get_firmware_revision(m)))
print("hardware_revision: {}".format(mm.get_hardware_revision(m)))
print(
"firmware_revision: {}".format(mm.get_firmware_revision(m))
)
print(
"hardware_revision: {}".format(mm.get_hardware_revision(m))
)
print()


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

0 comments on commit afa8d64

Please sign in to comment.