blob: 4647f06eb5cd3c4e81194114932208109f2a381a [file] [log] [blame]
Alice Wang95c1b922022-07-20 11:37:51 +00001// Copyright 2022, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Tests for avmdtool.
16
17use std::fs;
18use std::process::Command;
Alice Wangb0351382022-09-16 12:39:34 +000019use tempfile::TempDir;
Alice Wang95c1b922022-07-20 11:37:51 +000020
21#[test]
22fn test_dump() {
Alice Wangb0351382022-09-16 12:39:34 +000023 let filename = "tests/data/test.avmd";
24 assert!(
25 fs::metadata(filename).is_ok(),
26 "File '{}' does not exist. You can re-create it with:
27 avmdtool create {} \\
28 --apex-payload microdroid vbmeta tests/data/test.apex \\
29 --apk microdroid_manager apk \\
30 tests/data/v3-only-with-rsa-pkcs1-sha256-4096.apk \\
31 --apk microdroid_manager extra-apk tests/data/v3-only-with-stamp.apk",
32 filename,
33 filename
34 );
35 let output = Command::new("./avmdtool").args(["dump", filename]).output().unwrap();
Alice Wang95c1b922022-07-20 11:37:51 +000036 assert!(output.status.success());
37 assert_eq!(output.stdout, fs::read("tests/data/test.avmd.dump").unwrap());
38}
Alice Wangb0351382022-09-16 12:39:34 +000039
40#[test]
41fn test_create() {
42 let test_dir = TempDir::new().unwrap();
43 let test_file_path = test_dir.path().join("tmp_test.amvd");
44 let output = Command::new("./avmdtool")
45 .args([
46 "create",
47 test_file_path.to_str().unwrap(),
48 "--apex-payload",
49 "microdroid",
50 "vbmeta",
51 "tests/data/test.apex",
52 "--apk",
53 "microdroid_manager",
54 "apk",
55 "tests/data/v3-only-with-rsa-pkcs1-sha256-4096.apk",
56 "--apk",
57 "microdroid_manager",
58 "extra-apk",
59 "tests/data/v3-only-with-stamp.apk",
60 ])
61 .output()
62 .unwrap();
63 assert!(output.status.success());
64 assert_eq!(fs::read(test_file_path).unwrap(), fs::read("tests/data/test.avmd").unwrap());
65}