Add Cmake Support

Added initial cmake suport to unit-test.py. Used
bmcweb as repo to test with so added missing dependencies
of boost and xxd as well.

Tested-by: Built and ran unit tests for bmcweb

Change-Id: If06b8484a96b9a711ef6aa42fc63138138077c30
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/build-unit-test-docker.sh b/build-unit-test-docker.sh
index 78cdfcb..f22aaa3 100755
--- a/build-unit-test-docker.sh
+++ b/build-unit-test-docker.sh
@@ -107,7 +107,8 @@
     valgrind \
     valgrind-dbg \
     lcov \
-    libpam0g-dev
+    libpam0g-dev \
+    xxd
 
 RUN pip install inflection
 RUN pip install pycodestyle
@@ -127,6 +128,10 @@
 RUN mkdir /usr/include/nlohmann/
 RUN cp -a json.hpp /usr/include/nlohmann/
 
+RUN curl -L -O https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.bz2
+RUN tar --bzip2 -xf boost_1_66_0.tar.bz2
+RUN cp -a -r boost_1_66_0/boost /usr/include
+
 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
 RUN mkdir -p $(dirname ${HOME})
 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
diff --git a/run-unit-test-docker.sh b/run-unit-test-docker.sh
index 5a07de9..a67bb40 100755
--- a/run-unit-test-docker.sh
+++ b/run-unit-test-docker.sh
@@ -69,6 +69,7 @@
 # Run the docker unit test container with the unit test execution script
 echo "Executing docker image"
 docker run --cap-add=sys_admin --rm=true \
+    --network host \
     --privileged=true \
     -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" \
     -e "MAKEFLAGS=${MAKEFLAGS}" \
diff --git a/scripts/unit-test.py b/scripts/unit-test.py
index 86efea0..4611c44 100755
--- a/scripts/unit-test.py
+++ b/scripts/unit-test.py
@@ -502,43 +502,55 @@
     else:
         printline = lambda *l: None
 
-    # First validate code formattting if repo has style formatting files.
+    # First validate code formatting if repo has style formatting files.
     # The format-code.sh checks for these files.
     CODE_SCAN_DIR = WORKSPACE + "/" + UNIT_TEST_PKG
     check_call_cmd(WORKSPACE, "./format-code.sh", CODE_SCAN_DIR)
 
-    # The rest of this script is CI testing, which currently only supports
-    # Automake based repos. Check if this repo is Automake, if not exit
-    if not os.path.isfile(CODE_SCAN_DIR + "/configure.ac"):
+    # Automake
+    if os.path.isfile(CODE_SCAN_DIR + "/configure.ac"):
+        prev_umask = os.umask(000)
+        # Determine dependencies and add them
+        dep_added = dict()
+        dep_added[UNIT_TEST_PKG] = False
+        # Create dependency tree
+        dep_tree = DepTree(UNIT_TEST_PKG)
+        build_dep_tree(UNIT_TEST_PKG,
+                       os.path.join(WORKSPACE, UNIT_TEST_PKG),
+                       dep_added,
+                       dep_tree)
+
+        # Reorder Dependency Tree
+        for pkg_name, regex_str in DEPENDENCIES_REGEX.iteritems():
+            dep_tree.ReorderDeps(pkg_name, regex_str)
+        if args.verbose:
+            dep_tree.PrintTree()
+        install_list = dep_tree.GetInstallList()
+        # install reordered dependencies
+        install_deps(install_list)
+        top_dir = os.path.join(WORKSPACE, UNIT_TEST_PKG)
+        os.chdir(top_dir)
+        # Refresh dynamic linker run time bindings for dependencies
+        check_call_cmd(top_dir, 'ldconfig')
+        # Run package unit tests
+        run_unit_tests(top_dir)
+        maybe_run_valgrind(top_dir)
+        maybe_run_coverage(top_dir)
+
+        os.umask(prev_umask)
+
+    # Cmake
+    elif os.path.isfile(CODE_SCAN_DIR + "/CMakeLists.txt"):
+        top_dir = os.path.join(WORKSPACE, UNIT_TEST_PKG)
+        os.chdir(top_dir)
+        check_call_cmd(top_dir, 'cmake', '.')
+        check_call_cmd(top_dir, 'cmake', '--build', '.', '--', '-j',
+                       str(multiprocessing.cpu_count()))
+        if make_target_exists('test'):
+            check_call_cmd(top_dir, 'ctest', '.')
+        maybe_run_valgrind(top_dir)
+        maybe_run_coverage(top_dir)
+
+    else:
         print "Not a supported repo for CI Tests, exit"
         quit()
-
-    prev_umask = os.umask(000)
-    # Determine dependencies and add them
-    dep_added = dict()
-    dep_added[UNIT_TEST_PKG] = False
-    # Create dependency tree
-    dep_tree = DepTree(UNIT_TEST_PKG)
-    build_dep_tree(UNIT_TEST_PKG,
-                   os.path.join(WORKSPACE, UNIT_TEST_PKG),
-                   dep_added,
-                   dep_tree)
-
-    # Reorder Dependency Tree
-    for pkg_name, regex_str in DEPENDENCIES_REGEX.iteritems():
-        dep_tree.ReorderDeps(pkg_name, regex_str)
-    if args.verbose:
-        dep_tree.PrintTree()
-    install_list = dep_tree.GetInstallList()
-    # install reordered dependencies
-    install_deps(install_list)
-    top_dir = os.path.join(WORKSPACE, UNIT_TEST_PKG)
-    os.chdir(top_dir)
-    # Refresh dynamic linker run time bindings for dependencies
-    check_call_cmd(top_dir, 'ldconfig')
-    # Run package unit tests
-    run_unit_tests(top_dir)
-    maybe_run_valgrind(top_dir)
-    maybe_run_coverage(top_dir)
-
-    os.umask(prev_umask)