summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLei YU <mine260309@gmail.com>2019-03-01 16:23:29 +0800
committerLei YU <mine260309@gmail.com>2019-03-13 11:01:53 +0800
commitb1501343b795ad8ded282a757501966a4615fe56 (patch)
treef6399d2ba465f0cc8297949fe76c4e9fc92eb5d5
parent716de5b8e3867fb829a2c1e39ade2b8f6aa1fa39 (diff)
downloadopenpower-pnor-code-mgmt-b1501343b795ad8ded282a757501966a4615fe56.tar.gz
openpower-pnor-code-mgmt-b1501343b795ad8ded282a757501966a4615fe56.zip
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>
-rwxr-xr-xtest/Makefile.am3
-rw-r--r--test/test_signature.cpp (renamed from test/utest.cpp)21
-rw-r--r--test/test_version.cpp58
3 files changed, 60 insertions, 22 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index e0a13f50d..da477d2a1 100755
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -40,7 +40,8 @@ utest_SOURCES = \
../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
index 0163bf016..b199c7467 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 000000000..a44edd8f4
--- /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");
+}
OpenPOWER on IntegriCloud