blob: 448d95e27aed0589de034e261afad5f0e277a117 [file] [log] [blame]
Lei YUb1501342019-03-01 16:23:29 +08001#include "version.hpp"
2
Adriana Kobylak5e0b2372021-12-08 21:59:30 +00003#include <openssl/evp.h>
Lei YUb1501342019-03-01 16:23:29 +08004
5#include <gtest/gtest.h>
6
7using namespace openpower::software::updater;
8
Adriana Kobylak5e0b2372021-12-08 21:59:30 +00009using EVP_MD_CTX_Ptr =
10 std::unique_ptr<EVP_MD_CTX, decltype(&::EVP_MD_CTX_free)>;
11
Lei YUb1501342019-03-01 16:23:29 +080012/** @brief Make sure we correctly get the Id from getId()*/
13TEST(VersionTest, TestGetId)
14{
15 auto version = "test-id";
Adriana Kobylak5e0b2372021-12-08 21:59:30 +000016 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++)
Lei YUb1501342019-03-01 16:23:29 +080027 {
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
35TEST(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
Patrick Williams7fb6c342023-05-10 07:50:18 -050051 const auto& [version,
52 extendedVersion] = Version::getVersions(versionString);
Lei YUb1501342019-03-01 16:23:29 +080053 EXPECT_EQ(version, "open-power-romulus-v2.2-rc1-48-g268344f-dirty");
54 EXPECT_EQ(extendedVersion, "buildroot-2018.11.1-7-g5d7cc8c,"
55 "skiboot-v6.2,"
56 "hostboot-3f1f218-pea87ca7,"
57 "occ-12c8088,"
58 "linux-4.19.13-openpower1-p8031295,"
59 "petitboot-1.9.2,"
60 "machine-xml-7410460,"
61 "hostboot-binaries-hw121518a.930,"
62 "capp-ucode-p9-dd2-v4,"
63 "sbe-cf61dc3,"
64 "hcode-hw123119a.930");
65}