Skip to content

Commit

Permalink
Merge pull request #2262 from magnmaeh/add-flexpret-support
Browse files Browse the repository at this point in the history
Support for FlexPRET platform
  • Loading branch information
lhstrh authored May 22, 2024
2 parents bfcba23 + 228d5b1 commit 9e909a8
Show file tree
Hide file tree
Showing 20 changed files with 645 additions and 79 deletions.
43 changes: 43 additions & 0 deletions .github/actions/setup-flexpret/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Install FlexPRET and dependencies (Linux only)
description: Install FlexPRET and dependencies (Linux only)
runs:
using: "composite"
steps:
- name: Setup
run: |
# Clone the FlexPRET repository
git clone --recurse-submodules https://github.com/pretis/flexpret
# This rest is copied directly from FlexPRET's `azure-pipelines.yml`
# Ubuntu 20.04 only has Verilator 4.028 but we neeed a more modern version
# so we do not use 'sudo apt-get install -y -qq verilator' here.
wget -q https://github.com/sifive/verilator/releases/download/4.036-0sifive2/verilator_4.036-0sifive2_amd64.deb -O verilator.deb
sudo dpkg -i verilator.deb
# Install riscv compiler
wget https://github.com/stnolting/riscv-gcc-prebuilt/releases/download/rv32i-4.0.0/riscv32-unknown-elf.gcc-12.1.0.tar.gz
sudo mkdir /opt/riscv
sudo tar -xzf riscv32-unknown-elf.gcc-12.1.0.tar.gz -C /opt/riscv/
rm riscv32-unknown-elf.gcc-12.1.0.tar.gz
# Update submodules
git submodule update --init --recursive
# Save location of RISC-V compiler to reuse later
echo "FP_RISCV_COMPILER=/opt/riscv" >> "$GITHUB_ENV"
shell: bash
- name: Build FlexPRET and install to SDK
run: |
# Step into cloned directory
cd flexpret
# Save pwd to environment variable so we can find `env.bash` in later steps
echo "FP_DIR=$(pwd)" >> "$GITHUB_ENV"
# Source environment
source env.bash
# Build FlexPRET's high memory configuration and install it to SDK
cd $FP_PATH && cmake -DFP_CONFIG=highmem -B build && cd build && make all install
shell: bash
30 changes: 30 additions & 0 deletions .github/workflows/all-embedded.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Tests for embedded platforms
name: CI (embedded platforms)

on:
workflow_dispatch:
push:
branches:
- master
pull_request:
types: [synchronize, opened, reopened, ready_for_review, converted_to_draft]
merge_group:

env:
# 2020.11
vcpkgGitRef: 0bf3923f9fab4001c00f0f429682a0853b5749e0

concurrency:
group: all-embedded-${{ github.ref }}-${{ github.event_path }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
check-diff:
uses: ./.github/workflows/check-diff.yml

c-embedded:
uses: ./.github/workflows/c-embedded.yml
needs: check-diff
if: ${{ needs.check-diff.outputs.run_c == 'true' }}

# Add more languages if supported
25 changes: 25 additions & 0 deletions .github/workflows/c-embedded.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: C embedded

on:
workflow_dispatch:
workflow_call:


concurrency:
group: c-embedded-${{ github.ref }}-${{ github.event_path }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
# Run the C Arduino integration tests.
arduino:
uses: ./.github/workflows/c-arduino-tests.yml
with:
all-platforms: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}

# Run the C Zephyr integration tests.
zephyr:
uses: ./.github/workflows/c-zephyr-tests.yml

# Run the C FlexPRET integration tests.
flexpret:
uses: ./.github/workflows/c-flexpret-tests.yml
58 changes: 58 additions & 0 deletions .github/workflows/c-flexpret-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: C FlexPRET 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:
flexpret-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 FlexPRET
uses: ./.github/actions/setup-flexpret
- 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 FlexPRET smoke tests
run: |
cd "$FP_DIR" && source env.bash && cd -
export RISCV_TOOL_PATH_PREFIX=$FP_RISCV_COMPILER
./gradlew core:integrationTest \
--tests org.lflang.tests.runtime.CFlexPRETTest.* \
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' }}
10 changes: 0 additions & 10 deletions .github/workflows/only-c.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ jobs:
with:
target: "C"

# Run the C Arduino integration tests.
arduino:
uses: ./.github/workflows/c-arduino-tests.yml
with:
all-platforms: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}

