Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Patmos platform #2383

Merged
merged 29 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1144a7b
Support for Patmos platform
lhstrh Jul 31, 2024
e6f38fd
update
EhsanKhodadad Aug 22, 2024
0e8cf6d
github workflow for Patmos platform added
EhsanKhodadad Aug 22, 2024
587ebff
github workflow for Patmos platform added 2
EhsanKhodadad Aug 22, 2024
e3cef42
Pushes the RTI image to Docker Hub when the repo owner is lf-lang
EhsanKhodadad Aug 23, 2024
5c62323
Merge branch 'master' into master
lhstrh Aug 26, 2024
2ba7cda
install needed tools added to setup-patmos/action.yml
EhsanKhodadad Aug 26, 2024
55e4323
spotless + gitk installation removed
EhsanKhodadad Aug 27, 2024
83eddde
Merge remote-tracking branch 'origin/master'
EhsanKhodadad Sep 4, 2024
d5d24cb
Spotless
EhsanKhodadad Sep 4, 2024
bf4ade9
print added to patmos tests
EhsanKhodadad Sep 9, 2024
b571f4c
Patmos Category added
EhsanKhodadad Sep 10, 2024
21f7b5b
t-crest directory added to the PATH
EhsanKhodadad Sep 10, 2024
7c3c4f8
bug fixed
EhsanKhodadad Sep 10, 2024
5420d2e
REQUIRED added to patmos-clang
EhsanKhodadad Sep 12, 2024
3466c44
echo path added
EhsanKhodadad Sep 12, 2024
d06856f
which patmos-clang added
EhsanKhodadad Sep 12, 2024
5092b09
save PATH into GITHUB_ENV
EhsanKhodadad Sep 13, 2024
c1ac775
is quoted
EhsanKhodadad Sep 13, 2024
ccf962c
PATH modified and saved in GITHUB_ENV
EhsanKhodadad Sep 16, 2024
5ffa58c
export PATH added along with GITHUB_ENV
EhsanKhodadad Sep 16, 2024
f330ea3
setting PATH in GITHUB_ENV removed. Some other optional commands remo…
EhsanKhodadad Sep 16, 2024
f8d1e83
setting PATH in GITHUB_ENV returned without backslash
EhsanKhodadad Sep 17, 2024
06be510
Merge remote-tracking branch 'upstream/master'
EhsanKhodadad Oct 1, 2024
efe3d37
Merge remote-tracking branch 'upstream/master'
EhsanKhodadad Oct 21, 2024
f5de81e
Patmos tests are excluded from cuncurrent and regular-tests
EhsanKhodadad Oct 21, 2024
813fb6a
Patmos threaded basic test is removed
EhsanKhodadad Oct 21, 2024
a75c4f1
Merge remote-tracking branch 'upstream/master'
EhsanKhodadad Oct 24, 2024
46da427
reactor-cpp points to dfdac2c
EhsanKhodadad Oct 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/actions/setup-patmos/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Install Patmos and dependencies (Linux only)
description: Install Patmos and dependencies (Linux only)
runs:
using: "composite"
steps:
- name: Setup
run: |
# install needed tools
sudo apt install git openjdk-8-jdk cmake make g++ texinfo flex bison \
subversion libelf-dev graphviz libboost-dev libboost-program-options-dev ruby-full \
liblpsolve55-dev zlib1g-dev gtkwave gtkterm scala autoconf libfl2 expect verilator curl

# install sbt

sudo apt-get update
sudo apt-get install apt-transport-https curl gnupg -yqq
echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | sudo tee /etc/apt/sources.list.d/sbt.list
echo "deb https://repo.scala-sbt.org/scalasbt/debian /" | sudo tee /etc/apt/sources.list.d/sbt_old.list
curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | sudo -H gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/scalasbt-release.gpg --import
sudo chmod 644 /etc/apt/trusted.gpg.d/scalasbt-release.gpg
sudo apt-get update
sudo apt-get install sbt

# Clone the Patmos repository
export PATH=$PATH:$HOME/t-crest/local/bin
echo "PATH=$PATH:$HOME/t-crest/local/bin" >> "$GITHUB_ENV"
echo $PATH
mkdir ~/t-crest
cd ~/t-crest
git clone https://github.com/t-crest/patmos-misc.git misc
./misc/build.sh
patmos-clang --version
which patmos-clang
shell: bash
4 changes: 4 additions & 0 deletions .github/workflows/c-embedded.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ jobs:
# # Run the C FlexPRET integration tests.
# flexpret:
# uses: ./.github/workflows/c-flexpret-tests.yml

