From 79546994b0a307059f01388e4826d9a749ff415b Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 5 Jan 2023 12:48:54 -0800 Subject: [PATCH 01/63] Add Zephyr as target platform and add simple test --- org.lflang/src/org/lflang/TargetProperty.java | 1 + .../lflang/generator/c/CCmakeGenerator.java | 6 ++- test/C/src/zephyr/HelloZephyr.lf | 12 ++++++ test/C/src/zephyr/scripts/prj.conf | 16 +++++++ test/C/src/zephyr/scripts/zephyr.cmake | 10 +++++ test/C/src/zephyr/scripts/zephyr_build.sh | 42 +++++++++++++++++++ test/C/src/zephyr/scripts/zephyr_flash_nrf.sh | 9 ++++ 7 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 test/C/src/zephyr/HelloZephyr.lf create mode 100644 test/C/src/zephyr/scripts/prj.conf create mode 100644 test/C/src/zephyr/scripts/zephyr.cmake create mode 100644 test/C/src/zephyr/scripts/zephyr_build.sh create mode 100644 test/C/src/zephyr/scripts/zephyr_flash_nrf.sh diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index 14cc3bb4c8..53736c31be 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -1413,6 +1413,7 @@ public enum Platform { NRF52("Nrf52"), LINUX("Linux"), MAC("Darwin"), + ZEPHYR("Zephyr"), WINDOWS("Windows"); String cMakeName; diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index f63c9e1c2b..d6e15b343c 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -120,7 +120,11 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("cmake_minimum_required(VERSION " + MIN_CMAKE_VERSION + ")"); cMakeCode.pr("project("+executableName+" LANGUAGES C)"); cMakeCode.newLine(); - + if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}"); + cMakeCode.newLine(); + } + // The Test build type is the Debug type plus coverage generation cMakeCode.pr("if(CMAKE_BUILD_TYPE STREQUAL \"Test\")"); cMakeCode.pr(" set(CMAKE_BUILD_TYPE \"Debug\")"); diff --git a/test/C/src/zephyr/HelloZephyr.lf b/test/C/src/zephyr/HelloZephyr.lf new file mode 100644 index 0000000000..1f23d0ad72 --- /dev/null +++ b/test/C/src/zephyr/HelloZephyr.lf @@ -0,0 +1,12 @@ +target C { + platform: Zephyr, + build: "bash scripts/zephyr_build.sh qemu_cortex_m3 flash", + threading: false, + cmake-include: "scripts/zephyr.cmake" +} + +main reactor { + reaction(startup) {= + printf("Hello World!\n"); + =} +} \ No newline at end of file diff --git a/test/C/src/zephyr/scripts/prj.conf b/test/C/src/zephyr/scripts/prj.conf new file mode 100644 index 0000000000..0142c24b0c --- /dev/null +++ b/test/C/src/zephyr/scripts/prj.conf @@ -0,0 +1,16 @@ +# Enable printk +CONFIG_PRINTK=y +# Set the memory pool sufficently large. +CONFIG_HEAP_MEM_POOL_SIZE=2048 +# THis is the memory pool used by minimal libc +CONFIG_MINIMAL_LIBC=y +CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=50000 +# Enable FP printing +CONFIG_CBPRINTF_FP_SUPPORT=y +# Enable counters (used as HW clock) +CONFIG_COUNTER=y +# Have counter use the HW timer as basis +# FIXME: Use overlays etc to support all sorts of boards. I think this will only work in NRF boards. +CONFIG_COUNTER_TIMER1=y +# Set main stack size big enough +CONFIG_MAIN_STACK_SIZE=2048 \ No newline at end of file diff --git a/test/C/src/zephyr/scripts/zephyr.cmake b/test/C/src/zephyr/scripts/zephyr.cmake new file mode 100644 index 0000000000..363b00c8a3 --- /dev/null +++ b/test/C/src/zephyr/scripts/zephyr.cmake @@ -0,0 +1,10 @@ +# Disable the old target defined in the generated cmake file +set_target_properties(${LF_MAIN_TARGET} PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) +# Get the source files assoicated with the generated cmake build +get_target_property(LF_SOURCES ${LF_MAIN_TARGET} SOURCES) +# Get the compile definitions added to target +get_target_property(LF_COMPILE_DEFS ${LF_MAIN_TARGET} COMPILE_DEFINITIONS) +# Use these sources with Zephyr build. +target_compile_definitions(app PUBLIC ${LF_COMPILE_DEFS}) +target_sources(app PRIVATE ${LF_SOURCES}) +zephyr_library_compile_options(-Wl,--print-memory-usage) diff --git a/test/C/src/zephyr/scripts/zephyr_build.sh b/test/C/src/zephyr/scripts/zephyr_build.sh new file mode 100644 index 0000000000..a726e60b2f --- /dev/null +++ b/test/C/src/zephyr/scripts/zephyr_build.sh @@ -0,0 +1,42 @@ +#!/usr/bin/bash + +echo "Building Zephyr application" +SCRIPT_DIR=$(dirname $0) + +set -e # Return on first error + +# Verify command line arguments +if [ $# -lt 1 ]; then + echo "ERROR: Please pass the board to zephyr_build.sh. e.g. ./zephyr_build.sh qemu_cortex_m3 flash" + exit 1 +fi + +# Set some global variables +export BOARD=$1 +export LF_SRC_DIRECTORY=$(pwd) + +cp $LF_SRC_DIRECTORY/$SCRIPT_DIR/prj.conf $LF_SOURCE_GEN_DIRECTORY/ +cp $LF_SRC_DIRECTORY/$SCRIPT_DIR/Kconfig $LF_SOURCE_GEN_DIRECTORY/ + +cd $LF_SOURCE_GEN_DIRECTORY + +# Build project +west build -b $BOARD + +if [[ "$2" == "flash" ]]; then + +if [[ "$BOARD" == "nrf"* ]]; then + echo "--- Flashing to NRF board" + # Flash application + bash $LF_SRC_DIRECTORY/$SCRIPT_DIR/zephyr_flash_nrf.sh . + + # Debug application + # FIXME: Fix the issues here. Why isnt gdb working when invoked from this script? + # $LF_SRC_DIRECTORY/../scripts/zephyr_debug_nrf.sh +elif [[ "$BOARD" == "qemu"* ]]; then + echo "--- Executing on QEMU emulation" + west build -t run +else + echo "Unrecognized board $BOARD" + exit 1 +fi diff --git a/test/C/src/zephyr/scripts/zephyr_flash_nrf.sh b/test/C/src/zephyr/scripts/zephyr_flash_nrf.sh new file mode 100644 index 0000000000..7659051d43 --- /dev/null +++ b/test/C/src/zephyr/scripts/zephyr_flash_nrf.sh @@ -0,0 +1,9 @@ +# Erase and flash application onto NRF52 +# Takes the path to the build folder as an argument +SRC_GEN_PATH=$1 + +NRFJPROG=nrfjprog.exe +echo "--- Executing zephyr_flash_nrf.sh" +eval $NRFJPROG -e +eval $NRFJPROG --program $SRC_GEN_PATH/build/zephyr/zephyr.hex --sectorerase --verify +eval $NRFJPROG --hardreset From 4fb62694a20a06a6ac99bd1f0ab012279fc7a1d5 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 5 Jan 2023 13:52:16 -0800 Subject: [PATCH 02/63] Fix zepyr target property and add Kconfig --- org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java | 2 +- test/C/src/zephyr/HelloZephyr.lf | 2 +- test/C/src/zephyr/scripts/Kconfig | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 test/C/src/zephyr/scripts/Kconfig diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index d6e15b343c..8a3db4c6c7 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -121,7 +121,7 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("project("+executableName+" LANGUAGES C)"); cMakeCode.newLine(); if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { - cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}"); + cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})"); cMakeCode.newLine(); } diff --git a/test/C/src/zephyr/HelloZephyr.lf b/test/C/src/zephyr/HelloZephyr.lf index 1f23d0ad72..f4d5b898da 100644 --- a/test/C/src/zephyr/HelloZephyr.lf +++ b/test/C/src/zephyr/HelloZephyr.lf @@ -1,5 +1,5 @@ target C { - platform: Zephyr, + platform: "Zephyr", build: "bash scripts/zephyr_build.sh qemu_cortex_m3 flash", threading: false, cmake-include: "scripts/zephyr.cmake" diff --git a/test/C/src/zephyr/scripts/Kconfig b/test/C/src/zephyr/scripts/Kconfig new file mode 100644 index 0000000000..0ffe175530 --- /dev/null +++ b/test/C/src/zephyr/scripts/Kconfig @@ -0,0 +1 @@ +source "Kconfig.zephyr" \ No newline at end of file From 934099f651d572e8720af565ea3ec723b11fcda2 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Sat, 7 Jan 2023 14:27:35 -0800 Subject: [PATCH 03/63] Use newlib --- test/C/src/zephyr/scripts/prj.conf | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/C/src/zephyr/scripts/prj.conf b/test/C/src/zephyr/scripts/prj.conf index 0142c24b0c..383044f32b 100644 --- a/test/C/src/zephyr/scripts/prj.conf +++ b/test/C/src/zephyr/scripts/prj.conf @@ -2,9 +2,8 @@ CONFIG_PRINTK=y # Set the memory pool sufficently large. CONFIG_HEAP_MEM_POOL_SIZE=2048 -# THis is the memory pool used by minimal libc -CONFIG_MINIMAL_LIBC=y -CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=50000 +# We use NEWLIB to get access to `atexit` +CONFIG_NEWLIB_LIBC=y # Enable FP printing CONFIG_CBPRINTF_FP_SUPPORT=y # Enable counters (used as HW clock) @@ -13,4 +12,4 @@ CONFIG_COUNTER=y # FIXME: Use overlays etc to support all sorts of boards. I think this will only work in NRF boards. CONFIG_COUNTER_TIMER1=y # Set main stack size big enough -CONFIG_MAIN_STACK_SIZE=2048 \ No newline at end of file +CONFIG_MAIN_STACK_SIZE=2048 From 0abab3872c96393516320b57ba6c0e2a5241c1a5 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Sat, 7 Jan 2023 14:28:14 -0800 Subject: [PATCH 04/63] Parse CompileDefinitions.txt from zephyr build script --- test/C/src/zephyr/scripts/zephyr_build.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/C/src/zephyr/scripts/zephyr_build.sh b/test/C/src/zephyr/scripts/zephyr_build.sh index a726e60b2f..d0b6e205d1 100644 --- a/test/C/src/zephyr/scripts/zephyr_build.sh +++ b/test/C/src/zephyr/scripts/zephyr_build.sh @@ -1,8 +1,11 @@ #!/usr/bin/bash echo "Building Zephyr application" +echo "ZEPHYR_BASE=${ZEPHYR_BASE}" SCRIPT_DIR=$(dirname $0) + + set -e # Return on first error # Verify command line arguments @@ -20,8 +23,15 @@ cp $LF_SRC_DIRECTORY/$SCRIPT_DIR/Kconfig $LF_SOURCE_GEN_DIRECTORY/ cd $LF_SOURCE_GEN_DIRECTORY +# Parse additional compile defs +COMPILE_DEFS="" +while IFS= read -r line; do + COMPILE_DEFS="${COMPILE_DEFS} -D$line" +done < CompileDefinitions.txt +echo "Passing compile defs: $COMPILE_DEFS to cmake" + # Build project -west build -b $BOARD +west build -b $BOARD -- $COMPILE_DEFS if [[ "$2" == "flash" ]]; then From 0cae265f1aa496b4063cb6c7902054e3c2ccc772 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Sat, 7 Jan 2023 14:28:44 -0800 Subject: [PATCH 05/63] Update zephyr. --- test/C/src/zephyr/scripts/zephyr.cmake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/C/src/zephyr/scripts/zephyr.cmake b/test/C/src/zephyr/scripts/zephyr.cmake index 363b00c8a3..dbc9f701f9 100644 --- a/test/C/src/zephyr/scripts/zephyr.cmake +++ b/test/C/src/zephyr/scripts/zephyr.cmake @@ -2,9 +2,15 @@ set_target_properties(${LF_MAIN_TARGET} PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) # Get the source files assoicated with the generated cmake build get_target_property(LF_SOURCES ${LF_MAIN_TARGET} SOURCES) -# Get the compile definitions added to target get_target_property(LF_COMPILE_DEFS ${LF_MAIN_TARGET} COMPILE_DEFINITIONS) +get_target_property(LF_LINKS ${LF_MAIN_TARGET} LINK_LIBRARIES) +get_target_property(LF_INCLUDES ${LF_MAIN_TARGET} INCLUDE_DIRECTORIES) # Use these sources with Zephyr build. target_compile_definitions(app PUBLIC ${LF_COMPILE_DEFS}) target_sources(app PRIVATE ${LF_SOURCES}) +target_link_libraries(app PUBLIC ${LF_LINKS}) +target_include_directories(app PUBLIC ${LF_INCLUDES}) + +# Link corelib with zephyr +target_link_libraries(core PUBLIC zephyr_interface) zephyr_library_compile_options(-Wl,--print-memory-usage) From ffd466946863f39f37119d9a4f0861e5a3770987 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Sun, 8 Jan 2023 23:05:24 -0800 Subject: [PATCH 06/63] Fix cmake generator for zephyr --- .../lflang/generator/c/CCmakeGenerator.java | 51 +++++++++++++++++-- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 8a3db4c6c7..0cbb44f14b 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -182,11 +182,19 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("set(CMAKE_SYSTEM_NAME "+targetConfig.platformOptions.platform.getcMakeName()+")"); } - cMakeCode.pr(setUpMainTarget.getCmakeCode( - hasMain, - executableName, - Stream.concat(additionalSources.stream(), sources.stream()) - )); + if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + cMakeCode.pr(setUpMainTargetZephyr( + hasMain, + executableName, + Stream.concat(additionalSources.stream(), sources.stream()) + )); + } else { + cMakeCode.pr(setUpMainTarget( + hasMain, + executableName, + Stream.concat(additionalSources.stream(), sources.stream()) + )); + } cMakeCode.pr("target_link_libraries(${LF_MAIN_TARGET} PRIVATE core)"); @@ -345,4 +353,37 @@ private static String setUpMainTarget( code.newLine(); return code.toString(); } + + private static String setUpMainTargetZephyr( + boolean hasMain, + String executableName, + Stream cSources + ) { + var code = new CodeBuilder(); + code.pr("add_subdirectory(core)"); + code.pr("target_link_libraries(core PUBLIC zephyr_interface)"); + code.newLine(); + + if (hasMain) { + code.pr("# Declare a new executable target and list all its sources"); + code.pr("set(LF_MAIN_TARGET app)"); + code.pr("target_sources("); + } else { + code.pr("# Declare a new library target and list all its sources"); + code.pr("set(LF_MAIN_TARGET"+executableName+")"); + code.pr("add_library("); + } + code.indent(); + code.pr("${LF_MAIN_TARGET}"); + + if (hasMain) { + code.pr("PRIVATE"); + } + + cSources.forEach(code::pr); + code.unindent(); + code.pr(")"); + code.newLine(); + return code.toString(); + } } From 62362836a315fd01e0f8cd7f43eed9bd9716d04a Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Sun, 8 Jan 2023 23:20:55 -0800 Subject: [PATCH 07/63] HelloZephyr compiles and runs on qemu --- org.lflang/src/lib/c/reactor-c | 2 +- .../org/lflang/generator/c/CCmakeGenerator.java | 6 ++++-- test/C/src/zephyr/HelloZephyr.lf | 1 - test/C/src/zephyr/scripts/zephyr.cmake | 16 ---------------- test/C/src/zephyr/scripts/zephyr_build.sh | 2 ++ 5 files changed, 7 insertions(+), 20 deletions(-) delete mode 100644 test/C/src/zephyr/scripts/zephyr.cmake diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index d97620bb54..6dcdf0c657 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit d97620bb54734a25521271169dadae68b6b3ad9b +Subproject commit 6dcdf0c657614a78bf0dd61451287c3846d0cd7f diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 0cbb44f14b..7de898f1cf 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -118,13 +118,15 @@ CodeBuilder generateCMakeCode( cMakeCode.newLine(); cMakeCode.pr("cmake_minimum_required(VERSION " + MIN_CMAKE_VERSION + ")"); - cMakeCode.pr("project("+executableName+" LANGUAGES C)"); - cMakeCode.newLine(); + if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})"); cMakeCode.newLine(); } + cMakeCode.pr("project("+executableName+" LANGUAGES C)"); + cMakeCode.newLine(); + // The Test build type is the Debug type plus coverage generation cMakeCode.pr("if(CMAKE_BUILD_TYPE STREQUAL \"Test\")"); cMakeCode.pr(" set(CMAKE_BUILD_TYPE \"Debug\")"); diff --git a/test/C/src/zephyr/HelloZephyr.lf b/test/C/src/zephyr/HelloZephyr.lf index f4d5b898da..6274c4c174 100644 --- a/test/C/src/zephyr/HelloZephyr.lf +++ b/test/C/src/zephyr/HelloZephyr.lf @@ -2,7 +2,6 @@ target C { platform: "Zephyr", build: "bash scripts/zephyr_build.sh qemu_cortex_m3 flash", threading: false, - cmake-include: "scripts/zephyr.cmake" } main reactor { diff --git a/test/C/src/zephyr/scripts/zephyr.cmake b/test/C/src/zephyr/scripts/zephyr.cmake deleted file mode 100644 index dbc9f701f9..0000000000 --- a/test/C/src/zephyr/scripts/zephyr.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# Disable the old target defined in the generated cmake file -set_target_properties(${LF_MAIN_TARGET} PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) -# Get the source files assoicated with the generated cmake build -get_target_property(LF_SOURCES ${LF_MAIN_TARGET} SOURCES) -get_target_property(LF_COMPILE_DEFS ${LF_MAIN_TARGET} COMPILE_DEFINITIONS) -get_target_property(LF_LINKS ${LF_MAIN_TARGET} LINK_LIBRARIES) -get_target_property(LF_INCLUDES ${LF_MAIN_TARGET} INCLUDE_DIRECTORIES) -# Use these sources with Zephyr build. -target_compile_definitions(app PUBLIC ${LF_COMPILE_DEFS}) -target_sources(app PRIVATE ${LF_SOURCES}) -target_link_libraries(app PUBLIC ${LF_LINKS}) -target_include_directories(app PUBLIC ${LF_INCLUDES}) - -# Link corelib with zephyr -target_link_libraries(core PUBLIC zephyr_interface) -zephyr_library_compile_options(-Wl,--print-memory-usage) diff --git a/test/C/src/zephyr/scripts/zephyr_build.sh b/test/C/src/zephyr/scripts/zephyr_build.sh index d0b6e205d1..8212e36dac 100644 --- a/test/C/src/zephyr/scripts/zephyr_build.sh +++ b/test/C/src/zephyr/scripts/zephyr_build.sh @@ -50,3 +50,5 @@ else echo "Unrecognized board $BOARD" exit 1 fi + +fi \ No newline at end of file From 625b8ac15be9fc2f4d5cccc72f1eb28328f0b61f Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Mon, 9 Jan 2023 00:08:47 -0800 Subject: [PATCH 08/63] Add overlay file for esp32 --- test/C/src/zephyr/scripts/esp32.overlay | 3 +++ test/C/src/zephyr/scripts/zephyr_build.sh | 3 +++ 2 files changed, 6 insertions(+) create mode 100755 test/C/src/zephyr/scripts/esp32.overlay diff --git a/test/C/src/zephyr/scripts/esp32.overlay b/test/C/src/zephyr/scripts/esp32.overlay new file mode 100755 index 0000000000..241947b064 --- /dev/null +++ b/test/C/src/zephyr/scripts/esp32.overlay @@ -0,0 +1,3 @@ +&timer0 { + status = "okay"; +}; diff --git a/test/C/src/zephyr/scripts/zephyr_build.sh b/test/C/src/zephyr/scripts/zephyr_build.sh index 8212e36dac..600c97dc18 100644 --- a/test/C/src/zephyr/scripts/zephyr_build.sh +++ b/test/C/src/zephyr/scripts/zephyr_build.sh @@ -20,6 +20,9 @@ export LF_SRC_DIRECTORY=$(pwd) cp $LF_SRC_DIRECTORY/$SCRIPT_DIR/prj.conf $LF_SOURCE_GEN_DIRECTORY/ cp $LF_SRC_DIRECTORY/$SCRIPT_DIR/Kconfig $LF_SOURCE_GEN_DIRECTORY/ +mkdir $LF_SOURCE_GEN_DIRECTORY/boards +cp $LF_SRC_DIRECTORY/$SCRIPT_DIR/*.overlay $LF_SOURCE_GEN_DIRECTORY/boards/ + cd $LF_SOURCE_GEN_DIRECTORY From 574907c7e37fd9dd507caa39e2c1f47fd37ca279 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Mon, 9 Jan 2023 00:08:54 -0800 Subject: [PATCH 09/63] Bump reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 6dcdf0c657..2ea444d05b 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 6dcdf0c657614a78bf0dd61451287c3846d0cd7f +Subproject commit 2ea444d05b98b55536ba4e464a7ba3a5c2932908 From 3f8022f4dd4562f26d24e2ee03c2ff7a6aaf8013 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Mon, 9 Jan 2023 00:17:57 -0800 Subject: [PATCH 10/63] bump reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 2ea444d05b..c41810b21f 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 2ea444d05b98b55536ba4e464a7ba3a5c2932908 +Subproject commit c41810b21f49ecc33fc4e81e44f7d5e36b579105 From 87c78e50fa9cee287853bcfbb5f7e42ef3e63908 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Mon, 9 Jan 2023 17:57:00 -0800 Subject: [PATCH 11/63] Blinky works on nrf52 --- org.lflang/src/lib/c/reactor-c | 2 +- test/C/src/zephyr/scripts/prj.conf | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index c41810b21f..c7dfe42075 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit c41810b21f49ecc33fc4e81e44f7d5e36b579105 +Subproject commit c7dfe4207520018eebd68dce62893170eff42761 diff --git a/test/C/src/zephyr/scripts/prj.conf b/test/C/src/zephyr/scripts/prj.conf index 383044f32b..cdddfd7555 100644 --- a/test/C/src/zephyr/scripts/prj.conf +++ b/test/C/src/zephyr/scripts/prj.conf @@ -2,10 +2,8 @@ CONFIG_PRINTK=y # Set the memory pool sufficently large. CONFIG_HEAP_MEM_POOL_SIZE=2048 -# We use NEWLIB to get access to `atexit` CONFIG_NEWLIB_LIBC=y -# Enable FP printing -CONFIG_CBPRINTF_FP_SUPPORT=y +CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y # Enable counters (used as HW clock) CONFIG_COUNTER=y # Have counter use the HW timer as basis From 06e538d009884d9d7db10642b5cb4cc54cdfe692 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 12:11:44 -0800 Subject: [PATCH 12/63] Put CMakeLists.txt compile defs at top --- .../src/org/lflang/generator/c/CCmakeGenerator.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 7de898f1cf..af9ea82609 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -183,6 +183,12 @@ CodeBuilder generateCMakeCode( if (targetConfig.platformOptions.platform != Platform.AUTO) { cMakeCode.pr("set(CMAKE_SYSTEM_NAME "+targetConfig.platformOptions.platform.getcMakeName()+")"); } + + cMakeCode.pr("# Target definitions\n"); + targetConfig.compileDefinitions.forEach((key, value) -> cMakeCode.pr( + "add_compile_definitions("+key+"="+value+")\n" + )); + cMakeCode.newLine(); if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { cMakeCode.pr(setUpMainTargetZephyr( @@ -247,11 +253,6 @@ CodeBuilder generateCMakeCode( } cMakeCode.newLine(); - cMakeCode.pr("# Target definitions\n"); - targetConfig.compileDefinitions.forEach((key, value) -> cMakeCode.pr( - "target_compile_definitions(${LF_MAIN_TARGET} PUBLIC "+key+"="+value+")\n" - )); - cMakeCode.newLine(); if (CppMode) cMakeCode.pr("enable_language(CXX)"); From 2c9807133798ee4a60bc1721452804e8ead26fc0 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 13:52:03 -0800 Subject: [PATCH 13/63] Add test category for Zephyr --- org.lflang.tests/src/org/lflang/tests/TestBase.java | 1 + org.lflang.tests/src/org/lflang/tests/TestRegistry.java | 3 ++- org.lflang.tests/src/org/lflang/tests/runtime/CTest.java | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/TestBase.java b/org.lflang.tests/src/org/lflang/tests/TestBase.java index 942c5c531a..c8e6fde461 100644 --- a/org.lflang.tests/src/org/lflang/tests/TestBase.java +++ b/org.lflang.tests/src/org/lflang/tests/TestBase.java @@ -151,6 +151,7 @@ public static class Message { public static final String DESC_CONCURRENT = "Run concurrent tests."; public static final String DESC_TARGET_SPECIFIC = "Run target-specific tests"; public static final String DESC_ARDUINO = "Running Arduino tests."; + public static final String DESC_ZEPHYR = "Running Zephyr tests."; public static final String DESC_AS_CCPP = "Running C tests as CCpp."; public static final String DESC_SINGLE_THREADED = "Run non-concurrent and non-federated tests with threading = off."; public static final String DESC_SCHED_SWAPPING = "Running with non-default runtime scheduler "; diff --git a/org.lflang.tests/src/org/lflang/tests/TestRegistry.java b/org.lflang.tests/src/org/lflang/tests/TestRegistry.java index 60172bf5bf..1ad69103af 100644 --- a/org.lflang.tests/src/org/lflang/tests/TestRegistry.java +++ b/org.lflang.tests/src/org/lflang/tests/TestRegistry.java @@ -148,8 +148,9 @@ public enum TestCategory { DOCKER_FEDERATED(true, "docker" + File.separator + "federated"), SERIALIZATION(false), ARDUINO(false, TestLevel.BUILD), + ZEPHYR(false, TestLevel.BUILD), TARGET(false); - + /** * Whether or not we should compare coverage against other targets. */ diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java index 1e0eee6f2f..838b04f350 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java @@ -100,6 +100,15 @@ public void runWithThreadingOff() { super.runWithThreadingOff(); } + + @Test + public void runZephyrTests() { + Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); + super.runTestsFor(List.of(Target.C), + Message.DESC_ZEPHYR, + TestCategory.ZEPHYR::equals, Configurators::disableThreading, + false); + } @Test @Disabled("TODO only 27/96 tests pass") @Override From 5a7ac1fc577b237372605bcae82f83bc57620c3e Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 15:33:04 -0800 Subject: [PATCH 14/63] Update zephyr cmake and add conf files --- org.lflang/src/lib/c/reactor-c | 2 +- .../src/lib/platform/zephyr}/Kconfig | 0 .../lib/platform/zephyr/boards}/esp32.overlay | 0 .../zephyr/boards/nrf52dk_nrf52832_lf.conf | 1 + .../src/lib/platform/zephyr/prj_lf.conf | 14 +++++++++++++ .../lflang/generator/c/CCmakeGenerator.java | 1 + .../org/lflang/generator/c/CGenerator.java | 21 +++++++++++++++++++ test/C/src/zephyr/scripts/prj.conf | 13 ------------ test/C/src/zephyr/scripts/zephyr_build.sh | 15 ------------- 9 files changed, 38 insertions(+), 29 deletions(-) rename {test/C/src/zephyr/scripts => org.lflang/src/lib/platform/zephyr}/Kconfig (100%) rename {test/C/src/zephyr/scripts => org.lflang/src/lib/platform/zephyr/boards}/esp32.overlay (100%) create mode 100644 org.lflang/src/lib/platform/zephyr/boards/nrf52dk_nrf52832_lf.conf create mode 100644 org.lflang/src/lib/platform/zephyr/prj_lf.conf delete mode 100644 test/C/src/zephyr/scripts/prj.conf diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index c7dfe42075..b1200a6425 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit c7dfe4207520018eebd68dce62893170eff42761 +Subproject commit b1200a6425d8bdf04de6e12009d980cfafaf9227 diff --git a/test/C/src/zephyr/scripts/Kconfig b/org.lflang/src/lib/platform/zephyr/Kconfig similarity index 100% rename from test/C/src/zephyr/scripts/Kconfig rename to org.lflang/src/lib/platform/zephyr/Kconfig diff --git a/test/C/src/zephyr/scripts/esp32.overlay b/org.lflang/src/lib/platform/zephyr/boards/esp32.overlay similarity index 100% rename from test/C/src/zephyr/scripts/esp32.overlay rename to org.lflang/src/lib/platform/zephyr/boards/esp32.overlay diff --git a/org.lflang/src/lib/platform/zephyr/boards/nrf52dk_nrf52832_lf.conf b/org.lflang/src/lib/platform/zephyr/boards/nrf52dk_nrf52832_lf.conf new file mode 100644 index 0000000000..8bc7cfdbc5 --- /dev/null +++ b/org.lflang/src/lib/platform/zephyr/boards/nrf52dk_nrf52832_lf.conf @@ -0,0 +1 @@ +CONFIG_COUNTER_TIMER1=y diff --git a/org.lflang/src/lib/platform/zephyr/prj_lf.conf b/org.lflang/src/lib/platform/zephyr/prj_lf.conf new file mode 100644 index 0000000000..88613edc08 --- /dev/null +++ b/org.lflang/src/lib/platform/zephyr/prj_lf.conf @@ -0,0 +1,14 @@ +# Lingua Franca Zephyr configuration file + +# This is a generated file, do not edit. +# To supply additional configuration parameters add an additional +# configuration file to the build with +# west build -b qemu_cortex_m3 -- -DOVERLAY_CONFIG=my_conf.prj + +# Enable printf +CONFIG_PRINTK=y +# Use the newlib C library +CONFIG_NEWLIB_LIBC=y +CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y +# Enable the counter API used for hi-res clock +CONFIG_COUNTER=y diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index af9ea82609..87b1b35670 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -120,6 +120,7 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("cmake_minimum_required(VERSION " + MIN_CMAKE_VERSION + ")"); if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + cMakeCode.pr("set(CONF_FILE prj_lf.conf)"); cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})"); cMakeCode.newLine(); } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index e3b864b99f..81fc0b384b 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -596,6 +596,27 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { fileConfig.getSrcGenPath().resolve("toolchain/BoardOptions.cmake")); } + // If Zephyr target then copy default config and board files + // for Zephyr support + if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + FileUtil.copyDirectoryFromClassPath( + "/lib/platform/zephyr/boards", + fileConfig.getSrcGenPath().resolve("boards"), + false + ); + FileUtil.copyFileFromClassPath( + "/lib/platform/zephyr/prj_lf.conf", + fileConfig.getSrcGenPath().resolve("prj_lf.conf"), + true + ); + + FileUtil.copyFileFromClassPath( + "/lib/platform/zephyr/Kconfig", + fileConfig.getSrcGenPath().resolve("Kconfig"), + true + ); + } + // Write the generated code code.writeToFile(targetFile); } catch (IOException e) { diff --git a/test/C/src/zephyr/scripts/prj.conf b/test/C/src/zephyr/scripts/prj.conf deleted file mode 100644 index cdddfd7555..0000000000 --- a/test/C/src/zephyr/scripts/prj.conf +++ /dev/null @@ -1,13 +0,0 @@ -# Enable printk -CONFIG_PRINTK=y -# Set the memory pool sufficently large. -CONFIG_HEAP_MEM_POOL_SIZE=2048 -CONFIG_NEWLIB_LIBC=y -CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y -# Enable counters (used as HW clock) -CONFIG_COUNTER=y -# Have counter use the HW timer as basis -# FIXME: Use overlays etc to support all sorts of boards. I think this will only work in NRF boards. -CONFIG_COUNTER_TIMER1=y -# Set main stack size big enough -CONFIG_MAIN_STACK_SIZE=2048 diff --git a/test/C/src/zephyr/scripts/zephyr_build.sh b/test/C/src/zephyr/scripts/zephyr_build.sh index 600c97dc18..0255417c07 100644 --- a/test/C/src/zephyr/scripts/zephyr_build.sh +++ b/test/C/src/zephyr/scripts/zephyr_build.sh @@ -1,7 +1,5 @@ #!/usr/bin/bash - echo "Building Zephyr application" -echo "ZEPHYR_BASE=${ZEPHYR_BASE}" SCRIPT_DIR=$(dirname $0) @@ -18,21 +16,8 @@ fi export BOARD=$1 export LF_SRC_DIRECTORY=$(pwd) -cp $LF_SRC_DIRECTORY/$SCRIPT_DIR/prj.conf $LF_SOURCE_GEN_DIRECTORY/ -cp $LF_SRC_DIRECTORY/$SCRIPT_DIR/Kconfig $LF_SOURCE_GEN_DIRECTORY/ -mkdir $LF_SOURCE_GEN_DIRECTORY/boards -cp $LF_SRC_DIRECTORY/$SCRIPT_DIR/*.overlay $LF_SOURCE_GEN_DIRECTORY/boards/ - - cd $LF_SOURCE_GEN_DIRECTORY -# Parse additional compile defs -COMPILE_DEFS="" -while IFS= read -r line; do - COMPILE_DEFS="${COMPILE_DEFS} -D$line" -done < CompileDefinitions.txt -echo "Passing compile defs: $COMPILE_DEFS to cmake" - # Build project west build -b $BOARD -- $COMPILE_DEFS From bfdfd8537ebdb79c08faf85796862cf309451075 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 16:04:06 -0800 Subject: [PATCH 15/63] Add board and flash targer properties to build and support cmake native building of Zephyr --- org.lflang/src/org/lflang/TargetConfig.java | 4 +++- org.lflang/src/org/lflang/TargetProperty.java | 18 +++++++----------- .../lflang/generator/c/CCmakeGenerator.java | 12 +++++++++++- .../src/org/lflang/generator/c/CGenerator.java | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index b16dfadd19..b2ce5ce4a5 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -418,12 +418,14 @@ public static class PlatformOptions { /** * The base board we target when building LF on Arduino/Embedded Boards. For OS development and generic embedded systems, this value is unused. */ - public Board board = Board.UNO; + public String board = null; /** * The baud rate used as a parameter to certain embedded platforms. 9600 is a standard rate amongst systems like Arduino, so it's the default value. */ public int baudRate = 9600; + + public boolean flash = false; } /** diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index 53736c31be..8ee4494f16 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -327,15 +327,10 @@ public enum TargetProperty { config.platformOptions.baudRate = ASTUtils.toInteger(entry.getValue()); break; case BOARD: - Board b = (Board) UnionType.BOARD_UNION - .forName(ASTUtils.elementToSingleString(entry.getValue())); - if(b == null){ - String s = "Unidentified Board Type, LF supports the following board types: " + Arrays.asList(Board.values()).toString(); - err.reportError(s); - throw new AssertionError(s); - } - - config.platformOptions.board = b; + config.platformOptions.board = ASTUtils.elementToSingleString(entry.getValue()); + break; + case FLASH: + config.platformOptions.flash = ASTUtils.toBoolean(entry.getValue()) ; break; default: break; @@ -1327,8 +1322,9 @@ public TargetPropertyType getType() { public enum PlatformOption implements DictionaryElement { NAME("name", PrimitiveType.STRING), BAUDRATE("baud-rate", PrimitiveType.NON_NEGATIVE_INTEGER), - BOARD("board", PrimitiveType.STRING); - + BOARD("board", PrimitiveType.STRING), + FLASH("flash", PrimitiveType.BOOLEAN); + public final PrimitiveType type; private final String description; diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 87b1b35670..29cbb2ede4 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -120,8 +120,18 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("cmake_minimum_required(VERSION " + MIN_CMAKE_VERSION + ")"); if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + cMakeCode.pr("# Set default configuration file. To add custom configurations"); + cMakeCode.pr("# Pass -- -DOVERLAY_CONFIG=my_config.prj to either cmake or west"); cMakeCode.pr("set(CONF_FILE prj_lf.conf)"); - cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})"); + if (targetConfig.platformOptions.board != null) { + cMakeCode.pr("# Selecting board specified in target property"); + cMakeCode.pr("set(BOARD "+targetConfig.platformOptions.board+")"); + } else { + cMakeCode.pr("# Selecting default board"); + cMakeCode.pr("set(BOARD qemu_cortex_m3)"); + } + cMakeCode.pr("# We require Zephyr version 3.2.0"); + cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} EXACT 3.2.0)"); cMakeCode.newLine(); } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index 81fc0b384b..57cabe55a8 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -590,7 +590,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { StringBuilder s = new StringBuilder(); s.append("set(ARDUINO_BOARD \""); - s.append(targetConfig.platformOptions.board.getBoardName()); +// s.append(targetConfig.platformOptions.board.getBoardName()); s.append("\")"); FileUtil.writeToFile(s.toString(), fileConfig.getSrcGenPath().resolve("toolchain/BoardOptions.cmake")); From c0ed4223468a125327af96c1d96c2e2deb20cd05 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 16:23:56 -0800 Subject: [PATCH 16/63] Add special flash command for qemu --- .../src/org/lflang/generator/c/CCompiler.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 02333e3704..24052150aa 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -178,6 +178,10 @@ public boolean runCCompiler( System.out.println("SUCCESS: Compiling generated code for " + fileConfig.name + " finished with no errors."); } + if (targetConfig.platformOptions.platform == Platform.ZEPHYR && targetConfig.platformOptions.flash) { + LFCommand flash = buildWestFlashCommand(); + } + } return cMakeReturnCode == 0 && makeReturnCode == 0; } @@ -275,6 +279,27 @@ public LFCommand buildCmakeCommand() { return command; } + public LFCommand buildWestFlashCommand() { + // Set the build directory to be "build" + Path buildPath = fileConfig.getSrcGenPath().resolve("build"); + String board = targetConfig.platformOptions.board; + LFCommand cmd; + if (board == null || board.startsWith("qemu")) { + cmd = commandFactory.createCommand( + "west", List.of("build", "-t"), buildPath); + } else { + cmd = commandFactory.createCommand( + "west", List.of("flash"), buildPath); + } + if (cmd == null) { + errorReporter.reportError( + "Could not create west flash command." + ); + } + + return cmd; + } + /** * Check if the output produced by CMake has any known and common errors. * If a known error is detected, a specialized, more informative message From a252135659fb05239a026bbff19ddb84ae57e145 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 16:34:06 -0800 Subject: [PATCH 17/63] Fix west flash command --- org.lflang/src/org/lflang/generator/c/CCompiler.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 24052150aa..2f6e8cf342 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -179,7 +179,14 @@ public boolean runCCompiler( } if (targetConfig.platformOptions.platform == Platform.ZEPHYR && targetConfig.platformOptions.flash) { + System.out.println("Invoking flash command for Zephyr"); LFCommand flash = buildWestFlashCommand(); + int flashRet = flash.run(); + if (flashRet != 0) { + errorReporter.reportError("West flash command failed with error code " + flashRet); + } else { + System.out.println("SUCCESS: Flash application with west"); + } } } From 32bd83446481e92ba47dc7e6b86bb56d7c6690ed Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 16:47:50 -0800 Subject: [PATCH 18/63] Fix flash command --- .../src/org/lflang/generator/c/CCompiler.java | 8 ++++- test/C/src/zephyr/Blinky2.lf | 14 ++++++++ test/C/src/zephyr/HelloZephyr.lf | 9 +++-- test/C/src/zephyr/Timer.lf | 12 +++++++ test/C/src/zephyr/lib/Led.lf | 33 +++++++++++++++++++ 5 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 test/C/src/zephyr/Blinky2.lf create mode 100644 test/C/src/zephyr/Timer.lf create mode 100644 test/C/src/zephyr/lib/Led.lf diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 2f6e8cf342..59689ac110 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -286,6 +286,12 @@ public LFCommand buildCmakeCommand() { return command; } + /** + * Return a flash/emulate command using west. + * If board is null (defaults to qemu_cortex_m3) or qemu_* + * Return a flash command which runs the target as an emulation + * If ordinary target, return `west flash` + */ public LFCommand buildWestFlashCommand() { // Set the build directory to be "build" Path buildPath = fileConfig.getSrcGenPath().resolve("build"); @@ -293,7 +299,7 @@ public LFCommand buildWestFlashCommand() { LFCommand cmd; if (board == null || board.startsWith("qemu")) { cmd = commandFactory.createCommand( - "west", List.of("build", "-t"), buildPath); + "west", List.of("build", "-t", "run"), buildPath); } else { cmd = commandFactory.createCommand( "west", List.of("flash"), buildPath); diff --git a/test/C/src/zephyr/Blinky2.lf b/test/C/src/zephyr/Blinky2.lf new file mode 100644 index 0000000000..5a28caa464 --- /dev/null +++ b/test/C/src/zephyr/Blinky2.lf @@ -0,0 +1,14 @@ +target C { + platform: { + name: "Zephyr", + board: nrf52dk_nrf52832, + flash: true, + }, + threading: false, +} + +import NrfLeds from "lib/Led.lf" + +main reactor { + led0 = new NrfLeds() +} \ No newline at end of file diff --git a/test/C/src/zephyr/HelloZephyr.lf b/test/C/src/zephyr/HelloZephyr.lf index 6274c4c174..7c765aa7a6 100644 --- a/test/C/src/zephyr/HelloZephyr.lf +++ b/test/C/src/zephyr/HelloZephyr.lf @@ -1,8 +1,11 @@ target C { - platform: "Zephyr", - build: "bash scripts/zephyr_build.sh qemu_cortex_m3 flash", threading: false, -} + platform: { + name: Zephyr, + board: nrf52dk_nrf52832, + flash: true, + }, +} main reactor { reaction(startup) {= diff --git a/test/C/src/zephyr/Timer.lf b/test/C/src/zephyr/Timer.lf new file mode 100644 index 0000000000..ab40abd40d --- /dev/null +++ b/test/C/src/zephyr/Timer.lf @@ -0,0 +1,12 @@ + +target C { + platform: "Zephyr", + threading: false, +} + +main reactor { + timer t(0, 1 sec) + reaction(t) {= + printf("Hello\n"); + =} +} \ No newline at end of file diff --git a/test/C/src/zephyr/lib/Led.lf b/test/C/src/zephyr/lib/Led.lf new file mode 100644 index 0000000000..53293362c9 --- /dev/null +++ b/test/C/src/zephyr/lib/Led.lf @@ -0,0 +1,33 @@ +target C; + + +reactor NrfLeds { + preamble {= + #include + #include + #define LED0_NODE DT_ALIAS(led0) + #define LED1_NODE DT_ALIAS(led1) + #define LED2_NODE DT_ALIAS(led2) + #define LED3_NODE DT_ALIAS(led3) + static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(LED0_NODE, gpios); + static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios); + static const struct gpio_dt_spec led2 = GPIO_DT_SPEC_GET(LED2_NODE, gpios); + static const struct gpio_dt_spec led3 = GPIO_DT_SPEC_GET(LED3_NODE, gpios); + =} + timer t(0, 100 msec) + + reaction(startup) {= + gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE); + gpio_pin_configure_dt(&led1, GPIO_OUTPUT_ACTIVE); + gpio_pin_configure_dt(&led2, GPIO_OUTPUT_ACTIVE); + gpio_pin_configure_dt(&led3, GPIO_OUTPUT_ACTIVE); + =} + + reaction(t) {= + printf("Hello\n"); + gpio_pin_toggle_dt(&led0); + gpio_pin_toggle_dt(&led1); + gpio_pin_toggle_dt(&led2); + gpio_pin_toggle_dt(&led3); + =} +} From c5c0d582c2628f3301458393e39c9398528aa9ec Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 16:56:04 -0800 Subject: [PATCH 19/63] Make Zephyr tests --- .../src/org/lflang/tests/Configurators.java | 12 ++++++++++++ .../src/org/lflang/tests/runtime/CTest.java | 2 +- org.lflang/src/org/lflang/generator/c/CCompiler.java | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/Configurators.java b/org.lflang.tests/src/org/lflang/tests/Configurators.java index e73150c669..5ad3c8e156 100644 --- a/org.lflang.tests/src/org/lflang/tests/Configurators.java +++ b/org.lflang.tests/src/org/lflang/tests/Configurators.java @@ -62,6 +62,18 @@ public static boolean disableThreading(LFTest test) { return true; } + + public static boolean makeZephyrCompatible(LFTest test) { + test.getContext().getArgs().setProperty("threading", "false"); + test.getContext().getArgs().setProperty("platform.name", "Zephyr"); + test.getContext().getArgs().setProperty("platform.board", "qemu_cortex_m3"); + // TODO: In the future we want to execute to the test with QEMU + // but it requires parsing QEMU output until either: + // 1) A timeout + // 2) "exit" is printed to stdout. Then look if there is a FATAL ERROR printed somewhere + test.getContext().getArgs().setProperty("platform.flash", "false"); + return true; + } /** * Make no changes to the configuration. * diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java index 838b04f350..8817c87a63 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java @@ -106,7 +106,7 @@ public void runZephyrTests() { Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); super.runTestsFor(List.of(Target.C), Message.DESC_ZEPHYR, - TestCategory.ZEPHYR::equals, Configurators::disableThreading, + TestCategory.ZEPHYR::equals, Configurators::makeZephyrCompatible, false); } @Test diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 59689ac110..ac0ccce2c2 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -185,7 +185,7 @@ public boolean runCCompiler( if (flashRet != 0) { errorReporter.reportError("West flash command failed with error code " + flashRet); } else { - System.out.println("SUCCESS: Flash application with west"); + System.out.println("SUCCESS: Flashed application with west"); } } From 844ca145a1ffb19508cb873e8b43ae72715d9451 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 17:35:10 -0800 Subject: [PATCH 20/63] Add a separate CI flow for Zephyr --- .github/workflows/c-zephyr-tests.yml | 47 ++++++++++++++ .github/workflows/ci.yml | 5 ++ .../src/org/lflang/tests/runtime/CTest.java | 8 --- .../org/lflang/tests/runtime/CZephyrTest.java | 65 +++++++++++++++++++ 4 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/c-zephyr-tests.yml create mode 100644 org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml new file mode 100644 index 0000000000..3e82f68d85 --- /dev/null +++ b/.github/workflows/c-zephyr-tests.yml @@ -0,0 +1,47 @@ +name: C Zephyr tests + +on: + workflow_call: + inputs: + compiler-ref: + required: false + type: string + runtime-ref: + required: false + type: string + use-cpp: + required: false + type: boolean + default: false + scheduler: + required: false + type: string + +jobs: + run: + runs-on: ubuntu-latest + # FIXME: Can we specify the Zephyr version? We are currently hardcoding a + # requirement on exactly v3.2.0 + container: zephyrprojectrtos/ci:latest + env: + CMAKE_PREFIX_PATH: /opt/toolchains + steps: + - name: Check out lingua-franca repository + uses: actions/checkout@v3 + with: + repository: lf-lang/lingua-franca + submodules: true + ref: ${{ inputs.compiler-ref }} + fetch-depth: 0 + - name: Prepare build environment + uses: ./.github/actions/prepare-build-env + - name: Check out specific ref of reactor-c + uses: actions/checkout@v3 + with: + repository: lf-lang/reactor-c + path: org.lflang/src/lib/c/reactor-c + ref: ${{ inputs.runtime-ref }} + if: ${{ inputs.runtime-ref }} + - name: Perform Zephyr tests for C target with default scheduler + run: | + ./gradlew test --tests org.lflang.tests.runtime.CZephyrTests.* \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 094cb0f1db..c2c15f8b4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,6 +62,11 @@ jobs: c-tests: uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master needs: cancel + + # Run the C Zephyr integration tests. + c-tests: + uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@master + needs: cancel # Run the CCpp integration tests. ccpp-tests: diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java index 8817c87a63..52ed73fb00 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java @@ -101,14 +101,6 @@ public void runWithThreadingOff() { } - @Test - public void runZephyrTests() { - Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); - super.runTestsFor(List.of(Target.C), - Message.DESC_ZEPHYR, - TestCategory.ZEPHYR::equals, Configurators::makeZephyrCompatible, - false); - } @Test @Disabled("TODO only 27/96 tests pass") @Override diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java new file mode 100644 index 0000000000..68e84d58f6 --- /dev/null +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java @@ -0,0 +1,65 @@ +/************* +Copyright (c) 2023, The University of California at Berkeley. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***************/ +package org.lflang.tests.runtime; + +import java.util.List; + +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import org.lflang.Target; +import org.lflang.tests.Configurators; +import org.lflang.tests.RuntimeTest; +import org.lflang.tests.TestRegistry.TestCategory; + +/** + * Collection of Zephyr tests for the C target. + * + * @author Erling Rennemo Jellum + */ +public class CZephyrTest extends RuntimeTest { + + public CZephyrTest() { + super(Target.C); + } + + @Test + public void runZephyrTests() { + Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); + super.runTestsFor(List.of(Target.C), + Message.DESC_ZEPHYR, + TestCategory.ZEPHYR::equals, Configurators::makeZephyrCompatible, + false); + } + @Test + public void runGenericTests() { + Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); + super.runTestsFor(List.of(Target.C), + Message.DESC_GENERIC, + TestCategory.GENERIC::equals, Configurators::makeZephyrCompatible, + false); + } +} From cfcf8ed5e0e4c8949e32b078200b7a535916414e Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 17:39:49 -0800 Subject: [PATCH 21/63] Fix CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2c15f8b4a..9e888af960 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: needs: cancel # Run the C Zephyr integration tests. - c-tests: + c-zephyr-tests: uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@master needs: cancel From b79b2408fa2ca10d466a5a4ea3dabc05778f9848 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 17:42:27 -0800 Subject: [PATCH 22/63] Try to fix CI again... --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e888af960..b86d1f6f5b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,7 +65,7 @@ jobs: # Run the C Zephyr integration tests. c-zephyr-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@master + uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml needs: cancel # Run the CCpp integration tests. From 5f3526a3922f7fca9fd9eee615869617c8a8cc3e Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 17:45:08 -0800 Subject: [PATCH 23/63] CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b86d1f6f5b..3ab25a330c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,7 +65,7 @@ jobs: # Run the C Zephyr integration tests. c-zephyr-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml + uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@c-zephyr-support needs: cancel # Run the CCpp integration tests. From 9fd2de9b81260a2ccf1d84baac058fb09089090f Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 18:06:05 -0800 Subject: [PATCH 24/63] Exclude Zephyr tests from CCpp tests --- org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java index b584b7646e..98dbd1b37e 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CCppTest.java @@ -43,6 +43,7 @@ private static boolean isExcludedFromCCpp(TestCategory category) { boolean excluded = category == TestCategory.SERIALIZATION; excluded |= isWindows() && (category == TestCategory.DOCKER_FEDERATED || category == TestCategory.ARDUINO) ; excluded |= isMac() && (category == TestCategory.DOCKER_FEDERATED || category == TestCategory.DOCKER); + excluded |= category == TestCategory.ZEPHYR; return !excluded; } } From 5ea849aca48005583b49012b1bcff0d51714454b Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 20:55:37 -0800 Subject: [PATCH 25/63] Fix formatting and delete unneeded stuff --- org.lflang/src/lib/c/reactor-c | 2 +- test/C/src/zephyr/Blinky2.lf | 6 +-- test/C/src/zephyr/HelloZephyr.lf | 12 +++--- test/C/src/zephyr/Timer.lf | 10 ++--- test/C/src/zephyr/scripts/zephyr_build.sh | 42 ------------------- test/C/src/zephyr/scripts/zephyr_flash_nrf.sh | 9 ---- 6 files changed, 13 insertions(+), 68 deletions(-) delete mode 100644 test/C/src/zephyr/scripts/zephyr_build.sh delete mode 100644 test/C/src/zephyr/scripts/zephyr_flash_nrf.sh diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index b1200a6425..ad95c07efe 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit b1200a6425d8bdf04de6e12009d980cfafaf9227 +Subproject commit ad95c07efe2fe5c68d8d597904aef6d81fb37f61 diff --git a/test/C/src/zephyr/Blinky2.lf b/test/C/src/zephyr/Blinky2.lf index 5a28caa464..9fbaa42ebf 100644 --- a/test/C/src/zephyr/Blinky2.lf +++ b/test/C/src/zephyr/Blinky2.lf @@ -2,13 +2,13 @@ target C { platform: { name: "Zephyr", board: nrf52dk_nrf52832, - flash: true, + flash: true }, - threading: false, + threading: false } import NrfLeds from "lib/Led.lf" main reactor { led0 = new NrfLeds() -} \ No newline at end of file +} diff --git a/test/C/src/zephyr/HelloZephyr.lf b/test/C/src/zephyr/HelloZephyr.lf index 7c765aa7a6..0e858d02e0 100644 --- a/test/C/src/zephyr/HelloZephyr.lf +++ b/test/C/src/zephyr/HelloZephyr.lf @@ -3,12 +3,10 @@ target C { platform: { name: Zephyr, board: nrf52dk_nrf52832, - flash: true, - }, -} + flash: true + } +} main reactor { - reaction(startup) {= - printf("Hello World!\n"); - =} -} \ No newline at end of file + reaction(startup) {= printf("Hello World!\n"); =} +} diff --git a/test/C/src/zephyr/Timer.lf b/test/C/src/zephyr/Timer.lf index ab40abd40d..1a389d03dc 100644 --- a/test/C/src/zephyr/Timer.lf +++ b/test/C/src/zephyr/Timer.lf @@ -1,12 +1,10 @@ - target C { platform: "Zephyr", - threading: false, + threading: false } main reactor { timer t(0, 1 sec) - reaction(t) {= - printf("Hello\n"); - =} -} \ No newline at end of file + + reaction(t) {= printf("Hello\n"); =} +} diff --git a/test/C/src/zephyr/scripts/zephyr_build.sh b/test/C/src/zephyr/scripts/zephyr_build.sh deleted file mode 100644 index 0255417c07..0000000000 --- a/test/C/src/zephyr/scripts/zephyr_build.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/bash -echo "Building Zephyr application" -SCRIPT_DIR=$(dirname $0) - - - -set -e # Return on first error - -# Verify command line arguments -if [ $# -lt 1 ]; then - echo "ERROR: Please pass the board to zephyr_build.sh. e.g. ./zephyr_build.sh qemu_cortex_m3 flash" - exit 1 -fi - -# Set some global variables -export BOARD=$1 -export LF_SRC_DIRECTORY=$(pwd) - -cd $LF_SOURCE_GEN_DIRECTORY - -# Build project -west build -b $BOARD -- $COMPILE_DEFS - -if [[ "$2" == "flash" ]]; then - -if [[ "$BOARD" == "nrf"* ]]; then - echo "--- Flashing to NRF board" - # Flash application - bash $LF_SRC_DIRECTORY/$SCRIPT_DIR/zephyr_flash_nrf.sh . - - # Debug application - # FIXME: Fix the issues here. Why isnt gdb working when invoked from this script? - # $LF_SRC_DIRECTORY/../scripts/zephyr_debug_nrf.sh -elif [[ "$BOARD" == "qemu"* ]]; then - echo "--- Executing on QEMU emulation" - west build -t run -else - echo "Unrecognized board $BOARD" - exit 1 -fi - -fi \ No newline at end of file diff --git a/test/C/src/zephyr/scripts/zephyr_flash_nrf.sh b/test/C/src/zephyr/scripts/zephyr_flash_nrf.sh deleted file mode 100644 index 7659051d43..0000000000 --- a/test/C/src/zephyr/scripts/zephyr_flash_nrf.sh +++ /dev/null @@ -1,9 +0,0 @@ -# Erase and flash application onto NRF52 -# Takes the path to the build folder as an argument -SRC_GEN_PATH=$1 - -NRFJPROG=nrfjprog.exe -echo "--- Executing zephyr_flash_nrf.sh" -eval $NRFJPROG -e -eval $NRFJPROG --program $SRC_GEN_PATH/build/zephyr/zephyr.hex --sectorerase --verify -eval $NRFJPROG --hardreset From 50adea8fd58c9576eeafaa24209906192899b380 Mon Sep 17 00:00:00 2001 From: erling Date: Tue, 10 Jan 2023 21:06:26 -0800 Subject: [PATCH 26/63] Apply suggestions from code review --- .github/workflows/c-zephyr-tests.yml | 2 +- org.lflang.tests/src/org/lflang/tests/runtime/CTest.java | 1 - org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java | 1 + org.lflang/src/lib/platform/zephyr/Kconfig | 2 +- org.lflang/src/org/lflang/TargetConfig.java | 3 +++ org.lflang/src/org/lflang/TargetProperty.java | 2 +- 6 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 3e82f68d85..bc8349aca7 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -44,4 +44,4 @@ jobs: if: ${{ inputs.runtime-ref }} - name: Perform Zephyr tests for C target with default scheduler run: | - ./gradlew test --tests org.lflang.tests.runtime.CZephyrTests.* \ No newline at end of file + ./gradlew test --tests org.lflang.tests.runtime.CZephyrTests.* diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java index fac7298008..82225471a8 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java @@ -100,7 +100,6 @@ public void runWithThreadingOff() { super.runWithThreadingOff(); } - @Test @Disabled("TODO only 27/96 tests pass") @Override diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java index 68e84d58f6..8898343b43 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java @@ -63,3 +63,4 @@ public void runGenericTests() { false); } } + diff --git a/org.lflang/src/lib/platform/zephyr/Kconfig b/org.lflang/src/lib/platform/zephyr/Kconfig index 0ffe175530..5ba198ca54 100644 --- a/org.lflang/src/lib/platform/zephyr/Kconfig +++ b/org.lflang/src/lib/platform/zephyr/Kconfig @@ -1 +1 @@ -source "Kconfig.zephyr" \ No newline at end of file +source "Kconfig.zephyr" diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 46c6c6cfb3..d3566eb5b3 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -425,6 +425,9 @@ public static class PlatformOptions { */ public int baudRate = 9600; +/** + * Should LFC invoke external tools to flash the resulting binary onto the target board + */ public boolean flash = false; } diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index 3e6616f383..3099aed2cc 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -330,7 +330,7 @@ public enum TargetProperty { config.platformOptions.board = ASTUtils.elementToSingleString(entry.getValue()); break; case FLASH: - config.platformOptions.flash = ASTUtils.toBoolean(entry.getValue()) ; + config.platformOptions.flash = ASTUtils.toBoolean(entry.getValue()); break; default: break; From dc41379a1b2c9048dbbab077551b84e1b3cb702e Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Tue, 10 Jan 2023 21:54:20 -0800 Subject: [PATCH 27/63] Fix CMakeGenerator.java. --- .../src/org/lflang/generator/c/CCmakeGenerator.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 5dcc862e60..8ecb18e8a5 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -118,7 +118,7 @@ CodeBuilder generateCMakeCode( cMakeCode.newLine(); cMakeCode.pr("cmake_minimum_required(VERSION " + MIN_CMAKE_VERSION + ")"); - + if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { cMakeCode.pr("# Set default configuration file. To add custom configurations"); cMakeCode.pr("# Pass -- -DOVERLAY_CONFIG=my_config.prj to either cmake or west"); @@ -134,10 +134,10 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} EXACT 3.2.0)"); cMakeCode.newLine(); } - + cMakeCode.pr("project("+executableName+" LANGUAGES C)"); cMakeCode.newLine(); - + // The Test build type is the Debug type plus coverage generation cMakeCode.pr("if(CMAKE_BUILD_TYPE STREQUAL \"Test\")"); cMakeCode.pr(" set(CMAKE_BUILD_TYPE \"Debug\")"); @@ -194,7 +194,7 @@ CodeBuilder generateCMakeCode( if (targetConfig.platformOptions.platform != Platform.AUTO) { cMakeCode.pr("set(CMAKE_SYSTEM_NAME "+targetConfig.platformOptions.platform.getcMakeName()+")"); } - + cMakeCode.pr("# Target definitions\n"); targetConfig.compileDefinitions.forEach((key, value) -> cMakeCode.pr( "add_compile_definitions("+key+"="+value+")\n" @@ -208,7 +208,7 @@ CodeBuilder generateCMakeCode( Stream.concat(additionalSources.stream(), sources.stream()) )); } else { - cMakeCode.pr(setUpMainTarget( + cMakeCode.pr(setUpMainTarget.getCmakeCode( hasMain, executableName, Stream.concat(additionalSources.stream(), sources.stream()) @@ -253,7 +253,7 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("target_compile_definitions(${LF_MAIN_TARGET} PUBLIC NUMBER_OF_WORKERS="+targetConfig.workers+")"); cMakeCode.newLine(); } - + // Add additional flags so runtime can distinguish between multi-threaded and single-threaded mode if (targetConfig.threading) { cMakeCode.pr("# Set flag to indicate a multi-threaded runtime"); From 9363366f09b6c00740b85180357f804085c154a3 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 22:45:06 -0800 Subject: [PATCH 28/63] Setup zepyrrtos ci container with java and maven --- .github/workflows/c-zephyr-tests.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index bc8349aca7..ccca8d9ac4 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -33,6 +33,15 @@ jobs: submodules: true ref: ${{ inputs.compiler-ref }} fetch-depth: 0 + - name: Install java and others + run : | + apt update + wget https://download.oracle.com/java/17/archive/jdk-17.0.5_linux-x64_bin.tar.gz + tar xvzf jdk-17.0.5_linux-x64_bin.tar.gz -C /opt + export JAVA_HOME=/opt/jdk-17.0.5 + export PATH=$PATH:$JAVA_HOME/bin + apt install maven -y + - name: Prepare build environment uses: ./.github/actions/prepare-build-env - name: Check out specific ref of reactor-c From 100caf661623292cf21d9ce25db3bd4572d556ed Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 22:57:55 -0800 Subject: [PATCH 29/63] Dont run Zephyr tests with runWithThreadingOff --- org.lflang.tests/src/org/lflang/tests/Configurators.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/Configurators.java b/org.lflang.tests/src/org/lflang/tests/Configurators.java index 97e328d23d..c13f072c77 100644 --- a/org.lflang.tests/src/org/lflang/tests/Configurators.java +++ b/org.lflang.tests/src/org/lflang/tests/Configurators.java @@ -95,7 +95,8 @@ public static boolean compatibleWithThreadingOff(TestCategory category) { || category == TestCategory.SERIALIZATION || category == TestCategory.FEDERATED || category == TestCategory.DOCKER_FEDERATED - || category == TestCategory.DOCKER; + || category == TestCategory.DOCKER + || category == TestCategory.ZEPHYR; // SERIALIZATION, TARGET, and ARDUINO tests are excluded on Windows. excluded |= TestBase.isWindows() && (category == TestCategory.TARGET || category == TestCategory.ARDUINO); From a84b7e2afaef73252b15d01af35681c595c0a488 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 22:58:36 -0800 Subject: [PATCH 30/63] Update Zephyr CI --- .github/workflows/c-zephyr-tests.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index ccca8d9ac4..02951b7963 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -35,12 +35,12 @@ jobs: fetch-depth: 0 - name: Install java and others run : | - apt update - wget https://download.oracle.com/java/17/archive/jdk-17.0.5_linux-x64_bin.tar.gz - tar xvzf jdk-17.0.5_linux-x64_bin.tar.gz -C /opt - export JAVA_HOME=/opt/jdk-17.0.5 - export PATH=$PATH:$JAVA_HOME/bin - apt install maven -y + apt update + wget https://download.oracle.com/java/17/archive/jdk-17.0.5_linux-x64_bin.tar.gz + tar xvzf jdk-17.0.5_linux-x64_bin.tar.gz -C /opt + export JAVA_HOME=/opt/jdk-17.0.5 + export PATH=$PATH:$JAVA_HOME/bin + apt install maven -y - name: Prepare build environment uses: ./.github/actions/prepare-build-env From bb69449ada0f39a110a8ece4e49896640f0442f8 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 23:23:36 -0800 Subject: [PATCH 31/63] Install gradle to zephyr ci container --- .github/workflows/c-zephyr-tests.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 02951b7963..09b74ba054 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -36,11 +36,20 @@ jobs: - name: Install java and others run : | apt update - wget https://download.oracle.com/java/17/archive/jdk-17.0.5_linux-x64_bin.tar.gz - tar xvzf jdk-17.0.5_linux-x64_bin.tar.gz -C /opt - export JAVA_HOME=/opt/jdk-17.0.5 + JAVA_VERSION=17.0.5. + wget https://download.oracle.com/java/17/archive/jdk-${JAVA_VERSION}_linux-x64_bin.tar.gz + tar xvzf jdk-${JAVA_VERSION}_linux-x64_bin.tar.gz -C /opt + export JAVA_HOME=/opt/jdk-${JAVA_VERSION} export PATH=$PATH:$JAVA_HOME/bin apt install maven -y + GRADLE_VERSION=6.5.1 + wget + https://services.gradle.org/distributions/gradle-${VERSION}-bin.zip -P + /tmp + sudo unzip -d /opt/gradle /tmp/gradle-${VERSION}-bin.zip + sudo ln -s /opt/gradle/gradle-${VERSION} /opt/gradle/latest + export GRADLE_HOME=/opt/gradle/latest + export PATH=${GRADLE_HOME}/bin:${PATH} - name: Prepare build environment uses: ./.github/actions/prepare-build-env From 63e8eb2d00ba9e0fd730c2c18e86f4ee5803abb5 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Tue, 10 Jan 2023 23:50:50 -0800 Subject: [PATCH 32/63] Download and install zephyr in CI --- .github/workflows/c-zephyr-tests.yml | 39 ++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 09b74ba054..650eeee0c3 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -20,12 +20,41 @@ on: jobs: run: runs-on: ubuntu-latest - # FIXME: Can we specify the Zephyr version? We are currently hardcoding a - # requirement on exactly v3.2.0 - container: zephyrprojectrtos/ci:latest - env: - CMAKE_PREFIX_PATH: /opt/toolchains steps: + - name: Install zephyr and west + run : | + apt update && apt upgrade -y + wget https://apt.kitware.com/kitware-archive.sh + bash kitware-archive.sh + apt install --no-install-recommends git cmake ninja-build gperf \ + ccache dfu-util device-tree-compiler wget \ + python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ + make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 + sudo apt install python3-venv + python3 -m venv ~/zephyrproject/.venv + source ~/zephyrproject/.venv/bin/activate + pip install west + ZEPHYR_VERSION=v3.2.0 + west init --mr ${ZEPHYR_VERSION} ~/zephyrproject + cd ~/zephyrproject + west update + west zephyr-export + pip install -r ~/zephyrproject/zephyr/scripts/requirements.txt + + SDK_VERSION=0.15.2 + cd ~ + wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/zephyr-sdk-${SDK_VERSION}?linux-x86_64.tar.gz + wget -O - + https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/sha256.sum + | shasum --check --ignore-missing + + tar xvf zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz /opt + cd /opt/zephyr-sdk-${SDK_VERSION} + ./setup.sh + + sudo cp ~/zephyr-sdk-${SDK_VERSION}/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d + sudo udevadm control --reload + - name: Check out lingua-franca repository uses: actions/checkout@v3 with: From ab7024d6a353fc79d82c06ea0d1e5be7c7b5563c Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Wed, 11 Jan 2023 00:10:24 -0800 Subject: [PATCH 33/63] CI --- .github/workflows/c-zephyr-tests.yml | 60 ++++++++++++++-------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 650eeee0c3..90019ea0fc 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -21,39 +21,41 @@ jobs: run: runs-on: ubuntu-latest steps: + #FIXME: The ZEPHYR_VERSION and SDK_VERSION should not be hard-coded here. + # But I dont know where... - name: Install zephyr and west - run : | - apt update && apt upgrade -y - wget https://apt.kitware.com/kitware-archive.sh - bash kitware-archive.sh - apt install --no-install-recommends git cmake ninja-build gperf \ - ccache dfu-util device-tree-compiler wget \ - python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ - make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 - sudo apt install python3-venv - python3 -m venv ~/zephyrproject/.venv - source ~/zephyrproject/.venv/bin/activate - pip install west - ZEPHYR_VERSION=v3.2.0 - west init --mr ${ZEPHYR_VERSION} ~/zephyrproject - cd ~/zephyrproject - west update - west zephyr-export - pip install -r ~/zephyrproject/zephyr/scripts/requirements.txt + run : | + apt update && apt upgrade -y + wget https://apt.kitware.com/kitware-archive.sh + bash kitware-archive.sh + apt install --no-install-recommends git cmake ninja-build gperf \ + ccache dfu-util device-tree-compiler wget \ + python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ + make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 + sudo apt install python3-venv + python3 -m venv ~/zephyrproject/.venv + source ~/zephyrproject/.venv/bin/activate + pip install west + ZEPHYR_VERSION=v3.2.0 + west init --mr ${ZEPHYR_VERSION} ~/zephyrproject + cd ~/zephyrproject + west update + west zephyr-export + pip install -r ~/zephyrproject/zephyr/scripts/requirements.txt - SDK_VERSION=0.15.2 - cd ~ - wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/zephyr-sdk-${SDK_VERSION}?linux-x86_64.tar.gz - wget -O - - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/sha256.sum - | shasum --check --ignore-missing + SDK_VERSION=0.15.2 + cd ~ + wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/zephyr-sdk-${SDK_VERSION}?linux-x86_64.tar.gz + wget -O - + https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/sha256.sum + | shasum --check --ignore-missing - tar xvf zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz /opt - cd /opt/zephyr-sdk-${SDK_VERSION} - ./setup.sh + tar xvf zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz /opt + cd /opt/zephyr-sdk-${SDK_VERSION} + ./setup.sh - sudo cp ~/zephyr-sdk-${SDK_VERSION}/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d - sudo udevadm control --reload + sudo cp ~/zephyr-sdk-${SDK_VERSION}/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d + sudo udevadm control --reload - name: Check out lingua-franca repository uses: actions/checkout@v3 From cba6968b6819f35fadc5da9c3f0e13a6ed93b184 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Wed, 11 Jan 2023 08:08:50 -0800 Subject: [PATCH 34/63] CI --- .github/workflows/c-zephyr-tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 90019ea0fc..8f5b4aec90 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -25,10 +25,10 @@ jobs: # But I dont know where... - name: Install zephyr and west run : | - apt update && apt upgrade -y + sudo apt update && sudo apt upgrade -y wget https://apt.kitware.com/kitware-archive.sh - bash kitware-archive.sh - apt install --no-install-recommends git cmake ninja-build gperf \ + sudo bash kitware-archive.sh + sudo apt install --no-install-recommends git cmake ninja-build gperf \ ccache dfu-util device-tree-compiler wget \ python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 From 1e6afe951a52f739decbcc8081d9e4f461c42559 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Wed, 11 Jan 2023 08:19:00 -0800 Subject: [PATCH 35/63] CI --- .github/workflows/c-zephyr-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 8f5b4aec90..062a064456 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -45,7 +45,7 @@ jobs: SDK_VERSION=0.15.2 cd ~ - wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/zephyr-sdk-${SDK_VERSION}?linux-x86_64.tar.gz + wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/sha256.sum | shasum --check --ignore-missing From 70bbb2d7a38a19ab9cfc87106909a4de638bf04b Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Wed, 11 Jan 2023 09:05:03 -0800 Subject: [PATCH 36/63] CI --- .github/workflows/c-zephyr-tests.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 062a064456..cb9702034d 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -46,9 +46,7 @@ jobs: SDK_VERSION=0.15.2 cd ~ wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz - wget -O - - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/sha256.sum - | shasum --check --ignore-missing + wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/sha256.sum | shasum --check --ignore-missing tar xvf zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz /opt cd /opt/zephyr-sdk-${SDK_VERSION} From bcb2c8cb2e80e174d3da0f01a06c4ab7f9698a92 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Wed, 11 Jan 2023 09:33:49 -0800 Subject: [PATCH 37/63] CI --- .github/workflows/c-zephyr-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index cb9702034d..68c714731e 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -48,7 +48,7 @@ jobs: wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/sha256.sum | shasum --check --ignore-missing - tar xvf zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz /opt + tar xvf zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz --directory /opt cd /opt/zephyr-sdk-${SDK_VERSION} ./setup.sh From ea7ce7ce50604b73f8903b15748aa337c3a59c52 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 01:01:56 -0800 Subject: [PATCH 38/63] Remove zephyr tests from CI --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ab25a330c..0eb8b54aa6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,10 +63,11 @@ jobs: uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master needs: cancel + # FIXME: Find a way to efficiently install zephyr in CI. Maybe pull-down a docker container? # Run the C Zephyr integration tests. - c-zephyr-tests: - uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@c-zephyr-support - needs: cancel + # c-zephyr-tests: + # uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@c-zephyr-support + # needs: cancel # Run the CCpp integration tests. ccpp-tests: From 539a4719a6936cea3b8f43e8e891a1f669134f45 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 01:20:39 -0800 Subject: [PATCH 39/63] Try docker container for zephyr build --- .github/workflows/c-zephyr-tests.yml | 36 ++-------------------------- .github/workflows/ci.yml | 8 +++---- 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 68c714731e..bebeb7b28d 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -20,41 +20,9 @@ on: jobs: run: runs-on: ubuntu-latest + container: + image: zephyrprojectrtos/zephyr-build:latest steps: - #FIXME: The ZEPHYR_VERSION and SDK_VERSION should not be hard-coded here. - # But I dont know where... - - name: Install zephyr and west - run : | - sudo apt update && sudo apt upgrade -y - wget https://apt.kitware.com/kitware-archive.sh - sudo bash kitware-archive.sh - sudo apt install --no-install-recommends git cmake ninja-build gperf \ - ccache dfu-util device-tree-compiler wget \ - python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ - make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 - sudo apt install python3-venv - python3 -m venv ~/zephyrproject/.venv - source ~/zephyrproject/.venv/bin/activate - pip install west - ZEPHYR_VERSION=v3.2.0 - west init --mr ${ZEPHYR_VERSION} ~/zephyrproject - cd ~/zephyrproject - west update - west zephyr-export - pip install -r ~/zephyrproject/zephyr/scripts/requirements.txt - - SDK_VERSION=0.15.2 - cd ~ - wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz - wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${SDK_VERSION}/sha256.sum | shasum --check --ignore-missing - - tar xvf zephyr-sdk-${SDK_VERSION}_linux-x86_64.tar.gz --directory /opt - cd /opt/zephyr-sdk-${SDK_VERSION} - ./setup.sh - - sudo cp ~/zephyr-sdk-${SDK_VERSION}/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d - sudo udevadm control --reload - - name: Check out lingua-franca repository uses: actions/checkout@v3 with: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0eb8b54aa6..4bd836337f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,10 +64,10 @@ jobs: needs: cancel # FIXME: Find a way to efficiently install zephyr in CI. Maybe pull-down a docker container? - # Run the C Zephyr integration tests. - # c-zephyr-tests: - # uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@c-zephyr-support - # needs: cancel + Run the C Zephyr integration tests. + c-zephyr-tests: + uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@c-zephyr-support + needs: cancel # Run the CCpp integration tests. ccpp-tests: From 0e13a555551337a422c9790a08f82ca1a5c675aa Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 01:22:02 -0800 Subject: [PATCH 40/63] Fix mistake --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4bd836337f..e178cb0626 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: needs: cancel # FIXME: Find a way to efficiently install zephyr in CI. Maybe pull-down a docker container? - Run the C Zephyr integration tests. + # Run the C Zephyr integration tests. c-zephyr-tests: uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@c-zephyr-support needs: cancel From f83b51d740069e72e68f2450b03ec6015dda396a Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 01:39:54 -0800 Subject: [PATCH 41/63] CI Zephyr --- .github/workflows/c-zephyr-tests.yml | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index bebeb7b28d..7a88faf449 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -20,8 +20,6 @@ on: jobs: run: runs-on: ubuntu-latest - container: - image: zephyrprojectrtos/zephyr-build:latest steps: - name: Check out lingua-franca repository uses: actions/checkout@v3 @@ -30,24 +28,6 @@ jobs: submodules: true ref: ${{ inputs.compiler-ref }} fetch-depth: 0 - - name: Install java and others - run : | - apt update - JAVA_VERSION=17.0.5. - wget https://download.oracle.com/java/17/archive/jdk-${JAVA_VERSION}_linux-x64_bin.tar.gz - tar xvzf jdk-${JAVA_VERSION}_linux-x64_bin.tar.gz -C /opt - export JAVA_HOME=/opt/jdk-${JAVA_VERSION} - export PATH=$PATH:$JAVA_HOME/bin - apt install maven -y - GRADLE_VERSION=6.5.1 - wget - https://services.gradle.org/distributions/gradle-${VERSION}-bin.zip -P - /tmp - sudo unzip -d /opt/gradle /tmp/gradle-${VERSION}-bin.zip - sudo ln -s /opt/gradle/gradle-${VERSION} /opt/gradle/latest - export GRADLE_HOME=/opt/gradle/latest - export PATH=${GRADLE_HOME}/bin:${PATH} - - name: Prepare build environment uses: ./.github/actions/prepare-build-env - name: Check out specific ref of reactor-c @@ -60,3 +40,4 @@ jobs: - name: Perform Zephyr tests for C target with default scheduler run: | ./gradlew test --tests org.lflang.tests.runtime.CZephyrTests.* + uses: docker://zephyrprojectrtos/zephyr-build:latest From d55d45aeeec393f7a822d9e27c04c7ffba4bdbc0 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 01:40:53 -0800 Subject: [PATCH 42/63] Zephyr CI --- .github/workflows/c-zephyr-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 7a88faf449..87a94f9693 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -38,6 +38,6 @@ jobs: ref: ${{ inputs.runtime-ref }} if: ${{ inputs.runtime-ref }} - name: Perform Zephyr tests for C target with default scheduler + uses: docker://zephyrprojectrtos/zephyr-build:latest run: | ./gradlew test --tests org.lflang.tests.runtime.CZephyrTests.* - uses: docker://zephyrprojectrtos/zephyr-build:latest From f40c664b084cc8cc7acd9c141fb896e6c4a99426 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 01:45:23 -0800 Subject: [PATCH 43/63] CI Zephyr --- .github/workflows/c-zephyr-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 87a94f9693..a9d5b735f1 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -38,6 +38,7 @@ jobs: ref: ${{ inputs.runtime-ref }} if: ${{ inputs.runtime-ref }} - name: Perform Zephyr tests for C target with default scheduler - uses: docker://zephyrprojectrtos/zephyr-build:latest + container: + image: zephyrprojectrtos/zephyr-build:latest run: | ./gradlew test --tests org.lflang.tests.runtime.CZephyrTests.* From 97338958b5dae0356aaf084e0bef399970c05419 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 01:50:14 -0800 Subject: [PATCH 44/63] Uses checkout@v2 for zephyr CI --- .github/workflows/c-zephyr-tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index a9d5b735f1..6c53aa0e51 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -20,9 +20,11 @@ on: jobs: run: runs-on: ubuntu-latest + container: + image: zephyrprojectrtos/zephyr-build:latest steps: - name: Check out lingua-franca repository - uses: actions/checkout@v3 + uses: actions/checkout@v2 with: repository: lf-lang/lingua-franca submodules: true @@ -38,7 +40,5 @@ jobs: ref: ${{ inputs.runtime-ref }} if: ${{ inputs.runtime-ref }} - name: Perform Zephyr tests for C target with default scheduler - container: - image: zephyrprojectrtos/zephyr-build:latest run: | ./gradlew test --tests org.lflang.tests.runtime.CZephyrTests.* From 641ff081f6c6721bbb67473139faf2f489fc3aeb Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 01:56:32 -0800 Subject: [PATCH 45/63] Use v2 for all checkouts --- .github/workflows/c-zephyr-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 6c53aa0e51..a98917eb88 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -22,6 +22,7 @@ jobs: runs-on: ubuntu-latest container: image: zephyrprojectrtos/zephyr-build:latest + options: -u root --entrypoint /bin/sh steps: - name: Check out lingua-franca repository uses: actions/checkout@v2 @@ -33,7 +34,7 @@ jobs: - name: Prepare build environment uses: ./.github/actions/prepare-build-env - name: Check out specific ref of reactor-c - uses: actions/checkout@v3 + uses: actions/checkout@v2 with: repository: lf-lang/reactor-c path: org.lflang/src/lib/c/reactor-c From 653fdc7639dcd70d08f95afcb78d7e4d7e047efb Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 09:45:03 -0800 Subject: [PATCH 46/63] Ci zephyr --- .github/workflows/c-zephyr-tests.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index a98917eb88..b5c60f7b10 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -24,8 +24,23 @@ jobs: image: zephyrprojectrtos/zephyr-build:latest options: -u root --entrypoint /bin/sh steps: + - name: Install Java 17, Maven and set JAVA_HOME + run: | + sudo apt-get update + sudo apt-get install -y openjdk-17-jdk + sudo apt-get install -y maven + echo "export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64" | sudo tee -a /etc/environment + source /etc/environment + steps: + - name: Initialize zephyr + run: | + ZEPHYR_INSTALL=/workdir/zephyrproject + west init $ZEPHYR_INSTALL --mr v3.2.0 + cd $ZEPHYR_INSTALL + west update + export ZEPHYR_BASE $ZEPHYR_INSTALL/zephyr - name: Check out lingua-franca repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: lf-lang/lingua-franca submodules: true @@ -34,7 +49,7 @@ jobs: - name: Prepare build environment uses: ./.github/actions/prepare-build-env - name: Check out specific ref of reactor-c - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: lf-lang/reactor-c path: org.lflang/src/lib/c/reactor-c From 5f6a9c47c79bbcc954f56ec4ceac5d786db37d44 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 09:46:57 -0800 Subject: [PATCH 47/63] CI --- .github/workflows/c-zephyr-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index b5c60f7b10..261eb713e3 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -31,7 +31,6 @@ jobs: sudo apt-get install -y maven echo "export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64" | sudo tee -a /etc/environment source /etc/environment - steps: - name: Initialize zephyr run: | ZEPHYR_INSTALL=/workdir/zephyrproject From 49c67846473f4d75decdad8a32671334bac4ba66 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 09:56:36 -0800 Subject: [PATCH 48/63] CI --- .github/workflows/c-zephyr-tests.yml | 5 ++--- .../src/org/lflang/tests/runtime/CZephyrTest.java | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 261eb713e3..915e3e6f58 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -29,8 +29,7 @@ jobs: sudo apt-get update sudo apt-get install -y openjdk-17-jdk sudo apt-get install -y maven - echo "export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64" | sudo tee -a /etc/environment - source /etc/environment + export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 - name: Initialize zephyr run: | ZEPHYR_INSTALL=/workdir/zephyrproject @@ -56,4 +55,4 @@ jobs: if: ${{ inputs.runtime-ref }} - name: Perform Zephyr tests for C target with default scheduler run: | - ./gradlew test --tests org.lflang.tests.runtime.CZephyrTests.* + ./gradlew test --tests org.lflang.tests.runtime.CZephyrTest.* diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java index 8898343b43..3d9eed40c9 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java @@ -55,12 +55,12 @@ public void runZephyrTests() { false); } @Test - public void runGenericTests() { - Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); - super.runTestsFor(List.of(Target.C), - Message.DESC_GENERIC, - TestCategory.GENERIC::equals, Configurators::makeZephyrCompatible, - false); - } + // public void runGenericTests() { + // Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); + // super.runTestsFor(List.of(Target.C), + // Message.DESC_GENERIC, + // TestCategory.GENERIC::equals, Configurators::makeZephyrCompatible, + // false); + // } } From 1d0d3696842b2ac5cf4a28604a926fc587e87dd8 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 10:28:51 -0800 Subject: [PATCH 49/63] CI --- .github/workflows/c-zephyr-tests.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 915e3e6f58..a9b18f5ccb 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -32,11 +32,10 @@ jobs: export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 - name: Initialize zephyr run: | - ZEPHYR_INSTALL=/workdir/zephyrproject - west init $ZEPHYR_INSTALL --mr v3.2.0 - cd $ZEPHYR_INSTALL + west init /workdir/zephyrproject --mr v3.2.0 + cd /workdir/zephyrproject west update - export ZEPHYR_BASE $ZEPHYR_INSTALL/zephyr + export ZEPHYR_BASE=/workdir/zephyrproject/zephyr - name: Check out lingua-franca repository uses: actions/checkout@v3 with: From 435683d8d168a2564889b8d4ad66f11842a33bb0 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 10:29:27 -0800 Subject: [PATCH 50/63] Fix test file --- org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java index 3d9eed40c9..335aba4125 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java @@ -54,7 +54,7 @@ public void runZephyrTests() { TestCategory.ZEPHYR::equals, Configurators::makeZephyrCompatible, false); } - @Test + // @Test // public void runGenericTests() { // Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); // super.runTestsFor(List.of(Target.C), From 76da87ca46bd5d5773d64abc04fea56e539e483c Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 11:22:48 -0800 Subject: [PATCH 51/63] JAVA_HOME issues --- .github/workflows/c-zephyr-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index a9b18f5ccb..7ce7285434 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -29,7 +29,7 @@ jobs: sudo apt-get update sudo apt-get install -y openjdk-17-jdk sudo apt-get install -y maven - export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 + export JAVA_HOME_17_X64=/usr/lib/jvm/java-17-openjdk-amd64 - name: Initialize zephyr run: | west init /workdir/zephyrproject --mr v3.2.0 From d21a4bc5ac083de01a2d314c2a56726a416c1908 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 11:50:25 -0800 Subject: [PATCH 52/63] CI: Set environment variables properly --- .github/workflows/c-zephyr-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 7ce7285434..5962e26c03 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -29,13 +29,13 @@ jobs: sudo apt-get update sudo apt-get install -y openjdk-17-jdk sudo apt-get install -y maven - export JAVA_HOME_17_X64=/usr/lib/jvm/java-17-openjdk-amd64 + echo "JAVA_HOME_17_X64=/usr/lib/jvm/java-17-openjdk-amd64" >> $GITHUB_ENV - name: Initialize zephyr run: | west init /workdir/zephyrproject --mr v3.2.0 cd /workdir/zephyrproject west update - export ZEPHYR_BASE=/workdir/zephyrproject/zephyr + echo "ZEPHYR_BASE=/workdir/zephyrproject/zephyr" >> $GITHUB_ENV - name: Check out lingua-franca repository uses: actions/checkout@v3 with: From c472b1d0b1c16fb58a54c91f35d118b21c5b8ee5 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 14:03:04 -0800 Subject: [PATCH 53/63] Git safe issue --- .github/workflows/c-zephyr-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index 5962e26c03..ea3c8259af 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -52,6 +52,9 @@ jobs: path: org.lflang/src/lib/c/reactor-c ref: ${{ inputs.runtime-ref }} if: ${{ inputs.runtime-ref }} + - name: Fix git safe issue + run: | + git config --add safe.directory * --global - name: Perform Zephyr tests for C target with default scheduler run: | ./gradlew test --tests org.lflang.tests.runtime.CZephyrTest.* From f884466faeea1cc93bdd3434e35fa827c102dd73 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 14:21:39 -0800 Subject: [PATCH 54/63] git safe --- .github/workflows/c-zephyr-tests.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index ea3c8259af..dbf1346740 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -52,9 +52,8 @@ jobs: path: org.lflang/src/lib/c/reactor-c ref: ${{ inputs.runtime-ref }} if: ${{ inputs.runtime-ref }} - - name: Fix git safe issue - run: | - git config --add safe.directory * --global + - name: Try to get around git safe issues + run: chown root:root . + - name: Perform Zephyr tests for C target with default scheduler - run: | - ./gradlew test --tests org.lflang.tests.runtime.CZephyrTest.* + run: ./gradlew test --tests org.lflang.tests.runtime.CZephyrTest.* From 3f6c7f6147d33a7eb761dad27cb7ac32f13f4017 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 15:19:57 -0800 Subject: [PATCH 55/63] Try to fix zephyr SDK include error --- .github/workflows/c-zephyr-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/c-zephyr-tests.yml b/.github/workflows/c-zephyr-tests.yml index dbf1346740..8ad846c999 100644 --- a/.github/workflows/c-zephyr-tests.yml +++ b/.github/workflows/c-zephyr-tests.yml @@ -36,6 +36,7 @@ jobs: cd /workdir/zephyrproject west update echo "ZEPHYR_BASE=/workdir/zephyrproject/zephyr" >> $GITHUB_ENV + echo "ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-0.15.2/" >> $GITHUB_ENV - name: Check out lingua-franca repository uses: actions/checkout@v3 with: @@ -56,4 +57,4 @@ jobs: run: chown root:root . - name: Perform Zephyr tests for C target with default scheduler - run: ./gradlew test --tests org.lflang.tests.runtime.CZephyrTest.* + run: ./gradlew test --tests org.lflang.tests.runtime.CZephyrTest.runZephyrTests From e5e67931698cc199d22deceed3812bbd10a60e2f Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 15:54:34 -0800 Subject: [PATCH 56/63] Set target properties of Zepyr tests such that flashing is disabled. --- .../src/org/lflang/tests/Configurators.java | 16 ++++++++-------- .../org/lflang/tests/runtime/CZephyrTest.java | 2 +- test/C/src/zephyr/Blinky2.lf | 3 +-- test/C/src/zephyr/HelloZephyr.lf | 3 +-- test/C/src/zephyr/Timer.lf | 5 ++++- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/Configurators.java b/org.lflang.tests/src/org/lflang/tests/Configurators.java index c13f072c77..36ec20aba5 100644 --- a/org.lflang.tests/src/org/lflang/tests/Configurators.java +++ b/org.lflang.tests/src/org/lflang/tests/Configurators.java @@ -63,15 +63,15 @@ public static boolean disableThreading(LFTest test) { } - public static boolean makeZephyrCompatible(LFTest test) { + // TODO: In the future we want to execute to the test with QEMU + // but it requires parsing QEMU output until either: + // 1) A timeout + // 2) "exit" is printed to stdout. Then look if there is a FATAL ERROR printed somewhere + // So it would requre continously parsing the stdout and waiting for exit keyword + public static boolean platformZephyrQemuNoFlash(LFTest test) { test.getContext().getArgs().setProperty("threading", "false"); - test.getContext().getArgs().setProperty("platform.name", "Zephyr"); - test.getContext().getArgs().setProperty("platform.board", "qemu_cortex_m3"); - // TODO: In the future we want to execute to the test with QEMU - // but it requires parsing QEMU output until either: - // 1) A timeout - // 2) "exit" is printed to stdout. Then look if there is a FATAL ERROR printed somewhere - test.getContext().getArgs().setProperty("platform.flash", "false"); + // TODO: How can I set platform as a dictionary (platform.board platform.flash etc) + // test.getContext().getArgs().setProperty("platform", "Zephyr"); return true; } /** diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java index 335aba4125..d2d2876658 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java @@ -51,7 +51,7 @@ public void runZephyrTests() { Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); super.runTestsFor(List.of(Target.C), Message.DESC_ZEPHYR, - TestCategory.ZEPHYR::equals, Configurators::makeZephyrCompatible, + TestCategory.ZEPHYR::equals, Configurators::platformZephyrQemuNoFlash, false); } // @Test diff --git a/test/C/src/zephyr/Blinky2.lf b/test/C/src/zephyr/Blinky2.lf index 9fbaa42ebf..5fb6d6a53b 100644 --- a/test/C/src/zephyr/Blinky2.lf +++ b/test/C/src/zephyr/Blinky2.lf @@ -1,8 +1,7 @@ target C { platform: { - name: "Zephyr", + name: Zephyr, board: nrf52dk_nrf52832, - flash: true }, threading: false } diff --git a/test/C/src/zephyr/HelloZephyr.lf b/test/C/src/zephyr/HelloZephyr.lf index 0e858d02e0..2d55119ee2 100644 --- a/test/C/src/zephyr/HelloZephyr.lf +++ b/test/C/src/zephyr/HelloZephyr.lf @@ -2,8 +2,7 @@ target C { threading: false, platform: { name: Zephyr, - board: nrf52dk_nrf52832, - flash: true + board: qemu_cortex_m3, } } diff --git a/test/C/src/zephyr/Timer.lf b/test/C/src/zephyr/Timer.lf index 1a389d03dc..950fef04d5 100644 --- a/test/C/src/zephyr/Timer.lf +++ b/test/C/src/zephyr/Timer.lf @@ -1,5 +1,8 @@ target C { - platform: "Zephyr", + platform: { + name: Zephyr, + board: qemu_cortex_m3, + }, threading: false } From e3029a6d06bb1f9cadc8b78904ae6c27ec11729c Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Thu, 12 Jan 2023 18:23:30 -0800 Subject: [PATCH 57/63] Run formatter --- test/C/src/zephyr/Blinky2.lf | 2 +- test/C/src/zephyr/HelloZephyr.lf | 2 +- test/C/src/zephyr/Timer.lf | 2 +- test/C/src/zephyr/lib/Led.lf | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/test/C/src/zephyr/Blinky2.lf b/test/C/src/zephyr/Blinky2.lf index 5fb6d6a53b..039bb0172e 100644 --- a/test/C/src/zephyr/Blinky2.lf +++ b/test/C/src/zephyr/Blinky2.lf @@ -1,7 +1,7 @@ target C { platform: { name: Zephyr, - board: nrf52dk_nrf52832, + board: nrf52dk_nrf52832 }, threading: false } diff --git a/test/C/src/zephyr/HelloZephyr.lf b/test/C/src/zephyr/HelloZephyr.lf index 2d55119ee2..2c4a98890f 100644 --- a/test/C/src/zephyr/HelloZephyr.lf +++ b/test/C/src/zephyr/HelloZephyr.lf @@ -2,7 +2,7 @@ target C { threading: false, platform: { name: Zephyr, - board: qemu_cortex_m3, + board: qemu_cortex_m3 } } diff --git a/test/C/src/zephyr/Timer.lf b/test/C/src/zephyr/Timer.lf index 950fef04d5..cac30ae9b1 100644 --- a/test/C/src/zephyr/Timer.lf +++ b/test/C/src/zephyr/Timer.lf @@ -1,7 +1,7 @@ target C { platform: { name: Zephyr, - board: qemu_cortex_m3, + board: qemu_cortex_m3 }, threading: false } diff --git a/test/C/src/zephyr/lib/Led.lf b/test/C/src/zephyr/lib/Led.lf index 53293362c9..04999cf14b 100644 --- a/test/C/src/zephyr/lib/Led.lf +++ b/test/C/src/zephyr/lib/Led.lf @@ -1,5 +1,4 @@ -target C; - +target C reactor NrfLeds { preamble {= From 0fe9742689924fde371dcce6af659412eb4a042b Mon Sep 17 00:00:00 2001 From: erling Date: Fri, 13 Jan 2023 16:41:29 -0800 Subject: [PATCH 58/63] Apply suggestions from code review Co-authored-by: Peter Donovan <33707478+petervdonovan@users.noreply.github.com> --- org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java | 4 ++-- org.lflang/src/org/lflang/generator/c/CGenerator.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 8ecb18e8a5..35a4a8e3ad 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -120,8 +120,8 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("cmake_minimum_required(VERSION " + MIN_CMAKE_VERSION + ")"); if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { - cMakeCode.pr("# Set default configuration file. To add custom configurations"); - cMakeCode.pr("# Pass -- -DOVERLAY_CONFIG=my_config.prj to either cmake or west"); + cMakeCode.pr("# Set default configuration file. To add custom configurations,"); + cMakeCode.pr("# pass -- -DOVERLAY_CONFIG=my_config.prj to either cmake or west"); cMakeCode.pr("set(CONF_FILE prj_lf.conf)"); if (targetConfig.platformOptions.board != null) { cMakeCode.pr("# Selecting board specified in target property"); diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.java b/org.lflang/src/org/lflang/generator/c/CGenerator.java index fd787e315c..ebf5789b83 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.java @@ -590,7 +590,6 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { StringBuilder s = new StringBuilder(); s.append("set(ARDUINO_BOARD \""); -// s.append(targetConfig.platformOptions.board.getBoardName()); s.append("\")"); FileUtil.writeToFile(s.toString(), fileConfig.getSrcGenPath().resolve("toolchain/BoardOptions.cmake")); From ebff551f4451c8003e8ab4f22fefd9662bc72764 Mon Sep 17 00:00:00 2001 From: erling Date: Fri, 13 Jan 2023 16:42:28 -0800 Subject: [PATCH 59/63] Apply suggestions from code review --- .github/workflows/ci.yml | 1 - org.lflang.tests/src/org/lflang/tests/Configurators.java | 1 - .../src/org/lflang/tests/runtime/CZephyrTest.java | 8 -------- 3 files changed, 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e178cb0626..3ab25a330c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,7 +63,6 @@ jobs: uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master needs: cancel - # FIXME: Find a way to efficiently install zephyr in CI. Maybe pull-down a docker container? # Run the C Zephyr integration tests. c-zephyr-tests: uses: lf-lang/lingua-franca/.github/workflows/c-zephyr-tests.yml@c-zephyr-support diff --git a/org.lflang.tests/src/org/lflang/tests/Configurators.java b/org.lflang.tests/src/org/lflang/tests/Configurators.java index 36ec20aba5..81e015dfbf 100644 --- a/org.lflang.tests/src/org/lflang/tests/Configurators.java +++ b/org.lflang.tests/src/org/lflang/tests/Configurators.java @@ -62,7 +62,6 @@ public static boolean disableThreading(LFTest test) { return true; } - // TODO: In the future we want to execute to the test with QEMU // but it requires parsing QEMU output until either: // 1) A timeout diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java index d2d2876658..b63765c0f0 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CZephyrTest.java @@ -54,13 +54,5 @@ public void runZephyrTests() { TestCategory.ZEPHYR::equals, Configurators::platformZephyrQemuNoFlash, false); } - // @Test - // public void runGenericTests() { - // Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux"); - // super.runTestsFor(List.of(Target.C), - // Message.DESC_GENERIC, - // TestCategory.GENERIC::equals, Configurators::makeZephyrCompatible, - // false); - // } } From bfcca38742058a3b7d4850e3348b284bcb95db06 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Sat, 14 Jan 2023 20:56:19 +0100 Subject: [PATCH 60/63] Code generate call to exit() instead of return in main for zephyr --- org.lflang/src/lib/c/reactor-c | 2 +- .../generator/c/CMainFunctionGenerator.java | 21 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index ad95c07efe..26aefadf9e 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit ad95c07efe2fe5c68d8d597904aef6d81fb37f61 +Subproject commit 26aefadf9ec001785c8f6cfb16198d75f55c7e02 diff --git a/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java b/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java index 7b05a52923..f7ef30869b 100644 --- a/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java @@ -51,13 +51,22 @@ private String generateMainFunction() { "}", "void loop() {}" ); + } else if (targetConfig.platformOptions.platform == Platform.ZEPHYR) { + // The Zephyr "runtime" does not terminate when main returns. + // Rather, `exit` should be called explicitly. + return String.join("\n", + "void main(void) {", + " int res = lf_reactor_c_main(0, NULL);", + " exit(res);" + "}" + ); + } else { + return String.join("\n", + "int main(int argc, const char* argv[]) {", + " return lf_reactor_c_main(argc, argv);", + "}" + ); } - return String.join("\n", - "int main(int argc, const char* argv[]) {", - " return lf_reactor_c_main(argc, argv);", - "}" - ); - } /** * Generate code that is used to override the From ea2dfc8051ce1a424512e27d89622f6693b53c7d Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Sat, 14 Jan 2023 21:01:31 +0100 Subject: [PATCH 61/63] Typo --- .../src/org/lflang/generator/c/CMainFunctionGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java b/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java index f7ef30869b..07dbcab5d1 100644 --- a/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java @@ -57,7 +57,7 @@ private String generateMainFunction() { return String.join("\n", "void main(void) {", " int res = lf_reactor_c_main(0, NULL);", - " exit(res);" + " exit(res);", "}" ); } else { From e95aedf149fa409ca65eb439b92e499705480882 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Sat, 14 Jan 2023 21:11:33 +0100 Subject: [PATCH 62/63] Typo --- .../src/org/lflang/generator/c/CMainFunctionGenerator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java b/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java index 07dbcab5d1..f34f46345c 100644 --- a/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CMainFunctionGenerator.java @@ -67,6 +67,7 @@ private String generateMainFunction() { "}" ); } + } /** * Generate code that is used to override the From b7df70d3354079050d71fb1e655913a274761d81 Mon Sep 17 00:00:00 2001 From: Erling Rennemo Jellum Date: Sat, 14 Jan 2023 23:53:01 +0100 Subject: [PATCH 63/63] update reactor-c ref --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 26aefadf9e..d42631aa69 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 26aefadf9ec001785c8f6cfb16198d75f55c7e02 +Subproject commit d42631aa6902e98f0808a55bf6cef72b50bb7619