]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Add a module test integration to hwsim tests
authorJouni Malinen <j@w1.fi>
Thu, 20 Feb 2014 22:14:30 +0000 (00:14 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 21 Feb 2014 11:08:08 +0000 (13:08 +0200)
CONFIG_MODULE_TESTS=y build option can now be used to build in module
tests into hostapd and wpa_supplicant binaries. These test cases will be
used to get better testing coverage for various details that are
difficult to test otherwise through the control interface control. A
single control interface command is used to executed these tests within
the hwsim test framework. This commit adds just the new mechanism, but no
module tests are yet integrated into this mechanism.

Signed-off-by: Jouni Malinen <j@w1.fi>
hostapd/Makefile
hostapd/ctrl_iface.c
hostapd/hapd_module_tests.c [new file with mode: 0644]
tests/hwsim/example-hostapd.config
tests/hwsim/example-wpa_supplicant.config
tests/hwsim/test_module_tests.py [new file with mode: 0644]
wpa_supplicant/Makefile
wpa_supplicant/ctrl_iface.c
wpa_supplicant/wpas_module_tests.c [new file with mode: 0644]

index 111e8c309881442ed4fbd887d8e6e61633a5963d..25c560f236d09f642645e8d183775670fd6e8587 100644 (file)
@@ -70,6 +70,11 @@ NEED_SHA1=y
 OBJS += ../src/drivers/drivers.o
 CFLAGS += -DHOSTAPD
 
+ifdef CONFIG_MODULE_TESTS
+CFLAGS += -DCONFIG_MODULE_TESTS
+OBJS += hapd_module_tests.o
+endif
+
 ifdef CONFIG_WPA_TRACE
 CFLAGS += -DWPA_TRACE
 OBJS += ../src/utils/trace.o
index 4a9da5f6a85cdfd80d7993f990c644212db0c7fd..7f5de625ca8c13b253b2adc1da7ac54aeb097133 100644 (file)
@@ -1650,6 +1650,12 @@ static void hostapd_global_ctrl_iface_receive(int sock, void *eloop_ctx,
        } else if (os_strncmp(buf, "REMOVE ", 7) == 0) {
                if (hostapd_ctrl_iface_remove(interfaces, buf + 7) < 0)
                        reply_len = -1;
+#ifdef CONFIG_MODULE_TESTS
+       } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
+               int hapd_module_tests(void);
+               if (hapd_module_tests() < 0)
+                       reply_len = -1;
+#endif /* CONFIG_MODULE_TESTS */
        } else {
                wpa_printf(MSG_DEBUG, "Unrecognized global ctrl_iface command "
                           "ignored");
diff --git a/hostapd/hapd_module_tests.c b/hostapd/hapd_module_tests.c
new file mode 100644 (file)
index 0000000..f7887eb
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * hostapd module tests
+ * Copyright (c) 2014, Jouni Malinen <j@w1.fi>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+
+int hapd_module_tests(void)
+{
+       wpa_printf(MSG_INFO, "hostapd module tests");
+       return 0;
+}
index c565e428c973a41beca23f18d44856686d2294e6..95429ed6d06cf873ae4322cbf4316ef8b40f474e 100644 (file)
@@ -70,3 +70,4 @@ CONFIG_SAE=y
 CFLAGS += -DALL_DH_GROUPS
 
 CONFIG_TESTING_OPTIONS=y
+CONFIG_MODULE_TESTS=y
index 2923e835db1fe1eb753f7a548dbabb5f89b0e594..c603baa84912c9da335ba43bcba83122850a862d 100644 (file)
@@ -111,3 +111,4 @@ CFLAGS += -DALL_DH_GROUPS
 CONFIG_WNM=y
 
 CONFIG_TESTING_OPTIONS=y
+CONFIG_MODULE_TESTS=y
diff --git a/tests/hwsim/test_module_tests.py b/tests/hwsim/test_module_tests.py
new file mode 100644 (file)
index 0000000..a7171d9
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+#
+# Module tests
+# Copyright (c) 2014, Jouni Malinen <j@w1.fi>
+#
+# This software may be distributed under the terms of the BSD license.
+# See README for more details.
+
+import hostapd
+
+def test_module_wpa_supplicant(dev):
+    """wpa_supplicant module tests"""
+    if "OK" not in dev[0].global_request("MODULE_TESTS"):
+        raise Exception("Module tests failed")
+
+def test_module_hostapd(dev):
+    """hostapd module tests"""
+    hapd_global = hostapd.HostapdGlobal()
+    if "OK" not in hapd_global.ctrl.request("MODULE_TESTS"):
+        raise Exception("Module tests failed")
index d01b18f8b0785f46ee4df351b733be310bbf768f..8dc97b2813477ee244dbc3a83da388f38916e289 100644 (file)
@@ -97,6 +97,11 @@ OBJS += ../src/utils/os_$(CONFIG_OS).o
 OBJS_p += ../src/utils/os_$(CONFIG_OS).o
 OBJS_c += ../src/utils/os_$(CONFIG_OS).o
 
+ifdef CONFIG_MODULE_TESTS
+CFLAGS += -DCONFIG_MODULE_TESTS
+OBJS += wpas_module_tests.o
+endif
+
 ifdef CONFIG_WPA_TRACE
 CFLAGS += -DWPA_TRACE
 OBJS += ../src/utils/trace.o
index 0d881333495da3acf0f775eacf73f0d833041f91..e95b55bf064e7d1318b9828a409e319d42631424 100644 (file)
@@ -6761,6 +6761,12 @@ char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
        } else if (os_strcmp(buf, "STATUS") == 0) {
                reply_len = wpas_global_ctrl_iface_status(global, reply,
                                                          reply_size);
+#ifdef CONFIG_MODULE_TESTS
+       } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
+               int wpas_module_tests(void);
+               if (wpas_module_tests() < 0)
+                       reply_len = -1;
+#endif /* CONFIG_MODULE_TESTS */
        } else {
                os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
                reply_len = 16;
diff --git a/wpa_supplicant/wpas_module_tests.c b/wpa_supplicant/wpas_module_tests.c
new file mode 100644 (file)
index 0000000..48cb06f
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * wpa_supplicant module tests
+ * Copyright (c) 2014, Jouni Malinen <j@w1.fi>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+
+int wpas_module_tests(void)
+{
+       wpa_printf(MSG_INFO, "wpa_supplicant module tests");
+       return 0;
+}