# Run the C Patmos integration tests.
patmos:
uses: ./.github/workflows/c-patmos-tests.yml
56 changes: 56 additions & 0 deletions .github/workflows/c-patmos-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: C Patmos 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
all-platforms:
required: false
default: true
type: boolean

jobs:
Patmos-tests:
runs-on: ubuntu-latest
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: Setup and build Patmos
uses: ./.github/actions/setup-patmos
- name: Check out specific ref of reactor-c
uses: actions/checkout@v3
with:
repository: lf-lang/reactor-c
path: core/src/main/resources/lib/c/reactor-c
ref: ${{ inputs.runtime-ref }}
if: ${{ inputs.runtime-ref }}
- name: Run Patmos smoke tests
EhsanKhodadad marked this conversation as resolved.
Show resolved Hide resolved
run: |
./gradlew core:integrationTest \
--tests org.lflang.tests.runtime.CPatmosTest.* \
core:integrationTestCodeCoverageReport
rm -rf test/C/src-gen
- name: Report to CodeCov
uses: ./.github/actions/report-code-coverage
with:
files: core/build/reports/jacoco/integrationTestCodeCoverageReport/integrationTestCodeCoverageReport.xml
if: ${{ github.repository == 'lf-lang/lingua-franca' }}
4 changes: 2 additions & 2 deletions .github/workflows/rti-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
latest: false
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
if: ${{ endsWith(env.lf_version, '-snapshot') && github.repository_owner == 'lf-lang' }}
if: ${{ endsWith(env.lf_version, '-snapshot') && github.repository_owner == 'lf-lang' }}

