aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWei Li <weiwli@google.com>2022-01-12 14:34:05 -0800
committerWei Li <weiwli@google.com>2022-01-25 22:52:30 +0000
commit175d017dba7ed25e21afe26d2900cc9b4e3f7b8b (patch)
tree6a085fb464d5f53d6c3b15131e7c3e1159e7eb84 /tests
parent305b9f6e8ffc634ad7bf054a4a488a097da6b24f (diff)
downloadbazel-175d017dba7ed25e21afe26d2900cc9b4e3f7b8b.tar.gz
Add apex compression in Bazel apex rule.
Bug: 207551677 Test: b build //build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal Test: b test //build/bazel/tests/apex:build.bazel.examples.apex.minimal_apex Test: b test //build/bazel/tests/apex:build.bazel.examples.apex.minimal_capex Change-Id: I43286187a4ca569294fa6ae8af2d5deb4567c0a2
Diffstat (limited to 'tests')
-rw-r--r--tests/apex/BUILD13
-rw-r--r--tests/apex/apex_test.bzl42
-rwxr-xr-xtests/apex/apex_test.sh88
3 files changed, 143 insertions, 0 deletions
diff --git a/tests/apex/BUILD b/tests/apex/BUILD
index 95806062..22032728 100644
--- a/tests/apex/BUILD
+++ b/tests/apex/BUILD
@@ -1,4 +1,5 @@
load(":apex_diff_test.bzl", "apex_diff_test")
+load(":apex_test.bzl", "apex_compression_test")
apex_diff_test(
name = "com.android.tzdata",
@@ -17,3 +18,15 @@ apex_diff_test(
apex1 = "//packages/modules/adb/apex:com.android.adbd",
apex2 = "@make_injection//:target/product/generic/system/apex/com.android.adbd.capex",
)
+
+apex_compression_test(
+ name = "build.bazel.examples.apex.minimal_apex",
+ apex = "//build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal",
+ compressed = False,
+)
+
+apex_compression_test(
+ name = "build.bazel.examples.apex.minimal_capex",
+ apex = "//build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal_compressed",
+ compressed = True,
+)
diff --git a/tests/apex/apex_test.bzl b/tests/apex/apex_test.bzl
new file mode 100644
index 00000000..a9181ec1
--- /dev/null
+++ b/tests/apex/apex_test.bzl
@@ -0,0 +1,42 @@
+"""
+Copyright (C) 2022 The Android Open Source Project
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+
+def apex_compression_test(name, apex, compressed, **kwargs):
+ """This verifies APEX or compressed APEX file:
+ 1) has the correct file extension name
+ 2) contains the required files specified by the APEX file format
+ """
+
+ native.sh_library(
+ name = name + "_wrapper_sh_lib",
+ data = [apex],
+ )
+
+ args = ["$(location " + apex + ")"]
+ if compressed:
+ args.append("compressed")
+
+ native.sh_test(
+ name = name,
+ srcs = ["apex_test.sh"],
+ deps = ["@bazel_tools//tools/bash/runfiles"],
+ data = [
+ ":" + name + "_wrapper_sh_lib",
+ "@bazel_tools//tools/zip:zipper",
+ apex,
+ ],
+ args = args,
+ )
diff --git a/tests/apex/apex_test.sh b/tests/apex/apex_test.sh
new file mode 100755
index 00000000..78f89eb6
--- /dev/null
+++ b/tests/apex/apex_test.sh
@@ -0,0 +1,88 @@
+#!/bin/bash
+
+# Copyright (C) 2022 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+set -xeuo pipefail
+
+readonly arg_apex_filepath=$1
+arg_compressed=false
+[ $# -eq 2 ] && [ "$2" = "compressed" ] && arg_compressed=true
+
+readonly ZIPPER=$(rlocation bazel_tools/tools/zip/zipper/zipper)
+readonly -a APEX_FILES=(
+ "apex_manifest.pb"
+ "AndroidManifest.xml"
+ "apex_payload.img"
+ "apex_pubkey"
+ "META-INF/CERT\.SF"
+ "META-INF/CERT\.RSA"
+ "META-INF/MANIFEST\.MF"
+)
+readonly -a CAPEX_FILES=(
+ "apex_manifest.pb"
+ "AndroidManifest.xml"
+ "original_apex"
+ "apex_pubkey"
+ "META-INF/CERT\.SF"
+ "META-INF/CERT\.RSA"
+ "META-INF/MANIFEST\.MF"
+)
+
+# Check if apex file contains specified files
+function apex_contains_files() {
+ local apex_filepath=$1
+ shift
+ local expected_files=("$@")
+ local apex_entries=$($ZIPPER v "$apex_filepath")
+ for file in "${expected_files[@]}"; do
+ if ! echo -e "$apex_entries" | grep "$file"; then
+ echo "Failed to find file $file in $apex_filepath"
+ exit 1
+ fi
+ done
+}
+
+# Test compressed apex file required files.
+function test_capex_contains_required_files() {
+ if [ "${arg_apex_filepath: -6}" != ".capex" ]; then
+ echo "@arg_apex_filepath does not have .capex as extension."
+ exit 1
+ fi
+ apex_contains_files "$arg_apex_filepath" "${CAPEX_FILES[@]}"
+
+ # Check files in original_apex extracted from the compressed apex file
+ local apex_file_dir=$(dirname "$arg_apex_filepath")
+ local extracted_capex=$(mktemp -d -p "$apex_file_dir")
+ $ZIPPER x "$arg_apex_filepath" -d "$extracted_capex"
+ apex_contains_files "$extracted_capex/original_apex" "${APEX_FILES[@]}"
+ rm -rf "${extracted_capex}"
+}
+
+# Test apex file contains required files
+function test_apex_contains_required_files() {
+ if [ "${arg_apex_filepath: -5}" != ".apex" ]; then
+ echo "@arg_apex_filepath does not have .apex as extension."
+ exit 1
+ fi
+ apex_contains_files "$arg_apex_filepath" "${APEX_FILES[@]}"
+}
+
+if [ $arg_compressed == true ]; then
+ test_capex_contains_required_files
+else
+ test_apex_contains_required_files
+fi
+
+echo "Passed all test cases." \ No newline at end of file