From ea449b5bfee82892f526fe5ace8d31c32d57809c Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 21 Feb 2014 00:14:30 +0200 Subject: [PATCH] tests: Add a module test integration to hwsim tests 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 --- hostapd/Makefile | 5 +++++ hostapd/ctrl_iface.c | 6 ++++++ hostapd/hapd_module_tests.c | 17 +++++++++++++++++ tests/hwsim/example-hostapd.config | 1 + tests/hwsim/example-wpa_supplicant.config | 1 + tests/hwsim/test_module_tests.py | 20 ++++++++++++++++++++ wpa_supplicant/Makefile | 5 +++++ wpa_supplicant/ctrl_iface.c | 6 ++++++ wpa_supplicant/wpas_module_tests.c | 17 +++++++++++++++++ 9 files changed, 78 insertions(+) create mode 100644 hostapd/hapd_module_tests.c create mode 100644 tests/hwsim/test_module_tests.py create mode 100644 wpa_supplicant/wpas_module_tests.c diff --git a/hostapd/Makefile b/hostapd/Makefile index 111e8c309..25c560f23 100644 --- a/hostapd/Makefile +++ b/hostapd/Makefile @@ -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 diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c index 4a9da5f6a..7f5de625c 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -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 index 000000000..f7887ebfb --- /dev/null +++ b/hostapd/hapd_module_tests.c @@ -0,0 +1,17 @@ +/* + * hostapd module tests + * Copyright (c) 2014, Jouni Malinen + * + * 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; +} diff --git a/tests/hwsim/example-hostapd.config b/tests/hwsim/example-hostapd.config index c565e428c..95429ed6d 100644 --- a/tests/hwsim/example-hostapd.config +++ b/tests/hwsim/example-hostapd.config @@ -70,3 +70,4 @@ CONFIG_SAE=y CFLAGS += -DALL_DH_GROUPS CONFIG_TESTING_OPTIONS=y +CONFIG_MODULE_TESTS=y diff --git a/tests/hwsim/example-wpa_supplicant.config b/tests/hwsim/example-wpa_supplicant.config index 2923e835d..c603baa84 100644 --- a/tests/hwsim/example-wpa_supplicant.config +++ b/tests/hwsim/example-wpa_supplicant.config @@ -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 index 000000000..a7171d99c --- /dev/null +++ b/tests/hwsim/test_module_tests.py @@ -0,0 +1,20 @@ +#!/usr/bin/python +# +# Module tests +# Copyright (c) 2014, Jouni Malinen +# +# 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") diff --git a/wpa_supplicant/Makefile b/wpa_supplicant/Makefile index d01b18f8b..8dc97b281 100644 --- a/wpa_supplicant/Makefile +++ b/wpa_supplicant/Makefile @@ -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 diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 0d8813334..e95b55bf0 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -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 index 000000000..48cb06f15 --- /dev/null +++ b/wpa_supplicant/wpas_module_tests.c @@ -0,0 +1,17 @@ +/* + * wpa_supplicant module tests + * Copyright (c) 2014, Jouni Malinen + * + * 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; +}