diff options
author | Wei Li <weiwli@google.com> | 2023-07-10 15:50:38 -0700 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-14 01:24:23 +0000 |
commit | a0b85cd7316729d978973c13e9bd5ccf8073a591 (patch) | |
tree | aed98f88ab88cd15c3ea7852d3c68e44f7403fbc | |
parent | 7e6fdb5d329febf8565b48f6b1671bf7551f15f1 (diff) |
Add integration test for m build SBOM of APEXs/APKs.
Bug: 266726655
Test: build/soong/tests/sbom_test.sh
(cherry picked from https://android-review.googlesource.com/q/commit:59df0ee44206557cbe18ce42117b201f4d858bee)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:b68bfc65d82c360656adeec56efaf24775658d30)
Merged-In: Id8002042f607f8e158f561ca47e0a84a8b8927e2
Change-Id: Id8002042f607f8e158f561ca47e0a84a8b8927e2
-rwxr-xr-x | tests/sbom_test.sh | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/tests/sbom_test.sh b/tests/sbom_test.sh index 19987f204..30a1d377f 100755 --- a/tests/sbom_test.sh +++ b/tests/sbom_test.sh @@ -223,4 +223,65 @@ function test_sbom_aosp_cf_x86_64_phone { cleanup "${out_dir}" } -test_sbom_aosp_cf_x86_64_phone
\ No newline at end of file +function test_sbom_unbundled_apex { + # Setup + out_dir="$(setup)" + + # run_soong to build com.android.adbd.apex + run_soong "module_arm64" "${out_dir}" "sbom deapexer" "com.android.adbd" + + deapexer=${out_dir}/host/linux-x86/bin/deapexer + debugfs=${out_dir}/host/linux-x86/bin/debugfs_static + apex_file=${out_dir}/target/product/module_arm64/system/apex/com.android.adbd.apex + echo "============ Diffing files in $apex_file and SBOM" + set +e + # deapexer prints the list of all files and directories + # sed extracts the file/directory names + # grep removes directories + # sed removes leading ./ in file names + diff -I /system/apex/com.android.adbd.apex -I apex_manifest.pb \ + <($deapexer --debugfs_path=$debugfs list --extents ${apex_file} | sed -E 's#(.*) \[.*\]$#\1#' | grep -v "/$" | sed -E 's#^\./(.*)#\1#' | sort -n) \ + <(grep '"fileName": ' ${apex_file}.spdx.json | sed -E 's/.*"fileName": "(.*)",/\1/' | sort -n ) + + if [ $? != "0" ]; then + echo "Diffs found in $apex_file and SBOM" + exit 1 + else + echo "No diffs." + fi + set -e + + # Teardown + cleanup "${out_dir}" +} + +function test_sbom_unbundled_apk { + # Setup + out_dir="$(setup)" + + # run_soong to build Browser2.apk + run_soong "module_arm64" "${out_dir}" "sbom" "Browser2" + + sbom_file=${out_dir}/target/product/module_arm64/system/product/app/Browser2/Browser2.apk.spdx.json + echo "============ Diffing files in Browser2.apk and SBOM" + set +e + # There is only one file in SBOM of APKs + diff \ + <(echo "/system/product/app/Browser2/Browser2.apk" ) \ + <(grep '"fileName": ' ${sbom_file} | sed -E 's/.*"fileName": "(.*)",/\1/' ) + + if [ $? != "0" ]; then + echo "Diffs found in $sbom_file" + exit 1 + else + echo "No diffs." + fi + set -e + + # Teardown + cleanup "${out_dir}" +} + +test_sbom_aosp_cf_x86_64_phone +test_sbom_unbundled_apex +test_sbom_unbundled_apk
\ No newline at end of file |