# Run the C Zephyr integration tests.
zephyr:
uses: ./.github/workflows/c-zephyr-tests.yml

# Run the CCpp integration tests.
ccpp:
uses: ./.github/workflows/c-tests.yml
Expand Down
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 and ZEPHYR have their own test suites, so we don't need to rerun.
// ARDUINO, ZEPHYR and FLEXPRET have their own test suites, so we don't need to rerun.
boolean excluded =
category == TestCategory.CONCURRENT
|| category == TestCategory.SERIALIZATION
Expand All @@ -244,7 +244,8 @@ public static boolean compatibleWithThreadingOff(TestCategory category) {
|| category == TestCategory.VERIFIER
|| category == TestCategory.ZEPHYR_UNTHREADED
|| category == TestCategory.ZEPHYR_BOARDS
|| category == TestCategory.ZEPHYR_THREADED;
|| category == TestCategory.ZEPHYR_THREADED
|| category == TestCategory.FLEXPRET;

// 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
@@ -0,0 +1,80 @@
/*************
* 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 CFlexPRETTest extends TestBase {

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

@Test
public void buildFlexPRETConcurrent() {
Assumptions.assumeTrue(isLinux(), "FlexPRET tests only supported on Linux");
super.runTestsFor(
List.of(Target.C),
"Build concurrent tests for FlexPRET.",
TestCategory.CONCURRENT::equals,
Transformers::noChanges,
Configurators::makeFlexPRETCompatible,
TestLevel.BUILD,
false);
}

@Test
public void buildFlexPRETBasicTestsUnthreaded() {
Assumptions.assumeTrue(isLinux(), "FlexPRET tests only supported on Linux");
super.runTestsFor(
List.of(Target.C),
"Build basic tests for FlexPRET in single threaded mode.",
TestCategory.BASIC::equals,
Transformers::noChanges,
Configurators::makeFlexPRETCompatibleUnthreaded,
TestLevel.BUILD,
false);
}

@Test
public void buildFlexPRETBasicTests() {
Assumptions.assumeTrue(isLinux(), "FlexPRET tests only supported on Linux");
super.runTestsFor(
List.of(Target.C),
"Build basic tests for FlexPRET.",
TestCategory.BASIC::equals,
Transformers::noChanges,
Configurators::makeFlexPRETCompatible,
TestLevel.BUILD,
false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,21 @@ public static String generateFederateNeighborStructure(FederateInstance federate
return code.toString();
}

public static String surroundWithIfElseFederated(String insideIf, String insideElse) {
if (insideElse == null) {
return surroundWithIfFederated(insideIf);
} else {
return """
#ifdef FEDERATED
%s
#else
%s
#endif // FEDERATED
"""
.formatted(insideIf, insideElse);
}
}

/**
* Surround {@code code} with blocks to ensure that code only executes if the program is
* federated.
Expand All @@ -465,6 +480,21 @@ public static String surroundWithIfFederated(String code) {
.formatted(code);
}

public static String surroundWithIfElseFederatedCentralized(String insideIf, String insideElse) {
if (insideElse == null) {
return surroundWithIfFederatedCentralized(insideIf);
} else {
return """
#ifdef FEDERATED_CENTRALIZED
%s
#else
%s
#endif // FEDERATED_CENTRALIZED
"""
.formatted(insideIf, insideElse);
}
}

/**
* Surround {@code code} with blocks to ensure that code only executes if the program is federated
* and has a centralized coordination.
Expand Down
Loading

0 comments on commit 9e909a8

Please sign in to comment.