Skip to content

Commit

Permalink
Add tests for rp2040 powered by rp2040js emulator
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Guyot <[email protected]>
  • Loading branch information
pguyot committed Sep 3, 2023
1 parent 70edffe commit 09fc0a4
Show file tree
Hide file tree
Showing 15 changed files with 1,002 additions and 1 deletion.
17 changes: 17 additions & 0 deletions .github/workflows/pico-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,20 @@ jobs:
cd build
cmake .. -G Ninja
ninja
- name: Install nvm and nodejs 20
run: |
set -euo pipefail
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
source $HOME/.nvm/nvm.sh
nvm install 20
- name: Run tests with rp2040js
shell: bash
working-directory: ./src/platforms/rp2040/tests
run: |
set -euo pipefail
source $HOME/.nvm/nvm.sh
nvm use node
npm install
npx tsx run-tests.ts ../build/tests/rp2040_tests.uf2
30 changes: 30 additions & 0 deletions CMakeModules/FetchUnity.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# This file is part of AtomVM.
#
# Copyright 2023 Paul Guyot <[email protected]>
#
# 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
#

include(FetchContent)

FetchContent_Declare(
unity
GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
GIT_TAG v2.5.2
GIT_SHALLOW 1
)

FetchContent_MakeAvailable(unity)
18 changes: 18 additions & 0 deletions doc/src/build-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,24 @@ From the root of the project:
cmake .. -G Ninja
ninja

### Running tests

Tests for Pico/RP2040 are run on the desktop (or CI) using [rp2040js](https://github.com/wokwi/rp2040js).
Running tests currently require nodejs 20.

Change directory to the `src/platforms/rp2040/tests` directory under the AtomVM source tree root:

shell$ cd <atomvm-source-tree-root>
shell$ cd src/platforms/rp2040/tests

Install the emulator and required Javascript dependencies:

shell$ npm install

We are assuming tests were built as part of regular build of AtomVM. Run them with the commands:

shell$ npx tsx run-tests.ts ../build/tests/rp2040_tests.uf2

## Building for NodeJS/Web

Two different builds are possible, depending on link options: for NodeJS and
Expand Down
1 change: 1 addition & 0 deletions src/platforms/rp2040/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ set(
)

add_subdirectory(src)
add_subdirectory(tests)
2 changes: 1 addition & 1 deletion src/platforms/rp2040/src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ set(
${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}
)

add_library(libAtomVM${PLATFORM_LIB_SUFFIX} ${SOURCE_FILES} ${HEADER_FILES})
add_library(libAtomVM${PLATFORM_LIB_SUFFIX} STATIC ${SOURCE_FILES} ${HEADER_FILES})
target_compile_features(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC c_std_11)
if(CMAKE_COMPILER_IS_GNUCC)
target_compile_options(libAtomVM${PLATFORM_LIB_SUFFIX} PRIVATE -Wall -pedantic -Wextra)
Expand Down
20 changes: 20 additions & 0 deletions src/platforms/rp2040/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# This file is part of AtomVM.
#
# Copyright 2023 Paul Guyot <[email protected]>
#
# 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
#
node_modules
54 changes: 54 additions & 0 deletions src/platforms/rp2040/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# This file is part of AtomVM.
#
# Copyright 2023 Paul Guyot <[email protected]>
#
# 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
#

cmake_minimum_required (VERSION 3.14)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../CMakeModules")
include(FetchUnity)

add_executable(rp2040_tests test_main.c)

target_compile_features(rp2040_tests PUBLIC c_std_11)
if(CMAKE_COMPILER_IS_GNUCC)
target_compile_options(rp2040_tests PUBLIC -ggdb)
target_compile_options(rp2040_tests PRIVATE -Wall -pedantic -Wextra)
endif()

# libAtomVM needs to find Pico's platform_smp.h header
set(HAVE_PLATFORM_SMP_H ON)
target_link_libraries(rp2040_tests PUBLIC libAtomVM)
# Also add lib where platform_smp.h header is
target_include_directories(libAtomVM PUBLIC ../src/lib)

target_link_libraries(rp2040_tests PUBLIC hardware_regs pico_stdlib pico_binary_info unity)

set(
PLATFORM_LIB_SUFFIX
${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}
)

target_link_libraries(rp2040_tests PRIVATE libAtomVM${PLATFORM_LIB_SUFFIX})

# could not get rp2040js to work with stdio USB
pico_enable_stdio_usb(AtomVM 0)
pico_enable_stdio_uart(AtomVM 1)

# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(rp2040_tests)
Loading

0 comments on commit 09fc0a4

Please sign in to comment.