From b68bfc65d82c360656adeec56efaf24775658d30 Mon Sep 17 00:00:00 2001 From: Wei Li Date: Mon, 10 Jul 2023 15:50:38 -0700 Subject: [PATCH] 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) Merged-In: Id8002042f607f8e158f561ca47e0a84a8b8927e2 Change-Id: Id8002042f607f8e158f561ca47e0a84a8b8927e2 --- tests/sbom_test.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) 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