Skip to content

Commit

Permalink
refactor: move all tests to tests dir
Browse files Browse the repository at this point in the history
  • Loading branch information
vfusco committed Jan 23, 2024
1 parent 2b7c19a commit 060f5b0
Show file tree
Hide file tree
Showing 108 changed files with 74,452 additions and 789 deletions.
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
**/*.dtb
**/*.bin
**/*.md

**/Dockerfile*
**/*.deb

build
third-party/downloads
Expand Down
112 changes: 55 additions & 57 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
name: Build/Test/Release
on: [push]
env:
KERNEL_VERSION: v0.19.1
LINUX_VERSION: 6.5.9-ctsi-1-v0.19.1
TOOLS_VERSION: v0.14.0
TEST_VERSION: v0.30.0
CARTESI_TESTS_PATH: /usr/share/cartesi-machine/tests
CARTESI_IMAGES_PATH: /usr/share/cartesi-machine/images
CARTESI_UARCH_PATH: /usr/share/cartesi-machine/uarch/uarch-ram.bin
jobs:
build:
name: Build
Expand Down Expand Up @@ -77,7 +69,7 @@ jobs:
token: ${{ secrets.DEPOT_TOKEN }}

- name: Export deb package artifact (amd64)
run: make copy BUILD_PLATFORM=linux/amd64 ARCH=amd64 DEBIAN_IMG=cartesi/machine-emulator:amd64_deb
run: make copy BUILD_PLATFORM=linux/amd64 DEB_ARCH=amd64 DEBIAN_IMG=cartesi/machine-emulator:amd64_deb

- name: Build debian package (arm64)
uses: depot/build-push-action@v1
Expand All @@ -98,7 +90,7 @@ jobs:
token: ${{ secrets.DEPOT_TOKEN }}

- name: Export deb package artifact (arm64)
run: make copy BUILD_PLATFORM=linux/arm64 ARCH=arm64 DEBIAN_IMG=cartesi/machine-emulator:arm64_deb
run: make copy BUILD_PLATFORM=linux/arm64 DEB_ARCH=arm64 DEBIAN_IMG=cartesi/machine-emulator:arm64_deb

- name: Upload artifacts
uses: actions/upload-artifact@master
Expand All @@ -114,6 +106,7 @@ jobs:
test_amd64:
name: Test (linux/amd64)
needs: build
if: false
runs-on: ubuntu-latest-8-cores
steps:
- name: Checkout machine emulator source code
Expand All @@ -140,15 +133,14 @@ jobs:
- name: Set up Depot CLI
uses: depot/setup-action@v1

- name: Build docker image
id: docker_build
- name: Build machine-emulator "builder" docker image
uses: depot/build-push-action@v1
with:
file: Dockerfile
context: .
target: installer
target: builder
platforms: linux/amd64
tags: ${{ github.repository_owner }}/machine-emulator:devel
tags: ${{ github.repository_owner }}/machine-emulator:builder
push: false
load: true
cache-from: type=gha,scope=debian
Expand All @@ -160,91 +152,93 @@ jobs:
project: ${{ vars.DEPOT_PROJECT }}
token: ${{ secrets.DEPOT_TOKEN }}

- name: Download [rootfs.ext2]
uses: Legion2/[email protected]
with:
repository: ${{ github.repository_owner }}/machine-emulator-tools
tag: ${{ env.TOOLS_VERSION }}
file: rootfs-tools-${{ env.TOOLS_VERSION }}.ext2

- name: Download [kernel.bin]
uses: Legion2/[email protected]
- name: Build machine-emulator docker image
uses: depot/build-push-action@v1
with:
repository: ${{ github.repository_owner }}/image-kernel
tag: ${{ env.KERNEL_VERSION }}
file: linux-${{ env.LINUX_VERSION }}.bin

- name: Move images to cartesi images folder
run: |
mkdir -m 755 -p ${{ env.CARTESI_IMAGES_PATH }}
mv linux-*.bin rootfs-*.ext2 ${{ env.CARTESI_IMAGES_PATH }}
cd ${{ env.CARTESI_IMAGES_PATH }} && ln -s linux-${{ env.LINUX_VERSION }}.bin linux.bin
cd ${{ env.CARTESI_IMAGES_PATH }} && ln -s rootfs-tools-${{ env.TOOLS_VERSION }}.ext2 rootfs.ext2
file: Dockerfile
context: .
platforms: linux/amd64
tags: ${{ github.repository_owner }}/machine-emulator:devel
push: false
load: true
cache-from: type=gha,scope=debian
cache-to: type=gha,mode=max,scope=debian
build-args: |
RELEASE=${{ (startsWith(github.ref, 'refs/tags/v') && 'yes' || 'no') }}
GIT_COMMIT=${GITHUB_SHA}
MACHINE_EMULATOR_VERSION=${{ env.MACHINE_EMULATOR_VERSION }}
project: ${{ vars.DEPOT_PROJECT }}
token: ${{ secrets.DEPOT_TOKEN }}

- name: Download test suite
uses: Legion2/download-release-action@v2.1.0
- name: Build machine-emulator "tests" docker image
uses: depot/build-push-action@v1
with:
repository: ${{ github.repository_owner }}/machine-tests
tag: ${{ env.TEST_VERSION }}
file: machine-tests-${{ env.TEST_VERSION }}.tar.gz
file: tests/Dockerfile
context: .
platforms: linux/amd64
tags: ${{ github.repository_owner }}/machine-emulator:tests
push: false
load: true
cache-from: type=gha,scope=debian
cache-to: type=gha,mode=max,scope=debian
build-args: |
MACHINE_EMULATOR_VERSION=${{ env.MACHINE_EMULATOR_VERSION }}
project: ${{ vars.DEPOT_PROJECT }}
token: ${{ secrets.DEPOT_TOKEN }}

- name: Untar test suite
run: mkdir -p ${{ env.CARTESI_TESTS_PATH }} && tar -xzf machine-tests-${{ env.TEST_VERSION }}.tar.gz -C ${{ env.CARTESI_TESTS_PATH }}

- name: Simple boot inside the docker image
run: docker run --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel /usr/bin/cartesi-machine /bin/true
run: docker run --rm -t ${{ github.repository_owner }}/machine-emulator:tests /usr/bin/cartesi-machine /bin/true

- name: Run test suite inside the docker image
run: docker run --rm -v ${{ env.CARTESI_TESTS_PATH }}:${{ env.CARTESI_TESTS_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel /usr/bin/cartesi-machine-tests --test-path=${{ env.CARTESI_TESTS_PATH }} run
run: docker run --rm -t ${{ github.repository_owner }}/machine-emulator:tests /usr/bin/cartesi-machine-tests run

- name: Save and Load
run: |
mkdir -m 755 -p ${{ env.CARTESI_IMAGES_PATH }}/snapshots
docker run --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel /usr/bin/cartesi-machine --max-mcycle=0 --store=${{ env.CARTESI_IMAGES_PATH }}/snapshots/save_and_load_test
docker run --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel /usr/bin/cartesi-machine --load=${{ env.CARTESI_IMAGES_PATH }}/snapshots/save_and_load_test
sudo rm -rf ${{ env.CARTESI_IMAGES_PATH }}/snapshots
docker run --rm -t ${{ github.repository_owner }}/machine-emulator:tests /usr/share/cartesi-machine/tests/scripts/test-save-and-load.sh
- name: Run test scripts
run: |
docker run --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -v ${{ env.CARTESI_TESTS_PATH }}:${{ env.CARTESI_TESTS_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel ./src/tests/run.sh
docker run --rm -t ${{ github.repository_owner }}/machine-emulator:tests /usr/share/cartesi-machine/tests/scripts/run-lua-tests.sh
- name: Run grpc lua test scripts
run: |
docker run --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -v ${{ env.CARTESI_TESTS_PATH }}:${{ env.CARTESI_TESTS_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel ./src/tests/test-grpc-server.sh remote-cartesi-machine cartesi-machine cartesi-machine-tests ${{ env.CARTESI_TESTS_PATH }}
docker run --rm -t ${{ github.repository_owner }}/machine-emulator:tests /usr/share/cartesi-machine/tests/scripts/test-grpc-server.sh remote-cartesi-machine cartesi-machine cartesi-machine-tests
- name: Run jsonrpc lua test scripts
run: |
docker run --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -v ${{ env.CARTESI_TESTS_PATH }}:${{ env.CARTESI_TESTS_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel ./src/tests/test-jsonrpc-server.sh jsonrpc-remote-cartesi-machine cartesi-machine cartesi-machine-tests ${{ env.CARTESI_TESTS_PATH }}
docker run --rm -t ${{ github.repository_owner }}/machine-emulator:tests /usr/share/cartesi-machine/tests/scripts/test-jsonrpc-server.sh jsonrpc-remote-cartesi-machine cartesi-machine cartesi-machine-tests
- name: Run Merkle tree tests
run: |
docker run --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -v ${{ env.CARTESI_TESTS_PATH }}:${{ env.CARTESI_TESTS_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel ./src/tests/test-merkle-tree-hash --log2-root-size=30 --log2-leaf-size=12 --input=./src/tests/test-merkle-tree-hash
docker run --rm -t ${{ github.repository_owner }}/machine-emulator:tests test-merkle-tree-hash --log2-root-size=30 --log2-leaf-size=12 --input=/usr/bin/test-merkle-tree-hash
- name: Run C API tests
run: |
docker run --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -v ${{ env.CARTESI_TESTS_PATH }}:${{ env.CARTESI_TESTS_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel ./src/tests/test-machine-c-api
docker run --rm -t ${{ github.repository_owner }}/machine-emulator:tests test-machine-c-api
- name: Test microarchitecture interpreter
if: false
run: |
docker run --rm -t ${{ github.repository_owner }}/machine-emulator:devel make uarch-tests run-uarch-tests JOBS=-j$(nproc)
docker run --rm -t ${{ github.repository_owner }}/machine-emulator:tests make uarch-tests run-uarch-tests JOBS=-j$(nproc)
- name: Run rv64ui test suite on microarchitecture
run: |
docker run --rm -v ${{ env.CARTESI_TESTS_PATH }}:${{ env.CARTESI_TESTS_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel /usr/bin/uarch-riscv-tests --test-path=${{ env.CARTESI_TESTS_PATH }} run
docker run --rm -t ${{ github.repository_owner }}/machine-emulator:tests uarch-riscv-tests run
- name: Run test suite with Microarchitecture
run: |
docker run --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -v ${{ env.CARTESI_TESTS_PATH }}:${{ env.CARTESI_TESTS_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel /usr/bin/cartesi-machine-tests --test-path=${{ env.CARTESI_TESTS_PATH }} --jobs=$(nproc) run_uarch
docker run --rm -t ${{ github.repository_owner }}/machine-emulator:tests cartesi-machine-tests--jobs=$(nproc) run_uarch
- name: Run test suite with microarchitecture and host based interpreters comparing machine hashes at every step
run: |
docker run --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -v ${{ env.CARTESI_TESTS_PATH }}:${{ env.CARTESI_TESTS_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel /usr/bin/cartesi-machine-tests --test="^rv64ui.*$" --test-path=${{ env.CARTESI_TESTS_PATH }} --jobs=$(nproc) run_host_and_uarch
docker run --rm -t ${{ github.repository_owner }}/machine-emulator:tests cartesi-machine-tests --test="^rv64ui.*$" --jobs=$(nproc) run_host_and_uarch
- name: Create uarch json logs to be used to test the Solidity based microarchitecture interpreter
run: |
mkdir -p /opt/cartesi/share/logs/uarch-riscv-tests-json-logs
docker run --rm -v /opt/cartesi/share/logs:/opt/cartesi/share/logs -v ${{ env.CARTESI_TESTS_PATH }}:${{ env.CARTESI_TESTS_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel /usr/bin/uarch-riscv-tests --test-path=${{ env.CARTESI_TESTS_PATH }} --output-dir=/opt/cartesi/share/logs/uarch-riscv-tests-json-logs --proofs --proofs-frequency=1 json-step-logs
docker run --rm -v /opt/cartesi/share/logs:/opt/cartesi/share/logs -v ${{ env.CARTESI_TESTS_PATH }}:${{ env.CARTESI_TESTS_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel /usr/bin/uarch-riscv-tests --test-path=${{ env.CARTESI_TESTS_PATH }} --output-dir=/opt/cartesi/share/logs/uarch-riscv-tests-json-logs --proofs json-reset-log
docker run --rm -v /opt/cartesi/share/logs:/opt/cartesi/share/logs -t ${{ github.repository_owner }}/machine-emulator:tests uarch-riscv-tests --output-dir=/opt/cartesi/share/logs/uarch-riscv-tests-json-logs --proofs --proofs-frequency=1 json-step-logs
docker run --rm -v /opt/cartesi/share/logs:/opt/cartesi/share/logs -t ${{ github.repository_owner }}/machine-emulator:tests uarch-riscv-tests --output-dir=/opt/cartesi/share/logs/uarch-riscv-tests-json-logs --proofs json-reset-log
- name: Compress uarch json logs
run: tar -czf uarch-riscv-tests-json-logs.tar.gz -C /opt/cartesi/share/logs/uarch-riscv-tests-json-logs .
Expand All @@ -258,6 +252,7 @@ jobs:
test_arm64:
name: Test (linux/arm64)
needs: build
if: false
runs-on: ubuntu-latest-8-cores
steps:
- name: Checkout machine emulator source code
Expand Down Expand Up @@ -454,6 +449,7 @@ jobs:
coverage:
name: Coverage
runs-on: ubuntu-latest-8-cores
if: false
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -552,6 +548,7 @@ jobs:
sanitize:
name: Sanitize
runs-on: ubuntu-22.04
if: false
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -638,6 +635,7 @@ jobs:
name: Publish artifacts
needs: [static-analysis, coverage, sanitize, test_amd64, test_arm64]
runs-on: ubuntu-22.04
if: false
steps:
- name: Checkout emulator source code
uses: actions/checkout@v3
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "lib/grpc-interfaces"]
path = lib/grpc-interfaces
url = ../grpc-interfaces.git
[submodule "tests/riscv-tests"]
path = tests/riscv-tests
url = ../riscv-tests.git
[submodule "tests/riscv-arch-test"]
path = tests/riscv-arch-test
url = ../riscv-arch-test.git
34 changes: 11 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ ARG SANITIZE=no

RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \
build-essential vim wget git clang-tidy-15 clang-format-15 lcov \
libboost1.81-dev libssl-dev \
ca-certificates pkg-config lua5.4 liblua5.4-dev \
libgrpc++-dev libprotobuf-dev protobuf-compiler-grpc \
luarocks xxd && \
update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 120 && \
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-15 120 && \
build-essential vim wget git clang-tidy-15 clang-format-15 lcov \
libboost1.81-dev libssl-dev \
ca-certificates pkg-config lua5.4 liblua5.4-dev \
libgrpc++-dev libprotobuf-dev protobuf-compiler-grpc \
luarocks xxd && \
update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 120 && \
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-15 120 && \
rm -rf /var/lib/apt/lists/*


Expand All @@ -37,34 +37,22 @@ COPY third-party third-party
RUN make -j$(nproc) dep

FROM --platform=$TARGETPLATFORM dep-builder as builder
ARG DEB_FILENAME=cartesi-machine.deb

COPY . .
RUN make -j$(nproc) git_commit=$GIT_COMMIT release=$RELEASE coverage=$COVERAGE sanitize=$SANITIZE


FROM --platform=$TARGETPLATFORM builder as debian-packager
RUN make install-uarch debian-package DESTDIR=$PWD/_install

FROM --platform=$TARGETPLATFORM debian-packager as installer
ARG MACHINE_EMULATOR_VERSION=0.0.0
ARG TARGETARCH

RUN make install-tests
RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y \
./cartesi-machine-v${MACHINE_EMULATOR_VERSION}_${TARGETARCH}.deb \
&& rm -rf /var/lib/apt/lists/*

ENV CARTESI_TESTS_PATH="/usr/share/cartesi-machine/tests"
ENV CARTESI_IMAGES_PATH="/usr/share/cartesi-machine/images"
RUN make install-uarch debian-package DESTDIR=$PWD/_install

FROM --platform=$TARGETPLATFORM debian:bookworm-20230725-slim
ARG MACHINE_EMULATOR_VERSION=0.0.0
ARG TARGETARCH

COPY --from=installer \
/usr/src/emulator/cartesi-machine-v${MACHINE_EMULATOR_VERSION}_${TARGETARCH}.deb \
cartesi-machine.deb
COPY --from=debian-packager \
/usr/src/emulator/cartesi-machine-v${MACHINE_EMULATOR_VERSION}_${TARGETARCH}.deb \
cartesi-machine.deb
RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y \
./cartesi-machine.deb \
&& rm -rf /var/lib/apt/lists/* \
Expand Down
Loading

0 comments on commit 060f5b0

Please sign in to comment.