From c070b9015ec8f824cd607b2a3cd0e139ba69b020 Mon Sep 17 00:00:00 2001 From: Daniele Palmas Date: Wed, 25 Jun 2025 11:19:16 +0200 Subject: [PATCH] test,modem-helpers-qmi: add unit tests for bands Signed-off-by: Daniele Palmas --- src/tests/test-modem-helpers-qmi.c | 153 +++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/src/tests/test-modem-helpers-qmi.c b/src/tests/test-modem-helpers-qmi.c index 576beb68..5d6f2b9c 100644 --- a/src/tests/test-modem-helpers-qmi.c +++ b/src/tests/test-modem-helpers-qmi.c @@ -1929,6 +1929,154 @@ test_registration_state_from_qmi_system_info_5g_5gs_home (void) MM_MODEM_ACCESS_TECHNOLOGY_5GNR); } +/*****************************************************************************/ +/* Test modem bands helpers */ + +static void +test_supported_bands_eutran_telit_fn990 (void) +{ + g_autoptr(GArray) mm_bands_arr = NULL; + g_autoptr(GArray) mm_bands_arr_expected = NULL; + g_autoptr(GArray) extended_qmi_lte_bands = NULL; + static const guint16 qmi_bands[] = { + 1, 2, 3, 4, 5, 6, 7, 8, + 12, 13, 14, 17, 18, 19, 20, 25, + 26, 28, 29, 30, 32, 34, 38, 39, + 40, 41, 42, 43, 46, 48, 66, 71, + }; + static const MMModemBand mm_bands[] = { + MM_MODEM_BAND_EUTRAN_1, MM_MODEM_BAND_EUTRAN_2, MM_MODEM_BAND_EUTRAN_3, MM_MODEM_BAND_EUTRAN_4, + MM_MODEM_BAND_EUTRAN_5, MM_MODEM_BAND_EUTRAN_6, MM_MODEM_BAND_EUTRAN_7, MM_MODEM_BAND_EUTRAN_8, + MM_MODEM_BAND_EUTRAN_12, MM_MODEM_BAND_EUTRAN_13, MM_MODEM_BAND_EUTRAN_14, MM_MODEM_BAND_EUTRAN_17, + MM_MODEM_BAND_EUTRAN_18, MM_MODEM_BAND_EUTRAN_19, MM_MODEM_BAND_EUTRAN_20, MM_MODEM_BAND_EUTRAN_25, + MM_MODEM_BAND_EUTRAN_26, MM_MODEM_BAND_EUTRAN_28, MM_MODEM_BAND_EUTRAN_29, MM_MODEM_BAND_EUTRAN_30, + MM_MODEM_BAND_EUTRAN_32, MM_MODEM_BAND_EUTRAN_34, MM_MODEM_BAND_EUTRAN_38, MM_MODEM_BAND_EUTRAN_39, + MM_MODEM_BAND_EUTRAN_40, MM_MODEM_BAND_EUTRAN_41, MM_MODEM_BAND_EUTRAN_42, MM_MODEM_BAND_EUTRAN_43, + MM_MODEM_BAND_EUTRAN_46, MM_MODEM_BAND_EUTRAN_48, MM_MODEM_BAND_EUTRAN_66, MM_MODEM_BAND_EUTRAN_71, + }; + + extended_qmi_lte_bands = g_array_sized_new (FALSE, FALSE, sizeof (guint16), G_N_ELEMENTS (qmi_bands)); + mm_bands_arr_expected = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), G_N_ELEMENTS (mm_bands)); + g_array_append_vals (mm_bands_arr_expected, &mm_bands, G_N_ELEMENTS (mm_bands)); + g_array_append_vals (extended_qmi_lte_bands, &qmi_bands, G_N_ELEMENTS (qmi_bands)); + + mm_bands_arr = mm_modem_bands_from_qmi_band_capabilities (0, 0, extended_qmi_lte_bands, NULL, NULL); + + g_assert_cmpmem ( + mm_bands_arr->data, mm_bands_arr->len * sizeof (MMModemBand), + mm_bands_arr_expected->data, mm_bands_arr_expected->len * sizeof (MMModemBand) + ); +} + +static void +test_supported_bands_cdma_generic (void) +{ + g_autoptr(GArray) mm_bands_arr = NULL; + g_autoptr(GArray) mm_bands_arr_expected = NULL; + static const MMModemBand mm_bands[] = { + MM_MODEM_BAND_CDMA_BC0, MM_MODEM_BAND_CDMA_BC3, MM_MODEM_BAND_CDMA_BC12, MM_MODEM_BAND_CDMA_BC14, + MM_MODEM_BAND_CDMA_BC17, MM_MODEM_BAND_CDMA_BC19, + }; + QmiDmsBandCapability cdma_bands = ( + QMI_DMS_BAND_CAPABILITY_BC_0_A_SYSTEM | QMI_DMS_BAND_CAPABILITY_BC_3_A_SYSTEM | + QMI_DMS_BAND_CAPABILITY_BC_12 | QMI_DMS_BAND_CAPABILITY_BC_14 | + QMI_DMS_BAND_CAPABILITY_BC_17 | QMI_DMS_BAND_CAPABILITY_BC_19 + ); + + mm_bands_arr_expected = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), G_N_ELEMENTS (mm_bands)); + g_array_append_vals (mm_bands_arr_expected, &mm_bands, G_N_ELEMENTS (mm_bands)); + + mm_bands_arr = mm_modem_bands_from_qmi_band_capabilities (cdma_bands, 0, NULL, NULL, NULL); + + g_assert_cmpmem ( + mm_bands_arr->data, mm_bands_arr->len * sizeof (MMModemBand), + mm_bands_arr_expected->data, mm_bands_arr_expected->len * sizeof (MMModemBand) + ); +} + +static void +test_mm_bands_to_qmi_eutran_telit_fn990 (void) +{ + g_autoptr(GArray) mm_bands_arr = NULL; + static const MMModemBand mm_bands[] = { + MM_MODEM_BAND_EUTRAN_1, MM_MODEM_BAND_EUTRAN_2, MM_MODEM_BAND_EUTRAN_3, MM_MODEM_BAND_EUTRAN_4, + MM_MODEM_BAND_EUTRAN_5, MM_MODEM_BAND_EUTRAN_6, MM_MODEM_BAND_EUTRAN_7, MM_MODEM_BAND_EUTRAN_8, + MM_MODEM_BAND_EUTRAN_12, MM_MODEM_BAND_EUTRAN_13, MM_MODEM_BAND_EUTRAN_14, MM_MODEM_BAND_EUTRAN_17, + MM_MODEM_BAND_EUTRAN_18, MM_MODEM_BAND_EUTRAN_19, MM_MODEM_BAND_EUTRAN_20, MM_MODEM_BAND_EUTRAN_25, + MM_MODEM_BAND_EUTRAN_26, MM_MODEM_BAND_EUTRAN_28, MM_MODEM_BAND_EUTRAN_29, MM_MODEM_BAND_EUTRAN_30, + MM_MODEM_BAND_EUTRAN_32, MM_MODEM_BAND_EUTRAN_34, MM_MODEM_BAND_EUTRAN_38, MM_MODEM_BAND_EUTRAN_39, + MM_MODEM_BAND_EUTRAN_40, MM_MODEM_BAND_EUTRAN_41, MM_MODEM_BAND_EUTRAN_42, MM_MODEM_BAND_EUTRAN_43, + MM_MODEM_BAND_EUTRAN_46, MM_MODEM_BAND_EUTRAN_48, MM_MODEM_BAND_EUTRAN_66, MM_MODEM_BAND_EUTRAN_71, + }; + guint64 extended_qmi_lte_bands[4]; + guint extended_qmi_lte_bands_size = G_N_ELEMENTS (extended_qmi_lte_bands); + guint64 extended_qmi_lte_bands_expected[4] = { + 0b101001111110001010111011000011110011100011111111, + 0b1000010, + 0, + 0, + }; + guint extended_qmi_lte_bands_expected_size = G_N_ELEMENTS (extended_qmi_lte_bands_expected); + /* The following are not needed for this test, but mm_modem_bands_to_qmi_band_preference does not check for NULL */ + QmiNasBandPreference nas_bands_preference; + QmiNasLteBandPreference nas_lte_bands_preference; + + mm_bands_arr = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), G_N_ELEMENTS (mm_bands)); + g_array_append_vals (mm_bands_arr, &mm_bands, G_N_ELEMENTS (mm_bands)); + + mm_modem_bands_to_qmi_band_preference ( + mm_bands_arr, + &nas_bands_preference, + &nas_lte_bands_preference, + extended_qmi_lte_bands, + extended_qmi_lte_bands_size, + NULL, + 0, + NULL + ); + + g_assert_cmpmem ( + extended_qmi_lte_bands, extended_qmi_lte_bands_size * sizeof (guint64), + extended_qmi_lte_bands_expected, extended_qmi_lte_bands_expected_size * sizeof (guint64) + ); +} + +static void +test_mm_bands_to_qmi_cdma_generic (void) +{ + g_autoptr(GArray) mm_bands_arr = NULL; + static const MMModemBand mm_bands[] = { + MM_MODEM_BAND_CDMA_BC0, MM_MODEM_BAND_CDMA_BC3, MM_MODEM_BAND_CDMA_BC12, MM_MODEM_BAND_CDMA_BC14, + MM_MODEM_BAND_CDMA_BC17, MM_MODEM_BAND_CDMA_BC19, + }; + QmiNasBandPreference nas_bands_preference; + QmiNasBandPreference nas_bands_preference_expected; + /* Not needed for this test, but mm_modem_bands_to_qmi_band_preference does not check for NULL */ + QmiNasLteBandPreference nas_lte_bands_preference; + + mm_bands_arr = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), G_N_ELEMENTS (mm_bands)); + g_array_append_vals (mm_bands_arr, &mm_bands, G_N_ELEMENTS (mm_bands)); + nas_bands_preference_expected = ( + QMI_NAS_BAND_PREFERENCE_BC_0_A_SYSTEM | QMI_NAS_BAND_PREFERENCE_BC_0_B_SYSTEM | + QMI_NAS_BAND_PREFERENCE_BC_3_A_SYSTEM | QMI_NAS_BAND_PREFERENCE_BC_12 | + QMI_NAS_BAND_PREFERENCE_BC_14 | QMI_NAS_BAND_PREFERENCE_BC_17 | + QMI_NAS_BAND_PREFERENCE_BC_19 + ); + + mm_modem_bands_to_qmi_band_preference ( + mm_bands_arr, + &nas_bands_preference, + &nas_lte_bands_preference, + NULL, + 0, + NULL, + 0, + NULL + ); + + g_assert_true (nas_bands_preference == nas_bands_preference_expected); +} + /*****************************************************************************/ int main (int argc, char **argv) @@ -2007,5 +2155,10 @@ int main (int argc, char **argv) g_test_add_func ("/MM/qmi/registration-state-from-system-info/4g/eps-home", test_registration_state_from_qmi_system_info_4g_eps_home); g_test_add_func ("/MM/qmi/registration-state-from-system-info/5g/5gs-home", test_registration_state_from_qmi_system_info_5g_5gs_home); + g_test_add_func ("/MM/qmi/supported-bands/eutran/telit/fn990", test_supported_bands_eutran_telit_fn990); + g_test_add_func ("/MM/qmi/supported-bands/cdma/generic", test_supported_bands_cdma_generic); + g_test_add_func ("/MM/qmi/mm-bands-to-qmi/eutran/telit/fn990", test_mm_bands_to_qmi_eutran_telit_fn990); + g_test_add_func ("/MM/qmi/mm-bands-to-qmi/cdma/generic", test_mm_bands_to_qmi_cdma_generic); + return g_test_run (); }