aboutsummaryrefslogtreecommitdiffstats
path: root/hostapd/ctrl_iface.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2015-06-28 18:35:43 (GMT)
committerJouni Malinen <j@w1.fi>2015-06-29 20:23:56 (GMT)
commit2da525651d9aa49854bff51f7e4faf9273f68868 (patch)
treecc4f9c4f170df82c3c404891df38ccbcb5f5a539 /hostapd/ctrl_iface.c
parent0937ea746bceb3d98c9fe0d4461e228d9d904221 (diff)
downloadhostap-2da525651d9aa49854bff51f7e4faf9273f68868.zip
hostap-2da525651d9aa49854bff51f7e4faf9273f68868.tar.gz
hostap-2da525651d9aa49854bff51f7e4faf9273f68868.tar.bz2
Add backtrace-based error path testing mechanism
The new TEST_FAIL and GET_FAIL control interface commands can be used similarly to the earlier TEST_ALLOC_FAIL/GET_ALLOC_FAIL design. The new version is more generic framework allowing any function to be annotated for failure testing with the TEST_FAIL() macro. This mechanism is only available in builds with CONFIG_WPA_TRACE_BFD=y and CONFIG_TESTING_OPTIONS=y. For other builds, the TEST_FAIL() macro is defined to return 0 to allow the compiler to remove the test code from normal production builds. As the first test site, allow os_get_random() to be marked for failing based on call backtrace. Signed-off-by: Jouni Malinen <j@w1.fi>
Diffstat (limited to 'hostapd/ctrl_iface.c')
-rw-r--r--hostapd/ctrl_iface.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index 8ab2941..4eee851 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -1746,6 +1746,45 @@ static int hostapd_ctrl_get_alloc_fail(struct hostapd_data *hapd,
#endif /* WPA_TRACE_BFD */
}
+
+static int hostapd_ctrl_test_fail(struct hostapd_data *hapd, char *cmd)
+{
+#ifdef WPA_TRACE_BFD
+ extern char wpa_trace_test_fail_func[256];
+ extern unsigned int wpa_trace_test_fail_after;
+ char *pos;
+
+ wpa_trace_test_fail_after = atoi(cmd);
+ pos = os_strchr(cmd, ':');
+ if (pos) {
+ pos++;
+ os_strlcpy(wpa_trace_test_fail_func, pos,
+ sizeof(wpa_trace_test_fail_func));
+ } else {
+ wpa_trace_test_fail_after = 0;
+ }
+
+ return 0;
+#else /* WPA_TRACE_BFD */
+ return -1;
+#endif /* WPA_TRACE_BFD */
+}
+
+
+static int hostapd_ctrl_get_fail(struct hostapd_data *hapd,
+ char *buf, size_t buflen)
+{
+#ifdef WPA_TRACE_BFD
+ extern char wpa_trace_test_fail_func[256];
+ extern unsigned int wpa_trace_test_fail_after;
+
+ return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
+ wpa_trace_test_fail_func);
+#else /* WPA_TRACE_BFD */
+ return -1;
+#endif /* WPA_TRACE_BFD */
+}
+
#endif /* CONFIG_TESTING_OPTIONS */
@@ -2079,6 +2118,11 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
} else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
reply_len = hostapd_ctrl_get_alloc_fail(hapd, reply,
reply_size);
+ } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
+ if (hostapd_ctrl_test_fail(hapd, buf + 10) < 0)
+ reply_len = -1;
+ } else if (os_strcmp(buf, "GET_FAIL") == 0) {
+ reply_len = hostapd_ctrl_get_fail(hapd, reply, reply_size);
#endif /* CONFIG_TESTING_OPTIONS */
} else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
if (hostapd_ctrl_iface_chan_switch(hapd->iface, buf + 12))