From d8727a6f6c3dfa00b6e0598fbc3a82c0a04b0091 Mon Sep 17 00:00:00 2001 From: Peter M Date: Tue, 8 Apr 2025 19:31:30 +0200 Subject: [PATCH] CI: Add Elixir pack_test Need the ability to add modules to Elixir testing eg for GenServer tests (https://github.com/atomvm/AtomVM/pull/1476) etc. Signed-off-by: Peter M --- CMakeModules/BuildElixir.cmake | 61 +++++++++++++++++++++++++++ tests/libs/exavmlib/CMakeLists.txt | 6 ++- tests/libs/exavmlib/Some.Submodule.ex | 25 +++++++++++ tests/libs/exavmlib/Tests.ex | 1 + 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 tests/libs/exavmlib/Some.Submodule.ex diff --git a/CMakeModules/BuildElixir.cmake b/CMakeModules/BuildElixir.cmake index 400650722..493757310 100644 --- a/CMakeModules/BuildElixir.cmake +++ b/CMakeModules/BuildElixir.cmake @@ -94,3 +94,64 @@ macro(pack_runnable avm_name main) add_dependencies(${avm_name} ${avm_name}_main ${ARCHIVE_TARGETS} PackBEAM) endmacro() + + +macro(pack_test avm_name main) + find_package(Elixir REQUIRED) + + # Compile the main module + add_custom_command( + OUTPUT Elixir.${main}.beam + COMMAND elixirc ${CMAKE_CURRENT_SOURCE_DIR}/${main}.ex + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${main}.ex + COMMENT "Compiling ${main}.ex" + VERBATIM + ) + + add_custom_target( + ${avm_name}_main + DEPENDS Elixir.${main}.beam + ) + + # Compile test modules + foreach(module_name ${ARGN}) + add_custom_command( + OUTPUT Elixir.${module_name}.beam + COMMAND elixirc ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}.ex + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}.ex + COMMENT "Compiling ${module_name}.ex" + VERBATIM + ) + set(TEST_BEAMS ${TEST_BEAMS} Elixir.${module_name}.beam) + endforeach() + + add_custom_target( + ${avm_name}_tests + DEPENDS ${TEST_BEAMS} + ) + + if(AVM_RELEASE) + set(INCLUDE_LINES "") + else() + set(INCLUDE_LINES "-i") + endif() + + # Set up standard libraries + set(ARCHIVE_TARGETS estdlib eavmlib exavmlib etest) + foreach(archive_name ${ARCHIVE_TARGETS}) + if(${archive_name} STREQUAL "exavmlib") + set(ARCHIVES ${ARCHIVES} ${CMAKE_BINARY_DIR}/libs/${archive_name}/lib/${archive_name}.avm) + else() + set(ARCHIVES ${ARCHIVES} ${CMAKE_BINARY_DIR}/libs/${archive_name}/src/${archive_name}.avm) + endif() + endforeach() + + add_custom_target( + ${avm_name} ALL + COMMAND ${CMAKE_BINARY_DIR}/tools/packbeam/PackBEAM ${INCLUDE_LINES} ${avm_name}.avm Elixir.${main}.beam ${TEST_BEAMS} ${ARCHIVES} + COMMENT "Packing test ${avm_name}.avm" + VERBATIM + ) + add_dependencies(${avm_name} ${avm_name}_main ${avm_name}_tests ${ARCHIVE_TARGETS} PackBEAM) + +endmacro() diff --git a/tests/libs/exavmlib/CMakeLists.txt b/tests/libs/exavmlib/CMakeLists.txt index 4e9c419c8..f1ddb570e 100644 --- a/tests/libs/exavmlib/CMakeLists.txt +++ b/tests/libs/exavmlib/CMakeLists.txt @@ -22,4 +22,8 @@ project(test_exavmlib) include(BuildElixir) -pack_runnable(Tests Tests estdlib eavmlib exavmlib etest) +set(TEST_MODULES + Some.Submodule +) + +pack_test(Tests Tests ${TEST_MODULES}) diff --git a/tests/libs/exavmlib/Some.Submodule.ex b/tests/libs/exavmlib/Some.Submodule.ex new file mode 100644 index 000000000..1a0380def --- /dev/null +++ b/tests/libs/exavmlib/Some.Submodule.ex @@ -0,0 +1,25 @@ +# +# This file is part of AtomVM. +# +# Copyright 2024 Davide Bettio +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later +# + +defmodule Some.Submodule do + def start do + :ok + end +end diff --git a/tests/libs/exavmlib/Tests.ex b/tests/libs/exavmlib/Tests.ex index fe34c30e8..5c12e0c9c 100644 --- a/tests/libs/exavmlib/Tests.ex +++ b/tests/libs/exavmlib/Tests.ex @@ -28,6 +28,7 @@ defmodule Tests do def start() do :ok = IO.puts("Running Elixir tests") + :ok = Some.Submodule.start() :ok = test_enum() :ok = test_exception() :ok = test_chars_protocol()