Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically generate test meta #3482

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/addtestsmeta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: AddTestMeta

on:
push:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
genMeta:
if: github.repository_owner != 'stellar'
runs-on: ubuntu-latest

strategy:
fail-fast: false
# need to run in sequence to avoid conflicts when pushing commits
max-parallel: 1
matrix:
toolchain: [ "clang"]
protocol: ["current", "next"]
scenario: ["--record-test-tx-meta"]
steps:
- name: Compute cache key
# this step works around a limitation in actions/cache
# that does not allow updating a cache
# so what we do here instead is
# 1. generate a new id that gets refreshed every hour
# the limit is to reduce the chance of hitting the
# global 5GB limit per repo
# 2. use that id as part of the cache identifier
# 3. fallback (restore-keys) to the most recent cache
id: cache_extra_id
run: |
echo "::set-output name=id::$(( $(date +'%s') / 60 / 60 ))"
- name: Cache
uses: actions/[email protected]
with:
path: |
/home/runner/.ccache
# we do not include ${{ matrix.protocol }} in this cache key. That flag ultimately causes
# an altered -D define, which _does_ cause a ccache direct-mode miss, but only one file
# has any difference when preprocessed, so ccache still gets a fallback cpp-mode hit. The
# one file that does vary (that compiles-in the protocol version number) is small enough
# that we can tolerate a miss and/or hold both versions of it in cache.
key: ${{ runner.os }}-${{ matrix.toolchain }}-cacheID-${{ steps.cache_extra_id.outputs.id }}
restore-keys: |
${{ runner.os }}-${{ matrix.toolchain }}-cacheID-
- uses: actions/checkout@v2
with:
fetch-depth: 200
submodules: true
- name: install core packages
run: |
sudo apt-get update
sudo apt-get -y install --no-install-recommends apt-utils dialog git iproute2 procps lsb-release
- name: install tool chain
run: |
sudo apt-get -y install libstdc++-8-dev clang-format-10 ccache
if test "${{ matrix.toolchain }}" = "gcc" ; then
sudo apt-get -y install cpp-8 gcc-8 g++-8
else
sudo apt-get -y install clang-10 llvm-10
fi
- name: install dependencies
run: sudo apt-get -y install postgresql git build-essential pkg-config autoconf automake libtool bison flex libpq-dev parallel libunwind-dev
- name: Build
run: |
if test "${{ matrix.toolchain }}" = "gcc" ; then
export CC='gcc'
export CXX='g++'
else
export CC='clang'
export CXX='clang++'
fi
echo Build with $CC and $CXX
./ci-build.sh --use-temp-db --protocol ${{ matrix.protocol }} ${{ matrix.scenario }}
- name: Commit Changes
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: 'Adjust meta for tests ${{ matrix.protocol }}'
add: '-A test-tx-meta-baseline'
pull: '--rebase --autostash'
38 changes: 26 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ Then, running:
## Running and updating TxMeta checks

The `stellar-core test` unit tests can be run in two special modes that hash the
TxMeta of each transaction executed. These two modes can increase confidence
TxMeta of each transaction executed during tests. These two modes can increase confidence
that a change to stellar-core does not alter the semantics of any transactions.
The two modes are:

Expand All @@ -245,21 +245,35 @@ The two modes are:

Continuous integration tests automatically run the `--check-test-tx-meta` mode
against a pair of captured baseline directories stored in the repository, called
`test-tx-meta-baseline-current` (for the current protocol) and
`text-tx-meta-baseline-next` (for the next protocol). If you make _intentional_
changes to the semantics of any transactions, or add any new transactions that
need to have their hashes recorded, you can re-record the baseline using a
command like:
`test-tx-meta-baseline/current` (for the current protocol) and
`text-tx-meta-baseline/next` (for the next protocol).

stellar-core test [tx] --all-versions --rng-seed 12345 --record-test-tx-meta test-tx-meta-baseline-current

for a build with only the current protocol enabled, and:

stellar-core test [tx] --all-versions --rng-seed 12345 --record-test-tx-meta test-tx-meta-baseline-next

for a build configured with `--enable-next-protocol-version-unsafe-for-production`.
If you make _intentional_changes to the semantics of any transaction, or modify
tests, you can re-record the baseline in two ways.

These commands will rewrite the baseline files, which are human-readable JSON
files. You should then inspect to see that only the transactions you expected to
see change did so. If so, commit the changes as a new set of baselines for
future tests.

### having automation push to your branch in Github (easiest)

For this, all you need to do is push the latest `master` branch from upstream to your `master` branch in your fork (running something like `git push origin master:master`), and ensure that "Github actions" are enabled (they should be by default) in your fork.

After that, commits authored by "github-actions-bot" get automatically added to branches in your fork as needed.
If you want to keep those changes and continue to work on your branch, you'll have to "pull" them back to your local branch (`git pull origin myBranch`), otherwise you can (after fixing your code) discard them by force pushing your branch (`git push -f origin myBranch`), but this will associate "meta changes" to your Github user, which is probably not what you want.

### generate changes manually

For this, you will need two builds: one compiled normally, and the other "next" configured with the future protocol version enabled.

Using a command like:

stellar-core test [tx] --all-versions --rng-seed 12345 --record-test-tx-meta test-tx-meta-baseline/current

for a build with only the current protocol enabled, and:

stellar-core test [tx] --all-versions --rng-seed 12345 --record-test-tx-meta test-tx-meta-baseline/next

for a build configured with `--enable-next-protocol-version-unsafe-for-production`.
26 changes: 23 additions & 3 deletions ci-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export TEMP_POSTGRES=0

PROTOCOL_CONFIG=""

PARTITIONS_ENABLED=1

while [[ -n "$1" ]]; do
COMMAND="$1"
shift
Expand All @@ -32,7 +34,17 @@ while [[ -n "$1" ]]; do
exit 1
fi
export TEST_SPEC='[tx]'
export STELLAR_CORE_TEST_PARAMS="--ll fatal -r simple --all-versions --rng-seed 12345 --check-test-tx-meta ${PWD}/test-tx-meta-baseline-${PROTOCOL}"
export STELLAR_CORE_TEST_PARAMS="--ll fatal -r simple --all-versions --rng-seed 12345 --check-test-tx-meta ${PWD}/test-tx-meta-baseline/${PROTOCOL}"
;;
"--record-test-tx-meta")
if [[ -z "${PROTOCOL}" ]]; then
echo 'must specify --protocol before --record-test-tx-meta'
exit 1
fi
export TEST_SPEC='[tx]'
export STELLAR_CORE_TEST_PARAMS="--ll fatal -r simple --all-versions --rng-seed 12345 --record-test-tx-meta ${PWD}/test-tx-meta-baseline/${PROTOCOL}"
export BATCHSIZE=500
PARTITIONS_ENABLED=0
;;
"--protocol")
PROTOCOL="$1"
Expand Down Expand Up @@ -175,8 +187,16 @@ if [ $TEMP_POSTGRES -eq 0 ] ; then
fi

export ALL_VERSIONS=1
export NUM_PARTITIONS=$((NPROCS*2))
export RUN_PARTITIONS
if [ $PARTITIONS_ENABLED -eq 1 ] ; then
export NUM_PARTITIONS=$((NPROCS*2))
export RUN_PARTITIONS
else
unset NUM_PARTITIONS
unset RUN_PARTITIONS
fi

echo "NUM_PARTITIONS=$NUM_PARTITIONS ; RUN_PARTITIONS=$RUN_PARTITIONS"

ulimit -n 256
time make check

Expand Down