From 6cffd1dd4f15542b7ae41bb21d6dd924ce3e101f Mon Sep 17 00:00:00 2001 From: Sichan Yoo Date: Wed, 13 Nov 2024 14:16:16 -0800 Subject: [PATCH] Update smoke test script and codegen script to use in internal build system. --- scripts/codegen.sh | 1 + scripts/run-smoke-tests.sh | 84 ++++++++++++++++---------------------- 2 files changed, 36 insertions(+), 49 deletions(-) diff --git a/scripts/codegen.sh b/scripts/codegen.sh index 53e38550e87..5b31deb0435 100755 --- a/scripts/codegen.sh +++ b/scripts/codegen.sh @@ -35,6 +35,7 @@ rm -rf SmokeTests/* cd AWSSDKSwiftCLI unset AWS_SWIFT_SDK_USE_LOCAL_DEPS swift run AWSSDKSwiftCLI generate-package-manifest "$@" .. +swift run AWSSDKSwiftCLI generate-smoke-tests-package-manifest .. swift run AWSSDKSwiftCLI generate-doc-index .. cd .. diff --git a/scripts/run-smoke-tests.sh b/scripts/run-smoke-tests.sh index 227cce92af1..59d631286a4 100755 --- a/scripts/run-smoke-tests.sh +++ b/scripts/run-smoke-tests.sh @@ -1,9 +1,5 @@ #!/bin/bash -# This script must be run from the directory containing aws-sdk-swift. -SMOKE_TESTS_DIR="aws-sdk-swift/SmokeTests/" -cd "$SMOKE_TESTS_DIR" || { echo "ERROR: Failed to change directory to $SMOKE_TESTS_DIR"; exit 1; } - print_header() { local header=$1 print_empty_line @@ -15,69 +11,59 @@ print_empty_line() { echo "" } -print_header "SETUP SMOKE TESTS" +print_header "SETTING UP SMOKE TESTS" -# Clean build -swift package clean > /dev/null 2>&1 +# This script must be run from . that contains smoke test runner executables under ./Executables. +SMOKE_TESTS_DIR="./Executables" +if [[ -d "$SMOKE_TESTS_DIR" ]]; then + echo "INFO: Directory '$SMOKE_TESTS_DIR' exists in $(pwd)." +else + echo "ERROR: Directory '$SMOKE_TESTS_DIR' does not exist in $(pwd)." + exit 1 +fi -# Expect comma-separated service names from AWS_SMOKE_TEST_SERVICE_IDS environment variable. -# The service names in environment variable must be in the format "AWSName", e.g., "AWSS3". +# Expect comma-separated sdkId's from AWS_SMOKE_TEST_SERVICE_IDS environment variable. +# Each sdkId is processed following same logic as in Swift codegen. # The resulting array will be in the format "AWSNameSmokeTestRunner", e.g., "AWSS3SmokeTestRunner". if [ -z "$AWS_SMOKE_TEST_SERVICE_IDS" ]; then + # If env var isn't set, exit script echo "INFO: The environment variable AWS_SMOKE_TEST_SERVICE_IDS is not set or is empty." - echo "INFO: It must set to a comma-separated string of service names for which you want to run smoke test for." echo "INFO: Exiting run-smoke-tests.sh with exit code 0." exit 0 else IFS=',' read -r -a testRunnerNames <<< "$AWS_SMOKE_TEST_SERVICE_IDS" for i in "${!testRunnerNames[@]}"; do - testRunnerNames[$i]="${testRunnerNames[$i]}SmokeTestRunner" + # Remove whitespace from sdkId + value="${testRunnerNames[$i]// /}" + + # Capitalize the first letter of sdkId + value="$(echo "${value:0:1}" | tr '[:lower:]' '[:upper:]')${value:1}" + + # Remove "Service" suffix from sdkId if it exists + value="${value%Service}" + + # Add "AWS" prefix and "SmokeTestRunner" suffix to the modified value + value="AWS${value}SmokeTestRunner" + + # Update the original array with the modified value + testRunnerNames[$i]="$value" done - echo "INFO: Retrieved the value of AWS_SMOKE_TEST_SERVICE_IDS: $AWS_SMOKE_TEST_SERVICE_IDS." - echo "INFO: Constructed test runner names: ${testRunnerNames[@]}" + echo "INFO: Retrieved value of \$AWS_SMOKE_TEST_SERVICE_IDS env var: \"$AWS_SMOKE_TEST_SERVICE_IDS\"" + IFS=','; echo "INFO: Constructed test runner names: [${testRunnerNames[*]}]" fi -# Array of test failure logs. -testFailureLogs=() - -print_header "RUN SMOKE TESTS" +print_header "RUNNING SMOKE TESTS" for testRunnerName in "${testRunnerNames[@]}"; do - # If test runner was generated under SmokeTests/ - if [ -d "$testRunnerName" ]; then - echo "INFO: Found smoke tests for the service ${testRunnerName%SmokeTestRunner}." - echo "INFO: Building smoke test(s) for the service ${testRunnerName%SmokeTestRunner}..." - # Build the test runner executable (discard output for clean log) - swift build --target "$testRunnerName" > /dev/null 2>&1 - echo "INFO: Running smoke test(s) for the service ${testRunnerName%SmokeTestRunner}..." - # Run executable and save output to `testRunOutput` - testRunOutput=$(swift run --quiet "$testRunnerName") - # Get test runner exit code - testRunExitCode=$? - # If exit code was 1, one or more tests failed. Save its output to array. - if [ "$testRunExitCode" -eq 1 ]; then - testFailureLogs+=("$testRunOutput") - fi + # If test runner executable exists under ./Executables/ + if [ -x "./Executables/$testRunnerName" ]; then + echo "INFO: Running ${testRunnerName}..." + # Run executable + ./Executables/"$testRunnerName" print_empty_line # If no smoke tests were generated, no-op else - echo "INFO: No smoke tests found for the service ${testRunnerName%SmokeTestRunner}. Skipping..." + echo "INFO: ${testRunnerName} not found. Skipping..." print_empty_line fi done - -print_header "SMOKE TEST RESULTS" - -# Log any failure outputs if present and exit with 1 -if [ ${#testFailureLogs[@]} -gt 0 ]; then - echo "# One or more smoke test(s) failed. See the log(s) for failed test runner(s) below:" - print_empty_line - for failureLog in "${testFailureLogs[@]}"; do - echo "${failureLog}" - print_empty_line - done - exit 1 -else - echo "INFO: Every smoke test for every service passed!" - exit 0 -fi