Skip to content

Commit 69e880e

Browse files
author
Tianjie
committed
Add a unittest for fingerprint calculation
Add a test to check the build fingerprint when the dynamic build id is in use. Bug: 186786987 Test: th Change-Id: I44d6be0c18552f319bcb8d19cca5659ce580d26c
1 parent 57b9a53 commit 69e880e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

init/property_service_test.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <android-base/properties.h>
2525
#include <android-base/scopeguard.h>
26+
#include <android-base/strings.h>
2627
#include <gtest/gtest.h>
2728

2829
using android::base::GetProperty;
@@ -90,5 +91,39 @@ TEST(property_service, userspace_reboot_not_supported) {
9091
EXPECT_FALSE(SetProperty("sys.powerctl", "reboot,userspace"));
9192
}
9293

94+
TEST(property_service, check_fingerprint_with_legacy_build_id) {
95+
std::string legacy_build_id = GetProperty("ro.build.legacy.id", "");
96+
if (legacy_build_id.empty()) {
97+
GTEST_SKIP() << "Skipping test, legacy build id isn't set.";
98+
}
99+
100+
std::string vbmeta_digest = GetProperty("ro.boot.vbmeta.digest", "");
101+
ASSERT_GE(vbmeta_digest.size(), 8u);
102+
std::string build_id = GetProperty("ro.boot.build.id", "");
103+
// Check that the build id is constructed with the prefix of vbmeta digest
104+
std::string expected_build_id = legacy_build_id + "." + vbmeta_digest.substr(0, 8);
105+
ASSERT_EQ(expected_build_id, build_id);
106+
// Check that the fingerprint is constructed with the expected format.
107+
std::string fingerprint = GetProperty("ro.build.fingerprint", "");
108+
std::vector<std::string> fingerprint_fields = {
109+
GetProperty("ro.product.brand", ""),
110+
"/",
111+
GetProperty("ro.product.name", ""),
112+
"/",
113+
GetProperty("ro.product.device", ""),
114+
":",
115+
GetProperty("ro.build.version.release_or_codename", ""),
116+
"/",
117+
expected_build_id,
118+
"/",
119+
GetProperty("ro.build.version.incremental", ""),
120+
":",
121+
GetProperty("ro.build.type", ""),
122+
"/",
123+
GetProperty("ro.build.tags", "")};
124+
125+
ASSERT_EQ(android::base::Join(fingerprint_fields, ""), fingerprint);
126+
}
127+
93128
} // namespace init
94129
} // namespace android

0 commit comments

Comments
 (0)