test: Add test for GetVersions()
Also split and rename the cases in utest.cpp into test_signature and
test_version.
Tested: Verify test is built and passed.
Change-Id: Ibe59355936d9366be8e3f56760bff7384a28a28c
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index e0a13f5..da477d2 100755
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -40,7 +40,8 @@
../ubi/watch.cpp \
../static/item_updater_static.cpp \
../static/activation_static.cpp \
- utest.cpp \
+ test_signature.cpp \
+ test_version.cpp \
msl_verify.cpp
utest_LDADD = -lstdc++fs
diff --git a/test/utest.cpp b/test/test_signature.cpp
similarity index 86%
rename from test/utest.cpp
rename to test/test_signature.cpp
index 0163bf0..b199c74 100644
--- a/test/utest.cpp
+++ b/test/test_signature.cpp
@@ -1,5 +1,4 @@
#include "image_verify.hpp"
-#include "version.hpp"
#include <openssl/sha.h>
@@ -8,28 +7,8 @@
#include <gtest/gtest.h>
-using namespace openpower::software::updater;
using namespace openpower::software::image;
-/** @brief Make sure we correctly get the Id from getId()*/
-TEST(VersionTest, TestGetId)
-{
- auto version = "test-id";
- unsigned char digest[SHA512_DIGEST_LENGTH];
- SHA512_CTX ctx;
- SHA512_Init(&ctx);
- SHA512_Update(&ctx, version, strlen(version));
- SHA512_Final(digest, &ctx);
- char mdString[SHA512_DIGEST_LENGTH * 2 + 1];
- for (int i = 0; i < SHA512_DIGEST_LENGTH; i++)
- {
- snprintf(&mdString[i * 2], 3, "%02x", (unsigned int)digest[i]);
- }
- std::string hexId = std::string(mdString);
- hexId = hexId.substr(0, 8);
- EXPECT_EQ(Version::getId(version), hexId);
-}
-
class SignatureTest : public testing::Test
{
static constexpr auto opensslCmd = "openssl dgst -sha256 -sign ";
diff --git a/test/test_version.cpp b/test/test_version.cpp
new file mode 100644
index 0000000..a44edd8
--- /dev/null
+++ b/test/test_version.cpp
@@ -0,0 +1,58 @@
+#include "version.hpp"
+
+#include <openssl/sha.h>
+
+#include <gtest/gtest.h>
+
+using namespace openpower::software::updater;
+
+/** @brief Make sure we correctly get the Id from getId()*/
+TEST(VersionTest, TestGetId)
+{
+ auto version = "test-id";
+ unsigned char digest[SHA512_DIGEST_LENGTH];
+ SHA512_CTX ctx;
+ SHA512_Init(&ctx);
+ SHA512_Update(&ctx, version, strlen(version));
+ SHA512_Final(digest, &ctx);
+ char mdString[SHA512_DIGEST_LENGTH * 2 + 1];
+ for (int i = 0; i < SHA512_DIGEST_LENGTH; i++)
+ {
+ snprintf(&mdString[i * 2], 3, "%02x", (unsigned int)digest[i]);
+ }
+ std::string hexId = std::string(mdString);
+ hexId = hexId.substr(0, 8);
+ EXPECT_EQ(Version::getId(version), hexId);
+}
+
+TEST(VersionTest, GetVersions)
+{
+ constexpr auto versionString =
+ "open-power-romulus-v2.2-rc1-48-g268344f-dirty\n"
+ "\tbuildroot-2018.11.1-7-g5d7cc8c\n"
+ "\tskiboot-v6.2\n"
+ "\thostboot-3f1f218-pea87ca7\n"
+ "\tocc-12c8088\n"
+ "\tlinux-4.19.13-openpower1-p8031295\n"
+ "\tpetitboot-1.9.2\n"
+ "\tmachine-xml-7410460\n"
+ "\thostboot-binaries-hw121518a.930\n"
+ "\tcapp-ucode-p9-dd2-v4\n"
+ "\tsbe-cf61dc3\n"
+ "\thcode-hw123119a.930";
+
+ const auto& [version, extendedVersion] =
+ Version::getVersions(versionString);
+ EXPECT_EQ(version, "open-power-romulus-v2.2-rc1-48-g268344f-dirty");
+ EXPECT_EQ(extendedVersion, "buildroot-2018.11.1-7-g5d7cc8c,"
+ "skiboot-v6.2,"
+ "hostboot-3f1f218-pea87ca7,"
+ "occ-12c8088,"
+ "linux-4.19.13-openpower1-p8031295,"
+ "petitboot-1.9.2,"
+ "machine-xml-7410460,"
+ "hostboot-binaries-hw121518a.930,"
+ "capp-ucode-p9-dd2-v4,"
+ "sbe-cf61dc3,"
+ "hcode-hw123119a.930");
+}