build: Build net_test_osi using GN + ninja

This CL adds support to build the net_test_osi target using GN + ninja.
The BUILD.gn file now pulls in gtest as a dependency. Missing libc
includes have been added to sources that prevented compilation on
Goobuntu (14.04).

The osi/include/log.h header has been modified to conditionally call the
Android log utilities vs plain-old printf on non-Android builds.

BUG=21339022

Change-Id: If3c356360c56c63b3bf551b41dc8d3269d8e7e09
diff --git a/system/osi/BUILD.gn b/system/osi/BUILD.gn
index d5e7ae1..91de6d8 100644
--- a/system/osi/BUILD.gn
+++ b/system/osi/BUILD.gn
@@ -41,9 +41,12 @@
     "include",
     "//"
   ]
+
+  libs = [ "-lpthread", "-lrt" ]
 }
 
 executable("net_test_osi") {
+  testonly = true
   sources = [
     "test/AlarmTestHarness.cpp",
     "test/AllocationTestHarness.cpp",
@@ -68,6 +71,7 @@
 
   deps = [
     "//osi",
+    "//testing/gtest:gtest_main",
   ]
 
   libs = [ "-lpthread", "-lrt" ]
diff --git a/system/osi/include/log.h b/system/osi/include/log.h
index a5de1cf..5527e01 100644
--- a/system/osi/include/log.h
+++ b/system/osi/include/log.h
@@ -18,6 +18,25 @@
 
 #pragma once
 
+/*
+ * TODO(armansito): Work-around until we figure out a way to generate logs in a
+ * platform-independent manner.
+ */
+#if defined(OS_GENERIC)
+
+/* syslog didn't work well here since we would be redefining LOG_DEBUG. */
+#include <stdio.h>
+
+#define LOGWRAPPER(fmt, args...) fprintf(stderr, fmt "\n", ## args)
+
+#define LOG_VERBOSE(...) LOGWRAPPER(__VA_ARGS__)
+#define LOG_DEBUG(...) LOGWRAPPER(__VA_ARGS__)
+#define LOG_INFO(...) LOGWRAPPER(__VA_ARGS__)
+#define LOG_WARN(...) LOGWRAPPER(__VA_ARGS__)
+#define LOG_ERROR(...) LOGWRAPPER(__VA_ARGS__)
+
+#else
+
 #include <cutils/log.h>
 
 #define LOG_VERBOSE(...) ALOGV(__VA_ARGS__)
@@ -25,3 +44,6 @@
 #define LOG_INFO(...)    ALOGI(__VA_ARGS__)
 #define LOG_WARN(...)    ALOGW(__VA_ARGS__)
 #define LOG_ERROR(...)   ALOGE(__VA_ARGS__)
+
+
+#endif
diff --git a/system/osi/src/alarm.c b/system/osi/src/alarm.c
index 1ce58bc..7a19748 100644
--- a/system/osi/src/alarm.c
+++ b/system/osi/src/alarm.c
@@ -26,6 +26,7 @@
 #include <string.h>
 #include <signal.h>
 #include <time.h>
+#include <pthread.h>
 
 #include "osi/include/alarm.h"
 #include "osi/include/allocator.h"
diff --git a/system/osi/src/config.c b/system/osi/src/config.c
index a98faa2..c6b73dc 100644
--- a/system/osi/src/config.c
+++ b/system/osi/src/config.c
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "osi/include/allocator.h"
 #include "osi/include/config.h"
diff --git a/system/osi/src/eager_reader.c b/system/osi/src/eager_reader.c
index 6f0a88f..125fd3f 100644
--- a/system/osi/src/eager_reader.c
+++ b/system/osi/src/eager_reader.c
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <stddef.h>
 #include <string.h>
+#include <unistd.h>
 #include <sys/eventfd.h>
 
 #include "osi/include/allocator.h"
diff --git a/system/osi/src/reactor.c b/system/osi/src/reactor.c
index 08b5098..68b0984 100644
--- a/system/osi/src/reactor.c
+++ b/system/osi/src/reactor.c
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <sys/epoll.h>
 #include <sys/eventfd.h>
+#include <unistd.h>
 
 #include "osi/include/allocator.h"
 #include "osi/include/list.h"
diff --git a/system/osi/src/semaphore.c b/system/osi/src/semaphore.c
index 5ee9926..c9b117d 100644
--- a/system/osi/src/semaphore.c
+++ b/system/osi/src/semaphore.c
@@ -24,6 +24,7 @@
 #include <malloc.h>
 #include <string.h>
 #include <sys/eventfd.h>
+#include <unistd.h>
 
 #include "osi/include/allocator.h"
 #include "osi/include/osi.h"