| 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 -e |
| 17 | |
| 18 | source codebuild/bin/s2n_setup_env.sh |
| 19 | |
| 20 | # Use prlimit to set the memlock limit to unlimited for linux. OSX is unlimited by default |
| 21 | # Codebuild Containers aren't allowing prlimit changes (and aren't being caught with the usual cgroup check) |
| 22 | if [[ "$OS_NAME" == "linux" && -n "$CODEBUILD_BUILD_ARN" ]]; then |
| 23 | PRLIMIT_LOCATION=`which prlimit` |
| 24 | sudo -E ${PRLIMIT_LOCATION} --pid "$$" --memlock=unlimited:unlimited; |
| 25 | fi |
| 26 | |
| 27 | # Set the version of GCC as Default if it's required |
| 28 | if [[ -n "$GCC_VERSION" ]] && [[ "$GCC_VERSION" != "NONE" ]]; then |
| 29 | alias gcc=$(which gcc-$GCC_VERSION); |
| 30 | fi |
| 31 | |
| 32 | # Find if the environment has more than 8 cores |
| 33 | JOBS=8 |
| 34 | if [[ -x "$(command -v nproc)" ]]; then |
| 35 | UNITS=$(nproc); |
| 36 | if [[ $UNITS -gt $JOBS ]]; then |
| 37 | JOBS=$UNITS; |
| 38 | fi |
| 39 | fi |
| 40 | |
| 41 | make clean; |
| 42 | |
| 43 | echo "Using $JOBS jobs for make.."; |
| 44 | echo "running with libcrypto: ${S2N_LIBCRYPTO}, gcc_version: ${GCC_VERSION}" |
| 45 | |
| 46 | test_linked_libcrypto() { |
| 47 | s2n_executable="$1" |
| 48 | so_path="${LIBCRYPTO_ROOT}/lib/libcrypto.so" |
| 49 | echo "Testing for linked libcrypto: ${so_path}" |
| 50 | echo "ldd:" |
| 51 | ldd "${s2n_executable}" |
| 52 | ldd "${s2n_executable}" | grep "${so_path}" || \ |
| 53 | { echo "Linked libcrypto is incorrect."; exit 1; } |
| 54 | echo "Test succeeded!" |
| 55 | } |
| 56 | |
| 57 | setup_apache_server() { |
| 58 | # Start the apache server if the list of tests isn't defined, meaning all tests |
| 59 | # are to be run, or if the renegotiate test is included in the list of tests. |
| 60 | if [[ -z $TOX_TEST_NAME ]] || [[ "${TOX_TEST_NAME}" == *"test_renegotiate_apache"* ]]; then |
| 61 | source codebuild/bin/s2n_apache2.sh |
| 62 | APACHE_CERT_DIR="$(pwd)/tests/pems" |
| 63 | |
| 64 | apache2_start "${APACHE_CERT_DIR}" |
| 65 | fi |
| 66 | } |
| 67 | |
| 68 | run_integration_v2_tests() { |
| 69 | setup_apache_server |
| 70 | "$CB_BIN_DIR/install_s2n_head.sh" "$(mktemp -d)" |
| 71 | cmake . -Bbuild \ |
| 72 | -DCMAKE_PREFIX_PATH=$LIBCRYPTO_ROOT \ |
| 73 | -DBUILD_SHARED_LIBS=on \ |
| 74 | -DS2N_INTEG_TESTS=on \ |
| 75 | -DPython3_EXECUTABLE=$(which python3) |
| 76 | cmake --build ./build --clean-first -- -j $(nproc) |
| 77 | test_linked_libcrypto ./build/bin/s2nc |
| 78 | test_linked_libcrypto ./build/bin/s2nd |
| 79 | cp -f ./build/bin/s2nc "$BASE_S2N_DIR"/bin/s2nc |
| 80 | cp -f ./build/bin/s2nd "$BASE_S2N_DIR"/bin/s2nd |
| 81 | cd ./build/ |
| 82 | for test_name in $TOX_TEST_NAME; do |
| 83 | test="${test_name//test_/}" |
| 84 | echo "Running... ctest --no-tests=error --output-on-failure --verbose -R ^integrationv2_${test}$" |
| 85 | ctest --no-tests=error --output-on-failure --verbose -R ^integrationv2_${test}$ |
| 86 | done |
| 87 | } |
| 88 | |
| 89 | run_unit_tests() { |
| 90 | cmake . -Bbuild \ |
| 91 | -DCMAKE_PREFIX_PATH=$LIBCRYPTO_ROOT \ |
| 92 | -DBUILD_SHARED_LIBS=on \ |
| 93 | -DS2N_ENFORCE_PROPER_LIBCRYPTO_FEATURE_PROBE=1 |
| 94 | cmake --build ./build -- -j $(nproc) |
| 95 | test_linked_libcrypto ./build/bin/s2nc |
| 96 | cmake --build build/ --target test -- ARGS="-L unit --output-on-failure -j $(nproc)" |
| 97 | } |
| 98 | |
| 99 | # Run Multiple tests on one flag. |
| 100 | if [[ "$TESTS" == "ALL" || "$TESTS" == "sawHMACPlus" ]] && [[ "$OS_NAME" == "linux" ]]; then make -C tests/saw tmp/verify_HMAC.log tmp/verify_drbg.log failure-tests; fi |
| 101 | |
| 102 | # Run Individual tests |
| 103 | if [[ "$TESTS" == "ALL" || "$TESTS" == "unit" ]]; then run_unit_tests; fi |
| 104 | if [[ "$TESTS" == "ALL" || "$TESTS" == "interning" ]]; then ./codebuild/bin/test_libcrypto_interning.sh; fi |
| 105 | if [[ "$TESTS" == "ALL" || "$TESTS" == "exec_leak" ]]; then ./codebuild/bin/test_exec_leak.sh; fi |
| 106 | if [[ "$TESTS" == "ALL" || "$TESTS" == "integrationv2" ]]; then run_integration_v2_tests; fi |
| 107 | if [[ "$TESTS" == "ALL" || "$TESTS" == "crt" ]]; then ./codebuild/bin/build_aws_crt_cpp.sh $(mktemp -d) $(mktemp -d); fi |
| 108 | if [[ "$TESTS" == "ALL" || "$TESTS" == "sharedandstatic" ]]; then ./codebuild/bin/test_install_shared_and_static.sh $(mktemp -d); fi |
| 109 | if [[ "$TESTS" == "ALL" || "$TESTS" == "dynamicload" ]]; then ./codebuild/bin/test_dynamic_load.sh $(mktemp -d); fi |
| 110 | if [[ "$TESTS" == "sawHMAC" ]] && [[ "$OS_NAME" == "linux" ]]; then make -C tests/saw/ tmp/verify_HMAC.log ; fi |
| 111 | if [[ "$TESTS" == "sawDRBG" ]]; then make -C tests/saw tmp/verify_drbg.log ; fi |
| 112 | if [[ "$TESTS" == "ALL" || "$TESTS" == "tls" ]]; then make -C tests/saw tmp/verify_handshake.log ; fi |
| 113 | if [[ "$TESTS" == "sawHMACFailure" ]]; then make -C tests/saw failure-tests ; fi |