1 #include "version.hpp"
2
3 #include <openssl/evp.h>
4
5 #include <gtest/gtest.h>
6
7 using namespace openpower::software::updater;
8
9 using EVP_MD_CTX_Ptr =
10 std::unique_ptr<EVP_MD_CTX, decltype(&::EVP_MD_CTX_free)>;
11
12 /** @brief Make sure we correctly get the Id from getId()*/
TEST(VersionTest,TestGetId)13 TEST(VersionTest, TestGetId)
14 {
15 auto version = "test-id";
16 unsigned char digest[EVP_MAX_MD_SIZE];
17 unsigned int digest_count = 0;
18
19 EVP_MD_CTX_Ptr ctx(EVP_MD_CTX_new(), &::EVP_MD_CTX_free);
20
21 EVP_DigestInit(ctx.get(), EVP_sha512());
22 EVP_DigestUpdate(ctx.get(), version, strlen(version));
23 EVP_DigestFinal(ctx.get(), digest, &digest_count);
24
25 char mdString[EVP_MAX_MD_SIZE * 2 + 1];
26 for (decltype(digest_count) i = 0; i < digest_count; i++)
27 {
28 snprintf(&mdString[i * 2], 3, "%02x", (unsigned int)digest[i]);
29 }
30 std::string hexId = std::string(mdString);
31 hexId = hexId.substr(0, 8);
32 EXPECT_EQ(Version::getId(version), hexId);
33 }
34
TEST(VersionTest,GetVersions)35 TEST(VersionTest, GetVersions)
36 {
37 constexpr auto versionString =
38 "open-power-romulus-v2.2-rc1-48-g268344f-dirty\n"
39 "\tbuildroot-2018.11.1-7-g5d7cc8c\n"
40 "\tskiboot-v6.2\n"
41 "\thostboot-3f1f218-pea87ca7\n"
42 "\tocc-12c8088\n"
43 "\tlinux-4.19.13-openpower1-p8031295\n"
44 "\tpetitboot-1.9.2\n"
45 "\tmachine-xml-7410460\n"
46 "\thostboot-binaries-hw121518a.930\n"
47 "\tcapp-ucode-p9-dd2-v4\n"
48 "\tsbe-cf61dc3\n"
49 "\thcode-hw123119a.930";
50
51 const auto& [version, extendedVersion] =
52 Version::getVersions(versionString);
53 EXPECT_EQ(version, "open-power-romulus-v2.2-rc1-48-g268344f-dirty");
54 EXPECT_EQ(extendedVersion,
55 "buildroot-2018.11.1-7-g5d7cc8c,"
56 "skiboot-v6.2,"
57 "hostboot-3f1f218-pea87ca7,"
58 "occ-12c8088,"
59 "linux-4.19.13-openpower1-p8031295,"
60 "petitboot-1.9.2,"
61 "machine-xml-7410460,"
62 "hostboot-binaries-hw121518a.930,"
63 "capp-ucode-p9-dd2-v4,"
64 "sbe-cf61dc3,"
65 "hcode-hw123119a.930");
66 }
67