Implement bmcweb ptest

Yocto implements ptest classes for recipes.  In general OpenBMC doesn't
implement ptest for any of its recipes.  This is the first in an attempt
to change that, specifically, this enables ptest for the bmcweb recipe.

Examples for ptest + meson recipes are pulled from here:
http://layers.openembedded.org/layerindex/branch/master/recipes/?q=inherits%3Aptest+inherits%3Ameson

This commit implements the base ptest functionalityrequired to be able
to install and run the unit tests already present in bmcweb.  The
specific changes are:
1. bmcweb recipe now inherits from ptest
2. When ptest is enabled, bmcweb now requires gtest and gmock
dependencies.  This is done by updating DEPENDS.  We also now require
bash at runtime, so that dependency is added, as that seems to be what
the upstream recipes do.
3. The meta-layer now includes a "run-ptest" script.  This seems to be
the common convention in the upstream yocto recipes to include in the
meta layer so we should do the same thing here for consistency, even if
it is a little unconventional or odd.

To enable this and try it out, insert the following into your local.conf
DISTRO_FEATURES_append = " ptest"
CORE_IMAGE_EXTRA_INSTALL += "bmcweb-ptest"

This will add bmcweb ptests to your build.  Keep in mind, this takes a
lot of flash space, so qemu is likely the best target, unless you're on
a system with eMMC, or a lot of SPI flash free.  Once your system has
booted, you can run the tests by executing ptest_runner.

https://wiki.yoctoproject.org/wiki/Ptest

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I8c45c98afb941953c1855de2f3db10deea465b2a
diff --git a/meta-phosphor/recipes-phosphor/interfaces/bmcweb/run-ptest b/meta-phosphor/recipes-phosphor/interfaces/bmcweb/run-ptest
new file mode 100644
index 0000000..f2a522a
--- /dev/null
+++ b/meta-phosphor/recipes-phosphor/interfaces/bmcweb/run-ptest
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+for i in `ls test/*_test`; do
+    $i
+    if [ $? -eq 0 ]; then
+        echo "PASS: $i"
+    else
+        echo "FAIL: $i"
+    fi
+done
diff --git a/meta-phosphor/recipes-phosphor/interfaces/bmcweb_git.bb b/meta-phosphor/recipes-phosphor/interfaces/bmcweb_git.bb
index 2125a6f..75791cf 100644
--- a/meta-phosphor/recipes-phosphor/interfaces/bmcweb_git.bb
+++ b/meta-phosphor/recipes-phosphor/interfaces/bmcweb_git.bb
@@ -17,6 +17,12 @@
 
 S = "${WORKDIR}/git"
 
+inherit meson ptest
+
+SRC_URI += " \
+    file://run-ptest \
+"
+
 DEPENDS = " \
     openssl \
     zlib \
@@ -27,6 +33,8 @@
     gtest \
     nlohmann-json \
     libtinyxml2 \
+    ${@bb.utils.contains('PTEST_ENABLED', '1', 'gtest', '', d)} \
+    ${@bb.utils.contains('PTEST_ENABLED', '1', 'gmock', '', d)} \
 "
 
 RDEPENDS_${PN} += " \
@@ -34,11 +42,19 @@
     phosphor-mapper \
 "
 
+do_install_ptest() {
+        install -d ${D}${PTEST_PATH}/test
+        cp -rf ${B}*_test ${D}${PTEST_PATH}/test/
+}
+
 FILES_${PN} += "${datadir}/** "
 
-inherit meson
 
-EXTRA_OEMESON = "--buildtype=minsize -Dtests=disabled -Dyocto-deps=enabled"
+EXTRA_OEMESON = " \
+    --buildtype=minsize \
+    -Dtests=${@bb.utils.contains('PTEST_ENABLED', '1', 'enabled', 'disabled', d)} \
+    -Dyocto-deps=enabled \
+"
 
 SYSTEMD_SERVICE_${PN} += "bmcweb.service bmcweb.socket"