|
| 1 | +#!/bin/bash -ex |
| 2 | +# |
| 3 | +# Copyright (C) 2021 HERE Europe B.V. |
| 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 | +# SPDX-License-Identifier: Apache-2.0 |
| 18 | +# License-Filename: LICENSE |
| 19 | + |
| 20 | +### |
| 21 | +### Script starts Mock server, install certificate, add it to trusted and |
| 22 | +### run FV functional test against it inside iOS Simulator (more info in OLPEDGE-1773) |
| 23 | +### NOTE: Simulator fails during application launch, so step is disabled until OLPEDGE-2543 is DONE. |
| 24 | +### |
| 25 | +### # TODO in OLPEDGE-2543 : |
| 26 | +## 1. Find out how to save xml report after Simulator test done. |
| 27 | +## 2. Fix `xcrun simctl launch` cmd below: errors from app like -999 etc. |
| 28 | +## 3. Functional test should be able to use this variable : IP_ADDR for connecting to Mock Server. It's possible solution for error -999 when connecting to Server. |
| 29 | +## 4. Need to find out how to parse `xcrun simctl spawn booted log stream` and catch finish of test-run. Otherwise it goes to infinite loop. |
| 30 | +## |
| 31 | +## export IP_ADDR=$(ipconfig getifaddr en0) |
| 32 | +## curl -s http://${IP_ADDR}:1080 |
| 33 | +## |
| 34 | +## |
| 35 | +## For linux fv network tests please refer to : ./scripts/linux/fv/gitlab-olp-cpp-sdk-functional-network-test.sh |
| 36 | + |
| 37 | + |
| 38 | +# For core dump backtrace |
| 39 | +ulimit -c unlimited |
| 40 | + |
| 41 | +# Set workspace location |
| 42 | +if [[ ${CI_PROJECT_DIR} == "" ]]; then |
| 43 | + export CI_PROJECT_DIR=$(pwd) |
| 44 | +fi |
| 45 | + |
| 46 | +if [[ ${GITHUB_RUN_ID} == "" ]]; then |
| 47 | + # Local run |
| 48 | + export GITHUB_RUN_ID=$(date '+%s') |
| 49 | + pushd tests/utils/mock-server |
| 50 | + echo ">>> Installing mock server SSL certificate into OS... >>>" |
| 51 | + # Import and Make trusted |
| 52 | + security import mock-server-cert.pem || true |
| 53 | + security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain mock-server-cert.pem || true |
| 54 | + # Validate cert: if trusted - succeeded , if not trusted - fails |
| 55 | + security verify-cert -c mock-server-cert.pem |
| 56 | + echo ">>> Starting Mock Server... >>>" |
| 57 | + npm install |
| 58 | + node server.js & export SERVER_PID=$! |
| 59 | + popd |
| 60 | +else |
| 61 | + # CI run |
| 62 | + pushd tests/utils/mock-server |
| 63 | + echo ">>> Installing mock server SSL certificate into OS... >>>" |
| 64 | + # Import and Make trusted |
| 65 | + sudo security import mock-server-cert.pem |
| 66 | + sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain mock-server-cert.pem |
| 67 | + # Validate cert: if trusted - succeeded , if not trusted - fails |
| 68 | + sudo security verify-cert -c mock-server-cert.pem |
| 69 | + echo ">>> Starting Mock Server... >>>" |
| 70 | + npm install |
| 71 | + node server.js & export SERVER_PID=$! |
| 72 | + popd |
| 73 | +fi |
| 74 | + |
| 75 | + |
| 76 | +# Node can start server in 1 second, but not faster. |
| 77 | +# Add waiter for server to be started. No other way to solve that. |
| 78 | +# Curl returns code 1 - means server still down. Curl returns 0 when server is up |
| 79 | +RC=1 |
| 80 | +while [[ ${RC} -ne 0 ]]; |
| 81 | +do |
| 82 | + set +e |
| 83 | + curl -s http://localhost:1080 |
| 84 | + RC=$? |
| 85 | + sleep 0.2 |
| 86 | + set -e |
| 87 | +done |
| 88 | + |
| 89 | +# Functional test should be able to use this variable : IP_ADDR for connecting to Mock Server. |
| 90 | +# Looks like localhost is not reachable for Simulator. |
| 91 | +export IP_ADDR=$(ipconfig getifaddr en0) |
| 92 | +curl -s http://${IP_ADDR}:1080 |
| 93 | + |
| 94 | +echo ">>> Start network tests ... >>>" |
| 95 | +# List available devices, runtimes on MacOS node |
| 96 | +xcrun simctl list |
| 97 | +xcrun simctl list devices |
| 98 | +xcrun simctl list runtimes |
| 99 | + |
| 100 | +export CurrentDeviceUDID=$(xcrun simctl list devices | grep "iPhone 11 (" | grep -v "unavailable" | grep -v "com.apple.CoreSimulator.SimDeviceType" | cut -d'(' -f2 | cut -d')' -f1 | head -1) |
| 101 | + |
| 102 | +# Create new Simulator device |
| 103 | + |
| 104 | +xcrun simctl list devices | grep "iPhone 11" |
| 105 | +xcrun simctl boot "iPhone 11" || true |
| 106 | +xcrun simctl list devices | grep "iPhone 11" |
| 107 | +xcrun simctl create ${GITHUB_RUN_ID}_iphone11 "com.apple.CoreSimulator.SimDeviceType.iPhone-11" |
| 108 | +xcrun simctl list devices | grep "iPhone 11" |
| 109 | +echo "Simulator created" |
| 110 | + |
| 111 | +#/Applications/Xcode_11.2.1.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -CurrentDeviceUDID ${CurrentDeviceUDID} & export SIMULATOR_PID=$! || /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -CurrentDeviceUDID ${CurrentDeviceUDID} & export SIMULATOR_PID=$! |
| 112 | +#echo "Simulator started device" |
| 113 | +# |
| 114 | +#xcrun simctl logverbose enable |
| 115 | +#xcrun simctl install ${CurrentDeviceUDID} ./build/tests/functional/network/ios/olp-cpp-sdk-functional-network-tests-tester/Debug-iphonesimulator/olp-ios-olp-cpp-sdk-functional-network-tests-lib-tester.app |
| 116 | +#echo "App installed" |
| 117 | +#xcrun simctl launch ${CurrentDeviceUDID} com.here.olp.olp-ios-olp-cpp-sdk-functional-network-tests-lib-tester |
| 118 | +# Need to find out how to parse `xcrun simctl spawn booted log stream` and catch finish of test-run. Otherwise it goes to infinite loop. |
| 119 | +# xcrun simctl spawn booted log stream | grep "olp-ios-olp-cpp-sdk-functional-network-tests-lib-tester:" | tee app.log |
| 120 | +#result=$? |
| 121 | +#echo "App launched" |
| 122 | +#xcrun simctl shutdown ${CurrentDeviceUDID} |
| 123 | +#echo "Simulator shutdown done" |
| 124 | + |
| 125 | +#echo ">>> Finished network tests >>>" |
| 126 | + |
| 127 | +# Terminate the mock server |
| 128 | +#kill -TERM $SERVER_PID || true |
| 129 | +#kill -TERM $SIMULATOR_PID || true |
| 130 | + |
| 131 | +#wait |
| 132 | + |
| 133 | +#exit ${result} |
0 commit comments