summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGunnar Mills <gmills@us.ibm.com>2017-03-27 21:49:16 -0500
committerPatrick Williams <patrick@stwcx.xyz>2017-03-29 18:17:11 +0000
commit1ea62e181f06a3c3ad284abf932a6fafd1748e2b (patch)
tree33b41ffbf9b500643d061c6902a4aeff98f3b04b /test
parent1408173b5c476c1fcd032b8e698cf661dab24e0a (diff)
downloadopenpower-pnor-code-mgmt-1ea62e181f06a3c3ad284abf932a6fafd1748e2b.tar.gz
openpower-pnor-code-mgmt-1ea62e181f06a3c3ad284abf932a6fafd1748e2b.zip
Add gtests
Added gtests for getVersion() and getId() Resolves openbmc/openbmc#1276. Change-Id: I10a824ae3da426e901defc34fa7f3c6c6a8496d3 Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
Diffstat (limited to 'test')
-rwxr-xr-xtest/Makefile.am16
-rwxr-xr-xtest/README.md20
-rw-r--r--test/utest.cpp64
3 files changed, 100 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100755
index 000000000..cac8e378c
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,16 @@
+AM_CPPFLAGS = -I$(top_srcdir)
+
+# gtest unit tests which run during a 'make check'
+check_PROGRAMS = utest
+
+# Run all 'check' test programs
+TESTS = $(check_PROGRAMS)
+
+# Build/add utest to test suite
+utest_CPPFLAGS = -Igtest $(GTEST_CPPFLAGS) $(AM_CPPFLAGS)
+utest_CXXFLAGS = $(PTHREAD_CFLAGS) $(PHOSPHOR_LOGGING_CFLAGS)
+utest_LDFLAGS = -lgtest_main -lgtest $(PTHREAD_LIBS) $(OESDK_TESTCASE_FLAGS) \
+ $(PHOSPHOR_LOGGING_LIBS) -lstdc++fs
+
+utest_SOURCES = utest.cpp
+utest_LDADD = $(top_builddir)/version_host_software_manager.o
diff --git a/test/README.md b/test/README.md
new file mode 100755
index 000000000..6e62971fe
--- /dev/null
+++ b/test/README.md
@@ -0,0 +1,20 @@
+Instructions on how to execute UTEST.
+
+* When using an SDK - make sure it has been built
+ for an x86 machine.
+
+- First, generate the configure script with a call
+ to ./bootstrap.sh.
+- Once configure script generated, configure with flags
+ "./configure ${CONFIGURE_FLAGS} --enable-oe-sdk"
+- Be sure to include --enable-oe-sdk or the tests
+ will not run properly.
+- Lastly "make check" will build the application
+ source along with unit tests. Make check also
+ runs the unit tests automatically.
+
+* WHEN RUNNING UTEST remember to take advantage
+ of the gtest capabilities. "./utest --help"
+ - --gtest_repeat=[COUNT]
+ - --gtest_shuffle
+ - --gtest_random_seed=[NUMBER]
diff --git a/test/utest.cpp b/test/utest.cpp
new file mode 100644
index 000000000..4da45a5f4
--- /dev/null
+++ b/test/utest.cpp
@@ -0,0 +1,64 @@
+#include "version_host_software_manager.hpp"
+#include <gtest/gtest.h>
+#include <experimental/filesystem>
+#include <stdlib.h>
+#include <fstream>
+#include <iostream>
+#include <sstream>
+#include <string>
+
+using namespace openpower::software::manager;
+namespace fs = std::experimental::filesystem;
+
+
+class VersionTest : public testing::Test
+{
+ protected:
+
+ virtual void SetUp()
+ {
+ char versionDir[] = "./versionXXXXXX";
+ _directory = mkdtemp(versionDir);
+
+ if (_directory.empty())
+ {
+ throw std::bad_alloc();
+ }
+ }
+
+ virtual void TearDown()
+ {
+ fs::remove_all(_directory);
+ }
+
+ std::string _directory;
+};
+
+/** @brief Make sure we correctly get the version from getVersion()*/
+TEST_F(VersionTest, TestGetVersion)
+{
+ auto tocFilePath = _directory + "/" + "pnor.toc";
+ auto version = "test-version";
+
+ std::ofstream file;
+ file.open(tocFilePath, std::ofstream::out);
+ ASSERT_TRUE(file.is_open());
+
+ file << "version=" << version << std::endl;
+ file.close();
+
+ EXPECT_EQ(Version::getVersion(tocFilePath), version);
+}
+
+/** @brief Make sure we correctly get the Id from getId()*/
+TEST_F(VersionTest, TestGetId)
+{
+ std::stringstream hexId;
+ auto version = "test-id";
+
+ hexId << std::hex << ((std::hash<std::string> {}(
+ version)) & 0xFFFFFFFF);
+
+ EXPECT_EQ(Version::getId(version), hexId.str());
+
+}
OpenPOWER on IntegriCloud