summaryrefslogtreecommitdiff
path: root/src/tests/test-wifi-ap-utils.c
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2011-03-13 12:50:40 -0500
committerDan Williams <dcbw@redhat.com>2011-03-13 12:50:40 -0500
commit32dedf4b83b736159b07eb73193258092318b5f0 (patch)
tree0b4475c7655ce6a34df198fe8d5ae0f210f948d5 /src/tests/test-wifi-ap-utils.c
parent0e348bad2a9348ed0838e5dca3c1c046168bcc63 (diff)
wifi: fix scanned signal strength calculation for WEXT-based drivers
The new wpa_supplicant D-Bus interface only passes back the 'level' of the scanned BSS, which with nl80211 drivers is almost always dBm, which NM handled fine. But WEXT-based drivers (ipw2x00, other older ones, and some vendor drivers) use a mix of values for the 'level' parameter, including the old WEXT 8-bit signed-value-in-unsigned-int scheme. Handle that. Alternatively, we could have the supplicant expose the 'flags' value from its internal BSS list over the bus.
Diffstat (limited to 'src/tests/test-wifi-ap-utils.c')
-rw-r--r--src/tests/test-wifi-ap-utils.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/tests/test-wifi-ap-utils.c b/src/tests/test-wifi-ap-utils.c
index da46b8cd6f..b9b262d845 100644
--- a/src/tests/test-wifi-ap-utils.c
+++ b/src/tests/test-wifi-ap-utils.c
@@ -1238,6 +1238,57 @@ test_wpa_ap_wpa_psk_connection_5 (guint idx)
/*******************************************/
+static void
+test_strength_dbm (void)
+{
+ /* boundary conditions first */
+ g_assert_cmpint (nm_ap_utils_level_to_quality (-1), ==, 100);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (-40), ==, 100);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (-30), ==, 100);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (-100), ==, 0);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (-200), ==, 0);
+
+ g_assert_cmpint (nm_ap_utils_level_to_quality (-81), ==, 32);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (-92), ==, 14);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (-74), ==, 44);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (-81), ==, 32);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (-66), ==, 57);
+}
+
+static void
+test_strength_percent (void)
+{
+ int i;
+
+ /* boundary conditions first */
+ g_assert_cmpint (nm_ap_utils_level_to_quality (0), ==, 0);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (100), ==, 100);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (110), ==, 100);
+
+ for (i = 0; i <= 100; i++)
+ g_assert_cmpint (nm_ap_utils_level_to_quality (i), ==, i);
+}
+
+static void
+test_strength_wext (void)
+{
+ /* boundary conditions that we assume aren't WEXT first */
+ g_assert_cmpint (nm_ap_utils_level_to_quality (256), ==, 100);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (110), ==, 100);
+
+ /* boundary conditions that we assume are WEXT */
+ g_assert_cmpint (nm_ap_utils_level_to_quality (111), ==, 0);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (150), ==, 0);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (225), ==, 100);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (255), ==, 100);
+
+ g_assert_cmpint (nm_ap_utils_level_to_quality (157), ==, 2);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (200), ==, 74);
+ g_assert_cmpint (nm_ap_utils_level_to_quality (215), ==, 99);
+}
+
+/*******************************************/
+
#if GLIB_CHECK_VERSION(2,25,12)
typedef GTestFixtureFunc TCFunc;
#else
@@ -1339,6 +1390,11 @@ int main (int argc, char **argv)
g_test_suite_add (suite, TESTCASE (test_ap_wpa_eap_connection_4, IDX_RSN_PSK));
g_test_suite_add (suite, TESTCASE (test_ap_wpa_eap_connection_5, IDX_RSN_PSK));
+ /* Scanned signal strength conversion tests */
+ g_test_suite_add (suite, TESTCASE (test_strength_dbm, NULL));
+ g_test_suite_add (suite, TESTCASE (test_strength_percent, NULL));
+ g_test_suite_add (suite, TESTCASE (test_strength_wext, NULL));
+
return g_test_run ();
}