Skip to content

Commit

Permalink
Allow specifying multiple clients for run_examples (#1148)
Browse files Browse the repository at this point in the history
  • Loading branch information
jul-sh authored Jun 15, 2020
1 parent e007ec8 commit 8019d83
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 52 deletions.
22 changes: 2 additions & 20 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ steps:
waitFor: ['run_tests_tsan']
timeout: 60m
entrypoint: 'bash'
args: ['./scripts/run_examples', '-s', 'base']
args: ['./scripts/run_examples', '-s', 'base', '-c', 'rust cpp nodejs']

- name: 'gcr.io/oak-ci/oak:latest'
id: run_examples_cpp
Expand All @@ -90,24 +90,6 @@ steps:
entrypoint: 'bash'
args: ['./scripts/run_examples', '-s', 'base', '-a', 'cpp']

# TODO(#1145): Integrate examples with multiple clients into our
# run_examples script, instead of listing them individually.
- name: 'gcr.io/oak-ci/oak:latest'
id: run_example_hello_world_nodejs
waitFor: ['run_examples_cpp']
timeout: 15m
entrypoint: 'bash'
args:
[
'./scripts/run_example',
'-s',
'base',
'-e',
'hello_world',
'-c',
'nodejs',
]

- name: 'gcr.io/oak-ci/oak:latest'
id: build_experimental
waitFor: ['run_tests']
Expand All @@ -118,7 +100,7 @@ steps:
# Run clang-tidy after the examples finish running, since they share the same `output_base`.
- name: 'gcr.io/oak-ci/oak:latest'
id: run_clang_tidy
waitFor: ['run_example_hello_world_nodejs']
waitFor: ['run_examples_cpp']
timeout: 30m
entrypoint: 'bash'
args: ['./scripts/run_clang_tidy']
Expand Down
67 changes: 40 additions & 27 deletions scripts/run_example
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ source "${SCRIPTS_DIR}/common"

server="base"
application_language="rust"
client_language="cpp"
client_languages="cpp"
buildargs=""
serverargs=""
while getopts "s:a:c:de:vh" opt; do
case "${opt}" in
h)
echo -e "Usage: ${0} [-h] [-s base|logless|none] [-a rust|cpp] [-c rust|cpp|nodejs] [-d] [-v] -e EXAMPLE [-- CLIENT_ARGS]
echo -e "Usage: ${0} [-h] [-s base|logless|none] [-a rust|cpp] [-c [rust|cpp|nodejs]...] [-d] [-v] -e EXAMPLE [-- CLIENT_ARGS]
Build and run the given example Oak Application and client.
Expand All @@ -26,7 +26,8 @@ Options:
-a Example application variant:
- rust (used by default)
- cpp
-c Example client variant:
-c Example client variants. Multiple clients can be specified by space
seperating them. Eg -c \"rust cpp nodejs\".
- rust
- cpp (used by default)
- nodejs
Expand All @@ -37,7 +38,7 @@ Options after -- will be passed to the example client program."
a)
application_language="${OPTARG}";;
c)
client_language="${OPTARG}";;
client_languages="${OPTARG}";;
s)
case "${OPTARG}" in
base|logless|none)
Expand Down Expand Up @@ -97,28 +98,40 @@ fi

readonly CLIENT_ARGS=("${@-}") # Choose client args provided after '--'.

