summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Android.bp51
-rw-r--r--tests/AndroidTest.xml28
-rw-r--r--tests/fuzz/verify_package_fuzzer.cpp37
-rw-r--r--tests/testdata/recovery-from-boot.pbin5404 -> 5410 bytes
-rw-r--r--tests/testdata/recovery.imgbin529707 -> 0 bytes
-rw-r--r--tests/testdata/recovery_bodybin0 -> 1293568 bytes
-rw-r--r--tests/testdata/recovery_headbin0 -> 45056 bytes
-rw-r--r--tests/testdata/recovery_tailbin0 -> 5191 bytes
-rw-r--r--tests/testdata/ziptest_fake-update.zip (renamed from tests/testdata/ziptest_dummy-update.zip)bin1090065 -> 1090065 bytes
-rw-r--r--tests/unit/host/imgdiff_test.cpp1
-rw-r--r--tests/unit/install_test.cpp44
-rw-r--r--tests/unit/package_test.cpp2
-rw-r--r--tests/unit/zip_test.cpp4
13 files changed, 153 insertions, 14 deletions
diff --git a/tests/Android.bp b/tests/Android.bp
index 4c23255ad..0559dc3b9 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -12,6 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "bootable_recovery_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["bootable_recovery_license"],
+}
+
cc_defaults {
name: "recovery_test_defaults",
@@ -31,7 +40,6 @@ cc_defaults {
"libpng",
"libprocessgroup",
"libselinux",
- "libz",
"libziparchive",
],
@@ -65,7 +73,7 @@ libapplypatch_static_libs = [
"libbase",
"libbrotli",
"libbz",
- "libz",
+ "libz_stable",
"libziparchive",
]
@@ -95,6 +103,24 @@ librecovery_static_libs = [
"libc++fs",
]
+// recovery image for unittests.
+// ========================================================
+genrule {
+ name: "recovery_image",
+ cmd: "cat $(location testdata/recovery_head) <(cat $(location testdata/recovery_body) | $(location minigzip)) $(location testdata/recovery_tail) > $(out)",
+ srcs: [
+ "testdata/recovery_head",
+ "testdata/recovery_body",
+ "testdata/recovery_tail",
+ ],
+ tools: [
+ "minigzip",
+ ],
+ out: [
+ "testdata/recovery.img",
+ ],
+}
+
cc_test {
name: "recovery_unit_test",
isolated: true,
@@ -128,6 +154,7 @@ cc_test {
data: [
"testdata/*",
+ ":recovery_image",
":res-testdata",
],
}
@@ -182,3 +209,23 @@ cc_test_host {
},
},
}
+
+cc_fuzz {
+ name: "libinstall_verify_package_fuzzer",
+ defaults: [
+ "recovery_test_defaults",
+ ],
+
+ srcs: ["fuzz/verify_package_fuzzer.cpp"],
+
+ corpus: [
+ "testdata/otasigned*.zip",
+ ],
+
+ static_libs: [
+ "libotautil",
+ "libinstall",
+ "librecovery_ui",
+ "libminui",
+ ],
+}
diff --git a/tests/AndroidTest.xml b/tests/AndroidTest.xml
new file mode 100644
index 000000000..0ac75e4ea
--- /dev/null
+++ b/tests/AndroidTest.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<configuration description="Runs recovery_host_test.">
+ <option name="null-device" value="true" />
+
+ <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer">
+ <option name="force-root" value="false" />
+ </target_preparer>
+ <option name="not-shardable" value="true" />
+
+ <test class="com.android.tradefed.testtype.HostGTest" >
+ <option name="module-name" value="recovery_host_test" />
+ <option name="native-test-timeout" value="5m"/>
+ </test>
+</configuration>
diff --git a/tests/fuzz/verify_package_fuzzer.cpp b/tests/fuzz/verify_package_fuzzer.cpp
new file mode 100644
index 000000000..baa44e070
--- /dev/null
+++ b/tests/fuzz/verify_package_fuzzer.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "fuzzer/FuzzedDataProvider.h"
+
+#include "install/install.h"
+#include "install/package.h"
+#include "recovery_ui/stub_ui.h"
+
+std::unique_ptr<Package> CreatePackage(std::vector<uint8_t>& content) {
+ return Package::CreateMemoryPackage(content, [](float) -> void {});
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ FuzzedDataProvider data_provider(data, size);
+ auto package_contents = data_provider.ConsumeRemainingBytes<uint8_t>();
+ if (package_contents.size() == 0) {
+ return 0;
+ }
+ auto package = CreatePackage(package_contents);
+ StubRecoveryUI ui;
+ verify_package(package.get(), &ui);
+ return 0;
+}
diff --git a/tests/testdata/recovery-from-boot.p b/tests/testdata/recovery-from-boot.p
index 06f6c299f..81738ed29 100644
--- a/tests/testdata/recovery-from-boot.p
+++ b/tests/testdata/recovery-from-boot.p
Binary files differ
diff --git a/tests/testdata/recovery.img b/tests/testdata/recovery.img
deleted file mode 100644
index b862e6f0c..000000000
--- a/tests/testdata/recovery.img
+++ /dev/null
Binary files differ
diff --git a/tests/testdata/recovery_body b/tests/testdata/recovery_body
new file mode 100644
index 000000000..48d7c10a5
--- /dev/null
+++ b/tests/testdata/recovery_body
Binary files differ
diff --git a/tests/testdata/recovery_head b/tests/testdata/recovery_head
new file mode 100644
index 000000000..7f494d098
--- /dev/null
+++ b/tests/testdata/recovery_head
Binary files differ
diff --git a/tests/testdata/recovery_tail b/tests/testdata/recovery_tail
new file mode 100644
index 000000000..7fe2c6ce8
--- /dev/null
+++ b/tests/testdata/recovery_tail
Binary files differ
diff --git a/tests/testdata/ziptest_dummy-update.zip b/tests/testdata/ziptest_fake-update.zip
index 6976bf155..6976bf155 100644
--- a/tests/testdata/ziptest_dummy-update.zip
+++ b/tests/testdata/ziptest_fake-update.zip
Binary files differ
diff --git a/tests/unit/host/imgdiff_test.cpp b/tests/unit/host/imgdiff_test.cpp
index e76ccbdfb..978ac7c2b 100644
--- a/tests/unit/host/imgdiff_test.cpp
+++ b/tests/unit/host/imgdiff_test.cpp
@@ -35,7 +35,6 @@
using android::base::get_unaligned;
-// Sanity check for the given imgdiff patch header.
static void verify_patch_header(const std::string& patch, size_t* num_normal, size_t* num_raw,
size_t* num_deflate) {
const size_t size = patch.size();
diff --git a/tests/unit/install_test.cpp b/tests/unit/install_test.cpp
index ee753494c..c3415479d 100644
--- a/tests/unit/install_test.cpp
+++ b/tests/unit/install_test.cpp
@@ -76,7 +76,7 @@ TEST(InstallTest, read_metadata_from_package_smoke) {
TEST(InstallTest, read_metadata_from_package_no_entry) {
TemporaryFile temp_file;
- BuildZipArchive({ { "dummy_entry", "" } }, temp_file.release(), kCompressStored);
+ BuildZipArchive({ { "fake_entry", "" } }, temp_file.release(), kCompressStored);
ZipArchiveHandle zip;
ASSERT_EQ(0, OpenArchive(temp_file.path, &zip));
@@ -153,7 +153,7 @@ TEST(InstallTest, SetUpNonAbUpdateCommands) {
TEST(InstallTest, SetUpNonAbUpdateCommands_MissingUpdateBinary) {
TemporaryFile temp_file;
// The archive must have something to be opened correctly.
- BuildZipArchive({ { "dummy_entry", "" } }, temp_file.release(), kCompressStored);
+ BuildZipArchive({ { "fake_entry", "" } }, temp_file.release(), kCompressStored);
// Missing update binary.
ZipArchiveHandle zip;
@@ -190,7 +190,7 @@ static void VerifyAbUpdateCommands(const std::string& serialno, bool success = t
ZipArchiveHandle zip;
ASSERT_EQ(0, OpenArchive(temp_file.path, &zip));
- ZipEntry payload_entry;
+ ZipEntry64 payload_entry;
ASSERT_EQ(0, FindEntry(zip, "payload.bin", &payload_entry));
std::map<std::string, std::string> metadata;
@@ -334,7 +334,7 @@ TEST(InstallTest, CheckPackageMetadata_device_type) {
metadata = android::base::Join(
std::vector<std::string>{
"ota-type=BRICK",
- "pre-device=dummy_device_type",
+ "pre-device=fake_device_type",
},
"\n");
TestCheckPackageMetadata(metadata, OtaType::BRICK, false);
@@ -358,7 +358,7 @@ TEST(InstallTest, CheckPackageMetadata_serial_number_smoke) {
std::vector<std::string>{
"ota-type=BRICK",
"pre-device=" + device,
- "serialno=dummy_serial",
+ "serialno=fake_serial",
},
"\n");
TestCheckPackageMetadata(metadata, OtaType::BRICK, false);
@@ -383,7 +383,7 @@ TEST(InstallTest, CheckPackageMetadata_multiple_serial_number) {
ASSERT_NE("", serialno);
std::vector<std::string> serial_numbers;
- // Creates a dummy serial number string.
+ // Creates a fake serial number string.
for (char c = 'a'; c <= 'z'; c++) {
serial_numbers.emplace_back(serialno.size(), c);
}
@@ -431,7 +431,7 @@ TEST(InstallTest, CheckPackageMetadata_ab_build_version) {
std::vector<std::string>{
"ota-type=AB",
"pre-device=" + device,
- "pre-build-incremental=dummy_build",
+ "pre-build-incremental=fake_build",
"post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()),
},
"\n");
@@ -459,7 +459,35 @@ TEST(InstallTest, CheckPackageMetadata_ab_fingerprint) {
std::vector<std::string>{
"ota-type=AB",
"pre-device=" + device,
- "pre-build=dummy_build_fingerprint",
+ "pre-build=fake_build_fingerprint",
+ "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()),
+ },
+ "\n");
+ TestCheckPackageMetadata(metadata, OtaType::AB, false);
+}
+
+TEST(InstallTest, CheckPackageMetadata_dynamic_fingerprint) {
+ std::string device = android::base::GetProperty("ro.product.device", "");
+ ASSERT_FALSE(device.empty());
+
+ std::string finger_print = android::base::GetProperty("ro.build.fingerprint", "");
+ ASSERT_FALSE(finger_print.empty());
+
+ std::string metadata = android::base::Join(
+ std::vector<std::string>{
+ "ota-type=AB",
+ "pre-device=please|work|" + device + "|please|work",
+ "pre-build=" + finger_print = "pass|this|test",
+ "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()),
+ },
+ "\n");
+ TestCheckPackageMetadata(metadata, OtaType::AB, true);
+
+ metadata = android::base::Join(
+ std::vector<std::string>{
+ "ota-type=AB",
+ "pre-device=" + device,
+ "pre-build=fake_build_fingerprint",
"post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()),
},
"\n");
diff --git a/tests/unit/package_test.cpp b/tests/unit/package_test.cpp
index 5e31f7fa5..164a93d57 100644
--- a/tests/unit/package_test.cpp
+++ b/tests/unit/package_test.cpp
@@ -106,7 +106,7 @@ TEST_F(PackageTest, GetZipArchiveHandle_extract_entry) {
// Check that we can extract one zip entry.
std::string_view entry_name = "dir1/file3.txt";
- ZipEntry entry;
+ ZipEntry64 entry;
ASSERT_EQ(0, FindEntry(zip, entry_name, &entry));
std::vector<uint8_t> extracted(entry_name.size());
diff --git a/tests/unit/zip_test.cpp b/tests/unit/zip_test.cpp
index 0753d64e1..e065bb859 100644
--- a/tests/unit/zip_test.cpp
+++ b/tests/unit/zip_test.cpp
@@ -28,7 +28,7 @@
#include "otautil/sysutil.h"
TEST(ZipTest, OpenFromMemory) {
- std::string zip_path = from_testdata_base("ziptest_dummy-update.zip");
+ std::string zip_path = from_testdata_base("ziptest_fake-update.zip");
MemMapping map;
ASSERT_TRUE(map.MapFile(zip_path));
@@ -37,7 +37,7 @@ TEST(ZipTest, OpenFromMemory) {
ASSERT_EQ(0, OpenArchiveFromMemory(map.addr, map.length, zip_path.c_str(), &handle));
static constexpr const char* BINARY_PATH = "META-INF/com/google/android/update-binary";
- ZipEntry binary_entry;
+ ZipEntry64 binary_entry;
// Make sure the package opens correctly and its entry can be read.
ASSERT_EQ(0, FindEntry(handle, BINARY_PATH, &binary_entry));