dcla_apex_comparison_test.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #!/bin/bash
  2. # Copyright (C) 2023 The Android Open Source Project
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -euo pipefail
  16. # Soong/Bazel integration test to build the mainline modules in mixed build and
  17. # compare the DCLA libs extracted from those modules to ensure they are identical.
  18. if [ ! -e "build/make/core/Makefile" ]; then
  19. echo "$0 must be run from the top of the Android source tree."
  20. exit 1
  21. fi
  22. TARGET_PRODUCTS=(
  23. module_arm64
  24. module_x86_64
  25. )
  26. MODULES=(
  27. # These modules depend on the DCLA libs
  28. com.android.adbd
  29. com.android.art
  30. com.android.art.debug
  31. com.android.art.testing
  32. com.android.btservices
  33. com.android.conscrypt
  34. com.android.i18n
  35. com.android.media
  36. com.android.media.swcodec
  37. com.android.resolv
  38. com.android.runtime
  39. com.android.tethering
  40. )
  41. BAZEL_TARGETS=(
  42. //packages/modules/adb/apex:com.android.adbd
  43. //frameworks/av/apex:com.android.media.swcodec
  44. )
  45. DCLA_LIBS=(
  46. libbase.so
  47. libc++.so
  48. libcrypto.so
  49. libcutils.so
  50. libstagefright_flacdec.so
  51. libutils.so
  52. )
  53. if [[ -z ${OUT_DIR+x} ]]; then
  54. OUT_DIR="out"
  55. fi
  56. if [[ -z ${ANDROID_HOST_OUT+x} ]]; then
  57. export ANDROID_HOST_OUT="out/host/linux-x86"
  58. fi
  59. ######################
  60. # Build deapexer and debugfs
  61. ######################
  62. DEAPEXER="${ANDROID_HOST_OUT}/bin/deapexer"
  63. DEBUGFS="${ANDROID_HOST_OUT}/bin/debugfs"
  64. if [[ ! -f "${DEAPEXER}" ]] || [[ ! -f "${DEBUGFS}" ]]; then
  65. build/soong/soong_ui.bash --make-mode --skip-soong-tests deapexer debugfs
  66. fi
  67. DEAPEXER="${DEAPEXER} --debugfs_path=${DEBUGFS}"
  68. ############
  69. # Test Setup
  70. ############
  71. OUTPUT_DIR="$(mktemp -d tmp.XXXXXX)"
  72. function call_bazel() {
  73. build/bazel/bin/bazel $@
  74. }
  75. function cleanup {
  76. rm -rf "${OUTPUT_DIR}"
  77. }
  78. trap cleanup EXIT
  79. #######
  80. # Tests
  81. #######
  82. function extract_dcla_libs() {
  83. local product=$1; shift
  84. local modules=("$@"); shift
  85. for module in "${modules[@]}"; do
  86. local apex="${OUTPUT_DIR}/${product}/${module}.apex"
  87. local extract_dir="${OUTPUT_DIR}/${product}/${module}/extract"
  88. $DEAPEXER extract "${apex}" "${extract_dir}"
  89. done
  90. }
  91. function compare_dcla_libs() {
  92. local product=$1; shift
  93. local modules=("$@"); shift
  94. for lib in "${DCLA_LIBS[@]}"; do
  95. for arch in lib lib64; do
  96. local prev_sha=""
  97. for module in "${modules[@]}"; do
  98. local file="${OUTPUT_DIR}/${product}/${module}/extract/${arch}/${lib}"
  99. if [[ ! -f "${file}" ]]; then
  100. # not all libs are present in a module
  101. echo "file doesn't exist: ${file}"
  102. continue
  103. fi
  104. sha=$(sha1sum ${file})
  105. sha="${sha% *}"
  106. if [ "${prev_sha}" == "" ]; then
  107. prev_sha="${sha}"
  108. elif [ "${sha}" != "${prev_sha}" ] && { [ "${lib}" != "libcrypto.so" ] || [[ "${module}" != *"com.android.tethering" ]]; }; then
  109. echo "Test failed, ${lib} has different hash value"
  110. exit 1
  111. fi
  112. done
  113. done
  114. done
  115. }
  116. export UNBUNDLED_BUILD_SDKS_FROM_SOURCE=true # don't rely on prebuilts
  117. export TARGET_BUILD_APPS="${MODULES[@]}"
  118. for product in "${TARGET_PRODUCTS[@]}"; do
  119. ###########
  120. # Build the mainline modules
  121. ###########
  122. packages/modules/common/build/build_unbundled_mainline_module.sh \
  123. --product "${product}" \
  124. --dist_dir "${OUTPUT_DIR}/${product}"
  125. bazel_apexes=()
  126. if [[ -n ${TEST_BAZEL+x} ]] && [ "${TEST_BAZEL}" = true ]; then
  127. export TARGET_PRODUCT="${product/module/aosp}"
  128. call_bazel build --config=bp2build --config=ci --config=android "${BAZEL_TARGETS[@]}"
  129. for target in "${BAZEL_TARGETS[@]}"; do
  130. apex_path="$(realpath $(call_bazel cquery --config=bp2build --config=android --config=ci --output=files $target))"
  131. mkdir -p ${OUTPUT_DIR}/${product}
  132. bazel_apex="bazel_$(basename $apex_path)"
  133. mv $apex_path ${OUTPUT_DIR}/${product}/${bazel_apex}
  134. bazel_apexes+=(${bazel_apex%".apex"})
  135. done
  136. fi
  137. all_modeuls=(${MODULES[@]} ${bazel_apexes[@]})
  138. extract_dcla_libs "${product}" "${all_modeuls[@]}"
  139. compare_dcla_libs "${product}" "${all_modeuls[@]}"
  140. done
  141. echo "Test passed"