- name: Update latest (released versions only)
uses: ./.github/actions/push-rti-docker
Expand All @@ -39,4 +39,4 @@ jobs:
latest: true
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
if: ${{ !endsWith(env.lf_version, '-snapshot') && github.repository_owner == 'lf-lang' }}
if: ${{ !endsWith(env.lf_version, '-snapshot') && github.repository_owner == 'lf-lang' }}
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public static boolean compatibleWithThreadingOff(TestCategory category) {

// CONCURRENT, FEDERATED, DOCKER_FEDERATED, DOCKER
// are not compatible with single-threaded execution.
// ARDUINO, ZEPHYR and FLEXPRET have their own test suites, so we don't need to rerun.
// ARDUINO, ZEPHYR, FLEXPRET, and PATMOS have their own test suites, so we don't need to rerun.
boolean excluded =
category == TestCategory.CONCURRENT
|| category == TestCategory.SERIALIZATION
Expand All @@ -245,7 +245,8 @@ public static boolean compatibleWithThreadingOff(TestCategory category) {
|| category == TestCategory.ZEPHYR_UNTHREADED
|| category == TestCategory.ZEPHYR_BOARDS
|| category == TestCategory.ZEPHYR_THREADED
|| category == TestCategory.FLEXPRET;
|| category == TestCategory.FLEXPRET
|| category == TestCategory.PATMOS;

// SERIALIZATION and TARGET tests are excluded on Windows.
excluded |= isWindows() && category == TestCategory.TARGET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private static boolean isExcludedFromCCpp(TestCategory category) {
excluded |= category == TestCategory.ZEPHYR_THREADED;
excluded |= category == TestCategory.ZEPHYR_BOARDS;
excluded |= category == TestCategory.ARDUINO;
excluded |= category == TestCategory.PATMOS;
excluded |= category == TestCategory.NO_INLINING;
excluded |= category == TestCategory.VERIFIER;
return !excluded;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*************
* 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.Test;
import org.lflang.target.Target;
import org.lflang.tests.Configurators;
import org.lflang.tests.TestBase;
import org.lflang.tests.TestRegistry.TestCategory;
import org.lflang.tests.Transformers;

public class CPatmosTest extends TestBase {

public CPatmosTest() {
super(Target.C);
}

@Test
public void buildPatmosBasicTestsUnthreaded() {
Assumptions.assumeTrue(isLinux(), "Patmos tests only supported on Linux");
super.runTestsFor(
List.of(Target.C),
"Build basic tests for Patmos in single threaded mode.",
TestCategory.BASIC::equals,
Transformers::noChanges,
Configurators::makePatmosCompatibleUnthreaded,
TestLevel.BUILD,
false);
}
}
45 changes: 44 additions & 1 deletion core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,16 @@ CodeBuilder generateCMakeCode(
cMakeCode.pr("set(FP_FLASH_DEVICE " + selectedFlashDevice.value() + ")");
cMakeCode.newLine();
} // No FP_FLASH_DEVICE will automatically become /dev/ttyUSB0

break;
case PATMOS:
cMakeCode.newLine();
cMakeCode.pr("# Include toolchain file and set project");
cMakeCode.pr(
"find_program(CLANG_EXECUTABLE NAMES patmos-clang REQUIRED DOC \"Path to the clang"
+ " front-end.\")");
cMakeCode.pr("set(CMAKE_C_COMPILER ${CLANG_EXECUTABLE})");
cMakeCode.pr("project(" + executableName + " LANGUAGES C)");
cMakeCode.newLine();
break;
default:
cMakeCode.pr("project(" + executableName + " LANGUAGES C)");
Expand Down Expand Up @@ -328,6 +337,13 @@ CodeBuilder generateCMakeCode(
executableName,
Stream.concat(additionalSources.stream(), sources.stream())));
break;
case PATMOS:
cMakeCode.pr(
setUpMainTargetPatmos(
hasMain,
executableName,
Stream.concat(additionalSources.stream(), sources.stream())));
break;
default:
cMakeCode.pr(
setUpMainTarget.getCmakeCode(
Expand Down Expand Up @@ -616,4 +632,31 @@ private static String setUpMainTargetFlexPRET(

return code.toString();
}

private static String setUpMainTargetPatmos(
boolean hasMain, String executableName, Stream<String> cSources) {
var code = new CodeBuilder();
code.pr("add_subdirectory(core)");
code.newLine();

code.pr("set(LF_MAIN_TARGET " + executableName + ")");
code.newLine();

if (hasMain) {
code.pr("# Declare a new executable target and list all its sources");
code.pr("add_executable(");
} else {
code.pr("# Declare a new library target and list all its sources");
code.pr("add_library(");
}
code.indent();
code.pr("${LF_MAIN_TARGET}");

cSources.forEach(code::pr);
code.unindent();
code.pr(")");
code.newLine();

return code.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum Platform {
MAC("Darwin"),
ZEPHYR("Zephyr"),
FLEXPRET("FlexPRET"),
PATMOS("Patmos"),
WINDOWS("Windows");

final String cMakeName;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/cpp/reactor-cpp
lhstrh marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 27 additions & 0 deletions core/src/testFixtures/java/org/lflang/tests/Configurators.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,33 @@ public static boolean makeFlexPRETCompatibleUnthreaded(TargetConfig config) {
return makeFlexPRETCompatible(config);
}

public static boolean makePatmosCompatible(TargetConfig config) {
/**
* Patmos has a maximum of eight hardware threads; override the chosen number of worker threads
* to be 0 (meaning run-time selects it).
*
* <p>This is to avoid failing tests that have e.g., `workers: 16`.
*/
WorkersProperty.INSTANCE.override(config, 0);

var platform = config.get(PlatformProperty.INSTANCE);
PlatformProperty.INSTANCE.override(
config,
new PlatformOptions(
Platform.PATMOS,
new Option<String>(true, "emulator"),
platform.port(),
platform.baudRate(),
new Option<Boolean>(true, false),
platform.userThreads()));
return true;
}

public static boolean makePatmosCompatibleUnthreaded(TargetConfig config) {
disableThreading(config);
return makePatmosCompatible(config);
}

/**
* Make no changes to the configuration.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ public enum TestCategory {
ZEPHYR_UNTHREADED(false, "zephyr" + File.separator + "unthreaded", TestLevel.BUILD),
ZEPHYR_BOARDS(false, "zephyr" + File.separator + "boards", TestLevel.BUILD),
FLEXPRET(false, "flexpret", TestLevel.BUILD),
PATMOS(false, "patmos", TestLevel.BUILD),
VERIFIER(false, "verifier", TestLevel.EXECUTION),
TARGET(false, "", TestLevel.EXECUTION);

Expand Down
11 changes: 11 additions & 0 deletions test/C/src/patmos/HelloPatmos.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
target C {
platform: "Patmos",
single-threaded: true,
build-type: Debug
}

main reactor {
reaction(startup) {=
printf("Hello World!\n");
=}
}
Loading