Skip to content

Commit

Permalink
Merge branch 'master' into spotbugs-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cmnrd authored Sep 20, 2023
2 parents 600c44d + d4c3ae4 commit 8fc7341
Show file tree
Hide file tree
Showing 49 changed files with 386 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-zephyr/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ runs:
- name: Setup environment variables
run: |
echo "SDK_VERSION=0.16.1" >> $GITHUB_ENV
echo "ZEPHYR_VERSION=3.3.0" >> $GITHUB_ENV
echo "ZEPHYR_VERSION=3.4.0" >> $GITHUB_ENV
shell: bash
- name: Dependencies
run: |
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/c-zephyr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ jobs:
if: ${{ inputs.runtime-ref }}
- name: Run Zephyr smoke tests
run: |
./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildZephyr* core:integrationTestCodeCoverageReport
./gradlew core:integrationTest \
--tests org.lflang.tests.runtime.CZephyrTest.buildZephyrUnthreaded* \
--tests org.lflang.tests.runtime.CZephyrTest.buildZephyrThreaded* core:integrationTestCodeCoverageReport
./.github/scripts/run-zephyr-tests.sh test/C/src-gen
rm -r test/C/src-gen
- name: Run basic tests
Expand All @@ -54,6 +56,10 @@ jobs:
./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildConcurrent* core:integrationTestCodeCoverageReport
./.github/scripts/run-zephyr-tests.sh test/C/src-gen
rm -r test/C/src-gen
- name: Run Zephyr board tests
run: |
./gradlew core:integrationTest --tests org.lflang.tests.runtime.CZephyrTest.buildZephyrBoards* core:integrationTestCodeCoverageReport
rm -r test/C/src-gen
- name: Report to CodeCov
uses: ./.github/actions/report-code-coverage
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private static boolean isExcludedFromCCpp(TestCategory category) {
isMac() && (category == TestCategory.DOCKER_FEDERATED || category == TestCategory.DOCKER);
excluded |= category == TestCategory.ZEPHYR_UNTHREADED;
excluded |= category == TestCategory.ZEPHYR_THREADED;
excluded |= category == TestCategory.ZEPHYR_BOARDS;
excluded |= category == TestCategory.ARDUINO;
excluded |= category == TestCategory.NO_INLINING;
excluded |= category == TestCategory.VERIFIER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ public void buildZephyrUnthreadedTests() {
false);
}

@Test
public void buildZephyrBoardsTests() {
Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux");
super.runTestsFor(
List.of(Target.C),
Message.DESC_ZEPHYR,
TestCategory.ZEPHYR_BOARDS::equals,
Configurators::noChanges,
TestLevel.BUILD,
false);
}

@Test
public void buildZephyrThreadedTests() {
Assumptions.assumeTrue(isLinux(), "Zephyr tests only run on Linux");
Expand Down
18 changes: 8 additions & 10 deletions core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ CodeBuilder generateCMakeCode(
cMakeCode.pr("# Selecting default board");
cMakeCode.pr("set(BOARD qemu_cortex_m3)");
}
cMakeCode.pr("# We recommend Zephyr v3.3.0 but we are compatible with older versions also");
cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} 3.3.0)");
cMakeCode.pr("# We recommend Zephyr v3.4.0 but we are compatible with older versions also");
cMakeCode.pr("find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} 3.4.0)");
cMakeCode.newLine();
cMakeCode.pr("project(" + executableName + " LANGUAGES C)");
cMakeCode.newLine();
Expand Down Expand Up @@ -326,25 +326,23 @@ CodeBuilder generateCMakeCode(
cMakeCode.newLine();
}

