| # Copyright 2022 Google LLC |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| #!/bin/bash |
| |
| # Script for building and running Matter RPC tool |
| |
| RPC_VENV="rpc_tool_venv" |
| BASEDIR=$(dirname "$0") |
| |
| # Install the required packages |
| install_packages () |
| { |
| python3 -m venv $HOME/$RPC_VENV |
| source $HOME/$RPC_VENV/bin/activate |
| python -m pip install --upgrade pip |
| pip install --require-hashes -r $BASEDIR/verify_rpc/requirements.txt |
| export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python |
| } |
| |
| |
| # Run RPC mobly tests |
| run_mobly_test () |
| { |
| source $HOME/$RPC_VENV/bin/activate |
| python $BASEDIR/verify_rpc/rpc_tool.py -c $BASEDIR/verify_rpc/test_config.yml |
| deactivate |
| } |
| |
| |
| # Run the unit tests |
| run_unit_tests () |
| { |
| source $HOME/$RPC_VENV/bin/activate |
| coverage run $BASEDIR/verify_rpc/rpc_tool_test.py && coverage report -m |
| deactivate |
| } |
| |
| |
| # Run the stress tests |
| run_stress_tests () |
| { |
| source $HOME/$RPC_VENV/bin/activate |
| python $BASEDIR/verify_rpc/stress_test_suite.py -c $BASEDIR/verify_rpc/test_config.yml |
| deactivate |
| } |
| |
| |
| usage () |
| { |
| echo "Usage: 'sh $0 build' or 'sh $0 run' or 'sh $0 stress'" |
| } |
| |
| # Exit if the script usage is invalid |
| if [ $# -ne 1 ]; then |
| usage |
| exit 1 |
| fi |
| |
| |
| # Install the packages of the tool |
| if [ $1 == "build" ]; then |
| install_packages |
| |
| # Run the RPC tests for SDK |
| elif [ $1 == "run" ]; then |
| run_mobly_test |
| |
| # Run the unit tests for tool |
| elif [ $1 == "unit_test" ]; then |
| run_unit_tests |
| |
| # Run the stress tests for SDK |
| elif [ $1 == "stress" ]; then |
| run_stress_tests |
| |
| else |
| echo "Invalid option" |
| usage |
| |
| fi |