| 1 | #!/bin/bash |
| 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 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 | # A copy of the License is located at |
| 7 | # |
| 8 | # http://aws.amazon.com/apache2.0 |
| 9 | # |
| 10 | # or in the "license" file accompanying this file. This file is distributed |
| 11 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | # express or implied. See the License for the specific language governing |
| 13 | # permissions and limitations under the License. |
| 14 | # |
| 15 | |
| 16 | set -eu |
| 17 | |
| 18 | source codebuild/bin/s2n_setup_env.sh |
| 19 | # Used to test if we're running in CodeBuild |
| 20 | CODEBUILD_BUILD_ARN_="${CODEBUILD_BUILD_ARN:-}" |
| 21 | |
| 22 | if [[ ${DISTRO} != "amazon linux" ]]; then |
| 23 | echo "Target Amazon Linux, but running on $DISTRO: Nothing to do." |
| 24 | exit 1; |
| 25 | else |
| 26 | # AL2023 case |
| 27 | BUILD_FLAGS="-DCMAKE_BUILD_TYPE=RelWithDebInfo" |
| 28 | # AL2 case; Linker flags are a workaround for system openssl |
| 29 | if [[ ${VERSION_ID} == '2' ]]; then |
| 30 | BUILD_FLAGS=$(echo -e '-DCMAKE_EXE_LINKER_FLAGS="-lcrypto -lz" \ |
| 31 | -DCMAKE_EXPORT_COMPILE_COMMANDS=ON') |
| 32 | fi |
| 33 | fi |
| 34 | |
| 35 | # Use prlimit to set the memlock limit to unlimited for linux. OSX is unlimited by default |
| 36 | # Codebuild Containers aren't allowing prlimit changes (and aren't being caught with the usual cgroup check) |
| 37 | if [[ "$OS_NAME" == "linux" && -z "$CODEBUILD_BUILD_ARN_" ]]; then |
| 38 | PRLIMIT_LOCATION=$(which prlimit) |
| 39 | sudo -E ${PRLIMIT_LOCATION} --pid "$$" --memlock=unlimited:unlimited; |
| 40 | fi |
| 41 | |
| 42 | case "$TESTS" in |
| 43 | "unit") |
| 44 | eval cmake . -Bbuild "${BUILD_FLAGS}" |
| 45 | cmake --build ./build -j "$(nproc)" |
| 46 | CTEST_PARALLEL_LEVEL="$(nproc)" cmake --build ./build --target test -- ARGS="-L unit --output-on-failure" |
| 47 | ;; |
| 48 | *) echo "Unknown test"; exit 1;; |
| 49 | esac |