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