diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7680982f2b..0212eb2ad9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,22 +18,31 @@ jobs: complete: if: always() - needs: [fmt, cargo-deny, rust-check-git-rev-deps, build] - runs-on: ubuntu-22.04 + needs: [fmt, cargo-deny, rust-check-git-rev-deps, build-linux, build-mac] + runs-on: + - namespace-profile-jammy-1-stellar-core + - nscloud-cache-exp-do-not-commit steps: - if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') run: exit 1 fmt: - runs-on: ubuntu-22.04 + runs-on: + - namespace-profile-jammy-1-stellar-core + - nscloud-cache-exp-do-not-commit steps: - - uses: actions/checkout@v4 - - run: rustup component add rustfmt - - run: rustup update - - run: cargo fmt --all --check + - uses: namespacelabs/nscloud-checkout-action@v7 + with: + fetch-depth: 1 + submodules: recursive + - run: rustup component add rustfmt + - run: rustup update + - run: cargo fmt --all --check cargo-deny: - runs-on: ubuntu-22.04 + runs-on: + - namespace-profile-jammy-1-stellar-core + - nscloud-cache-exp-do-not-commit strategy: matrix: checks: @@ -42,27 +51,31 @@ jobs: # Prevent sudden announcement of a new advisory from failing ci: continue-on-error: ${{ matrix.checks == 'advisories' }} steps: - - uses: actions/checkout@v4 - - uses: EmbarkStudios/cargo-deny-action@8d73959fce1cdc8989f23fdf03bec6ae6a6576ef - with: - command: check ${{ matrix.checks }} - # leave arguments empty so we don't test --all-features - # which will see conflicting env versions - arguments: + - uses: namespacelabs/nscloud-checkout-action@v7 + with: + fetch-depth: 1 + submodules: recursive + - uses: EmbarkStudios/cargo-deny-action@8d73959fce1cdc8989f23fdf03bec6ae6a6576ef + with: + command: check ${{ matrix.checks }} + # leave arguments empty so we don't test --all-features + # which will see conflicting env versions + arguments: rust-check-git-rev-deps: - runs-on: ubuntu-22.04 + runs-on: + - namespace-profile-jammy-1-stellar-core + - nscloud-cache-exp-do-not-commit steps: - - uses: actions/checkout@v4 - - uses: stellar/actions/rust-check-git-rev-deps@main - - build: - runs-on: ubuntu-jammy-16-cores-amd64 - env: - CACHED_PATHS: | - ~/.ccache - ~/.cargo - target + - uses: namespacelabs/nscloud-checkout-action@v7 + with: + fetch-depth: 1 + submodules: recursive + - uses: stellar/actions/rust-check-git-rev-deps@main + + build-linux: + runs-on: + - namespace-profile-jammy-32-stellar-core;overrides.cache-tag=config-${{ matrix.toolchain }}-${{ matrix.protocol }} strategy: fail-fast: false matrix: @@ -75,66 +88,32 @@ jobs: # using leading to random crashes: https://reviews.llvm.org/D148280 run: sudo sysctl vm.mmap_rnd_bits=28 - # We start with as cheap as possible a cache probe to see if we have an exact hit on this - # git commit ID (for a given OS/toolchain/protocol). If so we can skip all subsequent - # steps: we already tested this exact SHA. - # - # Unfortunately due to the way github actions control flow works, we have to repeat the - # step 'if' condition in each step, and cannot actually "exit early" and skip the job. - # There are a lot of duplicate bug reports filed on this aspect of github actions, don't - # bother filing another. - - name: Probe Cache - id: cache - uses: actions/cache/restore@v4 + - name: Checkout with Namespace Git mirrors cache + uses: namespacelabs/nscloud-checkout-action@v7 with: - path: ${{ env.CACHED_PATHS }} - key: ${{ runner.os }}-${{ matrix.toolchain }}-${{ matrix.protocol }}-${{ github.sha }} - lookup-only: true - - # When we have a cache miss on the exact commit SHA, we restore from the prefix without it. - # This will restore the most-recently-written cache (github does this date ordering itself). - - name: Restore Cache - if: steps.cache.outputs.cache-hit != 'true' - uses: actions/cache/restore@v4 - with: - path: ${{ env.CACHED_PATHS }} - key: ${{ steps.cache.outputs.cache-primary-key }} - restore-keys: | - ${{ runner.os }}-${{ matrix.toolchain }}-${{ matrix.protocol }} + fetch-depth: 1 + submodules: recursive - - uses: actions/checkout@v4 - if: steps.cache.outputs.cache-hit != 'true' + - name: Configure Namespace cache volume + uses: namespacelabs/nscloud-cache-action@v1 with: - fetch-depth: 200 - submodules: true - - name: install core packages - if: steps.cache.outputs.cache-hit != 'true' - 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 - if: steps.cache.outputs.cache-hit != 'true' - run: | - sudo apt-get -y install libstdc++-10-dev clang-format-12 ccache lldb - if test "${{ matrix.toolchain }}" = "gcc" ; then - sudo apt-get -y install cpp-10 gcc-10 g++-10 - else - sudo apt-get -y install clang-12 llvm-12 - fi + path: | + ~/.cargo + build-${{matrix.toolchain}}-${{matrix.protocol}} + + - name: install rustup + run: ./install-rust.sh + - name: install rustup components - if: steps.cache.outputs.cache-hit != 'true' run: rustup component add rustfmt + - name: install cargo-cache - if: steps.cache.outputs.cache-hit != 'true' run: cargo install --locked cargo-cache --version 0.8.3 + - name: install cargo-sweep - if: steps.cache.outputs.cache-hit != 'true' run: cargo install --locked cargo-sweep --version 0.7.0 - - name: install dependencies - if: steps.cache.outputs.cache-hit != 'true' - run: sudo apt-get -y install postgresql git build-essential pkg-config autoconf automake libtool bison flex libpq-dev parallel libunwind-dev sed perl + - name: Build - if: steps.cache.outputs.cache-hit != 'true' run: | if test "${{ matrix.toolchain }}" = "gcc" ; then export CC='gcc' @@ -144,26 +123,52 @@ jobs: export CXX='clang++' fi echo Build with $CC and $CXX - echo "Running first scenario" ./ci-build.sh --use-temp-db --protocol ${{ matrix.protocol }} - # We only _save_ to the cache when we had a cache miss and are running on master. - - name: Save cache after first build - uses: actions/cache/save@v4 - if: ${{ steps.cache.outputs.cache-hit != 'true' && github.ref_name == 'master' }} + build-mac: + runs-on: + - namespace-profile-macos-sequoia;overrides.cache-tag=config-macos-sequoia + steps: + + - name: Checkout with Namespace Git mirrors cache + uses: namespacelabs/nscloud-checkout-action@v7 + with: + fetch-depth: 1 + submodules: recursive + + - name: Configure Namespace cache volume + uses: namespacelabs/nscloud-cache-action@v1 with: - path: ${{ env.CACHED_PATHS }} - key: ${{ steps.cache.outputs.cache-primary-key }} + path: | + ~/.cargo + build-clang-current - - name: Build for check-test-tx-meta scenario - if: steps.cache.outputs.cache-hit != 'true' + - name: install prerequisites and uninstall brew rust, add rustup run: | - if test "${{ matrix.toolchain }}" = "gcc" ; then - export CC='gcc' - export CXX='g++' - else - export CC='clang' - export CXX='clang++' - fi - echo "Running second scenario with --check-test-tx-meta flag" - ./ci-build.sh --use-temp-db --protocol ${{ matrix.protocol }} --check-test-tx-meta + brew install libsodium libtool autoconf automake pkg-config libpq openssl parallel ccache bison gnu-sed perl coreutils + brew uninstall rust rustup + brew install rustup + + - name: install rustup components + run: | + rustup-init -y + rustup component add rustfmt rustc cargo clippy rust-src rust-std + + - name: install cargo-cache + run: | + cargo install --locked cargo-cache --version 0.8.3 + + - name: install cargo-sweep + run: | + cargo install --locked cargo-sweep --version 0.7.0 + + - name: Build + run: | + export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$(brew --prefix)/opt/libpq/lib/pkgconfig" + export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$(brew --prefix)/opt/openssl@3/lib/pkgconfig" + export PATH="$(brew --prefix bison)/bin:$PATH" + export CC='clang' + export CXX='clang++' + export CLANG_VERSION=none + export SKIP_FORMAT_CHECK=1 + ./ci-build.sh --disable-postgres --protocol current diff --git a/ci-build.sh b/ci-build.sh index 0152ea2251..b62119fbf1 100755 --- a/ci-build.sh +++ b/ci-build.sh @@ -26,13 +26,9 @@ while [[ -n "$1" ]]; do export TEMP_POSTGRES=1 echo Using temp database ;; - "--check-test-tx-meta") - if [[ -z "${PROTOCOL}" ]]; then - echo 'must specify --protocol before --check-test-tx-meta' - 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}" + "--disable-postgres") + export DISABLE_POSTGRES='--disable-postgres' + echo Disabling postgres ;; "--protocol") PROTOCOL="$1" @@ -54,20 +50,23 @@ while [[ -n "$1" ]]; do ;; *) echo Unknown parameter ${COMMAND} - echo Usage: $0 "[--disable-tests][--use-temp-db]" + echo Usage: $0 "[--disable-tests][--use-temp-db][--disable-postgres]" exit 1 ;; esac done -echo $TRAVIS_PULL_REQUEST - NPROCS=$(getconf _NPROCESSORS_ONLN) echo "Found $NPROCS processors" date +SRC_DIR=$(pwd) + +mkdir -p "build-${CC}-${PROTOCOL}" +cd "build-${CC}-${PROTOCOL}" + # Try to ensure we're using the real g++ and clang++ versions we want mkdir -p bin @@ -79,14 +78,16 @@ if test $CXX = 'clang++'; then RUN_PARTITIONS=$(seq 0 $((NPROCS-1))) # Use CLANG_VERSION environment variable if set, otherwise default to 12 CLANG_VER=${CLANG_VERSION:-12} - which clang-${CLANG_VER} - ln -sf `which clang-${CLANG_VER}` bin/clang - which clang++-${CLANG_VER} - ln -sf `which clang++-${CLANG_VER}` bin/clang++ - which llvm-symbolizer-${CLANG_VER} - ln -sf `which llvm-symbolizer-${CLANG_VER}` bin/llvm-symbolizer - clang -v - llvm-symbolizer --version || true + if test ${CLANG_VER} != 'none'; then + which clang-${CLANG_VER} + ln -sf `which clang-${CLANG_VER}` bin/clang + which clang++-${CLANG_VER} + ln -sf `which clang++-${CLANG_VER}` bin/clang++ + which llvm-symbolizer-${CLANG_VER} + ln -sf `which llvm-symbolizer-${CLANG_VER}` bin/llvm-symbolizer + clang -v + llvm-symbolizer --version || true + fi elif test $CXX = 'g++'; then RUN_PARTITIONS=$(seq $NPROCS $((2*NPROCS-1))) which gcc-10 @@ -97,7 +98,7 @@ elif test $CXX = 'g++'; then g++ -v fi -config_flags="--enable-asan --enable-extrachecks --enable-ccache --enable-sdfprefs --enable-threadsafety ${PROTOCOL_CONFIG}" +config_flags="--enable-asan --enable-extrachecks --enable-ccache --enable-sdfprefs --enable-threadsafety ${PROTOCOL_CONFIG} ${DISABLE_POSTGRES}" export CFLAGS="-O2 -g1 -fno-omit-frame-pointer -fsanitize-address-use-after-scope -fno-common" export CXXFLAGS="$CFLAGS" @@ -111,11 +112,11 @@ export ASAN_OPTIONS="quarantine_size_mb=100:malloc_context_size=4:detect_leaks=0 echo "config_flags = $config_flags" #### ccache config -export CCACHE_DIR=$HOME/.ccache +export CCACHE_DIR=$(pwd)/.ccache export CCACHE_COMPRESS=true export CCACHE_COMPRESSLEVEL=9 # cache size should be large enough for a full build -export CCACHE_MAXSIZE=500M +export CCACHE_MAXSIZE=800M export CCACHE_CPP2=true # periodically check to see if caches are old and purge them if so @@ -127,11 +128,11 @@ if [ -d "$CCACHE_DIR" ] ; then fi ccache -p - ccache -s +ccache -z date -time ./autogen.sh -time ./configure $config_flags +time (cd "${SRC_DIR}" && ./autogen.sh) +time "${SRC_DIR}/configure" $config_flags if [ -z "${SKIP_FORMAT_CHECK}" ]; then make format d=`git diff | wc -l` @@ -155,28 +156,27 @@ date time make -j$(($NPROCS - 1)) ccache -s -### incrementally purge old content from cargo source cache and target directory -cargo cache trim --limit 100M -cargo sweep --maxsize 500MB +### incrementally purge old content from target directory +(cd "${SRC_DIR}" && CARGO_TARGET_DIR="build-${CC}-${PROTOCOL}/target" cargo sweep --maxsize 800MB) if [ $WITH_TESTS -eq 0 ] ; then echo "Build done, skipping tests" exit 0 fi -if [ $TEMP_POSTGRES -eq 0 ] ; then - # Create postgres databases (drop first if they exist to ensure clean state) - export PGUSER=postgres - psql -c "drop database if exists test;" 2>/dev/null || true - psql -c "create database test;" - # we run NPROCS jobs in parallel - for j in $(seq 0 $((NPROCS-1))); do - base_instance=$((j*50)) - for i in $(seq $base_instance $((base_instance+15))); do - psql -c "drop database if exists test$i;" 2>/dev/null || true - psql -c "create database test$i;" - done - done +if [ $DISABLE_POSTGRES != '--disable-postgres' ] ; then + if [ $TEMP_POSTGRES -eq 0 ] ; then + # Create postgres databases + export PGUSER=postgres + psql -c "create database test;" + # we run NPROCS jobs in parallel + for j in $(seq 0 $((NPROCS-1))); do + base_instance=$((j*50)) + for i in $(seq $base_instance $((base_instance+15))); do + psql -c "create database test$i;" + done + done + fi fi export ALL_VERSIONS=1 @@ -184,7 +184,12 @@ export NUM_PARTITIONS=$((NPROCS*2)) export RUN_PARTITIONS export RND_SEED=$(($(date +%s) / 86400)) # Convert to days since epoch echo "Using RND_SEED: $RND_SEED" -ulimit -n 256 +ulimit -n 4096 +time make check + +echo Running fixed check-test-tx-meta tests +export TEST_SPEC='[tx]' +export STELLAR_CORE_TEST_PARAMS="--ll fatal -r simple --all-versions --rng-seed 12345 --check-test-tx-meta ${SRC_DIR}/test-tx-meta-baseline-${PROTOCOL}" time make check echo All done diff --git a/configure.ac b/configure.ac index c69efd0cce..1a38031dc5 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ # under the Apache License, Version 2.0. See the COPYING file at the root # of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 -AC_PREREQ([2.68]) +AC_PREREQ([2.71]) AC_INIT([stellar-core],[0.1],[],[],[http://www.stellar.org]) # tar-ustar is required for long file names when libsodium is bundled AM_INIT_AUTOMAKE([-Wall -Wextra -Wconversion subdir-objects tar-ustar silent-rules]) diff --git a/install-rust.sh b/install-rust.sh index 7c63afb5f0..d66cbe0198 100755 --- a/install-rust.sh +++ b/install-rust.sh @@ -7,6 +7,8 @@ # is version-controlled and run in CI to make the dependency explicit (and to # use a version newer than the debian packages). +rustup --version >/dev/null 2>&1 && exit 0 + # Fail on any error set -e diff --git a/src/Makefile.am b/src/Makefile.am index f4b53e8f9e..e269ae701f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -65,11 +65,11 @@ endif # !BUILD_TESTS if ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION CARGO_FEATURE_NEXT = --features next main/XDRFilesSha256.cpp: $(SRC_X_FILES) Makefile $(top_srcdir)/hash-xdrs.sh - $(top_srcdir)/hash-xdrs.sh protocol-next >$@ + $(top_srcdir)/hash-xdrs.sh $(top_srcdir)/src/protocol-next >$@ else CARGO_FEATURE_NEXT = main/XDRFilesSha256.cpp: $(SRC_X_FILES) Makefile $(top_srcdir)/hash-xdrs.sh - $(top_srcdir)/hash-xdrs.sh protocol-curr >$@ + $(top_srcdir)/hash-xdrs.sh $(top_srcdir)/src/protocol-curr >$@ endif stellar_core_LDADD = $(soci_LIBS) $(libmedida_LIBS) \ @@ -89,6 +89,7 @@ BUILT_SOURCES = $(SRC_X_FILES:.x=.h) main/StellarCoreVersion.cpp main/XDRFilesSh $(SRC_X_FILES:.x=.h): $(XDRC) SUFFIXES = .x .h .rs .x.h: + mkdir -p $(@D) $(XDRC) -hh -pedantic -o $@ $< BISON=bison @@ -124,9 +125,11 @@ RUST_TOOLCHAIN_CHANNEL=$(shell sed -n 's/channel *= *"\([^"]*\)"/\1/p' $(RUST_TO endif CARGO=cargo +$(RUST_TOOLCHAIN_CHANNEL) -# we pass RUST_TOOLCHAIN_CHANNEL by environment variable +# we pass some configuration by environment variable # to tests since they can't take command-line arguments. export RUST_TOOLCHAIN_CHANNEL +export top_srcdir +export top_builddir RUST_BUILD_DIR=$(top_builddir)/src/rust RUST_BIN_DIR=$(RUST_BUILD_DIR)/bin @@ -233,11 +236,12 @@ rust/RustBridge.cpp: rust/src/bridge.rs $(SRC_RUST_FILES) Makefile $(RUST_CXXBRI $(RUST_DEP_TREE_STAMP): $(wildcard rust/soroban/*/Cargo.*) Makefile $(RUST_TOOLCHAIN_FILE) rm -f $@ + mkdir -p $(RUST_BUILD_DIR)/src/dep-trees for proto in $(ALL_SOROBAN_PROTOCOLS); \ do \ - $(CARGO) tree --manifest-path rust/soroban/$${proto}/Cargo.toml --locked --package soroban-env-host --edges no-dev --target all \ + $(CARGO) tree --manifest-path $(top_srcdir)/src/rust/soroban/$${proto}/Cargo.toml --locked --package soroban-env-host --edges no-dev --target all \ | sed -e "s@$(abspath $(top_srcdir))/@@g" > $(RUST_BUILD_DIR)/src/dep-trees/$${proto}-actual.txt ; \ - if ! diff -u rust/src/dep-trees/$${proto}-expect.txt $(RUST_BUILD_DIR)/src/dep-trees/$${proto}-actual.txt; \ + if ! diff -u $(top_srcdir)/src/rust/src/dep-trees/$${proto}-expect.txt $(RUST_BUILD_DIR)/src/dep-trees/$${proto}-actual.txt; \ then \ echo "dep trees differ, please update $${proto}-expect.txt or roll back submodule"; \ exit 1; \ @@ -272,6 +276,7 @@ CARGOFLAGS_BUILDSTD := $(if $(findstring sanitizer,$(RUSTFLAGS_SANI)),-Zbuild-st RUSTFLAGS_CFGS := $(if $(findstring sanitizer,$(RUSTFLAGS_SANI)),--cfg curve25519_dalek_backend=\"serial\",) $(LIBRUST_STELLAR_CORE): $(RUST_HOST_DEPFILES) $(SRC_RUST_FILES) Makefile $(RUST_TOOLCHAIN_FILE) + cd $(abspath $(top_srcdir))/src/rust && \ CC="$(CC)" CXX="$(CXX)" LD="$(LD)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CXXSTDLIB="$(CXXSTDLIB)" LDFLAGS="$(LDFLAGS)" \ RUSTFLAGS="$(RUSTFLAGS_SANI) $(RUSTFLAGS_CFGS)" \ CARGO_NET_GIT_FETCH_WITH_CLI=true \ @@ -346,9 +351,11 @@ $(SOROBAN_LIBS_STAMP): $(wildcard rust/soroban/p*/Cargo.lock) Makefile $(RUST_DE FEATURE_FLAGS="$(CARGO_FEATURE_TRACY)" \ ;; \ esac ; \ - cd $(abspath $(RUST_BUILD_DIR))/soroban/$$proto && \ + mkdir -p $(SOROBAN_BUILD_DIR)/$$proto/target && \ + cd $(abspath $(top_srcdir))/src/rust/soroban/$$proto && \ CC="$(CC)" CXX="$(CXX)" LD="$(LD)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CXXSTDLIB="$(CXXSTDLIB)" LDFLAGS="$(LDFLAGS)" \ RUSTFLAGS="-Cmetadata=$$proto" \ + CARGO_TARGET_DIR=$(SOROBAN_BUILD_DIR)/$$proto/target \ CARGO_NET_GIT_FETCH_WITH_CLI=true \ $(CARGO) build \ --package soroban-env-host \ @@ -376,6 +383,7 @@ $(SOROBAN_LIBS_STAMP): $(wildcard rust/soroban/p*/Cargo.lock) Makefile $(RUST_DE LIBRUST_STELLAR_CORE=$(RUST_TARGET_DIR)/$(RUST_PROFILE_DIR)/librust_stellar_core.a $(LIBRUST_STELLAR_CORE): $(RUST_HOST_DEPFILES) $(SRC_RUST_FILES) Makefile $(SOROBAN_LIBS_STAMP) $(RUST_TOOLCHAIN_FILE) + cd $(abspath $(top_srcdir))/src/rust && \ CC="$(CC)" CXX="$(CXX)" LD="$(LD)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CXXSTDLIB="$(CXXSTDLIB)" LDFLAGS="$(LDFLAGS)" \ CARGO_NET_GIT_FETCH_WITH_CLI=true \ $(CARGO) rustc \ diff --git a/src/herder/test/TxSetTests.cpp b/src/herder/test/TxSetTests.cpp index eefc7b242c..8f3fd9efe3 100644 --- a/src/herder/test/TxSetTests.cpp +++ b/src/herder/test/TxSetTests.cpp @@ -2260,11 +2260,10 @@ TEST_CASE("txset nomination", "[txset]") { runIteration(); } - namespace fs = std::filesystem; - fs::path resultsPath = "testdata/txset/" + testName; - fs::create_directories(resultsPath.parent_path()); + auto resultsPath = getSrcTestDataPath("txset/" + testName); if (getenv("GENERATE_TEST_TXSETS")) { + std::filesystem::create_directories(resultsPath.parent_path()); std::ofstream resultsStream(resultsPath); for (auto const& result : testResults) { diff --git a/src/history/test/SerializeTests.cpp b/src/history/test/SerializeTests.cpp index acdae3c0e6..2ad2e694fe 100644 --- a/src/history/test/SerializeTests.cpp +++ b/src/history/test/SerializeTests.cpp @@ -4,6 +4,7 @@ #include "history/HistoryArchive.h" #include "test/Catch2.h" +#include "test/test.h" #include #include @@ -19,9 +20,8 @@ TEST_CASE("Serialization round trip", "[history]") "stellar-history.testnet.6714239.networkPassphrase.v2.json"}; for (size_t i = 0; i < testFiles.size(); i++) { - std::string fnPath = "testdata/"; - std::string testFilePath = fnPath + testFiles[i]; - SECTION("Serialize " + testFilePath) + auto testFilePath = getBuildTestDataPath(testFiles[i]); + SECTION("Serialize " + testFilePath.string()) { std::ifstream in(testFilePath); REQUIRE(in); diff --git a/src/ledger/test/LedgerCloseMetaStreamTests.cpp b/src/ledger/test/LedgerCloseMetaStreamTests.cpp index 15cce51582..759a839706 100644 --- a/src/ledger/test/LedgerCloseMetaStreamTests.cpp +++ b/src/ledger/test/LedgerCloseMetaStreamTests.cpp @@ -515,13 +515,11 @@ TEST_CASE_VERSIONS("meta stream contains reasonable meta", "[ledgerclosemeta]") if (ledgerSeq == targetSeq) { - std::string refJsonPath; - refJsonPath = fmt::format( - FMT_STRING( - "testdata/ledger-close-meta{}-v{}-protocol-{}{}.json"), + auto refJsonPath = getSrcTestDataPath(fmt::format( + FMT_STRING("ledger-close-meta{}-v{}-protocol-{}{}.json"), enableClassicEvents ? "-enable-classic-events" : "", lcm.v(), cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION, - isSoroban ? "-soroban" : ""); + isSoroban ? "-soroban" : "")); normalizeMeta(lcm); std::string have = xdrToCerealString(lcm, "LedgerCloseMeta"); if (getenv("GENERATE_TEST_LEDGER_CLOSE_META")) diff --git a/src/main/test/ApplicationUtilsTests.cpp b/src/main/test/ApplicationUtilsTests.cpp index ec40ad8a1e..19a686a8b0 100644 --- a/src/main/test/ApplicationUtilsTests.cpp +++ b/src/main/test/ApplicationUtilsTests.cpp @@ -173,18 +173,18 @@ TEST_CASE("application major version numbers", "[applicationutils]") TEST_CASE("standalone quorum intersection check", "[applicationutils]") { Config cfg = getTestConfig(); - const std::string JSON_ROOT = "testdata/check-quorum-intersection-json/"; + auto JSON_ROOT = getSrcTestDataPath("check-quorum-intersection-json"); SECTION("enjoys quorum intersection") { REQUIRE(checkQuorumIntersectionFromJson( - JSON_ROOT + "enjoys-intersection.json", cfg)); + JSON_ROOT / "enjoys-intersection.json", cfg)); } SECTION("does not enjoy quorum intersection") { REQUIRE(!checkQuorumIntersectionFromJson( - JSON_ROOT + "no-intersection.json", cfg)); + JSON_ROOT / "no-intersection.json", cfg)); } SECTION("malformed JSON") @@ -193,17 +193,17 @@ TEST_CASE("standalone quorum intersection check", "[applicationutils]") // Malformed key REQUIRE_THROWS_AS( - checkQuorumIntersectionFromJson(JSON_ROOT + "bad-key.json", cfg), + checkQuorumIntersectionFromJson(JSON_ROOT / "bad-key.json", cfg), KeyUtils::InvalidStrKey); // Wrong datatype REQUIRE_THROWS_AS(checkQuorumIntersectionFromJson( - JSON_ROOT + "bad-threshold-type.json", cfg), + JSON_ROOT / "bad-threshold-type.json", cfg), std::runtime_error); // No such file REQUIRE_THROWS_AS( - checkQuorumIntersectionFromJson(JSON_ROOT + "no-file.json", cfg), + checkQuorumIntersectionFromJson(JSON_ROOT / "no-file.json", cfg), std::runtime_error); } -} \ No newline at end of file +} diff --git a/src/main/test/ConfigTests.cpp b/src/main/test/ConfigTests.cpp index 05bdbd483a..808241f342 100644 --- a/src/main/test/ConfigTests.cpp +++ b/src/main/test/ConfigTests.cpp @@ -147,7 +147,7 @@ TEST_CASE("resolve node id", "[config]") TEST_CASE("load validators config", "[config]") { Config c; - c.load("testdata/stellar-core_example_validators.cfg"); + c.load(getBuildTestDataPath("stellar-core_example_validators.cfg")); auto actualS = c.toString(c.QUORUM_SET); std::string expected = R"({ "t" : 4, @@ -456,9 +456,8 @@ TEST_CASE("load example configs", "[config]") "stellar-core_testnet_validator.cfg"}; for (auto const& fn : testFiles) { - std::string fnPath = "testdata/"; - fnPath += fn; - SECTION("load config " + fnPath) + auto fnPath = getBuildTestDataPath(fn); + SECTION("load config " + fnPath.string()) { c.load(fnPath); } @@ -628,4 +627,4 @@ PUBLIC_KEY="GBVZFVEARURUJTN5ABZPKW36FHKVJK2GHXEVY2SZCCNU5I3CQMTZ3OES" )"; std::stringstream ss(configStr); c.load(ss); -} \ No newline at end of file +} diff --git a/src/test/check-sorobans b/src/test/check-sorobans index 3bde728460..74e5eaf920 100755 --- a/src/test/check-sorobans +++ b/src/test/check-sorobans @@ -28,9 +28,10 @@ SKIP_TESTS="host::declared_size::test::test_expected_size" set -e set -x -cd rust/soroban +cd "${top_srcdir}/src/rust/soroban" for i in p??; do cd $i + CARGO_TARGET_DIR="${top_builddir}/src/rust/soroban/${i}/target" \ RUSTFLAGS="-Cmetadata=${i}" cargo +${RUST_TOOLCHAIN_CHANNEL} \ test \ --locked \ diff --git a/src/test/selftest-nopg b/src/test/selftest-nopg index 18021b9ed2..ef297b0cdd 100755 --- a/src/test/selftest-nopg +++ b/src/test/selftest-nopg @@ -4,4 +4,4 @@ # under the Apache License, Version 2.0. See the COPYING file at the root # of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 -exec ./test/selftest-parallel ./test/run-selftest-nopg +exec "${top_srcdir}/src/test/selftest-parallel" "${top_srcdir}/src/test/run-selftest-nopg" diff --git a/src/test/selftest-parallel b/src/test/selftest-parallel index 8f37ec532d..6195171d86 100755 --- a/src/test/selftest-parallel +++ b/src/test/selftest-parallel @@ -89,5 +89,5 @@ for i in $RUN_PARTITIONS; do cat $TEST_PARTITIONS_DIR/test-partition-$i.txt >> $TESTS done -cat $TESTS | parallel -j $nparts -n $BATCHSIZE --line-buffer --tag-string '{%}' --progress --halt-on-error 2 runpart '{%}' "{}" +cat $TESTS | parallel -j $nparts -n $BATCHSIZE --line-buffer --tag-string '{%}' --halt-on-error 2 runpart '{%}' "{}" diff --git a/src/test/selftest-pg b/src/test/selftest-pg index b856805799..c99a178cb4 100755 --- a/src/test/selftest-pg +++ b/src/test/selftest-pg @@ -4,4 +4,4 @@ # under the Apache License, Version 2.0. See the COPYING file at the root # of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 -exec ./test/selftest-parallel ./test/run-selftest-pg +exec "${top_srcdir}/src/test/selftest-parallel" "${top_srcdir}/src/test/run-selftest-pg" diff --git a/src/test/test.cpp b/src/test/test.cpp index f0a49ce396..56e1b90d2b 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -337,6 +337,32 @@ getTestConfig(int instanceNumber, Config::TestDbMode mode) return *cfgs[instanceNumber]; } +std::filesystem::path +getSrcTestDataPath(std::filesystem::path rel) +{ + namespace fs = std::filesystem; + fs::path testdata("testdata"); + char* srcdir = getenv("top_srcdir"); + if (srcdir) + { + testdata = fs::path(srcdir) / "src" / testdata; + } + return testdata / rel; +} + +std::filesystem::path +getBuildTestDataPath(std::filesystem::path rel) +{ + namespace fs = std::filesystem; + fs::path testdata("testdata"); + char* builddir = getenv("top_builddir"); + if (builddir) + { + testdata = fs::path(builddir) / "src" / testdata; + } + return testdata / rel; +} + int runTest(CommandLineArgs const& args) { diff --git a/src/test/test.h b/src/test/test.h index a026102a77..27c9fac306 100644 --- a/src/test/test.h +++ b/src/test/test.h @@ -19,6 +19,9 @@ struct TransactionMeta; Config const& getTestConfig(int instanceNumber = 0, Config::TestDbMode mode = Config::TESTDB_DEFAULT); +std::filesystem::path getSrcTestDataPath(std::filesystem::path rel); +std::filesystem::path getBuildTestDataPath(std::filesystem::path rel); + void cleanupTmpDirs(); // Records or checks a TxMetadata value against a persistent record