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