if (targetConfig.threading) {
if (targetConfig.threading && targetConfig.platformOptions.platform != Platform.ZEPHYR) {
// If threaded computation is requested, add the threads option.
cMakeCode.pr("# Find threads and link to it");
cMakeCode.pr("find_package(Threads REQUIRED)");
cMakeCode.pr("target_link_libraries(${LF_MAIN_TARGET} PRIVATE Threads::Threads)");
cMakeCode.newLine();
// If the LF program itself is threaded, we need to define NUMBER_OF_WORKERS so that
// platform-specific C files will contain the appropriate functions
}

// Add additional flags so runtime can distinguish between multi-threaded and single-threaded
// mode
if (targetConfig.threading) {
cMakeCode.pr("# Set the number of workers to enable threading/tracing");
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");
cMakeCode.pr("target_compile_definitions( ${LF_MAIN_TARGET} PUBLIC LF_THREADED=1)");
} else {
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/resources/lib/platform/zephyr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Zephyr platform files
These are files needed to compile LF programs for the Zephyr target.
All of the files in the `boards` directory are for enabling a Timer peripheral for different devices so that we can use a Counter device for time-keeping. These device tree config overlays are copied from the `alarm` example found in the zephyr source tree under `samples/drivers/counter/alarm`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&tc0 {
clk = <4>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Enable RTC
CONFIG_I2C=y
CONFIG_COUNTER=y
CONFIG_COUNTER_MICROCHIP_MCP7940N=y
CONFIG_COUNTER_INIT_PRIORITY=65
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2021 Laird Connectivity
*
* SPDX-License-Identifier: Apache-2.0
*/

&i2c1 {
/* Connect MCP7940N MFP pin TP9 to P0.04 */
extrtc0: mcp7940n@6f {
int-gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&timer0 {
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&timer0 {
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&timer0 {
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <tokita.hiroshi@gmail.com>
*/

&timer0 {
status = "okay";
prescaler = <29999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <tokita.hiroshi@gmail.com>
*/

&timer0 {
status = "okay";
prescaler = <44999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <tokita.hiroshi@gmail.com>
*/

&timer0 {
status = "okay";
prescaler = <44999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <tokita.hiroshi@gmail.com>
*/

&timer0 {
status = "okay";
prescaler = <26999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <tokita.hiroshi@gmail.com>
*/

&timer0 {
status = "okay";
prescaler = <41999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <tokita.hiroshi@gmail.com>
*/

&timer0 {
status = "okay";
prescaler = <41999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <tokita.hiroshi@gmail.com>
*/

&timer0 {
status = "okay";
prescaler = <49999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <tokita.hiroshi@gmail.com>
*/

&timer0 {
status = "okay";
prescaler = <49999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <tokita.hiroshi@gmail.com>
*/

&timer0 {
status = "okay";
prescaler = <49999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2022 TOKITA Hiroshi <tokita.hiroshi@gmail.com>
*/

&timer0 {
status = "okay";
prescaler = <59999>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&timer1 {
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&rtc0 {
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&timer1 {
status = "okay";
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&rtc0 {
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright 2022 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

&stm0 {
prescaler = <1>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright 2022 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

&stm0 {
prescaler = <1>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&tc0 {
clk = <4>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&tc0 {
clk = <4>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&tc0 {
clk = <4>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&tc0 {
clk = <4>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&tc0 {
clk = <4>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&tc0 {
clk = <4>;
status = "okay";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
&timers2 {
st,prescaler = <83>;
counter {
status = "okay";
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# Copyright (c) 2022 O.S.Systems
#
# SPDX-License-Identifier: Apache-2.0
#
CONFIG_BUILD_WITH_TFM=y
CONFIG_TFM_PROFILE_TYPE_MEDIUM=y
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public static boolean compatibleWithThreadingOff(TestCategory category) {
|| category == TestCategory.ARDUINO
|| category == TestCategory.VERIFIER
|| category == TestCategory.ZEPHYR_UNTHREADED
|| category == TestCategory.ZEPHYR_BOARDS
|| category == TestCategory.ZEPHYR_THREADED;

// SERIALIZATION and TARGET tests are excluded on Windows.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ public enum TestCategory {
ARDUINO(false, "", TestLevel.BUILD),
ZEPHYR_THREADED(false, "zephyr" + File.separator + "threaded", TestLevel.BUILD),
ZEPHYR_UNTHREADED(false, "zephyr" + File.separator + "unthreaded", TestLevel.BUILD),
ZEPHYR_BOARDS(false, "zephyr" + File.separator + "boards", TestLevel.BUILD),
VERIFIER(false, "verifier", TestLevel.EXECUTION),
TARGET(false, "", TestLevel.EXECUTION);

Expand Down
40 changes: 40 additions & 0 deletions test/C/src/UnconnectedOutput.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Success here is not segfaulting.
target C {
timeout: 10 ms
}

reactor B(bank_index: int = 0) {
input in: int
output out_problem: int

reaction(in) -> out_problem {=
lf_set(out_problem, self->bank_index);
=}
}

reactor A {
input in: int
output out1: int
output out2: int
output out3: int

b = new[3] B()
(in)+ -> b.in
b.out_problem -> out1, out2, out3
}

main reactor {
m = new A()
timer t(0, 10 ms)

reaction(t) -> m.in {=
lf_set(m.in, 42);
=}

reaction(m.out3) {=
lf_print("out3 = %d", m.out3->value);
if (m.out3->value != 2) {
lf_print_error_and_exit("Expected 2.");
}
=}
}
Loading

0 comments on commit 8fc7341

Please sign in to comment.