Skip to content

Commit

Permalink
Add parallel tests execution to CI (#2155)
Browse files Browse the repository at this point in the history
  • Loading branch information
smiasojed authored Mar 22, 2024
1 parent bdefc46 commit bd488de
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 29 deletions.
43 changes: 32 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ jobs:
# at the same time, hence we use this workaround.
QUICKCHECK_TESTS: 0
run: |
cargo test --all-features --no-fail-fast --workspace --locked
cargo nextest run --all-features --no-fail-fast --workspace --locked
cargo test --all-features --no-fail-fast --workspace --doc --locked
pushd linting && cargo test --all-features --no-fail-fast --workspace && popd
pushd linting && cargo nextest run --all-features --no-fail-fast --workspace && popd
docs:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -444,7 +444,7 @@ jobs:
git config --global --add safe.directory '*'
# RUSTFLAGS are the cause target cache can't be used here
cargo build --all-features --workspace
cargo test --all-features --no-fail-fast --workspace --locked
cargo test --all-features --no-fail-fast --workspace --locked -- --skip ui_tests
# coverage with branches
grcov . --binary-path ./target/debug/ --source-dir . --output-type lcov --llvm --branch \
--ignore-not-existing --ignore "/*" --ignore "tests/*" --output-path lcov-w-branch.info
Expand All @@ -466,6 +466,9 @@ jobs:
shell: bash
container:
image: ${{ needs.set-image.outputs.IMAGE }}
strategy:
matrix:
partition: [1, 2, 3, 4]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -486,13 +489,21 @@ jobs:
RUSTFLAGS: -Clink-arg=-z -Clink-arg=nostart-stop-gc
run: |
# run all tests with --all-features, which will run the e2e-tests feature if present
scripts/for_all_contracts_exec.sh --path integration-tests --ignore static-buffer -- cargo test \
scripts/for_all_contracts_exec.sh --path integration-tests --ignore static-buffer --partition ${{ matrix.partition }}/4 -- cargo test \
--all-features --manifest-path {}
- name: Test static-buffer example
if: ${{ matrix.partition == 3 }}
env:
# Fix linking of `linkme`: https://github.com/dtolnay/linkme/issues/49
RUSTFLAGS: -Clink-arg=-z -Clink-arg=nostart-stop-gc
run: |
# run the static buffer test with a custom buffer size
cargo clean --manifest-path integration-tests/static-buffer/Cargo.toml
INK_STATIC_BUFFER_SIZE=30 cargo test --manifest-path integration-tests/static-buffer/Cargo.toml --all-features
- name: Run E2E test with on-chain contract
if: ${{ matrix.partition == 4 }}
env:
# Fix linking of `linkme`: https://github.com/dtolnay/linkme/issues/49
RUSTFLAGS: -Clink-arg=-z -Clink-arg=nostart-stop-gc
Expand Down Expand Up @@ -522,6 +533,14 @@ jobs:
fail-fast: false
matrix:
type: [WASM, RISCV]
partition: [1, 2, 3, 4]
exclude:
- type: RISCV
partition: 2
- type: RISCV
partition: 3
- type: RISCV
partition: 4
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -542,13 +561,15 @@ jobs:
rustup component add rust-src --toolchain stable
cargo contract -V
# Build all examples
scripts/for_all_contracts_exec.sh --path integration-tests -- cargo contract build --release --manifest-path {}
# Build the different features for the conditional compilation example
pushd ./integration-tests/conditional-compilation
cargo contract build --release --features "foo"
cargo contract build --release --features "bar"
cargo contract build --release --features "foo, bar"
popd
scripts/for_all_contracts_exec.sh --path integration-tests --partition ${{ matrix.partition }}/4 -- cargo contract build --release --manifest-path {}
if [ ${{ matrix.partition }} -eq 4 ]; then
# Build the different features for the conditional compilation example
pushd ./integration-tests/conditional-compilation
cargo contract build --release --features "foo"
cargo contract build --release --features "bar"
cargo contract build --release --features "foo, bar"
popd
fi
- name: Build Contract RISCV Examples
if: ${{ matrix.type == 'RISCV' }}
Expand Down
80 changes: 79 additions & 1 deletion crates/ink/tests/compile_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,112 @@
// limitations under the License.

#[test]
fn ui_tests() {
fn ui_tests_blake2b_pass() {
let t = trybuild::TestCases::new();

t.pass("tests/ui/blake2b/pass/*.rs");
}

#[test]
fn ui_tests_blake2b_fail() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/blake2b/fail/*.rs");
}

#[test]
fn ui_tests_selector_id_pass() {
let t = trybuild::TestCases::new();
t.pass("tests/ui/selector_id/pass/*.rs");
}

#[test]
fn ui_tests_selector_id_fail() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/selector_id/fail/*.rs");
}

#[test]
fn ui_tests_selector_bytes_pass() {
let t = trybuild::TestCases::new();

t.pass("tests/ui/selector_bytes/pass/*.rs");
}

#[test]
fn ui_tests_selector_bytes_fail() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/selector_bytes/fail/*.rs");
}

#[test]
fn ui_tests_contract_pass() {
let t = trybuild::TestCases::new();

t.pass("tests/ui/contract/pass/*.rs");
}

#[test]
fn ui_tests_contract_fail() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/contract/fail/*.rs");
}

#[test]
fn ui_tests_event_pass() {
let t = trybuild::TestCases::new();
t.pass("tests/ui/event/pass/*.rs");
}

#[test]
fn ui_tests_event_fail() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/event/fail/*.rs");
}

#[test]
fn ui_tests_storage_item_pass() {
let t = trybuild::TestCases::new();
t.pass("tests/ui/storage_item/pass/*.rs");
}

#[test]
fn ui_tests_storage_item_fail() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/storage_item/fail/*.rs");
}

#[test]
fn ui_tests_trait_def_pass() {
let t = trybuild::TestCases::new();
t.pass("tests/ui/trait_def/pass/*.rs");
}

#[test]
fn ui_tests_trait_def_fail() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/trait_def/fail/*.rs");
}

#[test]
fn ui_tests_chain_extension_pass() {
let t = trybuild::TestCases::new();
t.pass("tests/ui/chain_extension/E-01-simple.rs");
}

#[test]
fn ui_tests_pay_with_call_pass() {
let t = trybuild::TestCases::new();
t.pass("tests/ui/pay_with_call/pass/multiple_args.rs");
}

#[test]
fn ui_tests_scale_derive_pass() {
let t = trybuild::TestCases::new();
t.pass("tests/ui/scale_derive/pass/*.rs");
}

#[test]
fn ui_tests_scale_derive_fail() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/scale_derive/fail/*.rs");
}
72 changes: 55 additions & 17 deletions scripts/for_all_contracts_exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ OPTIONS
To ignore 'integration-tests/erc20' then supply 'erc20' as the argument.
-p, --path
Path to recursively find contract projects for which to execute the supplied command
--partition
Test partition, e.g. 1/2 or 2/3
-q, --quiet
Suppress output from this script, only output from the supplied command will be printed
EXAMPLES
${script_name} --path integration-tests -- cargo check --manifest-path
${script_name} --path integration-tests -- cargo contract build --manifest-path {} --release
${script_name} --path integration-tests --ignore erc20 -- cargo contract build --manifest-path {} --release
${script_name} --path integration-tests --partition 1/2 --ignore erc20 -- cargo contract build --manifest-path {} --release
EOF
}
Expand All @@ -36,7 +41,7 @@ shopt -s globstar

command=( "${@:2}" )

options=$(getopt -o p:i:q: --long path:,ignore:,quiet: -- "$@")
options=$(getopt -o p:i:q: --long path:,ignore:,quiet:,partition: -- "$@")
[ $? -eq 0 ] || {
>&2 echo "Incorrect option provided"
usage
Expand All @@ -59,6 +64,12 @@ while true; do
shift; # The arg is next in position args
quiet=true
;;
--partition)
shift; # The arg is next in position args
m=$(echo "$1" | cut -d'/' -f1)
n=$(echo "$1" | cut -d'/' -f2)
partitioning=true
;;
--)
shift
break
Expand All @@ -69,7 +80,9 @@ done

command=("${@}")

if [ -z "$path" ] || [ "${#command[@]}" -le 0 ]; then
if [ -z "$path" ] || ([ "$partitioning" = true ] && \
(! [[ "$m" =~ ^[0-9]+$ ]] || ! [[ "$n" =~ ^[0-9]+$ ]] || [ "$m" -gt "$n" ] || [ "$m" -le 0 ] || [ "$n" -le 0 ])) || \
[ "${#command[@]}" -le 0 ]; then
usage
exit 1
fi
Expand All @@ -87,26 +100,51 @@ for i in "${!command[@]}"; do
fi
done

for manifest_path in "$path"/**/Cargo.toml;
do if "$scripts_path"/is_contract.sh "$manifest_path"; then
manifest_parent="$(dirname "$manifest_path" | cut -d'/' -f2-)"
if [[ "${ignore[*]}" =~ ${manifest_parent} ]]; then
if [ "$quiet" = false ]; then
>&2 echo "Ignoring $manifest_path"
fi
continue
# filter out ignored paths and check if each manifest is a contract
filtered_manifests=()
for manifest_path in "$path"/**/Cargo.toml; do
manifest_parent="$(dirname "$manifest_path" | cut -d'/' -f2-)"
if [[ "${ignore[*]}" =~ ${manifest_parent} ]]; then
if [ "$quiet" = false ]; then
>&2 echo "Ignoring $manifest_path"
fi
command[$arg_index]="$manifest_path"
elif ! "$scripts_path"/is_contract.sh "$manifest_path"; then
if [ "$quiet" = false ]; then
>&2 echo Running: "${command[@]}"
>&2 echo "Skipping non contract: $manifest_path"
fi
"${command[@]}"
else
filtered_manifests+=("$manifest_path")
fi
done

if [ $? -eq 0 ]; then
successes+=("$manifest_path")
else
failures+=("$manifest_path")
# determine the total number of filtered Cargo.toml files
total_manifests=${#filtered_manifests[@]}
if [ "$partitioning" = true ]; then
# calculate the partition start and end index
partition_size=$(( total_manifests / n ))
start=$(( (m - 1) * partition_size ))
end=$(( m * partition_size - 1 ))
if [ "$m" -eq "$n" ]; then
# last partition
end=$(( total_manifests - 1 ))
fi
else
start=0
end=$(( total_manifests - 1 ))
fi

for (( i = start; i <= end; i++ )); do
manifest_path="${filtered_manifests[$i]}"
command[$arg_index]="$manifest_path"
if [ "$quiet" = false ]; then
>&2 echo Running: "${command[@]}"
fi
"${command[@]}"

if [ $? -eq 0 ]; then
successes+=("$manifest_path")
else
failures+=("$manifest_path")
fi
done

Expand Down

0 comments on commit bd488de

Please sign in to comment.