build: meson support for unit tests

Add support for building and running existing unit tests
under meson.

Fix a few test case failures that might surface from running
as non-root or without a full OpenBMC set of applications.

Fixes: openbmc/phosphor-logging#11

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I588c0b7d8dcdc60b9a03fee0b5d373d0023b0530
diff --git a/test/meson.build b/test/meson.build
new file mode 100644
index 0000000..19c81f2
--- /dev/null
+++ b/test/meson.build
@@ -0,0 +1,58 @@
+gtest_dep = dependency('gtest', main: true, disabler: true, required: false)
+gmock_dep = dependency('gmock', disabler: true, required: false)
+if not gtest_dep.found() or not gmock_dep.found()
+    gtest_proj = import('cmake').subproject('googletest', required: false)
+    if gtest_proj.found()
+        gtest_dep = declare_dependency(
+            dependencies: [
+                dependency('threads'),
+                gtest_proj.dependency('gtest'),
+                gtest_proj.dependency('gtest_main'),
+            ]
+        )
+        gmock_dep = gtest_proj.dependency('gmock')
+  else
+        assert(
+            not get_option('tests').enabled(),
+            'Googletest is required if tests are enabled'
+        )
+  endif
+endif
+
+tests = [
+    'elog_quiesce_test',
+    'elog_update_ts_test',
+    'extensions_test',
+    'remote_logging_test_address',
+    'remote_logging_test_config',
+    'remote_logging_test_port',
+    'sdtest',
+    'serialization_test_path',
+    'serialization_test_properties',
+    'elog_errorwrap_test',
+]
+foreach t : tests
+    test(
+        'test_' + t.underscorify(),
+        executable(
+            'test-' + t.underscorify(),
+            t + '.cpp',
+            log_manager_sources,
+            '../phosphor-rsyslog-config/server-conf.cpp',
+            link_with: libphosphor_logging,
+            cpp_args: [
+                '-DTESTCASE=' + t.underscorify(),
+                '-DTESTCASE_' + t.underscorify(),
+            ],
+            dependencies: [
+                cereal_dep,
+                gmock_dep,
+                gtest_dep,
+                pdi_dep,
+                sdbusplus_dep,
+                sdeventplus_dep,
+            ],
+            include_directories: include_directories('..', '../gen'),
+        )
+    )
+endforeach