mbed_unit_tests.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (c) 2021 Project CHIP Authors
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. cd "$(dirname "$0")"/../../..
  18. CHIP_ROOT=$PWD
  19. cd "$CHIP_ROOT"/src/test_driver/mbed/unit_tests/
  20. SUPPORTED_TOOLCHAIN=(GCC_ARM ARM)
  21. SUPPORTED_TARGET_BOARD=(CY8CPROTO_062_4343W)
  22. SUPPORTED_PROFILES=(release develop debug)
  23. SUPPORTED_COMMAND=(build flash build-flash)
  24. COMMAND=build
  25. TARGET_BOARD=CY8CPROTO_062_4343W
  26. TOOLCHAIN=GCC_ARM
  27. PROFILE=release
  28. for i in "$@"; do
  29. case $i in
  30. -b=* | --board=*)
  31. TARGET_BOARD="${i#*=}"
  32. shift
  33. ;;
  34. -t=* | --toolchain=*)
  35. TOOLCHAIN="${i#*=}"
  36. shift
  37. ;;
  38. -p=* | --profile=*)
  39. PROFILE="${i#*=}"
  40. shift
  41. ;;
  42. -c=* | --command=*)
  43. COMMAND="${i#*=}"
  44. shift
  45. ;;
  46. *)
  47. # unknown option
  48. ;;
  49. esac
  50. done
  51. if [[ ! " ${SUPPORTED_TARGET_BOARD[@]} " =~ " ${TARGET_BOARD} " ]]; then
  52. echo "ERROR: Target $TARGET_BOARD not supported"
  53. exit 1
  54. fi
  55. if [[ ! " ${SUPPORTED_TOOLCHAIN[@]} " =~ " ${TOOLCHAIN} " ]]; then
  56. echo "ERROR: Toolchain $TOOLCHAIN not supported"
  57. exit 1
  58. fi
  59. if [[ ! " ${SUPPORTED_PROFILES[@]} " =~ " ${PROFILE} " ]]; then
  60. echo "ERROR: Profile $PROFILE not supported"
  61. exit 1
  62. fi
  63. if [[ ! " ${SUPPORTED_COMMAND[@]} " =~ " ${COMMAND} " ]]; then
  64. echo "ERROR: Command $COMMAND not supported"
  65. exit 1
  66. fi
  67. set -e # Exit immediately if a command exits with a non-zero status.
  68. # Activate Matter environment
  69. source "$CHIP_ROOT"/scripts/activate.sh
  70. # Build directory setup
  71. BUILD_DIRECTORY=build-"$TARGET_BOARD"/"$PROFILE"/
  72. if [[ "$COMMAND" == *"build"* ]]; then
  73. echo "Build unit tests app for $TARGET_BOARD target with $TOOLCHAIN toolchain and $PROFILE profile"
  74. # Set Mbed OS path
  75. MBED_OS_PATH="$CHIP_ROOT"/third_party/mbed-os/repo
  76. # Set Mbed OS posix socket submodule path
  77. MBED_OS_POSIX_SOCKET_PATH="$CHIP_ROOT"/third_party/mbed-os-posix-socket/repo
  78. # Generate config file for selected target, toolchain and hardware
  79. mbed-tools configure -t "$TOOLCHAIN" -m "$TARGET_BOARD" -o "$BUILD_DIRECTORY" --mbed-os-path "$MBED_OS_PATH"
  80. # Remove old artifacts to force linking
  81. rm -rf "$BUILD_DIRECTORY/chip-"*
  82. # Build application
  83. cmake -S "./" -B "$BUILD_DIRECTORY" -GNinja -DCMAKE_BUILD_TYPE="$PROFILE" -DMBED_OS_PATH="$MBED_OS_PATH" -DMBED_OS_POSIX_SOCKET_PATH="$MBED_OS_POSIX_SOCKET_PATH"
  84. cmake --build "$BUILD_DIRECTORY"
  85. fi
  86. if [[ "$COMMAND" == *"flash"* ]]; then
  87. echo "Flash unit tests app to $TARGET_BOARD target [$TOOLCHAIN toolchain, $PROFILE profile]"
  88. # Flash scripts path setup
  89. MBED_FLASH_SCRIPTS_PATH=$CHIP_ROOT/config/mbed/scripts
  90. # Flash application
  91. "$OPENOCD_PATH"/bin/openocd -f "$MBED_FLASH_SCRIPTS_PATH/$TARGET_BOARD".tcl -c "program $BUILD_DIRECTORY/chip-mbed-unit-tests.elf verify reset exit"
  92. fi