blob: c0e1f9ef79d3f622d083bc1b9b8d4874b50f94a4 [file] [log] [blame]
Austin Schuhe89fa2d2019-08-14 20:24:23 -07001#!/bin/bash
2set -e
3#
4# Copyright 2018 Google Inc. All rights reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18if [[ "$1" == "mips-unknown-linux-gnu" ]]; then
19 TARGET_FLAG="--target mips-unknown-linux-gnu"
20 export CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_LINKER=mips-linux-gnu-gcc
21 export CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_RUNNER="qemu-mips -L /usr/mips-linux-gnu"
22fi
23
James Kuszmaul8e62b022022-03-22 09:33:25 -070024
25function check_test_result() {
26 if [[ $? == 0 ]]; then
27 echo OK: $1 passed.
28 else
29 echo KO: $1 failed.
30 exit 1
31 fi
32}
33
34cd ./rust_serialize_test
35cargo run $TARGET_FLAG -- --quiet
36check_test_result "Rust serde tests"
37
38cd ../rust_usage_test
Austin Schuhe89fa2d2019-08-14 20:24:23 -070039cargo test $TARGET_FLAG -- --quiet
James Kuszmaul8e62b022022-03-22 09:33:25 -070040check_test_result "Rust tests"
41
42cargo test $TARGET_FLAG --no-default-features --features no_std -- --quiet
43check_test_result "Rust tests (no_std)"
Austin Schuhe89fa2d2019-08-14 20:24:23 -070044
Austin Schuh272c6132020-11-14 16:37:52 -080045cargo run $TARGET_FLAG --bin=flatbuffers_alloc_check
James Kuszmaul8e62b022022-03-22 09:33:25 -070046check_test_result "Rust flatbuffers heap alloc test"
Austin Schuh272c6132020-11-14 16:37:52 -080047
48cargo run $TARGET_FLAG --bin=flexbuffers_alloc_check
James Kuszmaul8e62b022022-03-22 09:33:25 -070049check_test_result "Rust flexbuffers heap alloc test"
50
51# TODO(caspern): Fix this.
52# Temporarily disabled due to error in upstream configuration
53# https://github.com/google/flatbuffers/issues/6491
54#
55# rustup component add clippy
56# cargo clippy $TARGET_FLAG
57# check_test_result "No Cargo clippy lints test"
Austin Schuhe89fa2d2019-08-14 20:24:23 -070058
59cargo bench $TARGET_FLAG
James Kuszmaul8e62b022022-03-22 09:33:25 -070060
61# This test is dependent on flatc.
62if [[ -f ../../flatc ]]; then
63 cd outdir
64 cargo test
65 check_test_result "Rust generated file in \$OUT_DIR"
66 cd ..
67fi
68
69# RUST_NIGHTLY environment variable set in dockerfile.
70if [[ $RUST_NIGHTLY == 1 ]]; then
71 rustup +nightly component add miri
72 MIRIFLAGS="-Zmiri-disable-isolation" cargo +nightly miri test
73fi