wpas_module_tests.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * wpa_supplicant module tests
  3. * Copyright (c) 2014, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "utils/module_tests.h"
  11. #include "wpa_supplicant_i.h"
  12. #include "blacklist.h"
  13. static int wpas_blacklist_module_tests(void)
  14. {
  15. struct wpa_supplicant wpa_s;
  16. int ret = -1;
  17. os_memset(&wpa_s, 0, sizeof(wpa_s));
  18. wpa_blacklist_clear(&wpa_s);
  19. if (wpa_blacklist_get(NULL, NULL) != NULL ||
  20. wpa_blacklist_get(NULL, (u8 *) "123456") != NULL ||
  21. wpa_blacklist_get(&wpa_s, NULL) != NULL ||
  22. wpa_blacklist_get(&wpa_s, (u8 *) "123456") != NULL)
  23. goto fail;
  24. if (wpa_blacklist_add(NULL, NULL) == 0 ||
  25. wpa_blacklist_add(NULL, (u8 *) "123456") == 0 ||
  26. wpa_blacklist_add(&wpa_s, NULL) == 0)
  27. goto fail;
  28. if (wpa_blacklist_del(NULL, NULL) == 0 ||
  29. wpa_blacklist_del(NULL, (u8 *) "123456") == 0 ||
  30. wpa_blacklist_del(&wpa_s, NULL) == 0 ||
  31. wpa_blacklist_del(&wpa_s, (u8 *) "123456") == 0)
  32. goto fail;
  33. if (wpa_blacklist_add(&wpa_s, (u8 *) "111111") < 0 ||
  34. wpa_blacklist_add(&wpa_s, (u8 *) "111111") < 0 ||
  35. wpa_blacklist_add(&wpa_s, (u8 *) "222222") < 0 ||
  36. wpa_blacklist_add(&wpa_s, (u8 *) "333333") < 0 ||
  37. wpa_blacklist_add(&wpa_s, (u8 *) "444444") < 0 ||
  38. wpa_blacklist_del(&wpa_s, (u8 *) "333333") < 0 ||
  39. wpa_blacklist_del(&wpa_s, (u8 *) "xxxxxx") == 0 ||
  40. wpa_blacklist_get(&wpa_s, (u8 *) "xxxxxx") != NULL ||
  41. wpa_blacklist_get(&wpa_s, (u8 *) "111111") == NULL ||
  42. wpa_blacklist_get(&wpa_s, (u8 *) "222222") == NULL ||
  43. wpa_blacklist_get(&wpa_s, (u8 *) "444444") == NULL ||
  44. wpa_blacklist_del(&wpa_s, (u8 *) "111111") < 0 ||
  45. wpa_blacklist_del(&wpa_s, (u8 *) "222222") < 0 ||
  46. wpa_blacklist_del(&wpa_s, (u8 *) "444444") < 0 ||
  47. wpa_blacklist_add(&wpa_s, (u8 *) "111111") < 0 ||
  48. wpa_blacklist_add(&wpa_s, (u8 *) "222222") < 0 ||
  49. wpa_blacklist_add(&wpa_s, (u8 *) "333333") < 0)
  50. goto fail;
  51. ret = 0;
  52. fail:
  53. wpa_blacklist_clear(&wpa_s);
  54. if (ret)
  55. wpa_printf(MSG_ERROR, "blacklist module test failure");
  56. return ret;
  57. }
  58. int wpas_module_tests(void)
  59. {
  60. int ret = 0;
  61. wpa_printf(MSG_INFO, "wpa_supplicant module tests");
  62. if (wpas_blacklist_module_tests() < 0)
  63. ret = -1;
  64. #ifdef CONFIG_WPS
  65. if (wps_module_tests() < 0)
  66. ret = -1;
  67. #endif /* CONFIG_WPS */
  68. if (utils_module_tests() < 0)
  69. ret = -1;
  70. if (common_module_tests() < 0)
  71. ret = -1;
  72. if (crypto_module_tests() < 0)
  73. ret = -1;
  74. return ret;
  75. }