apex_cc_module_arch_variant_tests.sh 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. # Copyright (C) 2022 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 -uo pipefail
  16. # Integration test for verifying arch variant cflags set on cc modules included
  17. # in Bazel-built apexes in the real source tree.
  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. ############
  23. # Test Setup
  24. ############
  25. OUTPUT_DIR="$(mktemp -d tmp.XXXXXX)"
  26. BAZEL_OUTPUT_DIR="$OUTPUT_DIR/bazel"
  27. export TARGET_PRODUCT="aosp_arm64"
  28. [ "$#" -ge 1 ] && export TARGET_PRODUCT="$1"
  29. ARCH_VARIANT_CFLAG="armv8-a"
  30. [ "$#" -ge 2 ] && ARCH_VARIANT_CFLAG="$2"
  31. CPU_VARIANT_CFLAG=""
  32. [ "$#" -ge 3 ] && CPU_VARIANT_CFLAG="$3"
  33. function call_bazel() {
  34. build/bazel/bin/bazel --output_base="$BAZEL_OUTPUT_DIR" $@
  35. }
  36. function cleanup {
  37. # call bazel clean because some bazel outputs don't have w bits.
  38. call_bazel clean
  39. rm -rf "${OUTPUT_DIR}"
  40. }
  41. trap cleanup EXIT
  42. ######################
  43. # Run bp2build / Bazel
  44. ######################
  45. build/soong/soong_ui.bash --make-mode BP2BUILD_VERBOSE=1 --skip-soong-tests bp2build
  46. # Number of CppCompile actions with arch variant flag
  47. actions_with_arch_variant_num=$(call_bazel aquery --config=bp2build --config=ci --config=android \
  48. 'mnemonic("CppCompile", deps(//build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal))' | grep -c \'-march=$ARCH_VARIANT_CFLAG\')
  49. # Number of all CppCompile actions
  50. all_cppcompile_actions_num=0
  51. aquery_summary=$(call_bazel aquery --config=bp2build --config=ci --config=android --output=summary \
  52. 'mnemonic("CppCompile", deps(//build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal))' \
  53. | egrep -o '.*opt-ST.*: ([0-9]+)$' \
  54. | cut -d: -f2 -)
  55. while read -r num;
  56. do
  57. all_cppcompile_actions_num=$(($all_cppcompile_actions_num + $num))
  58. done <<< "$aquery_summary"
  59. if [ $actions_with_arch_variant_num -eq $all_cppcompile_actions_num ]
  60. then
  61. echo "Pass: arch variant is set."
  62. else
  63. echo "Error: number of CppCompile actions with arch variant set: actual=$actions_with_arch_variant_num, expected=$all_cppcompile_actions_num"
  64. exit 1
  65. fi
  66. if [ $CPU_VARIANT_CFLAG ]
  67. then
  68. # Number of CppCompiler actions with cpu variant flag
  69. actions_with_cpu_variant_num=$(call_bazel aquery --config=bp2build --config=ci --config=android \
  70. 'mnemonic("CppCompile", deps(//build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal))' | grep -c "\-mcpu=$CPU_VARIANT_CFLAG")
  71. if [ $actions_with_cpu_variant_num -eq $all_cppcompile_actions_num ]
  72. then
  73. echo "Pass: cpu variant is set."
  74. else
  75. echo "Error: number of CppCompile actions with cpu variant set: actual=$actions_with_cpu_variant_num, expected=$all_cppcompile_actions_num"
  76. exit 1
  77. fi
  78. fi