blob: 916028594cd672e40e13fd9c9e2841622112da59 [file] [log] [blame]
Jed Estepb8a693b2016-03-09 17:51:34 -08001/*
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 Baofada91c2016-10-27 18:16:06 -070026#include <memory>
Jed Estepb8a693b2016-03-09 17:51:34 -080027#include <string>
Tao Baofada91c2016-10-27 18:16:06 -070028#include <vector>
Jed Estepb8a693b2016-03-09 17:51:34 -080029
30#include <android-base/file.h>
31#include <android-base/stringprintf.h>
32#include <android-base/test_utils.h>
Tao Baod612b232018-03-12 21:18:52 -070033#include <bsdiff/bsdiff.h>
Tao Baofada91c2016-10-27 18:16:06 -070034#include <openssl/sha.h>
Jed Estepb8a693b2016-03-09 17:51:34 -080035
36#include "applypatch/applypatch.h"
Tao Bao36c35112016-10-25 14:17:26 -070037#include "applypatch/applypatch_modes.h"
Jed Estepb8a693b2016-03-09 17:51:34 -080038#include "common/test_constants.h"
Tianjie Xu3bbb20f2018-02-27 15:56:11 -080039#include "otautil/cache_location.h"
Tao Bao09e468f2017-09-29 14:39:33 -070040#include "otautil/print_sha1.h"
Jed Estepb8a693b2016-03-09 17:51:34 -080041
Tao Baod612b232018-03-12 21:18:52 -070042using namespace std::string_literals;
43
Tao Bao36c35112016-10-25 14:17:26 -070044static void sha1sum(const std::string& fname, std::string* sha1, size_t* fsize = nullptr) {
45 ASSERT_NE(nullptr, sha1);
Tao Baofada91c2016-10-27 18:16:06 -070046
Tao Bao36c35112016-10-25 14:17:26 -070047 std::string data;
48 ASSERT_TRUE(android::base::ReadFileToString(fname, &data));
Jed Estepb8a693b2016-03-09 17:51:34 -080049
Tao Bao36c35112016-10-25 14:17:26 -070050 if (fsize != nullptr) {
51 *fsize = data.size();
52 }
53
54 uint8_t digest[SHA_DIGEST_LENGTH];
55 SHA1(reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), digest);
56 *sha1 = print_sha1(digest);
Jed Estepb8a693b2016-03-09 17:51:34 -080057}
58
59static void mangle_file(const std::string& fname) {
Tianjie Xua88cc542017-10-25 13:16:54 -070060 std::string content(1024, '\0');
Tao Bao36c35112016-10-25 14:17:26 -070061 for (size_t i = 0; i < 1024; i++) {
62 content[i] = rand() % 256;
63 }
64 ASSERT_TRUE(android::base::WriteStringToFile(content, fname));
Jed Estepb8a693b2016-03-09 17:51:34 -080065}
66
Jed Estepb8a693b2016-03-09 17:51:34 -080067class ApplyPatchTest : public ::testing::Test {
Tao Bao36c35112016-10-25 14:17:26 -070068 public:
Tianjie Xua88cc542017-10-25 13:16:54 -070069 virtual void SetUp() override {
Tao Bao36c35112016-10-25 14:17:26 -070070 // set up files
71 old_file = from_testdata_base("old.file");
72 new_file = from_testdata_base("new.file");
Tianjie Xua88cc542017-10-25 13:16:54 -070073 nonexistent_file = from_testdata_base("nonexistent.file");
Jed Estepb8a693b2016-03-09 17:51:34 -080074
Tao Bao36c35112016-10-25 14:17:26 -070075 // set up SHA constants
Tao Bao8dd44e92016-11-21 11:16:56 -080076 sha1sum(old_file, &old_sha1, &old_size);
77 sha1sum(new_file, &new_sha1, &new_size);
Tao Bao36c35112016-10-25 14:17:26 -070078 srand(time(nullptr));
79 bad_sha1_a = android::base::StringPrintf("%040x", rand());
80 bad_sha1_b = android::base::StringPrintf("%040x", rand());
Tao Bao36c35112016-10-25 14:17:26 -070081 }
Jed Estepb8a693b2016-03-09 17:51:34 -080082
Tianjie Xua88cc542017-10-25 13:16:54 -070083 std::string old_file;
84 std::string new_file;
85 std::string nonexistent_file;
Jed Estepb8a693b2016-03-09 17:51:34 -080086
Tianjie Xua88cc542017-10-25 13:16:54 -070087 std::string old_sha1;
88 std::string new_sha1;
89 std::string bad_sha1_a;
90 std::string bad_sha1_b;
Jed Estepb8a693b2016-03-09 17:51:34 -080091
Tianjie Xua88cc542017-10-25 13:16:54 -070092 size_t old_size;
93 size_t new_size;
Jed Estepb8a693b2016-03-09 17:51:34 -080094};
95
Jed Estepb8a693b2016-03-09 17:51:34 -080096class ApplyPatchCacheTest : public ApplyPatchTest {
Tianjie Xua88cc542017-10-25 13:16:54 -070097 protected:
98 void SetUp() override {
99 ApplyPatchTest::SetUp();
Tianjie Xu3bbb20f2018-02-27 15:56:11 -0800100 CacheLocation::location().set_cache_temp_source(old_file);
Tao Bao36c35112016-10-25 14:17:26 -0700101 }
Jed Estepb8a693b2016-03-09 17:51:34 -0800102};
103
Tianjie Xua88cc542017-10-25 13:16:54 -0700104class ApplyPatchModesTest : public ::testing::Test {
105 protected:
106 void SetUp() override {
Tianjie Xu3bbb20f2018-02-27 15:56:11 -0800107 CacheLocation::location().set_cache_temp_source(cache_source.path);
Tianjie Xua88cc542017-10-25 13:16:54 -0700108 }
109
110 TemporaryFile cache_source;
111};
Jed Estepb8a693b2016-03-09 17:51:34 -0800112
Tianjie Xua5fd5ab2016-10-18 15:18:22 -0700113TEST_F(ApplyPatchTest, CheckModeSkip) {
Tao Bao36c35112016-10-25 14:17:26 -0700114 std::vector<std::string> sha1s;
115 ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
Tianjie Xua5fd5ab2016-10-18 15:18:22 -0700116}
117
Jed Estepb8a693b2016-03-09 17:51:34 -0800118TEST_F(ApplyPatchTest, CheckModeSingle) {
Tao Bao36c35112016-10-25 14:17:26 -0700119 std::vector<std::string> sha1s = { old_sha1 };
120 ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
Jed Estepb8a693b2016-03-09 17:51:34 -0800121}
122
123TEST_F(ApplyPatchTest, CheckModeMultiple) {
Tao Bao36c35112016-10-25 14:17:26 -0700124 std::vector<std::string> sha1s = { bad_sha1_a, old_sha1, bad_sha1_b };
125 ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
Jed Estepb8a693b2016-03-09 17:51:34 -0800126}
127
128TEST_F(ApplyPatchTest, CheckModeFailure) {
Tao Bao36c35112016-10-25 14:17:26 -0700129 std::vector<std::string> sha1s = { bad_sha1_a, bad_sha1_b };
130 ASSERT_NE(0, applypatch_check(&old_file[0], sha1s));
Jed Estepb8a693b2016-03-09 17:51:34 -0800131}
132
Tao Bao8dd44e92016-11-21 11:16:56 -0800133TEST_F(ApplyPatchTest, CheckModeEmmcTarget) {
134 // EMMC:old_file:size:sha1 should pass the check.
135 std::string src_file =
136 "EMMC:" + old_file + ":" + std::to_string(old_size) + ":" + old_sha1;
137 std::vector<std::string> sha1s;
138 ASSERT_EQ(0, applypatch_check(src_file.c_str(), sha1s));
139
140 // EMMC:old_file:(size-1):sha1:(size+1):sha1 should fail the check.
141 src_file = "EMMC:" + old_file + ":" + std::to_string(old_size - 1) + ":" + old_sha1 + ":" +
142 std::to_string(old_size + 1) + ":" + old_sha1;
143 ASSERT_EQ(1, applypatch_check(src_file.c_str(), sha1s));
144
145 // EMMC:old_file:(size-1):sha1:size:sha1:(size+1):sha1 should pass the check.
146 src_file = "EMMC:" + old_file + ":" +
147 std::to_string(old_size - 1) + ":" + old_sha1 + ":" +
148 std::to_string(old_size) + ":" + old_sha1 + ":" +
149 std::to_string(old_size + 1) + ":" + old_sha1;
150 ASSERT_EQ(0, applypatch_check(src_file.c_str(), sha1s));
151
152 // EMMC:old_file:(size+1):sha1:(size-1):sha1:size:sha1 should pass the check.
153 src_file = "EMMC:" + old_file + ":" +
154 std::to_string(old_size + 1) + ":" + old_sha1 + ":" +
155 std::to_string(old_size - 1) + ":" + old_sha1 + ":" +
156 std::to_string(old_size) + ":" + old_sha1;
157 ASSERT_EQ(0, applypatch_check(src_file.c_str(), sha1s));
158
159 // EMMC:new_file:(size+1):old_sha1:(size-1):old_sha1:size:old_sha1:size:new_sha1
160 // should pass the check.
161 src_file = "EMMC:" + new_file + ":" +
162 std::to_string(old_size + 1) + ":" + old_sha1 + ":" +
163 std::to_string(old_size - 1) + ":" + old_sha1 + ":" +
164 std::to_string(old_size) + ":" + old_sha1 + ":" +
165 std::to_string(new_size) + ":" + new_sha1;
166 ASSERT_EQ(0, applypatch_check(src_file.c_str(), sha1s));
167}
168
Tianjie Xua88cc542017-10-25 13:16:54 -0700169TEST_F(ApplyPatchCacheTest, CheckCacheCorruptedSourceSingle) {
170 TemporaryFile temp_file;
171 mangle_file(temp_file.path);
172 std::vector<std::string> sha1s_single = { old_sha1 };
173 ASSERT_EQ(0, applypatch_check(temp_file.path, sha1s_single));
174 ASSERT_EQ(0, applypatch_check(nonexistent_file.c_str(), sha1s_single));
Jed Estepb8a693b2016-03-09 17:51:34 -0800175}
176
Tianjie Xua88cc542017-10-25 13:16:54 -0700177TEST_F(ApplyPatchCacheTest, CheckCacheCorruptedSourceMultiple) {
178 TemporaryFile temp_file;
179 mangle_file(temp_file.path);
180 std::vector<std::string> sha1s_multiple = { bad_sha1_a, old_sha1, bad_sha1_b };
181 ASSERT_EQ(0, applypatch_check(temp_file.path, sha1s_multiple));
182 ASSERT_EQ(0, applypatch_check(nonexistent_file.c_str(), sha1s_multiple));
Jed Estepb8a693b2016-03-09 17:51:34 -0800183}
184
Tianjie Xua88cc542017-10-25 13:16:54 -0700185TEST_F(ApplyPatchCacheTest, CheckCacheCorruptedSourceFailure) {
186 TemporaryFile temp_file;
187 mangle_file(temp_file.path);
188 std::vector<std::string> sha1s_failure = { bad_sha1_a, bad_sha1_b };
189 ASSERT_NE(0, applypatch_check(temp_file.path, sha1s_failure));
190 ASSERT_NE(0, applypatch_check(nonexistent_file.c_str(), sha1s_failure));
Jed Estepb8a693b2016-03-09 17:51:34 -0800191}
192
Tianjie Xua88cc542017-10-25 13:16:54 -0700193TEST_F(ApplyPatchModesTest, InvalidArgs) {
Tao Bao36c35112016-10-25 14:17:26 -0700194 // At least two args (including the filename).
195 ASSERT_EQ(2, applypatch_modes(1, (const char* []){ "applypatch" }));
196
197 // Unrecognized args.
198 ASSERT_EQ(2, applypatch_modes(2, (const char* []){ "applypatch", "-x" }));
199}
200
Tianjie Xua88cc542017-10-25 13:16:54 -0700201TEST_F(ApplyPatchModesTest, PatchModeEmmcTarget) {
Tao Bao8dd44e92016-11-21 11:16:56 -0800202 std::string boot_img = from_testdata_base("boot.img");
203 size_t boot_img_size;
204 std::string boot_img_sha1;
205 sha1sum(boot_img, &boot_img_sha1, &boot_img_size);
206
207 std::string recovery_img = from_testdata_base("recovery.img");
Tao Baoe3499f92018-03-20 10:33:42 -0700208 size_t recovery_img_size;
Tao Bao8dd44e92016-11-21 11:16:56 -0800209 std::string recovery_img_sha1;
Tao Baoe3499f92018-03-20 10:33:42 -0700210 sha1sum(recovery_img, &recovery_img_sha1, &recovery_img_size);
211 std::string recovery_img_size_arg = std::to_string(recovery_img_size);
Tao Bao8dd44e92016-11-21 11:16:56 -0800212
213 std::string bonus_file = from_testdata_base("bonus.file");
214
215 // applypatch -b <bonus-file> <src-file> <tgt-file> <tgt-sha1> <tgt-size> <src-sha1>:<patch>
Tao Baoe3499f92018-03-20 10:33:42 -0700216 std::string src_file_arg =
Tao Bao8dd44e92016-11-21 11:16:56 -0800217 "EMMC:" + boot_img + ":" + std::to_string(boot_img_size) + ":" + boot_img_sha1;
Tao Baoe3499f92018-03-20 10:33:42 -0700218 TemporaryFile tgt_file;
219 std::string tgt_file_arg = "EMMC:"s + tgt_file.path;
220 std::string patch_arg = boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot.p");
221 std::vector<const char*> args = { "applypatch",
222 "-b",
223 bonus_file.c_str(),
224 src_file_arg.c_str(),
225 tgt_file_arg.c_str(),
226 recovery_img_sha1.c_str(),
227 recovery_img_size_arg.c_str(),
228 patch_arg.c_str() };
Tao Bao8dd44e92016-11-21 11:16:56 -0800229 ASSERT_EQ(0, applypatch_modes(args.size(), args.data()));
Tao Baoe3499f92018-03-20 10:33:42 -0700230}
231
232// Tests patching the EMMC target without a separate bonus file (i.e. recovery-from-boot patch has
233// everything).
234TEST_F(ApplyPatchModesTest, PatchModeEmmcTargetWithoutBonusFile) {
235 std::string boot_img = from_testdata_base("boot.img");
236 size_t boot_img_size;
237 std::string boot_img_sha1;
238 sha1sum(boot_img, &boot_img_sha1, &boot_img_size);
239
240 std::string recovery_img = from_testdata_base("recovery.img");
241 size_t recovery_img_size;
242 std::string recovery_img_sha1;
243 sha1sum(recovery_img, &recovery_img_sha1, &recovery_img_size);
244 std::string recovery_img_size_arg = std::to_string(recovery_img_size);
Tao Bao8dd44e92016-11-21 11:16:56 -0800245
246 // applypatch <src-file> <tgt-file> <tgt-sha1> <tgt-size> <src-sha1>:<patch>
Tao Baoe3499f92018-03-20 10:33:42 -0700247 std::string src_file_arg =
248 "EMMC:" + boot_img + ":" + std::to_string(boot_img_size) + ":" + boot_img_sha1;
249 TemporaryFile tgt_file;
250 std::string tgt_file_arg = "EMMC:"s + tgt_file.path;
251 std::string patch_arg =
252 boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot-with-bonus.p");
253 std::vector<const char*> args = { "applypatch",
254 src_file_arg.c_str(),
255 tgt_file_arg.c_str(),
256 recovery_img_sha1.c_str(),
257 recovery_img_size_arg.c_str(),
258 patch_arg.c_str() };
259 ASSERT_EQ(0, applypatch_modes(args.size(), args.data()));
260}
261
262TEST_F(ApplyPatchModesTest, PatchModeEmmcTargetWithMultiplePatches) {
263 std::string boot_img = from_testdata_base("boot.img");
264 size_t boot_img_size;
265 std::string boot_img_sha1;
266 sha1sum(boot_img, &boot_img_sha1, &boot_img_size);
267
268 std::string recovery_img = from_testdata_base("recovery.img");
269 size_t recovery_img_size;
270 std::string recovery_img_sha1;
271 sha1sum(recovery_img, &recovery_img_sha1, &recovery_img_size);
272 std::string recovery_img_size_arg = std::to_string(recovery_img_size);
273
274 std::string bonus_file = from_testdata_base("bonus.file");
Tao Bao8dd44e92016-11-21 11:16:56 -0800275
276 // applypatch -b <bonus-file> <src-file> <tgt-file> <tgt-sha1> <tgt-size> \
Tao Baoe3499f92018-03-20 10:33:42 -0700277 // <src-sha1-fake1>:<patch1> <src-sha1>:<patch2> <src-sha1-fake2>:<patch3>
278 std::string src_file_arg =
279 "EMMC:" + boot_img + ":" + std::to_string(boot_img_size) + ":" + boot_img_sha1;
280 TemporaryFile tgt_file;
281 std::string tgt_file_arg = "EMMC:"s + tgt_file.path;
Tao Bao8dd44e92016-11-21 11:16:56 -0800282 std::string bad_sha1_a = android::base::StringPrintf("%040x", rand());
283 std::string bad_sha1_b = android::base::StringPrintf("%040x", rand());
284 std::string patch1 = bad_sha1_a + ":" + from_testdata_base("recovery-from-boot.p");
285 std::string patch2 = boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot.p");
286 std::string patch3 = bad_sha1_b + ":" + from_testdata_base("recovery-from-boot.p");
Tao Baoe3499f92018-03-20 10:33:42 -0700287 std::vector<const char*> args = { "applypatch",
288 "-b",
289 bonus_file.c_str(),
290 src_file_arg.c_str(),
291 tgt_file_arg.c_str(),
292 recovery_img_sha1.c_str(),
293 recovery_img_size_arg.c_str(),
294 patch1.c_str(),
295 patch2.c_str(),
296 patch3.c_str() };
297 ASSERT_EQ(0, applypatch_modes(args.size(), args.data()));
Tao Bao8dd44e92016-11-21 11:16:56 -0800298}
299
Tao Baod612b232018-03-12 21:18:52 -0700300// Ensures that applypatch works with a bsdiff based recovery-from-boot.p.
301TEST_F(ApplyPatchModesTest, PatchModeEmmcTargetWithBsdiffPatch) {
302 std::string boot_img_file = from_testdata_base("boot.img");
303 std::string boot_img_sha1;
304 size_t boot_img_size;
305 sha1sum(boot_img_file, &boot_img_sha1, &boot_img_size);
306
307 std::string recovery_img_file = from_testdata_base("recovery.img");
308 std::string recovery_img_sha1;
309 size_t recovery_img_size;
310 sha1sum(recovery_img_file, &recovery_img_sha1, &recovery_img_size);
311
312 // Generate the bsdiff patch of recovery-from-boot.p.
313 std::string src_content;
314 ASSERT_TRUE(android::base::ReadFileToString(boot_img_file, &src_content));
315
316 std::string tgt_content;
317 ASSERT_TRUE(android::base::ReadFileToString(recovery_img_file, &tgt_content));
318
319 TemporaryFile patch_file;
320 ASSERT_EQ(0,
321 bsdiff::bsdiff(reinterpret_cast<const uint8_t*>(src_content.data()), src_content.size(),
322 reinterpret_cast<const uint8_t*>(tgt_content.data()), tgt_content.size(),
323 patch_file.path, nullptr));
324
325 // applypatch <src-file> <tgt-file> <tgt-sha1> <tgt-size> <src-sha1>:<patch>
326 std::string src_file_arg =
327 "EMMC:" + boot_img_file + ":" + std::to_string(boot_img_size) + ":" + boot_img_sha1;
328 TemporaryFile tgt_file;
329 std::string tgt_file_arg = "EMMC:"s + tgt_file.path;
330 std::string recovery_img_size_arg = std::to_string(recovery_img_size);
331 std::string patch_arg = boot_img_sha1 + ":" + patch_file.path;
332 std::vector<const char*> args = { "applypatch",
333 src_file_arg.c_str(),
334 tgt_file_arg.c_str(),
335 recovery_img_sha1.c_str(),
336 recovery_img_size_arg.c_str(),
337 patch_arg.c_str() };
338 ASSERT_EQ(0, applypatch_modes(args.size(), args.data()));
339
340 // Double check the patched recovery image.
341 std::string tgt_file_sha1;
342 size_t tgt_file_size;
343 sha1sum(tgt_file.path, &tgt_file_sha1, &tgt_file_size);
344 ASSERT_EQ(recovery_img_size, tgt_file_size);
345 ASSERT_EQ(recovery_img_sha1, tgt_file_sha1);
346}
347
Tianjie Xua88cc542017-10-25 13:16:54 -0700348TEST_F(ApplyPatchModesTest, PatchModeInvalidArgs) {
Tao Bao36c35112016-10-25 14:17:26 -0700349 // Invalid bonus file.
350 ASSERT_NE(0, applypatch_modes(3, (const char* []){ "applypatch", "-b", "/doesntexist" }));
351
352 std::string bonus_file = from_testdata_base("bonus.file");
353 // With bonus file, but missing args.
354 ASSERT_EQ(2, applypatch_modes(3, (const char* []){ "applypatch", "-b", bonus_file.c_str() }));
355
356 std::string boot_img = from_testdata_base("boot.img");
357 size_t boot_img_size;
358 std::string boot_img_sha1;
359 sha1sum(boot_img, &boot_img_sha1, &boot_img_size);
360
361 std::string recovery_img = from_testdata_base("recovery.img");
Tao Bao8dd44e92016-11-21 11:16:56 -0800362 size_t size;
Tao Bao36c35112016-10-25 14:17:26 -0700363 std::string recovery_img_sha1;
Tao Bao8dd44e92016-11-21 11:16:56 -0800364 sha1sum(recovery_img, &recovery_img_sha1, &size);
365 std::string recovery_img_size = std::to_string(size);
Tao Bao36c35112016-10-25 14:17:26 -0700366
367 // Bonus file is not supported in flash mode.
368 // applypatch -b <bonus-file> <src-file> <tgt-file> <tgt-sha1> <tgt-size>
369 TemporaryFile tmp4;
370 std::vector<const char*> args4 = {
371 "applypatch",
372 "-b",
373 bonus_file.c_str(),
374 boot_img.c_str(),
375 tmp4.path,
376 recovery_img_sha1.c_str(),
Tao Bao8dd44e92016-11-21 11:16:56 -0800377 recovery_img_size.c_str()
378 };
Tao Bao36c35112016-10-25 14:17:26 -0700379 ASSERT_NE(0, applypatch_modes(args4.size(), args4.data()));
380
381 // Failed to parse patch args.
382 TemporaryFile tmp5;
Tao Bao8dd44e92016-11-21 11:16:56 -0800383 std::string bad_arg1 =
384 "invalid-sha1:filename" + from_testdata_base("recovery-from-boot-with-bonus.p");
Tao Bao36c35112016-10-25 14:17:26 -0700385 std::vector<const char*> args5 = {
386 "applypatch",
387 boot_img.c_str(),
388 tmp5.path,
389 recovery_img_sha1.c_str(),
Tao Bao8dd44e92016-11-21 11:16:56 -0800390 recovery_img_size.c_str(),
391 bad_arg1.c_str()
Tao Bao36c35112016-10-25 14:17:26 -0700392 };
393 ASSERT_NE(0, applypatch_modes(args5.size(), args5.data()));
394
395 // Target size cannot be zero.
396 TemporaryFile tmp6;
Tao Bao8dd44e92016-11-21 11:16:56 -0800397 std::string patch = boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot-with-bonus.p");
Tao Bao36c35112016-10-25 14:17:26 -0700398 std::vector<const char*> args6 = {
399 "applypatch",
400 boot_img.c_str(),
401 tmp6.path,
402 recovery_img_sha1.c_str(),
403 "0", // target size
Tao Bao8dd44e92016-11-21 11:16:56 -0800404 patch.c_str()
Tao Bao36c35112016-10-25 14:17:26 -0700405 };
406 ASSERT_NE(0, applypatch_modes(args6.size(), args6.data()));
407}
408
Tianjie Xua88cc542017-10-25 13:16:54 -0700409TEST_F(ApplyPatchModesTest, CheckModeInvalidArgs) {
Tao Bao36c35112016-10-25 14:17:26 -0700410 // Insufficient args.
411 ASSERT_EQ(2, applypatch_modes(2, (const char* []){ "applypatch", "-c" }));
412}
413
Tianjie Xua88cc542017-10-25 13:16:54 -0700414TEST_F(ApplyPatchModesTest, ShowLicenses) {
Tao Bao36c35112016-10-25 14:17:26 -0700415 ASSERT_EQ(0, applypatch_modes(2, (const char* []){ "applypatch", "-l" }));
Jed Estepb8a693b2016-03-09 17:51:34 -0800416}