Skip to content

Commit

Permalink
Add support for eunit module
Browse files Browse the repository at this point in the history
Add a simplified implementation of eunit interface, with an output compatible
with unity test as parsed by Python dut module for qemu-based eunit testing.

Eunit can be used on rebar3 projects on generic_unix on both BEAM and AtomVM
with:

rebar3 eunit
rebar3 as test atomvm packbeam
atomvm ${ATOMVMDIR}/build/libs/etest/src/beams/eunit.beam \
    ${ATOMVMDIR}/build/libs/atomvmlib.avm \
    _build/test/lib/*.avm

Signed-off-by: Paul Guyot <pguyot@kallisys.net>
  • Loading branch information
pguyot committed Jun 27, 2024
1 parent 52c3419 commit 561b2df
Show file tree
Hide file tree
Showing 16 changed files with 451 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build-and-test-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ jobs:
run: |
./tests/test-structs
- name: "Test: test_etest.avm"
timeout-minutes: 5
working-directory: build
run: |
./src/AtomVM ./tests/libs/etest/test_etest.avm
- name: "Test: test_estdlib.avm"
timeout-minutes: 10
working-directory: build
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/build-and-test-on-freebsd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ jobs:
echo "%%"
./tests/test-structs
echo "%%"
echo "%% Running etest tests ..."
echo "%%"
./src/AtomVM tests/libs/etest/test_etest.avm
echo "%%"
echo "%% Running estdlib tests ..."
echo "%%"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-and-test-other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
cd build_tests
cmake ..
make erlang_test_modules
make test_etest
make test_estdlib
make test_eavmlib
make test_alisp
Expand Down Expand Up @@ -173,6 +174,7 @@ jobs:
cp ../build_tests/tests/erlang_tests/code_load/*.{avm,beam,hrl} tests/erlang_tests/code_load/ &&
mkdir -p tests/erlang_tests/code_load/beams/ &&
cp ../build_tests/tests/erlang_tests/code_load/beams/*.beam tests/erlang_tests/code_load/beams/ &&
cp ../build_tests/tests/libs/etest/*.avm tests/libs/etest/ &&
cp ../build_tests/tests/libs/estdlib/*.avm tests/libs/estdlib/ &&
cp ../build_tests/tests/libs/eavmlib/*.avm tests/libs/eavmlib/ &&
cp ../build_tests/tests/libs/alisp/*.avm tests/libs/alisp/ &&
Expand All @@ -190,6 +192,7 @@ jobs:
file ./tests/test-structs &&
./tests/test-structs &&
file ./src/AtomVM &&
./src/AtomVM tests/libs/etest/test_etest.avm &&
./src/AtomVM tests/libs/estdlib/test_estdlib.avm &&
./src/AtomVM tests/libs/eavmlib/test_eavmlib.avm &&
./src/AtomVM tests/libs/alisp/test_alisp.avm
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ jobs:
./tests/test-structs
valgrind ./tests/test-structs
- name: "Test: test_etest.avm"
timeout-minutes: 5
working-directory: build
run: |
./src/AtomVM ./tests/libs/etest/test_etest.avm
valgrind ./src/AtomVM ./tests/libs/etest/test_etest.avm
- name: "Test: test_estdlib.avm"
timeout-minutes: 10
working-directory: build
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/build-libraries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ jobs:
working-directory: build
run: make dialyzer

- name: "Test: test_alisp.avm"
timeout-minutes: 5
working-directory: build
run: |
./src/AtomVM ./tests/libs/etest/test_alisp.avm
valgrind ./src/AtomVM ./tests/libs/etest/test_alisp.avm
- name: "Test: test_etest.avm"
timeout-minutes: 5
working-directory: build
run: |
./src/AtomVM ./tests/libs/etest/test_etest.avm
valgrind ./src/AtomVM ./tests/libs/etest/test_etest.avm
- name: "Test: test_estdlib.avm"
timeout-minutes: 10
working-directory: build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-linux-artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
cd build_tests
cmake ..
make erlang_test_modules
make test_etest
make test_estdlib
make test_eavmlib
make test_alisp
Expand Down Expand Up @@ -237,6 +238,7 @@ jobs:
file ./tests/test-structs &&
./tests/test-structs &&
file ./src/AtomVM &&
./src/AtomVM tests/libs/etest/test_etest.avm &&
./src/AtomVM tests/libs/estdlib/test_estdlib.avm &&
./src/AtomVM tests/libs/eavmlib/test_eavmlib.avm &&
./src/AtomVM tests/libs/alisp/test_alisp.avm &&
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/esp32-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
set -eu
apt update
DEBIAN_FRONTEND=noninteractive apt install -y -q \
doxygen erlang-base erlang-dialyzer \
doxygen erlang-base erlang-dev erlang-dialyzer erlang-eunit \
libglib2.0-0 libpixman-1-0 \
gcc g++ zlib1g-dev libsdl2-2.0-0 libslirp0 libmbedtls-dev
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/pico-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ jobs:
run: sudo apt update

- name: "Install deps"
run: sudo apt install -y cmake gperf ninja-build gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib erlang-base erlang-dialyzer
run: |
sudo apt install -y \
cmake gperf ninja-build gcc-arm-none-eabi \
libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib \
erlang-base erlang-dev erlang-dialyzer erlang-eunit
- name: Build
shell: bash
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/run-tests-with-beam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,11 @@ jobs:
run: |
export PATH="${{ matrix.path_prefix }}$PATH"
erl -pa tests/libs/estdlib/ -pa tests/libs/estdlib/beams/ -pa libs/etest/src/beams -s tests -s init stop -noshell
# Test
- name: "Run tests/libs/etest/test_eunit with OTP eunit"
timeout-minutes: 10
working-directory: build
run: |
export PATH="${{ matrix.path_prefix }}$PATH"
erl -pa tests/libs/etest/beams -s test_eunit test -s init stop -noshell
3 changes: 2 additions & 1 deletion .github/workflows/wasm-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
cd build
cmake .. -G Ninja -DAVM_WARNINGS_ARE_ERRORS=ON
# test_eavmlib does not work with wasm due to http + ssl test
ninja AtomVM atomvmlib test_alisp hello_world run_script call_cast html5_events wasm_webserver
ninja AtomVM atomvmlib test_etest test_alisp hello_world run_script call_cast html5_events wasm_webserver
- name: Upload AtomVM and test modules
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -125,6 +125,7 @@ jobs:
node src/AtomVM.js ../../../../build/tests/libs/alisp/test_alisp.avm
# test_eavmlib does not work with wasm due to http + ssl test
# node src/AtomVM.js ../../../../build/tests/libs/eavmlib/test_eavmlib.avm
node src/AtomVM.js ../../../../build/tests/libs/etest/test_etest.avm
- name: "Rename and write sha256sum (node)"
if: startsWith(github.ref, 'refs/tags/')
Expand Down
33 changes: 31 additions & 2 deletions CMakeModules/BuildErlang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@

macro(pack_archive avm_name)

foreach(module_name ${ARGN})
set(multiValueArgs ERLC_FLAGS MODULES)
cmake_parse_arguments(PACK_ARCHIVE "" "" "${multiValueArgs}" ${ARGN})
list(JOIN PACK_ARCHIVE_ERLC_FLAGS " " PACK_ARCHIVE_ERLC_FLAGS)
foreach(module_name IN LISTS ${PACK_ARCHIVE_MODULES} PACK_ARCHIVE_MODULES PACK_ARCHIVE_UNPARSED_ARGUMENTS)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/beams/${module_name}.beam
COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/beams && erlc +debug_info -o ${CMAKE_CURRENT_BINARY_DIR}/beams -I ${CMAKE_SOURCE_DIR}/libs/include ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}.erl
COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/beams && erlc +debug_info ${PACK_ARCHIVE_ERLC_FLAGS} -o ${CMAKE_CURRENT_BINARY_DIR}/beams -I ${CMAKE_SOURCE_DIR}/libs/include ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}.erl
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}.erl
COMMENT "Compiling ${module_name}.erl"
VERBATIM
Expand Down Expand Up @@ -174,6 +177,32 @@ macro(pack_test test_avm_name)

endmacro()

macro(pack_eunit test_avm_name)

set(pack_eunit_${test_avm_name}_archives ${CMAKE_CURRENT_BINARY_DIR}/${test_avm_name}_lib.avm)
set(pack_eunit_${test_avm_name}_archive_targets ${test_avm_name}_lib)
foreach(archive_name ${ARGN})
set(pack_eunit_${test_avm_name}_archives ${pack_eunit_${test_avm_name}_archives} ${CMAKE_BINARY_DIR}/libs/${archive_name}/src/${archive_name}.avm)
set(pack_eunit_${test_avm_name}_archive_targets ${pack_eunit_${test_avm_name}_archive_targets} ${archive_name})
endforeach()

if(AVM_RELEASE)
set(INCLUDE_LINES "")
else()
set(INCLUDE_LINES "-i")
endif()

add_custom_target(
${test_avm_name} ALL
COMMAND ${CMAKE_BINARY_DIR}/tools/packbeam/PackBEAM ${INCLUDE_LINES} ${CMAKE_CURRENT_BINARY_DIR}/${test_avm_name}.avm ${CMAKE_BINARY_DIR}/libs/etest/src/beams/eunit.beam ${pack_eunit_${test_avm_name}_archives}
DEPENDS ${CMAKE_BINARY_DIR}/libs/etest/src/beams/eunit.beam
COMMENT "Packing runnable ${test_avm_name}.avm"
VERBATIM
)
add_dependencies(${test_avm_name} ${pack_eunit_${test_avm_name}_archive_targets} PackBEAM)

endmacro()

macro(pack_uf2 avm_name main)

add_custom_command(
Expand Down
1 change: 1 addition & 0 deletions libs/etest/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ include(BuildErlang)

set(ERLANG_MODULES
etest
eunit
)

pack_archive(etest ${ERLANG_MODULES})
Loading

0 comments on commit 561b2df

Please sign in to comment.