Add testcase

Add a basic test that simply runs the server.

Change-Id: Ie682df8cf4dd755852e4fb07ccbc83e8bb13d629
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/Makefile.am b/Makefile.am
index cbe848d..0215db3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,3 +9,5 @@
 	directory.cpp \
 	sensorset.cpp \
 	mainloop.cpp
+
+SUBDIRS = . test
diff --git a/configure.ac b/configure.ac
index fdb3c25..952fcda 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,5 +45,5 @@
 )
 
 # Create configured output
-AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([Makefile test/Makefile])
 AC_OUTPUT
diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644
index 0000000..29dac0c
--- /dev/null
+++ b/test/.gitignore
@@ -0,0 +1 @@
+phosphor-hwmon-test
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..efdc8c7
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,8 @@
+check_PROGRAMS =
+noinst_PROGRAMS = phosphor-hwmon-test
+
+phosphor_hwmon_test_SOURCES = \
+	test.cpp
+phosphor_hwmon_test_LDFLAGS = $(SYSTEMD_LIBS) $(PTHREAD_CFLAGS)
+phosphor_hwmon_test_CFLAGS = $(SYSTEMD_CFLAGS)
+phosphor_hwmon_test_LDADD = ${top_builddir}/libhwmon.la
diff --git a/test/test.cpp b/test/test.cpp
new file mode 100644
index 0000000..cf2fb37
--- /dev/null
+++ b/test/test.cpp
@@ -0,0 +1,59 @@
+/**
+ * Copyright © 2016 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "../mainloop.hpp"
+#include <iostream>
+#include <fstream>
+#include <cstdio>
+#include <unistd.h>
+#include <thread>
+
+auto server_thread(void* data)
+{
+    auto mgr = static_cast<MainLoop*>(data);
+
+    mgr->run();
+
+    return static_cast<void*>(nullptr);
+}
+
+void runTests(MainLoop& loop)
+{
+    loop.shutdown();
+    std::cout << "Success!\n";
+}
+
+int main()
+{
+    char tmpl[] = "/tmp/hwmon-test.XXXXXX";
+    std::string dir = mkdtemp(tmpl);
+    std::string entry = dir + "/temp1_input";
+    std::ofstream f{entry};
+    f << "1234";
+
+    auto loop = MainLoop(dir);
+    auto t = std::thread(server_thread, &loop);
+
+    runTests(loop);
+
+    // Wait for server thread to exit.
+    t.join();
+    unlink(entry.c_str());
+    rmdir(dir.c_str());
+
+    return 0;
+}
+
+// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4