Skip to content

Commit

Permalink
Merge pull request #23 from stacks-network/feat/mutation-testing
Browse files Browse the repository at this point in the history
Mutants Optimisations: big-packages, timeout multiplier, stacks-signer case
  • Loading branch information
wileyj authored Feb 15, 2024
2 parents ab70cdb + 8078776 commit 45654a9
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 119 deletions.
11 changes: 7 additions & 4 deletions stacks-core/mutation-testing/check-packages-and-shards/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# Check Packages and Shards action

Checks whether to run mutants on big ([stackslib](https://github.com/stacks-network/stacks-core/tree/develop/stackslib)/[stacks-node](https://github.com/stacks-network/stacks-core/tree/develop/testnet/stacks-node)) or small packages (all others), and whether to run them using strategy matrix or not.
Checks whether to run mutants on [stackslib](https://github.com/stacks-network/stacks-core/tree/develop/stackslib), [stacks-node](https://github.com/stacks-network/stacks-core/tree/develop/testnet/stacks-node), [stacks-signer](https://github.com/stacks-network/stacks-core/tree/develop/stacks-signer), or small packages (all others), and whether to run them using strategy matrix or not.

## Documentation

### Outputs
| Output | Description |
| ------------------------------- | ----------------------------------------------------- |
| `run_big_packages` | True if there are mutants on `stackslib` or `stacks-node` packages, false otherwise.
| `big_packages_with_shards` | True if there are more than 15 mutants on big packages.
| `run_stackslib` | True if there are mutants on `stackslib` package, false otherwise.
| `stackslib_with_shards` | True if there are more than 7 mutants on `stackslib` package.
| `run_stacks_node` | True if there are mutants on `stacks-node` package, false otherwise.
| `stacks_node_with_shards` | True if there are more than 19 mutants on `stacks-node` package.
| `run_small_packages` | True if there are mutants on small packages, false otherwise.
| `small_packages_with_shards` | True if there are more than 79 (119 if `big_packages_with_shards` is true) mutants on small packages.
| `small_packages_with_shards` | True if there are more than 79 mutants on small packages.
| `run_stacks_signer` | True if there are mutants on `stacks-signer` package.

## Usage

Expand Down
112 changes: 76 additions & 36 deletions stacks-core/mutation-testing/check-packages-and-shards/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@ branding:
color: "gray-dark"

outputs:
run_big_packages:
description: "True if there are packages on `stackslib` or `stacks-node`."
value: ${{ steps.check_packages_and_shards.outputs.run_big_packages }}
big_packages_with_shards:
description: "True if there are more than 16 mutants on `stackslib` and `stacks-node`."
value: ${{ steps.check_packages_and_shards.outputs.big_packages_with_shards }}
run_stackslib:
description: "True if there are mutants on `stackslib` package."
value: ${{ steps.check_packages_and_shards.outputs.run_stackslib }}
stackslib_with_shards:
description: "True if there are more than 7 mutants on `stackslib`."
value: ${{ steps.check_packages_and_shards.outputs.stackslib_with_shards }}
run_stacks_node:
description: "True if there are mutants on `stacks-node` package."
value: ${{ steps.check_packages_and_shards.outputs.run_stacks_node }}
stacks_node_with_shards:
description: "True if there are more than 19 mutants on `stacks-node`."
value: ${{ steps.check_packages_and_shards.outputs.stacks_node_with_shards }}
run_small_packages:
description: "True if there are packages on other packages than `stackslib` or `stacks-node`."
description: "True if there are mutants on other packages than `stackslib`, `stacks-node` or `stacks-signer`."
value: ${{ steps.check_packages_and_shards.outputs.run_small_packages }}
small_packages_with_shards:
description: "True if there are more than 79 (119 if `big_packages_with_shards` is true) mutants on small packages."
description: "True if there are more than 79 mutants on small packages."
value: ${{ steps.check_packages_and_shards.outputs.small_packages_with_shards }}
run_stacks_signer:
description: "True if there are mutants on `stacks-signer` package."
value: ${{ steps.check_packages_and_shards.outputs.run_stacks_signer }}

runs:
using: "composite"
Expand All @@ -28,11 +37,11 @@ runs:
with:
fetch-depth: 0

- uses: taiki-e/install-action@ac89944b5b150d78567ab6c02badfbe48b0b55aa # v2.20.16
- name: Install cargo-mutants
shell: bash
id: install_cargo_mutants
name: Install cargo-mutants
with:
tool: [email protected] # v24.1.1
run: |
cargo install --git https://github.com/ASuciuX/cargo-mutants --branch feat/variable-test-timeout cargo-mutants # v24.2.0 - with test timeout multiplier implementation
- name: Relative diff
id: relative_diff
Expand Down Expand Up @@ -115,15 +124,22 @@ runs:
exit 1
fi
# Split the differences from git into 2 parts, big packages ('stacks-node' and 'stackslib') and small packages (all others) and put them into separate files
# Split the differences from git into packages: 'stackslib', 'stacks-node', 'stacks-signer' and small packages (all others) and put them into separate files
while IFS= read -r line; do
package=$(echo "$line" | cut -d'/' -f1)
case $package in
"testnet" | "stackslib")
echo "$line" >> "mutants_by_packages/big_packages.txt"
"stackslib")
echo "$line" >> "mutants_by_packages/stackslib.txt"
;;
"testnet")
echo "$line" >> "mutants_by_packages/stacks-node.txt"
;;
"stacks-signer")
echo "$line" >> "mutants_by_packages/stacks-signer.txt"
;;
*)
echo "$line" >> "mutants_by_packages/small_packages.txt"
echo "$line" >> "mutants_by_packages/small-packages.txt"
;;
esac
done < all_mutants.txt
Expand All @@ -134,45 +150,69 @@ runs:
id: check_packages_and_shards
shell: bash
run: |
number_of_big_mutants=0
number_of_stackslib_mutants=0
number_of_stacks_node_mutants=0
number_of_small_mutants=0
# If big_packages file exists, count how many mutants there are
if [[ -s mutants_by_packages/big_packages.txt ]]; then
number_of_big_mutants=$(cat mutants_by_packages/big_packages.txt | awk 'END { print NR }' | tr -d '[:space:]')
# If stackslib.txt file exists, count how many mutants there are
if [[ -s mutants_by_packages/stackslib.txt ]]; then
number_of_stackslib_mutants=$(cat mutants_by_packages/stackslib.txt | awk 'END { print NR }' | tr -d '[:space:]')
fi
# If stacks-node.txt file exists, count how many mutants there are
if [[ -s mutants_by_packages/stacks-node.txt ]]; then
number_of_stacks_node_mutants=$(cat mutants_by_packages/stacks-node.txt | awk 'END { print NR }' | tr -d '[:space:]')
fi
# If small_packages file exists, count how many mutants there are
if [[ -s mutants_by_packages/small_packages.txt ]]; then
number_of_small_mutants=$(cat mutants_by_packages/small_packages.txt | awk 'END { print NR }' | tr -d '[:space:]')
# If small-packages.txt file exists, count how many mutants there are
if [[ -s mutants_by_packages/small-packages.txt ]]; then
number_of_small_mutants=$(cat mutants_by_packages/small-packages.txt | awk 'END { print NR }' | tr -d '[:space:]')
fi
# Set the mutants limit for when to run with shards on the small packages
# If there are mutants from big packages, check whether to run with or without shards, otherwise there's nothing to run
if [[ $number_of_big_mutants -gt 15 ]]; then
small_packages_shard_limit=119
echo "run_big_packages=true" >> "$GITHUB_OUTPUT"
echo "big_packages_with_shards=true" >> "$GITHUB_OUTPUT"
# If stacks_signer file exists and is not empty, run mutants on stacks-signer package
if [[ -s mutants_by_packages/stacks-signer.txt ]]; then
echo "run_stacks_signer=true" >> "$GITHUB_OUTPUT"
else
small_packages_shard_limit=79
if [[ $number_of_big_mutants -ne 0 ]]; then
echo "run_big_packages=true" >> "$GITHUB_OUTPUT"
echo "big_packages_with_shards=false" >> "$GITHUB_OUTPUT"
echo "run_stacks_signer=false" >> "$GITHUB_OUTPUT"
fi
# If there are mutants from stackslib package, check whether to run or not and with or without shards
if [[ $number_of_stackslib_mutants -ne 0 ]]; then
echo "run_stackslib=true" >> "$GITHUB_OUTPUT"
if [[ $number_of_stackslib_mutants -gt 7 ]]; then
echo "stackslib_with_shards=true" >> "$GITHUB_OUTPUT"
else
echo "stackslib_with_shards=false" >> "$GITHUB_OUTPUT"
fi
else
echo "run_stackslib=false" >> "$GITHUB_OUTPUT"
echo "stackslib_with_shards=false" >> "$GITHUB_OUTPUT"
fi
# If there are mutants from stacks-node package, check whether to run or not and with or without shards
if [[ $number_of_stacks_node_mutants -ne 0 ]]; then
echo "run_stacks_node=true" >> "$GITHUB_OUTPUT"
if [[ $number_of_stacks_node_mutants -gt 19 ]]; then
echo "stacks_node_with_shards=true" >> "$GITHUB_OUTPUT"
else
echo "run_big_packages=false" >> "$GITHUB_OUTPUT"
echo "stacks_node_with_shards=false" >> "$GITHUB_OUTPUT"
fi
else
echo "run_stacks_node=false" >> "$GITHUB_OUTPUT"
echo "stacks_node_with_shards=false" >> "$GITHUB_OUTPUT"
fi
# If there are mutants from small packages, check whether to run with or without shards, otherwise there's nothing to run
# If there are mutants from small packages, check whether to run or not and with or without shards
if [[ $number_of_small_mutants -ne 0 ]]; then
echo "run_small_packages=true" >> "$GITHUB_OUTPUT"
if [[ $number_of_small_mutants -gt $small_packages_shard_limit ]]; then
if [[ $number_of_small_mutants -gt 79 ]]; then
echo "small_packages_with_shards=true" >> "$GITHUB_OUTPUT"
else
echo "small_packages_with_shards=false" >> "$GITHUB_OUTPUT"
fi
else
echo "run_small_packages=false" >> "$GITHUB_OUTPUT"
echo "small_packages_with_shards=false" >> "$GITHUB_OUTPUT"
fi
exit 0
22 changes: 14 additions & 8 deletions stacks-core/mutation-testing/output-pr-mutants/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ Write the mutants tested in the previous jobs of the same workflow to github ste

