xref: /freebsd/contrib/wpa/wpa_supplicant/wpas_module_tests.c (revision 780fb4a2fa9a9aee5ac48a60b790f567c0dc13e9)
15b9c547cSRui Paulo /*
25b9c547cSRui Paulo  * wpa_supplicant module tests
35b9c547cSRui Paulo  * Copyright (c) 2014, Jouni Malinen <j@w1.fi>
45b9c547cSRui Paulo  *
55b9c547cSRui Paulo  * This software may be distributed under the terms of the BSD license.
65b9c547cSRui Paulo  * See README for more details.
75b9c547cSRui Paulo  */
85b9c547cSRui Paulo 
95b9c547cSRui Paulo #include "utils/includes.h"
105b9c547cSRui Paulo 
115b9c547cSRui Paulo #include "utils/common.h"
12*780fb4a2SCy Schubert #include "utils/module_tests.h"
135b9c547cSRui Paulo #include "wpa_supplicant_i.h"
145b9c547cSRui Paulo #include "blacklist.h"
155b9c547cSRui Paulo 
165b9c547cSRui Paulo 
175b9c547cSRui Paulo static int wpas_blacklist_module_tests(void)
185b9c547cSRui Paulo {
195b9c547cSRui Paulo 	struct wpa_supplicant wpa_s;
205b9c547cSRui Paulo 	int ret = -1;
215b9c547cSRui Paulo 
225b9c547cSRui Paulo 	os_memset(&wpa_s, 0, sizeof(wpa_s));
235b9c547cSRui Paulo 
245b9c547cSRui Paulo 	wpa_blacklist_clear(&wpa_s);
255b9c547cSRui Paulo 
265b9c547cSRui Paulo 	if (wpa_blacklist_get(NULL, NULL) != NULL ||
275b9c547cSRui Paulo 	    wpa_blacklist_get(NULL, (u8 *) "123456") != NULL ||
285b9c547cSRui Paulo 	    wpa_blacklist_get(&wpa_s, NULL) != NULL ||
295b9c547cSRui Paulo 	    wpa_blacklist_get(&wpa_s, (u8 *) "123456") != NULL)
305b9c547cSRui Paulo 		goto fail;
315b9c547cSRui Paulo 
325b9c547cSRui Paulo 	if (wpa_blacklist_add(NULL, NULL) == 0 ||
335b9c547cSRui Paulo 	    wpa_blacklist_add(NULL, (u8 *) "123456") == 0 ||
345b9c547cSRui Paulo 	    wpa_blacklist_add(&wpa_s, NULL) == 0)
355b9c547cSRui Paulo 		goto fail;
365b9c547cSRui Paulo 
375b9c547cSRui Paulo 	if (wpa_blacklist_del(NULL, NULL) == 0 ||
385b9c547cSRui Paulo 	    wpa_blacklist_del(NULL, (u8 *) "123456") == 0 ||
395b9c547cSRui Paulo 	    wpa_blacklist_del(&wpa_s, NULL) == 0 ||
405b9c547cSRui Paulo 	    wpa_blacklist_del(&wpa_s, (u8 *) "123456") == 0)
415b9c547cSRui Paulo 		goto fail;
425b9c547cSRui Paulo 
435b9c547cSRui Paulo 	if (wpa_blacklist_add(&wpa_s, (u8 *) "111111") < 0 ||
445b9c547cSRui Paulo 	    wpa_blacklist_add(&wpa_s, (u8 *) "111111") < 0 ||
455b9c547cSRui Paulo 	    wpa_blacklist_add(&wpa_s, (u8 *) "222222") < 0 ||
465b9c547cSRui Paulo 	    wpa_blacklist_add(&wpa_s, (u8 *) "333333") < 0 ||
475b9c547cSRui Paulo 	    wpa_blacklist_add(&wpa_s, (u8 *) "444444") < 0 ||
485b9c547cSRui Paulo 	    wpa_blacklist_del(&wpa_s, (u8 *) "333333") < 0 ||
495b9c547cSRui Paulo 	    wpa_blacklist_del(&wpa_s, (u8 *) "xxxxxx") == 0 ||
505b9c547cSRui Paulo 	    wpa_blacklist_get(&wpa_s, (u8 *) "xxxxxx") != NULL ||
515b9c547cSRui Paulo 	    wpa_blacklist_get(&wpa_s, (u8 *) "111111") == NULL ||
525b9c547cSRui Paulo 	    wpa_blacklist_get(&wpa_s, (u8 *) "222222") == NULL ||
535b9c547cSRui Paulo 	    wpa_blacklist_get(&wpa_s, (u8 *) "444444") == NULL ||
545b9c547cSRui Paulo 	    wpa_blacklist_del(&wpa_s, (u8 *) "111111") < 0 ||
555b9c547cSRui Paulo 	    wpa_blacklist_del(&wpa_s, (u8 *) "222222") < 0 ||
565b9c547cSRui Paulo 	    wpa_blacklist_del(&wpa_s, (u8 *) "444444") < 0 ||
575b9c547cSRui Paulo 	    wpa_blacklist_add(&wpa_s, (u8 *) "111111") < 0 ||
585b9c547cSRui Paulo 	    wpa_blacklist_add(&wpa_s, (u8 *) "222222") < 0 ||
595b9c547cSRui Paulo 	    wpa_blacklist_add(&wpa_s, (u8 *) "333333") < 0)
605b9c547cSRui Paulo 		goto fail;
615b9c547cSRui Paulo 
625b9c547cSRui Paulo 	ret = 0;
635b9c547cSRui Paulo fail:
645b9c547cSRui Paulo 	wpa_blacklist_clear(&wpa_s);
655b9c547cSRui Paulo 
665b9c547cSRui Paulo 	if (ret)
675b9c547cSRui Paulo 		wpa_printf(MSG_ERROR, "blacklist module test failure");
685b9c547cSRui Paulo 
695b9c547cSRui Paulo 	return ret;
705b9c547cSRui Paulo }
715b9c547cSRui Paulo 
725b9c547cSRui Paulo 
735b9c547cSRui Paulo int wpas_module_tests(void)
745b9c547cSRui Paulo {
755b9c547cSRui Paulo 	int ret = 0;
765b9c547cSRui Paulo 
775b9c547cSRui Paulo 	wpa_printf(MSG_INFO, "wpa_supplicant module tests");
785b9c547cSRui Paulo 
795b9c547cSRui Paulo 	if (wpas_blacklist_module_tests() < 0)
805b9c547cSRui Paulo 		ret = -1;
815b9c547cSRui Paulo 
825b9c547cSRui Paulo #ifdef CONFIG_WPS
835b9c547cSRui Paulo 	if (wps_module_tests() < 0)
845b9c547cSRui Paulo 		ret = -1;
855b9c547cSRui Paulo #endif /* CONFIG_WPS */
865b9c547cSRui Paulo 
875b9c547cSRui Paulo 	if (utils_module_tests() < 0)
885b9c547cSRui Paulo 		ret = -1;
895b9c547cSRui Paulo 
905b9c547cSRui Paulo 	if (common_module_tests() < 0)
915b9c547cSRui Paulo 		ret = -1;
925b9c547cSRui Paulo 
935b9c547cSRui Paulo 	if (crypto_module_tests() < 0)
945b9c547cSRui Paulo 		ret = -1;
955b9c547cSRui Paulo 
965b9c547cSRui Paulo 	return ret;
975b9c547cSRui Paulo }
98