Add Unit Tests For Hostapd AIDL
This should allow for testing hostapd AIDL implementation code
Bug: 361651437
Test: libhostapd_aidl_bp_unittest
Change-Id: If67b84ba4a2753b43987b2d79833c9616df73cf9
diff --git a/hostapd/aidl/hostapd.cpp b/hostapd/aidl/hostapd.cpp
index a3d4e28..b4326d1 100644
--- a/hostapd/aidl/hostapd.cpp
+++ b/hostapd/aidl/hostapd.cpp
@@ -35,6 +35,31 @@
#include "drivers/linux_ioctl.h"
}
+// don't use hostapd's wpa_printf for unit testing. It won't compile otherwise
+#ifdef ANDROID_HOSTAPD_UNITTEST
+#include <android-base/logging.h>
+constexpr size_t logbuf_size = 8192;
+static ::android::base::LogSeverity wpa_to_android_level(int level)
+{
+ if (level == MSG_ERROR)
+ return ::android::base::ERROR;
+ if (level == MSG_WARNING)
+ return ::android::base::WARNING;
+ if (level == MSG_INFO)
+ return ::android::base::INFO;
+ return ::android::base::DEBUG;
+}
+void wpa_printf(int level, const char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ char buffer[logbuf_size];
+ int res = snprintf(buffer, logbuf_size, fmt, ap);
+ if (res > 0 && res < logbuf_size) {
+ LOG(wpa_to_android_level(level)) << buffer;
+ }
+}
+#endif
+
// The AIDL implementation for hostapd creates a hostapd.conf dynamically for
// each interface. This file can then be used to hook onto the normal config
// file parsing logic in hostapd code. Helps us to avoid duplication of code