# Run the application client.
case "${client_language}" in
rust)
cargo run --release --target=x86_64-unknown-linux-musl --manifest-path="${SCRIPTS_DIR}/../examples/${EXAMPLE}/client/rust/Cargo.toml" -- \
--root-tls-certificate="${SCRIPTS_DIR}/../examples/certs/local/ca.pem" \
"${CLIENT_ARGS[@]-}"
;;
cpp)
"./bazel-client-bin/examples/${EXAMPLE}/client/client" "${TLS_ARGS[@]}" "${ADDITIONAL_ARGS[@]-}" "${CLIENT_ARGS[@]-}"
;;
nodejs)
nodejs_client="./examples/${EXAMPLE}/client/nodejs"
if [[ -d "${nodejs_client}" ]]; then
npm start --prefix "./examples/${EXAMPLE}/client/nodejs"
else
echo "The ${EXAMPLE} example does not contain a ${client_language} client."
exit 1
fi
;;
*)
echo "Invalid example client variant: ${client_language}"
exit 1;;
esac
# Run the application clients.
for client_language in $client_languages
do
case "${client_language}" in
rust)
rust_client_manifest="${SCRIPTS_DIR}/../examples/${EXAMPLE}/client/rust/Cargo.toml"
if [[ -d "${rust_client_manifest}" ]]; then
cargo run --release --target=x86_64-unknown-linux-musl --manifest-path="${rust_client_manifest}" -- \
--root-tls-certificate="${SCRIPTS_DIR}/../examples/certs/local/ca.pem" \
"${CLIENT_ARGS[@]-}"
else
echo "The ${EXAMPLE} example does not contain a ${client_language} client. Skipping this client."
fi
;;
cpp)
cpp_client="./bazel-client-bin/examples/${EXAMPLE}/client/client"
if [[ -d "${cpp_client}" ]]; then
"${cpp_client}" "${TLS_ARGS[@]}" "${ADDITIONAL_ARGS[@]-}" "${CLIENT_ARGS[@]-}"
else
echo "The ${EXAMPLE} example does not contain a ${client_language} client. Skipping this client."
fi
;;
nodejs)
nodejs_client="./examples/${EXAMPLE}/client/nodejs"
if [[ -d "${nodejs_client}" ]]; then
npm start --prefix "${nodejs_client}"
else
echo "The ${EXAMPLE} example does not contain a ${client_language} client. Skipping this client."
fi
;;
*)
echo "Invalid example client variant: ${client_language}"
exit 1;;
esac
done

kill_bg_pids
18 changes: 13 additions & 5 deletions scripts/run_examples
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ source "${SCRIPTS_DIR}/common"

server="base"
application_language="rust"
while getopts "s:a:h" opt; do
client_languages="cpp"
while getopts "s:a:c:h" opt; do
case "${opt}" in
h)
echo -e "Usage: ${0} [-s base|logless] [-a rust|cpp]
Expand All @@ -16,10 +17,17 @@ while getopts "s:a:h" opt; do
-a Example application variant:
- rust (default)
- cpp
-c Example client variants. Multiple clients can be specified by space
seperating them. Eg -c \"rust cpp nodejs\".
- rust
- cpp (used by default)
- nodejs
-h Print Help (this message) and exit"
exit 0;;
a)
application_language="${OPTARG}";;
c)
client_languages="${OPTARG}";;
s)
case "${OPTARG}" in
base|logless)
Expand All @@ -38,12 +46,12 @@ done
examples="$(find examples -mindepth 2 -maxdepth 4 -type d -regex '.*/module.*/'"${application_language}"'$' | cut -d'/' -f2 | uniq)"
for example in ${examples}; do
if [[ "${example}" == 'aggregator' ]]; then
"${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -e aggregator -- --bucket=test --data=1:10,2:20,3:30
"${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -c "${client_languages}" -e aggregator -- --bucket=test --data=1:10,2:20,3:30
elif [[ "${example}" == 'chat' ]]; then
"${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -e chat -- --test
"${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -c "${client_languages}" -e chat -- --test
elif [[ "${example}" == 'trusted_information_retrieval' ]]; then
"${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -c rust -e trusted_information_retrieval -- --latitude 0.0 --longitude 0.0
"${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -c "${client_languages}" -e trusted_information_retrieval -- --latitude 0.0 --longitude 0.0
else
"${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -e "${example}"
"${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -c "${client_languages}" -e "${example}"
fi
done

0 comments on commit 8019d83

Please sign in to comment.