xref: /aosp_15_r20/tools/netsim/scripts/cargo_test.sh (revision cf78ab8cffb8fc9207af348f23af247fb04370a6)
1#!/bin/bash
2# Copyright 2024 The Android Open Source Project
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# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Get the directory of the script
17REPO=$(dirname "$0")/../../..
18
19# Get the Rust version, package, and objs path from arguments
20RUST_PKG="$1"
21OUT_PATH="$2"
22RUST_VERSION="$3"
23
24# The possible values are "linux" and "darwin".
25OS=$(uname | tr '[:upper:]' '[:lower:]')
26
27source $REPO/tools/netsim/scripts/cargo_env.sh $OUT_PATH
28
29# Build the package
30ninja -C $OUT_PATH $RUST_PKG
31
32# Run the cargo command
33# TODO(360874898): prebuilt rust toolchain for darwin-aarch64 is supported from 1.77.1
34if [[ "$OS" == "darwin" && $(uname -m) == "arm64" ]]; then
35  cargo test -vv --package $RUST_PKG --manifest-path $REPO/tools/netsim/rust/Cargo.toml -- --nocapture
36else
37  $REPO/prebuilts/rust/$OS-x86/$RUST_VERSION/bin/cargo test -vv --package $RUST_PKG --manifest-path $REPO/tools/netsim/rust/Cargo.toml -- --nocapture
38fi
39