| Input | Description | Required | Default |
| ------------------------------- | ----------------------------------------------------- | ------------------------- | ------------------------- |
| `big_packages` | True if there were big packages running | true | |
| `shards_for_big_packages` | True if the big packages were running using matrix | true | |
| `small_packages` | True if there were small packages running | true | |
| `shards_for_small_packages` | True if the small packages were running using matrix | true | |
| `stackslib_package` | True if there were mutants running on stackslib package | true | |
| `shards_for_stackslib_package` | True if mutants on stackslib were running using matrix | true | |
| `stacks_node_package` | True if there were mutants running on stacks-node package | true | |
| `shards_for_stacks_node_package` | True if mutants on stacks-node were running using matrix | true | |
| `small_packages` | True if there were mutants running on small packages | true | |
| `shards_for_small_packages` | True if mutants on small packages were running using matrix | true | |
| `stacks_signer` | True if there were mutants running on stacks-signer package | true | |

## Usage

Expand All @@ -27,8 +30,11 @@ jobs:
id: output_pr_mutants
uses: stacks-network/actions/stacks-core/mutation-testing/output-pr-mutants@main
with:
big_packages: "true"
shards_for_big_packages: "false"
small_packages: "true"
shards_for_small_packages: "true"
stackslib_package: "true"
shards_for_stackslib_package: "false"
stacks_node_package: "true"
shards_for_stacks_node_package: "true"
small_packages: "false"
shards_for_small_packages: "false"
stacks_signer: "true"
```
47 changes: 36 additions & 11 deletions stacks-core/mutation-testing/output-pr-mutants/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@ branding:
color: "gray-dark"

inputs:
big_packages:
description: "True if there were big packages running."
stackslib_package:
description: "True if there were mutants running on stackslib package."
required: true
shards_for_big_packages:
description: "True if the big packages were running using matrix."
shards_for_stackslib_package:
description: "True if mutants on stackslib were running using matrix."
required: true
stacks_node_package:
description: "True if there were mutants running on stacks-node package."
required: true
shards_for_stacks_node_package:
description: "True if mutants on stacks-node were running using matrix."
required: true
small_packages:
description: "True if there were small packages running."
description: "True if there were mutants running on small packages."
required: true
shards_for_small_packages:
description: "True if the small packages were running using matrix."
description: "True if mutants on small packages were running using matrix."
required: true
stacks_signer:
description: "True if there were mutants running on stacks-signer package."
required: true

runs:
Expand All @@ -30,14 +39,25 @@ runs:
id: append_mutant_outcomes
shell: bash
run: |
# Check and append the folders that should be uploaded to artifacts for the big packages
if ${{ inputs.big_packages }} == "true"; then
if ${{ inputs.shards_for_big_packages }} == "true"; then
# Check and append the folders that should be uploaded to artifacts for the stackslib package
if ${{ inputs.stackslib_package }} == "true"; then
if ${{ inputs.shards_for_stackslib_package }} == "true"; then
for i in {0..7}; do
folders+=("mutants-shard-big-$i")
folders+=("mutants-shard-stackslib-$i")
done
else
folders+=("mutants-shard-big--1")
folders+=("mutants-shard-stackslib--1")
fi
fi
# Check and append the folders that should be uploaded to artifacts for the stacks-node package
if ${{ inputs.stacks_node_package }} == "true"; then
if ${{ inputs.shards_for_stacks_node_package }} == "true"; then
for i in {0..3}; do
folders+=("mutants-shard-stacks-node-$i")
done
else
folders+=("mutants-shard-stacks-node--1")
fi
fi
Expand All @@ -52,6 +72,11 @@ runs:
fi
fi
# Check and append the folder that should be uploaded to artifacts for the stacks-signer package
if ${{ inputs.stacks_signer }} == "true"; then
folders+=("mutants-shard-stacks-signer--1")
fi
files=("missed.txt" "caught.txt" "timeout.txt" "unviable.txt")
mkdir -p mutants-shards
Expand Down
4 changes: 2 additions & 2 deletions stacks-core/mutation-testing/pr-differences/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Run mutants for differences in pull requests, and upload the mutant outcomes and
| Input | Description | Required | Default |
| ------------------------------- | ----------------------------------------------------- | ------------------------- | ------------------------- |
| `shard` | The number of the shard to run (`-1` if ran without shards) | false | -1 |
| `package-dimension` | The dimension of the package. `big` for [stacks-node](https://github.com/stacks-network/stacks-core/tree/develop/testnet/stacks-node) and [stackslib](https://github.com/stacks-network/stacks-core/tree/develop/stackslib), `small` for others | true | |
| `package` | The package to run mutants on. [Stackslib](https://github.com/stacks-network/stacks-core/tree/develop/stackslib), [stacks-node](https://github.com/stacks-network/stacks-core/tree/develop/testnet/stacks-node) and [stacks-signer](https://github.com/stacks-network/stacks-core/tree/develop/stacks-signer) are independent, all others are run as `small`. | true | |

## Usage

Expand All @@ -25,5 +25,5 @@ jobs:
id: pr-differences-mutants
uses: stacks-network/actions/stacks-core/mutation-testing/pr-differences@main
with:
package-dimension: "big"
package-dimension: "small"
```
Loading

0 comments on commit 45654a9

Please sign in to comment.