diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Android.bp | 52 | ||||
-rw-r--r-- | tests/AndroidTest.xml | 33 | ||||
-rw-r--r-- | tests/component/resources_test.cpp | 120 | ||||
-rw-r--r-- | tests/unit/applypatch_modes_test.cpp (renamed from tests/component/applypatch_modes_test.cpp) | 0 | ||||
-rw-r--r-- | tests/unit/bootloader_message_test.cpp (renamed from tests/component/bootloader_message_test.cpp) | 0 | ||||
-rw-r--r-- | tests/unit/edify_test.cpp (renamed from tests/component/edify_test.cpp) | 0 | ||||
-rw-r--r-- | tests/unit/fuse_provider_test.cpp | 103 | ||||
-rw-r--r-- | tests/unit/fuse_sideload_test.cpp (renamed from tests/component/sideload_test.cpp) | 0 | ||||
-rw-r--r-- | tests/unit/imgdiff_test.cpp (renamed from tests/component/imgdiff_test.cpp) | 0 | ||||
-rw-r--r-- | tests/unit/install_test.cpp (renamed from tests/component/install_test.cpp) | 58 | ||||
-rw-r--r-- | tests/unit/locale_test.cpp | 4 | ||||
-rw-r--r-- | tests/unit/package_test.cpp | 5 | ||||
-rw-r--r-- | tests/unit/rangeset_test.cpp | 24 | ||||
-rw-r--r-- | tests/unit/resources_test.cpp | 99 | ||||
-rw-r--r-- | tests/unit/sysutil_test.cpp | 2 | ||||
-rw-r--r-- | tests/unit/uncrypt_test.cpp (renamed from tests/component/uncrypt_test.cpp) | 0 | ||||
-rw-r--r-- | tests/unit/update_verifier_test.cpp (renamed from tests/component/update_verifier_test.cpp) | 0 | ||||
-rw-r--r-- | tests/unit/updater_test.cpp (renamed from tests/component/updater_test.cpp) | 186 | ||||
-rw-r--r-- | tests/unit/verifier_test.cpp (renamed from tests/component/verifier_test.cpp) | 0 | ||||
-rw-r--r-- | tests/unit/zip_test.cpp | 3 |
20 files changed, 373 insertions, 316 deletions
diff --git a/tests/Android.bp b/tests/Android.bp index 09ef716d6..4969c087b 100644 --- a/tests/Android.bp +++ b/tests/Android.bp @@ -79,6 +79,8 @@ librecovery_static_libs = [ "libinstall", "librecovery_ui", "libminui", + "libfusesideload", + "libbootloader_message", "libotautil", "libhealthhalutils", @@ -87,10 +89,8 @@ librecovery_static_libs = [ "android.hardware.health@2.0", "android.hardware.health@1.0", - "libbootloader_message", "libext4_utils", "libfs_mgr", - "libfusesideload", "libhidl-gen-utils", "libhidlbase", "libhidltransport", @@ -107,6 +107,8 @@ cc_test { defaults: [ "recovery_test_defaults", + "libupdater_defaults", + "libupdater_device_defaults", ], test_suites: ["device-tests"], @@ -115,16 +117,23 @@ cc_test { "unit/*.cpp", ], - static_libs: libapplypatch_static_libs + [ - "libinstall", + static_libs: libapplypatch_static_libs + librecovery_static_libs + [ "librecovery_ui", + "libfusesideload", "libminui", "libotautil", - "libupdater", + "libupdater_device", + "libupdater_core", + "libupdate_verifier", + "libgtest_prod", + "libprotobuf-cpp-lite", ], - data: ["testdata/*"], + data: [ + "testdata/*", + ":res-testdata", + ], } cc_test { @@ -142,33 +151,6 @@ cc_test { ], } -cc_test { - name: "recovery_component_test", - isolated: true, - - defaults: [ - "recovery_test_defaults", - "libupdater_defaults", - ], - - test_suites: ["device-tests"], - - srcs: [ - "component/*.cpp", - ], - - static_libs: libapplypatch_static_libs + librecovery_static_libs + [ - "libupdater", - "libupdate_verifier", - "libprotobuf-cpp-lite", - ], - - data: [ - "testdata/*", - ":res-testdata", - ], -} - cc_test_host { name: "recovery_host_test", isolated: true, @@ -178,7 +160,7 @@ cc_test_host { ], srcs: [ - "component/imgdiff_test.cpp", + "unit/imgdiff_test.cpp", ], static_libs: [ @@ -197,6 +179,8 @@ cc_test_host { "libz", ], + test_suites: ["general-tests"], + data: ["testdata/*"], target: { diff --git a/tests/AndroidTest.xml b/tests/AndroidTest.xml deleted file mode 100644 index 6b86085aa..000000000 --- a/tests/AndroidTest.xml +++ /dev/null @@ -1,33 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2017 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="Config for recovery_component_test and recovery_unit_test"> - <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer"> - <option name="cleanup" value="true" /> - <option name="push" value="recovery_component_test->/data/local/tmp/recovery_component_test/recovery_component_test" /> - <option name="push" value="testdata->/data/local/tmp/recovery_component_test/testdata" /> - <option name="push" value="recovery_unit_test->/data/local/tmp/recovery_unit_test/recovery_unit_test" /> - <option name="push" value="testdata->/data/local/tmp/recovery_unit_test/testdata" /> - </target_preparer> - <option name="test-suite-tag" value="apct" /> - <test class="com.android.tradefed.testtype.GTest" > - <option name="native-test-device-path" value="/data/local/tmp/recovery_component_test" /> - <option name="module-name" value="recovery_component_test" /> - </test> - <test class="com.android.tradefed.testtype.GTest" > - <option name="native-test-device-path" value="/data/local/tmp/recovery_unit_test" /> - <option name="module-name" value="recovery_unit_test" /> - </test> -</configuration> diff --git a/tests/component/resources_test.cpp b/tests/component/resources_test.cpp deleted file mode 100644 index d7fdb8fa0..000000000 --- a/tests/component/resources_test.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2018 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 <dirent.h> -#include <stdio.h> -#include <stdlib.h> - -#include <memory> -#include <string> -#include <vector> - -#include <android-base/file.h> -#include <android-base/strings.h> -#include <gtest/gtest.h> -#include <png.h> - -#include "minui/minui.h" -#include "private/resources.h" - -static const std::string kLocale = "zu"; - -static const std::vector<std::string> kResourceImagesDirs{ - "res-mdpi/images/", "res-hdpi/images/", "res-xhdpi/images/", - "res-xxhdpi/images/", "res-xxxhdpi/images/", -}; - -static int png_filter(const dirent* de) { - if (de->d_type != DT_REG || !android::base::EndsWith(de->d_name, "_text.png")) { - return 0; - } - return 1; -} - -// Finds out all the PNG files to test, which stay under the same dir with the executabl.. -static std::vector<std::string> add_files() { - std::vector<std::string> files; - for (const std::string& images_dir : kResourceImagesDirs) { - static std::string exec_dir = android::base::GetExecutableDirectory(); - std::string dir_path = exec_dir + "/" + images_dir; - dirent** namelist; - int n = scandir(dir_path.c_str(), &namelist, png_filter, alphasort); - if (n == -1) { - printf("Failed to scandir %s: %s\n", dir_path.c_str(), strerror(errno)); - continue; - } - if (n == 0) { - printf("No file is added for test in %s\n", dir_path.c_str()); - } - - while (n--) { - std::string file_path = dir_path + namelist[n]->d_name; - files.push_back(file_path); - free(namelist[n]); - } - free(namelist); - } - return files; -} - -class ResourcesTest : public testing::TestWithParam<std::string> { - public: - static std::vector<std::string> png_list; - - protected: - void SetUp() override { - png_ = std::make_unique<PngHandler>(GetParam()); - ASSERT_TRUE(png_); - - ASSERT_EQ(PNG_COLOR_TYPE_GRAY, png_->color_type()) << "Recovery expects grayscale PNG file."; - ASSERT_LT(static_cast<png_uint_32>(5), png_->width()); - ASSERT_LT(static_cast<png_uint_32>(0), png_->height()); - ASSERT_EQ(1, png_->channels()) << "Recovery background text images expects 1-channel PNG file."; - } - - std::unique_ptr<PngHandler> png_{ nullptr }; -}; - -// Parses a png file and tests if it's qualified for the background text image under recovery. -TEST_P(ResourcesTest, ValidateLocale) { - std::vector<unsigned char> row(png_->width()); - for (png_uint_32 y = 0; y < png_->height(); ++y) { - png_read_row(png_->png_ptr(), row.data(), nullptr); - int w = (row[1] << 8) | row[0]; - int h = (row[3] << 8) | row[2]; - int len = row[4]; - EXPECT_LT(0, w); - EXPECT_LT(0, h); - EXPECT_LT(0, len) << "Locale string should be non-empty."; - EXPECT_NE(0, row[5]) << "Locale string is missing."; - - ASSERT_GE(png_->height(), y + 1 + h) << "Locale: " << kLocale << " is not found in the file."; - char* loc = reinterpret_cast<char*>(&row[5]); - if (matches_locale(loc, kLocale.c_str())) { - EXPECT_TRUE(android::base::StartsWith(loc, kLocale)); - break; - } - for (int i = 0; i < h; ++i, ++y) { - png_read_row(png_->png_ptr(), row.data(), nullptr); - } - } -} - -std::vector<std::string> ResourcesTest::png_list = add_files(); - -INSTANTIATE_TEST_CASE_P(BackgroundTextValidation, ResourcesTest, - ::testing::ValuesIn(ResourcesTest::png_list.cbegin(), - ResourcesTest::png_list.cend())); diff --git a/tests/component/applypatch_modes_test.cpp b/tests/unit/applypatch_modes_test.cpp index 08414b796..08414b796 100644 --- a/tests/component/applypatch_modes_test.cpp +++ b/tests/unit/applypatch_modes_test.cpp diff --git a/tests/component/bootloader_message_test.cpp b/tests/unit/bootloader_message_test.cpp index 95d875e69..95d875e69 100644 --- a/tests/component/bootloader_message_test.cpp +++ b/tests/unit/bootloader_message_test.cpp diff --git a/tests/component/edify_test.cpp b/tests/unit/edify_test.cpp index 8397bd38e..8397bd38e 100644 --- a/tests/component/edify_test.cpp +++ b/tests/unit/edify_test.cpp diff --git a/tests/unit/fuse_provider_test.cpp b/tests/unit/fuse_provider_test.cpp new file mode 100644 index 000000000..c5995dd7d --- /dev/null +++ b/tests/unit/fuse_provider_test.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2019 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 <stdint.h> +#include <unistd.h> + +#include <functional> +#include <string> +#include <vector> + +#include <android-base/file.h> +#include <android-base/logging.h> +#include <android-base/strings.h> +#include <android-base/unique_fd.h> +#include <gtest/gtest.h> + +#include "fuse_provider.h" +#include "fuse_sideload.h" +#include "install/install.h" + +TEST(FuseBlockMapTest, CreateFromBlockMap_smoke) { + TemporaryFile fake_block_device; + std::vector<std::string> lines = { + fake_block_device.path, "10000 4096", "3", "10 11", "20 21", "22 23", + }; + + TemporaryFile temp_file; + android::base::WriteStringToFile(android::base::Join(lines, '\n'), temp_file.path); + auto block_map_data = FuseBlockDataProvider::CreateFromBlockMap(temp_file.path, 4096); + + ASSERT_TRUE(block_map_data); + ASSERT_EQ(10000, block_map_data->file_size()); + ASSERT_EQ(4096, block_map_data->fuse_block_size()); + ASSERT_EQ(RangeSet({ { 10, 11 }, { 20, 21 }, { 22, 23 } }), block_map_data->ranges()); +} + +TEST(FuseBlockMapTest, ReadBlockAlignedData_smoke) { + std::string content; + content.reserve(40960); + for (char c = 0; c < 10; c++) { + content += std::string(4096, c); + } + TemporaryFile fake_block_device; + ASSERT_TRUE(android::base::WriteStringToFile(content, fake_block_device.path)); + + std::vector<std::string> lines = { + fake_block_device.path, + "20000 4096", + "1", + "0 5", + }; + TemporaryFile temp_file; + android::base::WriteStringToFile(android::base::Join(lines, '\n'), temp_file.path); + auto block_map_data = FuseBlockDataProvider::CreateFromBlockMap(temp_file.path, 4096); + + std::vector<uint8_t> result(2000); + ASSERT_TRUE(block_map_data->ReadBlockAlignedData(result.data(), 2000, 1)); + ASSERT_EQ(std::vector<uint8_t>(content.begin() + 4096, content.begin() + 6096), result); + + result.resize(20000); + ASSERT_TRUE(block_map_data->ReadBlockAlignedData(result.data(), 20000, 0)); + ASSERT_EQ(std::vector<uint8_t>(content.begin(), content.begin() + 20000), result); +} + +TEST(FuseBlockMapTest, ReadBlockAlignedData_large_fuse_block) { + std::string content; + for (char c = 0; c < 10; c++) { + content += std::string(4096, c); + } + + TemporaryFile temp_file; + ASSERT_TRUE(android::base::WriteStringToFile(content, temp_file.path)); + + std::vector<std::string> lines = { + temp_file.path, "36384 4096", "2", "0 5", "6 10", + }; + TemporaryFile block_map; + ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(lines, '\n'), block_map.path)); + + auto block_map_data = FuseBlockDataProvider::CreateFromBlockMap(block_map.path, 16384); + ASSERT_TRUE(block_map_data); + + std::vector<uint8_t> result(20000); + // Out of bound read + ASSERT_FALSE(block_map_data->ReadBlockAlignedData(result.data(), 20000, 2)); + ASSERT_TRUE(block_map_data->ReadBlockAlignedData(result.data(), 20000, 1)); + // expected source block contains: 4, 6-9 + std::string expected = content.substr(16384, 4096) + content.substr(24576, 15904); + ASSERT_EQ(std::vector<uint8_t>(expected.begin(), expected.end()), result); +} diff --git a/tests/component/sideload_test.cpp b/tests/unit/fuse_sideload_test.cpp index 6add99f41..6add99f41 100644 --- a/tests/component/sideload_test.cpp +++ b/tests/unit/fuse_sideload_test.cpp diff --git a/tests/component/imgdiff_test.cpp b/tests/unit/imgdiff_test.cpp index e76ccbdfb..e76ccbdfb 100644 --- a/tests/component/imgdiff_test.cpp +++ b/tests/unit/imgdiff_test.cpp diff --git a/tests/component/install_test.cpp b/tests/unit/install_test.cpp index 385132939..4ec409908 100644 --- a/tests/component/install_test.cpp +++ b/tests/unit/install_test.cpp @@ -33,6 +33,7 @@ #include <ziparchive/zip_writer.h> #include "install/install.h" +#include "install/wipe_device.h" #include "otautil/paths.h" #include "private/setup_commands.h" @@ -204,7 +205,7 @@ TEST(InstallTest, SetUpNonAbUpdateCommands) { std::string binary_path = std::string(td.path) + "/update_binary"; Paths::Get().set_temporary_update_binary(binary_path); std::vector<std::string> cmd; - ASSERT_EQ(0, SetUpNonAbUpdateCommands(package, zip, 0, status_fd, &cmd)); + ASSERT_TRUE(SetUpNonAbUpdateCommands(package, zip, 0, status_fd, &cmd)); ASSERT_EQ(4U, cmd.size()); ASSERT_EQ(binary_path, cmd[0]); ASSERT_EQ("3", cmd[1]); // RECOVERY_API_VERSION @@ -216,7 +217,7 @@ TEST(InstallTest, SetUpNonAbUpdateCommands) { // With non-zero retry count. update_binary will be removed automatically. cmd.clear(); - ASSERT_EQ(0, SetUpNonAbUpdateCommands(package, zip, 2, status_fd, &cmd)); + ASSERT_TRUE(SetUpNonAbUpdateCommands(package, zip, 2, status_fd, &cmd)); ASSERT_EQ(5U, cmd.size()); ASSERT_EQ(binary_path, cmd[0]); ASSERT_EQ("3", cmd[1]); // RECOVERY_API_VERSION @@ -243,7 +244,7 @@ TEST(InstallTest, SetUpNonAbUpdateCommands_MissingUpdateBinary) { TemporaryDir td; Paths::Get().set_temporary_update_binary(std::string(td.path) + "/update_binary"); std::vector<std::string> cmd; - ASSERT_EQ(INSTALL_CORRUPT, SetUpNonAbUpdateCommands(package, zip, 0, status_fd, &cmd)); + ASSERT_FALSE(SetUpNonAbUpdateCommands(package, zip, 0, status_fd, &cmd)); CloseArchive(zip); } @@ -270,19 +271,18 @@ static void VerifyAbUpdateCommands(const std::string& serialno, bool success = t ZipArchiveHandle zip; ASSERT_EQ(0, OpenArchive(temp_file.path, &zip)); - ZipString payload_name("payload.bin"); ZipEntry payload_entry; - ASSERT_EQ(0, FindEntry(zip, payload_name, &payload_entry)); + ASSERT_EQ(0, FindEntry(zip, "payload.bin", &payload_entry)); std::map<std::string, std::string> metadata; ASSERT_TRUE(ReadMetadataFromPackage(zip, &metadata)); if (success) { - ASSERT_EQ(0, CheckPackageMetadata(metadata, OtaType::AB)); + ASSERT_TRUE(CheckPackageMetadata(metadata, OtaType::AB)); int status_fd = 10; std::string package = "/path/to/update.zip"; std::vector<std::string> cmd; - ASSERT_EQ(0, SetUpAbUpdateCommands(package, zip, status_fd, &cmd)); + ASSERT_TRUE(SetUpAbUpdateCommands(package, zip, status_fd, &cmd)); ASSERT_EQ(5U, cmd.size()); ASSERT_EQ("/system/bin/update_engine_sideload", cmd[0]); ASSERT_EQ("--payload=file://" + package, cmd[1]); @@ -290,7 +290,7 @@ static void VerifyAbUpdateCommands(const std::string& serialno, bool success = t ASSERT_EQ("--headers=" + properties, cmd[3]); ASSERT_EQ("--status_fd=" + std::to_string(status_fd), cmd[4]); } else { - ASSERT_EQ(INSTALL_ERROR, CheckPackageMetadata(metadata, OtaType::AB)); + ASSERT_FALSE(CheckPackageMetadata(metadata, OtaType::AB)); } CloseArchive(zip); } @@ -325,7 +325,7 @@ TEST(InstallTest, SetUpAbUpdateCommands_MissingPayloadPropertiesTxt) { int status_fd = 10; std::string package = "/path/to/update.zip"; std::vector<std::string> cmd; - ASSERT_EQ(INSTALL_CORRUPT, SetUpAbUpdateCommands(package, zip, status_fd, &cmd)); + ASSERT_FALSE(SetUpAbUpdateCommands(package, zip, status_fd, &cmd)); CloseArchive(zip); } @@ -358,8 +358,8 @@ TEST(InstallTest, SetUpAbUpdateCommands_MultipleSerialnos) { VerifyAbUpdateCommands(long_serialno); } -static void test_check_package_metadata(const std::string& metadata_string, OtaType ota_type, - int exptected_result) { +static void TestCheckPackageMetadata(const std::string& metadata_string, OtaType ota_type, + bool exptected_result) { TemporaryFile temp_file; BuildZipArchive( { @@ -387,7 +387,7 @@ TEST(InstallTest, CheckPackageMetadata_ota_type) { "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()), }, "\n"); - test_check_package_metadata(metadata, OtaType::AB, INSTALL_ERROR); + TestCheckPackageMetadata(metadata, OtaType::AB, false); // Checks if ota-type matches metadata = android::base::Join( @@ -397,9 +397,9 @@ TEST(InstallTest, CheckPackageMetadata_ota_type) { "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()), }, "\n"); - test_check_package_metadata(metadata, OtaType::AB, 0); + TestCheckPackageMetadata(metadata, OtaType::AB, true); - test_check_package_metadata(metadata, OtaType::BRICK, INSTALL_ERROR); + TestCheckPackageMetadata(metadata, OtaType::BRICK, false); } TEST(InstallTest, CheckPackageMetadata_device_type) { @@ -409,7 +409,7 @@ TEST(InstallTest, CheckPackageMetadata_device_type) { "ota-type=BRICK", }, "\n"); - test_check_package_metadata(metadata, OtaType::BRICK, INSTALL_ERROR); + TestCheckPackageMetadata(metadata, OtaType::BRICK, false); // device type mismatches metadata = android::base::Join( @@ -418,7 +418,7 @@ TEST(InstallTest, CheckPackageMetadata_device_type) { "pre-device=dummy_device_type", }, "\n"); - test_check_package_metadata(metadata, OtaType::BRICK, INSTALL_ERROR); + TestCheckPackageMetadata(metadata, OtaType::BRICK, false); } TEST(InstallTest, CheckPackageMetadata_serial_number_smoke) { @@ -432,7 +432,7 @@ TEST(InstallTest, CheckPackageMetadata_serial_number_smoke) { "pre-device=" + device, }, "\n"); - test_check_package_metadata(metadata, OtaType::BRICK, 0); + TestCheckPackageMetadata(metadata, OtaType::BRICK, true); // Serial number mismatches metadata = android::base::Join( @@ -442,7 +442,7 @@ TEST(InstallTest, CheckPackageMetadata_serial_number_smoke) { "serialno=dummy_serial", }, "\n"); - test_check_package_metadata(metadata, OtaType::BRICK, INSTALL_ERROR); + TestCheckPackageMetadata(metadata, OtaType::BRICK, false); std::string serialno = android::base::GetProperty("ro.serialno", ""); ASSERT_NE("", serialno); @@ -453,7 +453,7 @@ TEST(InstallTest, CheckPackageMetadata_serial_number_smoke) { "serialno=" + serialno, }, "\n"); - test_check_package_metadata(metadata, OtaType::BRICK, 0); + TestCheckPackageMetadata(metadata, OtaType::BRICK, true); } TEST(InstallTest, CheckPackageMetadata_multiple_serial_number) { @@ -477,7 +477,7 @@ TEST(InstallTest, CheckPackageMetadata_multiple_serial_number) { "serialno=" + android::base::Join(serial_numbers, '|'), }, "\n"); - test_check_package_metadata(metadata, OtaType::BRICK, INSTALL_ERROR); + TestCheckPackageMetadata(metadata, OtaType::BRICK, false); serial_numbers.emplace_back(serialno); std::shuffle(serial_numbers.begin(), serial_numbers.end(), std::default_random_engine()); @@ -488,7 +488,7 @@ TEST(InstallTest, CheckPackageMetadata_multiple_serial_number) { "serialno=" + android::base::Join(serial_numbers, '|'), }, "\n"); - test_check_package_metadata(metadata, OtaType::BRICK, 0); + TestCheckPackageMetadata(metadata, OtaType::BRICK, true); } TEST(InstallTest, CheckPackageMetadata_ab_build_version) { @@ -506,7 +506,7 @@ TEST(InstallTest, CheckPackageMetadata_ab_build_version) { "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()), }, "\n"); - test_check_package_metadata(metadata, OtaType::AB, 0); + TestCheckPackageMetadata(metadata, OtaType::AB, true); metadata = android::base::Join( std::vector<std::string>{ @@ -516,7 +516,7 @@ TEST(InstallTest, CheckPackageMetadata_ab_build_version) { "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()), }, "\n"); - test_check_package_metadata(metadata, OtaType::AB, INSTALL_ERROR); + TestCheckPackageMetadata(metadata, OtaType::AB, false); } TEST(InstallTest, CheckPackageMetadata_ab_fingerprint) { @@ -534,7 +534,7 @@ TEST(InstallTest, CheckPackageMetadata_ab_fingerprint) { "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()), }, "\n"); - test_check_package_metadata(metadata, OtaType::AB, 0); + TestCheckPackageMetadata(metadata, OtaType::AB, true); metadata = android::base::Join( std::vector<std::string>{ @@ -544,7 +544,7 @@ TEST(InstallTest, CheckPackageMetadata_ab_fingerprint) { "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()), }, "\n"); - test_check_package_metadata(metadata, OtaType::AB, INSTALL_ERROR); + TestCheckPackageMetadata(metadata, OtaType::AB, false); } TEST(InstallTest, CheckPackageMetadata_ab_post_timestamp) { @@ -558,7 +558,7 @@ TEST(InstallTest, CheckPackageMetadata_ab_post_timestamp) { "pre-device=" + device, }, "\n"); - test_check_package_metadata(metadata, OtaType::AB, INSTALL_ERROR); + TestCheckPackageMetadata(metadata, OtaType::AB, false); // post timestamp should be larger than the timestamp on device. metadata = android::base::Join( @@ -568,7 +568,7 @@ TEST(InstallTest, CheckPackageMetadata_ab_post_timestamp) { "post-timestamp=0", }, "\n"); - test_check_package_metadata(metadata, OtaType::AB, INSTALL_ERROR); + TestCheckPackageMetadata(metadata, OtaType::AB, false); // fingerprint is required for downgrade metadata = android::base::Join( @@ -579,7 +579,7 @@ TEST(InstallTest, CheckPackageMetadata_ab_post_timestamp) { "ota-downgrade=yes", }, "\n"); - test_check_package_metadata(metadata, OtaType::AB, INSTALL_ERROR); + TestCheckPackageMetadata(metadata, OtaType::AB, false); std::string finger_print = android::base::GetProperty("ro.build.fingerprint", ""); ASSERT_NE("", finger_print); @@ -593,5 +593,5 @@ TEST(InstallTest, CheckPackageMetadata_ab_post_timestamp) { "ota-downgrade=yes", }, "\n"); - test_check_package_metadata(metadata, OtaType::AB, 0); + TestCheckPackageMetadata(metadata, OtaType::AB, true); } diff --git a/tests/unit/locale_test.cpp b/tests/unit/locale_test.cpp index cdaba0e8b..c69434c12 100644 --- a/tests/unit/locale_test.cpp +++ b/tests/unit/locale_test.cpp @@ -27,7 +27,7 @@ TEST(LocaleTest, Misc) { EXPECT_FALSE(matches_locale("en-GB", "en")); EXPECT_FALSE(matches_locale("en-GB", "en-US")); EXPECT_FALSE(matches_locale("en-US", "")); - // Empty locale prefix in the PNG file will match the input locale. - EXPECT_TRUE(matches_locale("", "en-US")); + // Empty locale prefix in the PNG file should not match the input locale. + EXPECT_FALSE(matches_locale("", "en-US")); EXPECT_TRUE(matches_locale("sr-Latn", "sr-Latn-BA")); } diff --git a/tests/unit/package_test.cpp b/tests/unit/package_test.cpp index a735a699e..5e31f7fa5 100644 --- a/tests/unit/package_test.cpp +++ b/tests/unit/package_test.cpp @@ -105,10 +105,9 @@ TEST_F(PackageTest, GetZipArchiveHandle_extract_entry) { ASSERT_TRUE(zip); // Check that we can extract one zip entry. - std::string entry_name = "dir1/file3.txt"; - ZipString path(entry_name.c_str()); + std::string_view entry_name = "dir1/file3.txt"; ZipEntry entry; - ASSERT_EQ(0, FindEntry(zip, path, &entry)); + ASSERT_EQ(0, FindEntry(zip, entry_name, &entry)); std::vector<uint8_t> extracted(entry_name.size()); ASSERT_EQ(0, ExtractToMemory(zip, &entry, extracted.data(), extracted.size())); diff --git a/tests/unit/rangeset_test.cpp b/tests/unit/rangeset_test.cpp index fc72f2f6d..699f933a0 100644 --- a/tests/unit/rangeset_test.cpp +++ b/tests/unit/rangeset_test.cpp @@ -18,6 +18,7 @@ #include <sys/types.h> #include <limits> +#include <optional> #include <vector> #include <gtest/gtest.h> @@ -248,6 +249,29 @@ TEST(RangeSetTest, ToString) { ASSERT_EQ("6,1,3,4,6,15,22", RangeSet::Parse("6,1,3,4,6,15,22").ToString()); } +TEST(RangeSetTest, GetSubRanges_invalid) { + RangeSet range0({ { 1, 11 }, { 20, 30 } }); + ASSERT_FALSE(range0.GetSubRanges(0, 21)); // too many blocks + ASSERT_FALSE(range0.GetSubRanges(21, 1)); // start block OOB +} + +TEST(RangeSetTest, GetSubRanges_empty) { + RangeSet range0({ { 1, 11 }, { 20, 30 } }); + ASSERT_EQ(RangeSet{}, range0.GetSubRanges(1, 0)); // empty num_of_blocks +} + +TEST(RangeSetTest, GetSubRanges_smoke) { + RangeSet range0({ { 10, 11 } }); + ASSERT_EQ(RangeSet({ { 10, 11 } }), range0.GetSubRanges(0, 1)); + + RangeSet range1({ { 10, 11 }, { 20, 21 }, { 30, 31 } }); + ASSERT_EQ(range1, range1.GetSubRanges(0, 3)); + ASSERT_EQ(RangeSet({ { 20, 21 } }), range1.GetSubRanges(1, 1)); + + RangeSet range2({ { 1, 11 }, { 20, 25 }, { 30, 35 } }); + ASSERT_EQ(RangeSet({ { 10, 11 }, { 20, 25 }, { 30, 31 } }), range2.GetSubRanges(9, 7)); +} + TEST(SortedRangeSetTest, Insert) { SortedRangeSet rs({ { 2, 3 }, { 4, 6 }, { 8, 14 } }); rs.Insert({ 1, 2 }); diff --git a/tests/unit/resources_test.cpp b/tests/unit/resources_test.cpp index c3f72718f..302744308 100644 --- a/tests/unit/resources_test.cpp +++ b/tests/unit/resources_test.cpp @@ -14,12 +14,62 @@ * limitations under the License. */ +#include <dirent.h> +#include <stdio.h> +#include <stdlib.h> + +#include <memory> #include <string> +#include <vector> +#include <android-base/file.h> +#include <android-base/strings.h> #include <gtest/gtest.h> +#include <png.h> #include "common/test_constants.h" #include "minui/minui.h" +#include "private/resources.h" + +static const std::string kLocale = "zu"; + +static const std::vector<std::string> kResourceImagesDirs{ + "res-mdpi/images/", "res-hdpi/images/", "res-xhdpi/images/", + "res-xxhdpi/images/", "res-xxxhdpi/images/", +}; + +static int png_filter(const dirent* de) { + if (de->d_type != DT_REG || !android::base::EndsWith(de->d_name, "_text.png")) { + return 0; + } + return 1; +} + +// Finds out all the PNG files to test, which stay under the same dir with the executabl.. +static std::vector<std::string> add_files() { + std::vector<std::string> files; + for (const std::string& images_dir : kResourceImagesDirs) { + static std::string exec_dir = android::base::GetExecutableDirectory(); + std::string dir_path = exec_dir + "/" + images_dir; + dirent** namelist; + int n = scandir(dir_path.c_str(), &namelist, png_filter, alphasort); + if (n == -1) { + printf("Failed to scandir %s: %s\n", dir_path.c_str(), strerror(errno)); + continue; + } + if (n == 0) { + printf("No file is added for test in %s\n", dir_path.c_str()); + } + + while (n--) { + std::string file_path = dir_path + namelist[n]->d_name; + files.push_back(file_path); + free(namelist[n]); + } + free(namelist); + } + return files; +} TEST(ResourcesTest, res_create_multi_display_surface) { GRSurface** frames; @@ -35,3 +85,52 @@ TEST(ResourcesTest, res_create_multi_display_surface) { } free(frames); } + +class ResourcesTest : public testing::TestWithParam<std::string> { + public: + static std::vector<std::string> png_list; + + protected: + void SetUp() override { + png_ = std::make_unique<PngHandler>(GetParam()); + ASSERT_TRUE(png_); + + ASSERT_EQ(PNG_COLOR_TYPE_GRAY, png_->color_type()) << "Recovery expects grayscale PNG file."; + ASSERT_LT(static_cast<png_uint_32>(5), png_->width()); + ASSERT_LT(static_cast<png_uint_32>(0), png_->height()); + ASSERT_EQ(1, png_->channels()) << "Recovery background text images expects 1-channel PNG file."; + } + + std::unique_ptr<PngHandler> png_{ nullptr }; +}; + +// Parses a png file and tests if it's qualified for the background text image under recovery. +TEST_P(ResourcesTest, ValidateLocale) { + std::vector<unsigned char> row(png_->width()); + for (png_uint_32 y = 0; y < png_->height(); ++y) { + png_read_row(png_->png_ptr(), row.data(), nullptr); + int w = (row[1] << 8) | row[0]; + int h = (row[3] << 8) | row[2]; + int len = row[4]; + EXPECT_LT(0, w); + EXPECT_LT(0, h); + EXPECT_LT(0, len) << "Locale string should be non-empty."; + EXPECT_NE(0, row[5]) << "Locale string is missing."; + + ASSERT_GE(png_->height(), y + 1 + h) << "Locale: " << kLocale << " is not found in the file."; + char* loc = reinterpret_cast<char*>(&row[5]); + if (matches_locale(loc, kLocale.c_str())) { + EXPECT_TRUE(android::base::StartsWith(loc, kLocale)); + break; + } + for (int i = 0; i < h; ++i, ++y) { + png_read_row(png_->png_ptr(), row.data(), nullptr); + } + } +} + +std::vector<std::string> ResourcesTest::png_list = add_files(); + +INSTANTIATE_TEST_CASE_P(BackgroundTextValidation, ResourcesTest, + ::testing::ValuesIn(ResourcesTest::png_list.cbegin(), + ResourcesTest::png_list.cend())); diff --git a/tests/unit/sysutil_test.cpp b/tests/unit/sysutil_test.cpp index 3466e8eec..64b8956f7 100644 --- a/tests/unit/sysutil_test.cpp +++ b/tests/unit/sysutil_test.cpp @@ -67,7 +67,7 @@ TEST(SysUtilTest, ParseBlockMapFile_invalid_size) { "/dev/abc", "42949672950 4294967295", "1", - "0 9", + "0 10", }; TemporaryFile temp_file; diff --git a/tests/component/uncrypt_test.cpp b/tests/unit/uncrypt_test.cpp index e97d589a6..e97d589a6 100644 --- a/tests/component/uncrypt_test.cpp +++ b/tests/unit/uncrypt_test.cpp diff --git a/tests/component/update_verifier_test.cpp b/tests/unit/update_verifier_test.cpp index e27e58c22..e27e58c22 100644 --- a/tests/component/update_verifier_test.cpp +++ b/tests/unit/update_verifier_test.cpp diff --git a/tests/component/updater_test.cpp b/tests/unit/updater_test.cpp index a0a7b66ab..8993dd8b7 100644 --- a/tests/component/updater_test.cpp +++ b/tests/unit/updater_test.cpp @@ -52,21 +52,20 @@ #include "updater/blockimg.h" #include "updater/install.h" #include "updater/updater.h" +#include "updater/updater_runtime.h" using namespace std::string_literals; using PackageEntries = std::unordered_map<std::string, std::string>; -struct selabel_handle* sehandle = nullptr; - static void expect(const char* expected, const std::string& expr_str, CauseCode cause_code, - UpdaterInfo* info = nullptr) { + Updater* updater) { std::unique_ptr<Expr> e; int error_count = 0; ASSERT_EQ(0, ParseString(expr_str, &e, &error_count)); ASSERT_EQ(0, error_count); - State state(expr_str, info); + State state(expr_str, updater); std::string result; bool status = Evaluate(&state, e, &result); @@ -85,6 +84,11 @@ static void expect(const char* expected, const std::string& expr_str, CauseCode ASSERT_EQ(cause_code, state.cause_code); } +static void expect(const char* expected, const std::string& expr_str, CauseCode cause_code) { + Updater updater(std::make_unique<UpdaterRuntime>(nullptr)); + expect(expected, expr_str, cause_code, &updater); +} + static void BuildUpdatePackage(const PackageEntries& entries, int fd) { FILE* zip_file_ptr = fdopen(fd, "wb"); ZipWriter zip_writer(zip_file_ptr); @@ -102,38 +106,6 @@ static void BuildUpdatePackage(const PackageEntries& entries, int fd) { ASSERT_EQ(0, fclose(zip_file_ptr)); } -static void RunBlockImageUpdate(bool is_verify, const PackageEntries& entries, - const std::string& image_file, const std::string& result, - CauseCode cause_code = kNoCause) { - CHECK(entries.find("transfer_list") != entries.end()); - - // Build the update package. - TemporaryFile zip_file; - BuildUpdatePackage(entries, zip_file.release()); - - MemMapping map; - ASSERT_TRUE(map.MapFile(zip_file.path)); - ZipArchiveHandle handle; - ASSERT_EQ(0, OpenArchiveFromMemory(map.addr, map.length, zip_file.path, &handle)); - - // Set up the handler, command_pipe, patch offset & length. - UpdaterInfo updater_info; - updater_info.package_zip = handle; - TemporaryFile temp_pipe; - updater_info.cmd_pipe = fdopen(temp_pipe.release(), "wbe"); - updater_info.package_zip_addr = map.addr; - updater_info.package_zip_len = map.length; - - std::string new_data = entries.find("new_data.br") != entries.end() ? "new_data.br" : "new_data"; - std::string script = is_verify ? "block_image_verify" : "block_image_update"; - script += R"((")" + image_file + R"(", package_extract_file("transfer_list"), ")" + new_data + - R"(", "patch_data"))"; - expect(result.c_str(), script, cause_code, &updater_info); - - ASSERT_EQ(0, fclose(updater_info.cmd_pipe)); - CloseArchive(handle); -} - static std::string GetSha1(std::string_view content) { uint8_t digest[SHA_DIGEST_LENGTH]; SHA1(reinterpret_cast<const uint8_t*>(content.data()), content.size(), digest); @@ -159,29 +131,26 @@ static Value* BlobToString(const char* name, State* state, return args[0].release(); } -class UpdaterTest : public ::testing::Test { +class UpdaterTestBase { protected: - void SetUp() override { + UpdaterTestBase() : updater_(std::make_unique<UpdaterRuntime>(nullptr)) {} + + void SetUp() { RegisterBuiltins(); RegisterInstallFunctions(); RegisterBlockImageFunctions(); - RegisterFunction("blob_to_string", BlobToString); - // Each test is run in a separate process (isolated mode). Shared temporary files won't cause // conflicts. Paths::Get().set_cache_temp_source(temp_saved_source_.path); Paths::Get().set_last_command_file(temp_last_command_.path); Paths::Get().set_stash_directory_base(temp_stash_base_.path); - // Enable a special command "abort" to simulate interruption. - Command::abort_allowed_ = true; - last_command_file_ = temp_last_command_.path; image_file_ = image_temp_file_.path; } - void TearDown() override { + void TearDown() { // Clean up the last_command_file if any. ASSERT_TRUE(android::base::RemoveFileIfExists(last_command_file_)); @@ -191,16 +160,80 @@ class UpdaterTest : public ::testing::Test { ASSERT_TRUE(android::base::RemoveFileIfExists(updated_marker)); } + void RunBlockImageUpdate(bool is_verify, PackageEntries entries, const std::string& image_file, + const std::string& result, CauseCode cause_code = kNoCause) { + CHECK(entries.find("transfer_list") != entries.end()); + std::string new_data = + entries.find("new_data.br") != entries.end() ? "new_data.br" : "new_data"; + std::string script = is_verify ? "block_image_verify" : "block_image_update"; + script += R"((")" + image_file + R"(", package_extract_file("transfer_list"), ")" + new_data + + R"(", "patch_data"))"; + entries.emplace(Updater::SCRIPT_NAME, script); + + // Build the update package. + TemporaryFile zip_file; + BuildUpdatePackage(entries, zip_file.release()); + + // Set up the handler, command_pipe, patch offset & length. + TemporaryFile temp_pipe; + ASSERT_TRUE(updater_.Init(temp_pipe.release(), zip_file.path, false)); + ASSERT_TRUE(updater_.RunUpdate()); + ASSERT_EQ(result, updater_.GetResult()); + + // Parse the cause code written to the command pipe. + int received_cause_code = kNoCause; + std::string pipe_content; + ASSERT_TRUE(android::base::ReadFileToString(temp_pipe.path, &pipe_content)); + auto lines = android::base::Split(pipe_content, "\n"); + for (std::string_view line : lines) { + if (android::base::ConsumePrefix(&line, "log cause: ")) { + ASSERT_TRUE(android::base::ParseInt(line.data(), &received_cause_code)); + } + } + ASSERT_EQ(cause_code, received_cause_code); + } + TemporaryFile temp_saved_source_; TemporaryDir temp_stash_base_; std::string last_command_file_; std::string image_file_; + Updater updater_; + private: TemporaryFile temp_last_command_; TemporaryFile image_temp_file_; }; +class UpdaterTest : public UpdaterTestBase, public ::testing::Test { + protected: + void SetUp() override { + UpdaterTestBase::SetUp(); + + RegisterFunction("blob_to_string", BlobToString); + // Enable a special command "abort" to simulate interruption. + Command::abort_allowed_ = true; + } + + void TearDown() override { + UpdaterTestBase::TearDown(); + } + + void SetUpdaterCmdPipe(int fd) { + FILE* cmd_pipe = fdopen(fd, "w"); + ASSERT_NE(nullptr, cmd_pipe); + updater_.cmd_pipe_.reset(cmd_pipe); + } + + void SetUpdaterOtaPackageHandle(ZipArchiveHandle handle) { + updater_.package_handle_ = handle; + } + + void FlushUpdaterCommandPipe() const { + fflush(updater_.cmd_pipe_.get()); + } +}; + TEST_F(UpdaterTest, getprop) { expect(android::base::GetProperty("ro.product.device", "").c_str(), "getprop(\"ro.product.device\")", @@ -317,13 +350,12 @@ TEST_F(UpdaterTest, package_extract_file) { ASSERT_EQ(0, OpenArchive(zip_path.c_str(), &handle)); // Need to set up the ziphandle. - UpdaterInfo updater_info; - updater_info.package_zip = handle; + SetUpdaterOtaPackageHandle(handle); // Two-argument version. TemporaryFile temp_file1; std::string script("package_extract_file(\"a.txt\", \"" + std::string(temp_file1.path) + "\")"); - expect("t", script, kNoCause, &updater_info); + expect("t", script, kNoCause, &updater_); // Verify the extracted entry. std::string data; @@ -332,32 +364,30 @@ TEST_F(UpdaterTest, package_extract_file) { // Now extract another entry to the same location, which should overwrite. script = "package_extract_file(\"b.txt\", \"" + std::string(temp_file1.path) + "\")"; - expect("t", script, kNoCause, &updater_info); + expect("t", script, kNoCause, &updater_); ASSERT_TRUE(android::base::ReadFileToString(temp_file1.path, &data)); ASSERT_EQ(kBTxtContents, data); // Missing zip entry. The two-argument version doesn't abort. script = "package_extract_file(\"doesntexist\", \"" + std::string(temp_file1.path) + "\")"; - expect("", script, kNoCause, &updater_info); + expect("", script, kNoCause, &updater_); // Extract to /dev/full should fail. script = "package_extract_file(\"a.txt\", \"/dev/full\")"; - expect("", script, kNoCause, &updater_info); + expect("", script, kNoCause, &updater_); // One-argument version. package_extract_file() gives a VAL_BLOB, which needs to be converted to // VAL_STRING for equality test. script = "blob_to_string(package_extract_file(\"a.txt\")) == \"" + kATxtContents + "\""; - expect("t", script, kNoCause, &updater_info); + expect("t", script, kNoCause, &updater_); script = "blob_to_string(package_extract_file(\"b.txt\")) == \"" + kBTxtContents + "\""; - expect("t", script, kNoCause, &updater_info); + expect("t", script, kNoCause, &updater_); // Missing entry. The one-argument version aborts the evaluation. script = "package_extract_file(\"doesntexist\")"; - expect(nullptr, script, kPackageExtractFileFailure, &updater_info); - - CloseArchive(handle); + expect(nullptr, script, kPackageExtractFileFailure, &updater_); } TEST_F(UpdaterTest, read_file) { @@ -563,17 +593,15 @@ TEST_F(UpdaterTest, set_progress) { expect(nullptr, "set_progress(\".3.5\")", kArgsParsingFailure); TemporaryFile tf; - UpdaterInfo updater_info; - updater_info.cmd_pipe = fdopen(tf.release(), "w"); - expect(".52", "set_progress(\".52\")", kNoCause, &updater_info); - fflush(updater_info.cmd_pipe); + SetUpdaterCmdPipe(tf.release()); + expect(".52", "set_progress(\".52\")", kNoCause, &updater_); + FlushUpdaterCommandPipe(); std::string cmd; ASSERT_TRUE(android::base::ReadFileToString(tf.path, &cmd)); ASSERT_EQ(android::base::StringPrintf("set_progress %f\n", .52), cmd); // recovery-updater protocol expects 2 tokens ("set_progress <frac>"). ASSERT_EQ(2U, android::base::Split(cmd, " ").size()); - ASSERT_EQ(0, fclose(updater_info.cmd_pipe)); } TEST_F(UpdaterTest, show_progress) { @@ -588,17 +616,15 @@ TEST_F(UpdaterTest, show_progress) { expect(nullptr, "show_progress(\".3\", \"5a\")", kArgsParsingFailure); TemporaryFile tf; - UpdaterInfo updater_info; - updater_info.cmd_pipe = fdopen(tf.release(), "w"); - expect(".52", "show_progress(\".52\", \"10\")", kNoCause, &updater_info); - fflush(updater_info.cmd_pipe); + SetUpdaterCmdPipe(tf.release()); + expect(".52", "show_progress(\".52\", \"10\")", kNoCause, &updater_); + FlushUpdaterCommandPipe(); std::string cmd; ASSERT_TRUE(android::base::ReadFileToString(tf.path, &cmd)); ASSERT_EQ(android::base::StringPrintf("progress %f %d\n", .52, 10), cmd); // recovery-updater protocol expects 3 tokens ("progress <frac> <secs>"). ASSERT_EQ(3U, android::base::Split(cmd, " ").size()); - ASSERT_EQ(0, fclose(updater_info.cmd_pipe)); } TEST_F(UpdaterTest, block_image_update_parsing_error) { @@ -993,44 +1019,20 @@ TEST_F(UpdaterTest, last_command_verify) { ASSERT_EQ(-1, access(last_command_file_.c_str(), R_OK)); } -class ResumableUpdaterTest : public testing::TestWithParam<size_t> { +class ResumableUpdaterTest : public UpdaterTestBase, public testing::TestWithParam<size_t> { protected: void SetUp() override { - RegisterBuiltins(); - RegisterInstallFunctions(); - RegisterBlockImageFunctions(); - - Paths::Get().set_cache_temp_source(temp_saved_source_.path); - Paths::Get().set_last_command_file(temp_last_command_.path); - Paths::Get().set_stash_directory_base(temp_stash_base_.path); - + UpdaterTestBase::SetUp(); // Enable a special command "abort" to simulate interruption. Command::abort_allowed_ = true; - index_ = GetParam(); - image_file_ = image_temp_file_.path; - last_command_file_ = temp_last_command_.path; } void TearDown() override { - // Clean up the last_command_file if any. - ASSERT_TRUE(android::base::RemoveFileIfExists(last_command_file_)); - - // Clear partition updated marker if any. - std::string updated_marker{ temp_stash_base_.path }; - updated_marker += "/" + GetSha1(image_temp_file_.path) + ".UPDATED"; - ASSERT_TRUE(android::base::RemoveFileIfExists(updated_marker)); + UpdaterTestBase::TearDown(); } - TemporaryFile temp_saved_source_; - TemporaryDir temp_stash_base_; - std::string last_command_file_; - std::string image_file_; size_t index_; - - private: - TemporaryFile temp_last_command_; - TemporaryFile image_temp_file_; }; static std::string g_source_image; diff --git a/tests/component/verifier_test.cpp b/tests/unit/verifier_test.cpp index ded23c52f..ded23c52f 100644 --- a/tests/component/verifier_test.cpp +++ b/tests/unit/verifier_test.cpp diff --git a/tests/unit/zip_test.cpp b/tests/unit/zip_test.cpp index dfe617ebe..0753d64e1 100644 --- a/tests/unit/zip_test.cpp +++ b/tests/unit/zip_test.cpp @@ -37,10 +37,9 @@ 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"; - ZipString binary_path(BINARY_PATH); ZipEntry binary_entry; // Make sure the package opens correctly and its entry can be read. - ASSERT_EQ(0, FindEntry(handle, binary_path, &binary_entry)); + ASSERT_EQ(0, FindEntry(handle, BINARY_PATH, &binary_entry)); TemporaryFile tmp_binary; ASSERT_NE(-1, tmp_binary.fd); |