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 29, 2024
1 parent 2b7c19a commit 1a2b2a9
Show file tree
Hide file tree
Showing 109 changed files with 74,640 additions and 967 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
386 changes: 182 additions & 204 deletions .github/workflows/build.yml

Large diffs are not rendered by default.

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
37 changes: 14 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,25 @@ 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
COPY --from=debian-packager /usr/local/lib/lua /usr/local/lib/lua
COPY --from=debian-packager /usr/local/share/lua /usr/local/share/lua

RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y \
./cartesi-machine.deb \
&& rm -rf /var/lib/apt/lists/* \
Expand Down
190 changes: 120 additions & 70 deletions Makefile

Large diffs are not rendered by default.

66 changes: 43 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,30 @@ The emulator implements RISC-V's RV64IMASU ISA. The letters after RV specify the
Run `make help` for a list of target options. Here are some of them:

```
Main targets:
* all - build the src/ code. To build from a clean clone, run: make submodules downloads dep all
uarch - build microarchitecture (requires riscv64-cartesi-linux-gnu-* toolchain)
uarch-with-linux-env - build microarchitecture using the linux-env docker image
build-tests-all - build all tests (machine, uarch and misc)
build-tests-machine - Build machine emulator tests (requires rv64gc-lp64d riscv64-cartesi-linux-gnu-* toolchain)
build-tests-machine-with-toolchain - Build machine emulator tests using the rv64gc-lp64d toolchain docker image
build-tests-uarch - build microarchitecture rv64i instruction tests (requires rv64ima-lp64 riscv64-cartesi-linux-gnu-* toolchain)
build-tests-uarch-with-toolchain - build microarchitecture rv64i instruction tests using the rv64ima-lp64 toolchain docker image
build-tests-misc - build miscellaneous tests
build-tests-misc-with-builder-image - build miscellaneous tests using the cartesi/machine-emulator:builder image
test-machine - Run machine emulator tests
test-uarch - Run uarch tests
test-misc - Run miscellaneous tests
test - Run all tests
doc - build the doxygen documentation (requires doxygen)
Docker images targets:
build-emulator-image - Build the machine-emulator debian based docker image
build-debian-package - Build the cartesi-machine.deb package from image
build-linux-env - Build the linux environment docker image
Cleaning targets:
clean - clean the src/ artifacts
depclean - clean + dependencies
distclean - depclean + profile information and downloads
Docker targets:
build-debian-image - Build the machine-emulator debian based docker image
clean - clean the src/ artifacts
depclean - clean + dependencies
distclean - depclean + profile information and downloads
```

### Requirements
Expand Down Expand Up @@ -46,7 +64,7 @@ sudo luarocks install --lua-version=5.4 luaposix

##### MacPorts
```bash
sudo port install clang-15 boost libtool wget pkgconfig grpc openssl lua lua-luarocks
sudo port install clang-15 boost181 wget pkgconfig grpc lua54 lua-luarocks

sudo luarocks install --lua-version=5.4 lpeg
sudo luarocks install --lua-version=5.4 dkjson
Expand All @@ -70,16 +88,13 @@ For emulator scripts to work it is expected that `lua5.4` binary is available in
### Build

```bash
make submodules
make downloads
make dep
git clone --recurse-submodules -j3 https://github.com/cartesi/machine-emulator.git
make
```

Cleaning:

```bash
make depclean
make clean
```

Expand All @@ -102,8 +117,6 @@ sudo make install PREFIX=/usr/local
Both `libcartesi` and `libcartes_jsonrpc` C libraries can be compiled in standalone, either as static or shared library:

```bash
make submodules
make downloads
make dep
make bundle-boost
make -C src release=yes libcartesi.a libcartesi_jsonrpc.a libcartesi.so libcartesi_jsonrpc.so
Expand Down Expand Up @@ -134,21 +147,30 @@ make -C src release=yes \

## Running Tests

Copy the tests binaries to a directory called `tests` and run: (Eg.: )
To build and execute the all tests run:

```bash
make build-tests-all
make test
```

The default search path for binaries is `machine-emulator/tests`. Alternatively you can specify the binaries path using the `CARTESI_TESTS_PATH` variable as in:
To execute the machine test suite run:

```bash
make build-tests-machine-with-toolchain
make test-machine
```

To execute the uarch test suite run:

```bash
make test CARTESI_TESTS_PATH=/full/path/to/test/binaries
make build-tests-uarch-with-toolchain
make test-uarch
```

## Linter

We use clang-tidy 14 as the linter.
We use clang-tidy 15 as the linter.

### Install

Expand Down Expand Up @@ -219,26 +241,24 @@ Make sure you run `make clean` to clean up any previous compilation.
For GCC-based coverage run the following command.

```bash
make coverage-toolchain=gcc -j$(nproc)
make coverage=yes COVERAGE_TOOLCHAIN=gcc -j$(nproc)
make build-tests-all coverage=yes COVERAGE_TOOLCHAIN=gcc -j$(nproc)
```

For clang-based coverage run the following command.

```bash
make coverage-toolchain=clang -j$(nproc)
make coverage=yes COVERAGE_TOOLCHAIN=clang -j$(nproc)
make build-tests-all coverage=yes COVERAGE_TOOLCHAIN=clang -j$(nproc)
```

### Running coverage

After building the emulator with coverage enable, you should run the following command.
You need to specify the binaries test path using the `CARTESI_TESTS_PATH` variable.
You also need to specify the directory containing the kernel and rootfs with the `CARTESI_IMAGES_PATH` variable.
For instance:

```bash
make coverage=yes test-all coverage-report \
CARTESI_TESTS_PATH=$(realpath ../tests/build) \
CARTESI_IMAGES_PATH=$(realpath ./src)
make test coverage-report coverage=yes COVERAGE_TOOLCHAIN=gcc
```

This command will generate a coverage report in the src directory.
Expand Down
Loading

0 comments on commit 1a2b2a9

Please sign in to comment.