Alice Wang | 95c1b92 | 2022-07-20 11:37:51 +0000 | [diff] [blame] | 1 | // 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 | |
| 17 | use std::fs; |
| 18 | use std::process::Command; |
Alice Wang | b035138 | 2022-09-16 12:39:34 +0000 | [diff] [blame] | 19 | use tempfile::TempDir; |
Alice Wang | 95c1b92 | 2022-07-20 11:37:51 +0000 | [diff] [blame] | 20 | |
| 21 | #[test] |
| 22 | fn test_dump() { |
Alice Wang | b035138 | 2022-09-16 12:39:34 +0000 | [diff] [blame] | 23 | 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 Wang | 95c1b92 | 2022-07-20 11:37:51 +0000 | [diff] [blame] | 36 | assert!(output.status.success()); |
| 37 | assert_eq!(output.stdout, fs::read("tests/data/test.avmd.dump").unwrap()); |
| 38 | } |
Alice Wang | b035138 | 2022-09-16 12:39:34 +0000 | [diff] [blame] | 39 | |
| 40 | #[test] |
| 41 | fn 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 | } |