Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agree to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <fcntl.h> |
| 18 | #include <gtest/gtest.h> |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <sys/stat.h> |
| 22 | #include <sys/statvfs.h> |
| 23 | #include <sys/types.h> |
| 24 | #include <time.h> |
| 25 | |
Tao Bao | fada91c | 2016-10-27 18:16:06 -0700 | [diff] [blame] | 26 | #include <memory> |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 27 | #include <string> |
Tao Bao | fada91c | 2016-10-27 18:16:06 -0700 | [diff] [blame] | 28 | #include <vector> |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 29 | |
| 30 | #include <android-base/file.h> |
| 31 | #include <android-base/stringprintf.h> |
| 32 | #include <android-base/test_utils.h> |
Tao Bao | fada91c | 2016-10-27 18:16:06 -0700 | [diff] [blame] | 33 | #include <openssl/sha.h> |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 34 | |
| 35 | #include "applypatch/applypatch.h" |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 36 | #include "applypatch/applypatch_modes.h" |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 37 | #include "common/test_constants.h" |
Tianjie Xu | 3bbb20f | 2018-02-27 15:56:11 -0800 | [diff] [blame] | 38 | #include "otautil/cache_location.h" |
Tao Bao | 09e468f | 2017-09-29 14:39:33 -0700 | [diff] [blame] | 39 | #include "otautil/print_sha1.h" |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 40 | |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 41 | static void sha1sum(const std::string& fname, std::string* sha1, size_t* fsize = nullptr) { |
| 42 | ASSERT_NE(nullptr, sha1); |
Tao Bao | fada91c | 2016-10-27 18:16:06 -0700 | [diff] [blame] | 43 | |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 44 | std::string data; |
| 45 | ASSERT_TRUE(android::base::ReadFileToString(fname, &data)); |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 46 | |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 47 | if (fsize != nullptr) { |
| 48 | *fsize = data.size(); |
| 49 | } |
| 50 | |
| 51 | uint8_t digest[SHA_DIGEST_LENGTH]; |
| 52 | SHA1(reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), digest); |
| 53 | *sha1 = print_sha1(digest); |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | static void mangle_file(const std::string& fname) { |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 57 | std::string content(1024, '\0'); |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 58 | for (size_t i = 0; i < 1024; i++) { |
| 59 | content[i] = rand() % 256; |
| 60 | } |
| 61 | ASSERT_TRUE(android::base::WriteStringToFile(content, fname)); |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 64 | class ApplyPatchTest : public ::testing::Test { |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 65 | public: |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 66 | virtual void SetUp() override { |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 67 | // set up files |
| 68 | old_file = from_testdata_base("old.file"); |
| 69 | new_file = from_testdata_base("new.file"); |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 70 | nonexistent_file = from_testdata_base("nonexistent.file"); |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 71 | |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 72 | // set up SHA constants |
Tao Bao | 8dd44e9 | 2016-11-21 11:16:56 -0800 | [diff] [blame] | 73 | sha1sum(old_file, &old_sha1, &old_size); |
| 74 | sha1sum(new_file, &new_sha1, &new_size); |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 75 | srand(time(nullptr)); |
| 76 | bad_sha1_a = android::base::StringPrintf("%040x", rand()); |
| 77 | bad_sha1_b = android::base::StringPrintf("%040x", rand()); |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 78 | } |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 79 | |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 80 | std::string old_file; |
| 81 | std::string new_file; |
| 82 | std::string nonexistent_file; |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 83 | |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 84 | std::string old_sha1; |
| 85 | std::string new_sha1; |
| 86 | std::string bad_sha1_a; |
| 87 | std::string bad_sha1_b; |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 88 | |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 89 | size_t old_size; |
| 90 | size_t new_size; |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 91 | }; |
| 92 | |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 93 | class ApplyPatchCacheTest : public ApplyPatchTest { |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 94 | protected: |
| 95 | void SetUp() override { |
| 96 | ApplyPatchTest::SetUp(); |
Tianjie Xu | 3bbb20f | 2018-02-27 15:56:11 -0800 | [diff] [blame] | 97 | CacheLocation::location().set_cache_temp_source(old_file); |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 98 | } |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 99 | }; |
| 100 | |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 101 | class ApplyPatchModesTest : public ::testing::Test { |
| 102 | protected: |
| 103 | void SetUp() override { |
Tianjie Xu | 3bbb20f | 2018-02-27 15:56:11 -0800 | [diff] [blame] | 104 | CacheLocation::location().set_cache_temp_source(cache_source.path); |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | TemporaryFile cache_source; |
| 108 | }; |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 109 | |
Tianjie Xu | a5fd5ab | 2016-10-18 15:18:22 -0700 | [diff] [blame] | 110 | TEST_F(ApplyPatchTest, CheckModeSkip) { |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 111 | std::vector<std::string> sha1s; |
| 112 | ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s)); |
Tianjie Xu | a5fd5ab | 2016-10-18 15:18:22 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 115 | TEST_F(ApplyPatchTest, CheckModeSingle) { |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 116 | std::vector<std::string> sha1s = { old_sha1 }; |
| 117 | ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s)); |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | TEST_F(ApplyPatchTest, CheckModeMultiple) { |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 121 | std::vector<std::string> sha1s = { bad_sha1_a, old_sha1, bad_sha1_b }; |
| 122 | ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s)); |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | TEST_F(ApplyPatchTest, CheckModeFailure) { |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 126 | std::vector<std::string> sha1s = { bad_sha1_a, bad_sha1_b }; |
| 127 | ASSERT_NE(0, applypatch_check(&old_file[0], sha1s)); |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Tao Bao | 8dd44e9 | 2016-11-21 11:16:56 -0800 | [diff] [blame] | 130 | TEST_F(ApplyPatchTest, CheckModeEmmcTarget) { |
| 131 | // EMMC:old_file:size:sha1 should pass the check. |
| 132 | std::string src_file = |
| 133 | "EMMC:" + old_file + ":" + std::to_string(old_size) + ":" + old_sha1; |
| 134 | std::vector<std::string> sha1s; |
| 135 | ASSERT_EQ(0, applypatch_check(src_file.c_str(), sha1s)); |
| 136 | |
| 137 | // EMMC:old_file:(size-1):sha1:(size+1):sha1 should fail the check. |
| 138 | src_file = "EMMC:" + old_file + ":" + std::to_string(old_size - 1) + ":" + old_sha1 + ":" + |
| 139 | std::to_string(old_size + 1) + ":" + old_sha1; |
| 140 | ASSERT_EQ(1, applypatch_check(src_file.c_str(), sha1s)); |
| 141 | |
| 142 | // EMMC:old_file:(size-1):sha1:size:sha1:(size+1):sha1 should pass the check. |
| 143 | src_file = "EMMC:" + old_file + ":" + |
| 144 | std::to_string(old_size - 1) + ":" + old_sha1 + ":" + |
| 145 | std::to_string(old_size) + ":" + old_sha1 + ":" + |
| 146 | std::to_string(old_size + 1) + ":" + old_sha1; |
| 147 | ASSERT_EQ(0, applypatch_check(src_file.c_str(), sha1s)); |
| 148 | |
| 149 | // EMMC:old_file:(size+1):sha1:(size-1):sha1:size:sha1 should pass the check. |
| 150 | src_file = "EMMC:" + old_file + ":" + |
| 151 | std::to_string(old_size + 1) + ":" + old_sha1 + ":" + |
| 152 | std::to_string(old_size - 1) + ":" + old_sha1 + ":" + |
| 153 | std::to_string(old_size) + ":" + old_sha1; |
| 154 | ASSERT_EQ(0, applypatch_check(src_file.c_str(), sha1s)); |
| 155 | |
| 156 | // EMMC:new_file:(size+1):old_sha1:(size-1):old_sha1:size:old_sha1:size:new_sha1 |
| 157 | // should pass the check. |
| 158 | src_file = "EMMC:" + new_file + ":" + |
| 159 | std::to_string(old_size + 1) + ":" + old_sha1 + ":" + |
| 160 | std::to_string(old_size - 1) + ":" + old_sha1 + ":" + |
| 161 | std::to_string(old_size) + ":" + old_sha1 + ":" + |
| 162 | std::to_string(new_size) + ":" + new_sha1; |
| 163 | ASSERT_EQ(0, applypatch_check(src_file.c_str(), sha1s)); |
| 164 | } |
| 165 | |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 166 | TEST_F(ApplyPatchCacheTest, CheckCacheCorruptedSourceSingle) { |
| 167 | TemporaryFile temp_file; |
| 168 | mangle_file(temp_file.path); |
| 169 | std::vector<std::string> sha1s_single = { old_sha1 }; |
| 170 | ASSERT_EQ(0, applypatch_check(temp_file.path, sha1s_single)); |
| 171 | ASSERT_EQ(0, applypatch_check(nonexistent_file.c_str(), sha1s_single)); |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 172 | } |
| 173 | |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 174 | TEST_F(ApplyPatchCacheTest, CheckCacheCorruptedSourceMultiple) { |
| 175 | TemporaryFile temp_file; |
| 176 | mangle_file(temp_file.path); |
| 177 | std::vector<std::string> sha1s_multiple = { bad_sha1_a, old_sha1, bad_sha1_b }; |
| 178 | ASSERT_EQ(0, applypatch_check(temp_file.path, sha1s_multiple)); |
| 179 | ASSERT_EQ(0, applypatch_check(nonexistent_file.c_str(), sha1s_multiple)); |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 182 | TEST_F(ApplyPatchCacheTest, CheckCacheCorruptedSourceFailure) { |
| 183 | TemporaryFile temp_file; |
| 184 | mangle_file(temp_file.path); |
| 185 | std::vector<std::string> sha1s_failure = { bad_sha1_a, bad_sha1_b }; |
| 186 | ASSERT_NE(0, applypatch_check(temp_file.path, sha1s_failure)); |
| 187 | ASSERT_NE(0, applypatch_check(nonexistent_file.c_str(), sha1s_failure)); |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 188 | } |
| 189 | |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 190 | TEST_F(ApplyPatchModesTest, InvalidArgs) { |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 191 | // At least two args (including the filename). |
| 192 | ASSERT_EQ(2, applypatch_modes(1, (const char* []){ "applypatch" })); |
| 193 | |
| 194 | // Unrecognized args. |
| 195 | ASSERT_EQ(2, applypatch_modes(2, (const char* []){ "applypatch", "-x" })); |
| 196 | } |
| 197 | |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 198 | TEST_F(ApplyPatchModesTest, PatchModeEmmcTarget) { |
Tao Bao | 8dd44e9 | 2016-11-21 11:16:56 -0800 | [diff] [blame] | 199 | std::string boot_img = from_testdata_base("boot.img"); |
| 200 | size_t boot_img_size; |
| 201 | std::string boot_img_sha1; |
| 202 | sha1sum(boot_img, &boot_img_sha1, &boot_img_size); |
| 203 | |
| 204 | std::string recovery_img = from_testdata_base("recovery.img"); |
| 205 | size_t size; |
| 206 | std::string recovery_img_sha1; |
| 207 | sha1sum(recovery_img, &recovery_img_sha1, &size); |
| 208 | std::string recovery_img_size = std::to_string(size); |
| 209 | |
| 210 | std::string bonus_file = from_testdata_base("bonus.file"); |
| 211 | |
| 212 | // applypatch -b <bonus-file> <src-file> <tgt-file> <tgt-sha1> <tgt-size> <src-sha1>:<patch> |
| 213 | TemporaryFile tmp1; |
| 214 | std::string src_file = |
| 215 | "EMMC:" + boot_img + ":" + std::to_string(boot_img_size) + ":" + boot_img_sha1; |
| 216 | std::string tgt_file = "EMMC:" + std::string(tmp1.path); |
| 217 | std::string patch = boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot.p"); |
| 218 | std::vector<const char*> args = { |
| 219 | "applypatch", |
| 220 | "-b", |
| 221 | bonus_file.c_str(), |
| 222 | src_file.c_str(), |
| 223 | tgt_file.c_str(), |
| 224 | recovery_img_sha1.c_str(), |
| 225 | recovery_img_size.c_str(), |
| 226 | patch.c_str() |
| 227 | }; |
| 228 | ASSERT_EQ(0, applypatch_modes(args.size(), args.data())); |
| 229 | |
| 230 | // applypatch <src-file> <tgt-file> <tgt-sha1> <tgt-size> <src-sha1>:<patch> |
| 231 | TemporaryFile tmp2; |
| 232 | patch = boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot-with-bonus.p"); |
| 233 | tgt_file = "EMMC:" + std::string(tmp2.path); |
| 234 | std::vector<const char*> args2 = { |
| 235 | "applypatch", |
| 236 | src_file.c_str(), |
| 237 | tgt_file.c_str(), |
| 238 | recovery_img_sha1.c_str(), |
| 239 | recovery_img_size.c_str(), |
| 240 | patch.c_str() |
| 241 | }; |
| 242 | ASSERT_EQ(0, applypatch_modes(args2.size(), args2.data())); |
| 243 | |
| 244 | // applypatch -b <bonus-file> <src-file> <tgt-file> <tgt-sha1> <tgt-size> \ |
| 245 | // <src-sha1-fake>:<patch1> <src-sha1>:<patch2> |
| 246 | TemporaryFile tmp3; |
| 247 | tgt_file = "EMMC:" + std::string(tmp3.path); |
| 248 | std::string bad_sha1_a = android::base::StringPrintf("%040x", rand()); |
| 249 | std::string bad_sha1_b = android::base::StringPrintf("%040x", rand()); |
| 250 | std::string patch1 = bad_sha1_a + ":" + from_testdata_base("recovery-from-boot.p"); |
| 251 | std::string patch2 = boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot.p"); |
| 252 | std::string patch3 = bad_sha1_b + ":" + from_testdata_base("recovery-from-boot.p"); |
| 253 | std::vector<const char*> args3 = { |
| 254 | "applypatch", |
| 255 | "-b", |
| 256 | bonus_file.c_str(), |
| 257 | src_file.c_str(), |
| 258 | tgt_file.c_str(), |
| 259 | recovery_img_sha1.c_str(), |
| 260 | recovery_img_size.c_str(), |
| 261 | patch1.c_str(), |
| 262 | patch2.c_str(), |
| 263 | patch3.c_str() |
| 264 | }; |
| 265 | ASSERT_EQ(0, applypatch_modes(args3.size(), args3.data())); |
| 266 | } |
| 267 | |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 268 | TEST_F(ApplyPatchModesTest, PatchModeInvalidArgs) { |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 269 | // Invalid bonus file. |
| 270 | ASSERT_NE(0, applypatch_modes(3, (const char* []){ "applypatch", "-b", "/doesntexist" })); |
| 271 | |
| 272 | std::string bonus_file = from_testdata_base("bonus.file"); |
| 273 | // With bonus file, but missing args. |
| 274 | ASSERT_EQ(2, applypatch_modes(3, (const char* []){ "applypatch", "-b", bonus_file.c_str() })); |
| 275 | |
| 276 | std::string boot_img = from_testdata_base("boot.img"); |
| 277 | size_t boot_img_size; |
| 278 | std::string boot_img_sha1; |
| 279 | sha1sum(boot_img, &boot_img_sha1, &boot_img_size); |
| 280 | |
| 281 | std::string recovery_img = from_testdata_base("recovery.img"); |
Tao Bao | 8dd44e9 | 2016-11-21 11:16:56 -0800 | [diff] [blame] | 282 | size_t size; |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 283 | std::string recovery_img_sha1; |
Tao Bao | 8dd44e9 | 2016-11-21 11:16:56 -0800 | [diff] [blame] | 284 | sha1sum(recovery_img, &recovery_img_sha1, &size); |
| 285 | std::string recovery_img_size = std::to_string(size); |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 286 | |
| 287 | // Bonus file is not supported in flash mode. |
| 288 | // applypatch -b <bonus-file> <src-file> <tgt-file> <tgt-sha1> <tgt-size> |
| 289 | TemporaryFile tmp4; |
| 290 | std::vector<const char*> args4 = { |
| 291 | "applypatch", |
| 292 | "-b", |
| 293 | bonus_file.c_str(), |
| 294 | boot_img.c_str(), |
| 295 | tmp4.path, |
| 296 | recovery_img_sha1.c_str(), |
Tao Bao | 8dd44e9 | 2016-11-21 11:16:56 -0800 | [diff] [blame] | 297 | recovery_img_size.c_str() |
| 298 | }; |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 299 | ASSERT_NE(0, applypatch_modes(args4.size(), args4.data())); |
| 300 | |
| 301 | // Failed to parse patch args. |
| 302 | TemporaryFile tmp5; |
Tao Bao | 8dd44e9 | 2016-11-21 11:16:56 -0800 | [diff] [blame] | 303 | std::string bad_arg1 = |
| 304 | "invalid-sha1:filename" + from_testdata_base("recovery-from-boot-with-bonus.p"); |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 305 | std::vector<const char*> args5 = { |
| 306 | "applypatch", |
| 307 | boot_img.c_str(), |
| 308 | tmp5.path, |
| 309 | recovery_img_sha1.c_str(), |
Tao Bao | 8dd44e9 | 2016-11-21 11:16:56 -0800 | [diff] [blame] | 310 | recovery_img_size.c_str(), |
| 311 | bad_arg1.c_str() |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 312 | }; |
| 313 | ASSERT_NE(0, applypatch_modes(args5.size(), args5.data())); |
| 314 | |
| 315 | // Target size cannot be zero. |
| 316 | TemporaryFile tmp6; |
Tao Bao | 8dd44e9 | 2016-11-21 11:16:56 -0800 | [diff] [blame] | 317 | std::string patch = boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot-with-bonus.p"); |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 318 | std::vector<const char*> args6 = { |
| 319 | "applypatch", |
| 320 | boot_img.c_str(), |
| 321 | tmp6.path, |
| 322 | recovery_img_sha1.c_str(), |
| 323 | "0", // target size |
Tao Bao | 8dd44e9 | 2016-11-21 11:16:56 -0800 | [diff] [blame] | 324 | patch.c_str() |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 325 | }; |
| 326 | ASSERT_NE(0, applypatch_modes(args6.size(), args6.data())); |
| 327 | } |
| 328 | |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 329 | TEST_F(ApplyPatchModesTest, CheckModeInvalidArgs) { |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 330 | // Insufficient args. |
| 331 | ASSERT_EQ(2, applypatch_modes(2, (const char* []){ "applypatch", "-c" })); |
| 332 | } |
| 333 | |
Tianjie Xu | a88cc54 | 2017-10-25 13:16:54 -0700 | [diff] [blame] | 334 | TEST_F(ApplyPatchModesTest, ShowLicenses) { |
Tao Bao | 36c3511 | 2016-10-25 14:17:26 -0700 | [diff] [blame] | 335 | ASSERT_EQ(0, applypatch_modes(2, (const char* []){ "applypatch", "-l" })); |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 336 | } |