Skip to content

Commit

Permalink
Merge branch 'main' into transient-fed
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardalee committed Jul 10, 2024
2 parents a7ffdaf + 4abce72 commit 59d4279
Show file tree
Hide file tree
Showing 93 changed files with 2,048 additions and 1,223 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ on:

jobs:
build:

runs-on: macos-latest

steps:
- name: Requirements
run: brew install doxygen
&& brew install sphinx-doc
&& pip3 install sphinx-rtd-theme
&& pip3 install breathe
&& pip3 install sphinx-sitemap
&& pip3 install exhale
run: |
brew install doxygen
brew install sphinx-doc
python3 -m venv .venv
source .venv/bin/activate
pip3 install sphinx-rtd-theme
pip3 install breathe
pip3 install sphinx-sitemap
pip3 install exhale
- name: Checkout repo
uses: actions/[email protected]
- name: Build docs
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ jobs:
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}
if: ${{ !github.event.pull_request.draft ||contains( github.event.pull_request.labels.*.name, 'zephyr') }}

lf-default-flexpret:
needs: [fetch-lf]
uses: lf-lang/lingua-franca/.github/workflows/c-flexpret-tests.yml@master
with:
runtime-ref: ${{ github.ref }}
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}
if: ${{ !github.event.pull_request.draft ||contains( github.event.pull_request.labels.*.name, 'flexpret') }}

lf-default:
needs: [fetch-lf]
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
run:
strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
platform: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.platform }}

steps:
Expand All @@ -24,4 +24,13 @@ jobs:
cd build
cmake .. ${{ inputs.cmake-args }}
cmake --build .
make test
sudo make test
- name: Run RTI unit tests
run: |
cd core/federated/RTI
mkdir build
cd build
cmake ..
cmake --build .
ctest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ util/tracing/trace_to_csv.o
util/tracing/trace_to_influxdb
util/tracing/trace_to_influxdb.o
util/tracing/trace_util.o

# Generated trace lib
trace/**/*.a
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ if(DEFINED LF_SINGLE_THREADED)
add_compile_definitions(LF_SINGLE_THREADED=1)
endif()

# Warnings as errors
add_compile_options(-Werror)

set(Test test)
set(Lib lib)
set(CoreLibPath core)
set(CoreLib reactor-c)
Expand All @@ -42,7 +38,6 @@ include_directories(${CMAKE_SOURCE_DIR}/include/core/utils)
include_directories(${CMAKE_SOURCE_DIR}/include/api)

enable_testing()
add_subdirectory(${Test})
add_subdirectory(${Lib})
add_subdirectory(${CoreLibPath})

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ To run tests for the multithreaded runtime, provide a nonzero number of workers
when invoking `cmake`. For example:

- `cmake .. -DNUMBER_OF_WORKERS=2`
- `cmake --build .`
- `sudo make test`

Note that one of the tests in the multithreaded test suite requires sudo because
it changes the scheduling policy and priorities.

To define/undefine other preprocessor definitions such as `LOG_LEVEL`, pass them as
arguments to `cmake` in the same way as with `NUMBER_OF_WORKERS`, using the same
Expand Down
34 changes: 24 additions & 10 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,26 @@ lf_enable_compiler_warnings(reactor-c)

if (DEFINED LF_TRACE)
include(${LF_ROOT}/trace/api/CMakeLists.txt)
if(NOT LF_TRACE_PLUGIN)
set(LF_TRACE_PLUGIN lf::trace-impl)
target_link_libraries(reactor-c PUBLIC lf::trace-api)
# If the user specified an external trace plugin. Find it and link with it
if (LF_TRACE_PLUGIN)
message(STATUS "Linking trace plugin library ${LF_TRACE_PLUGIN}")
find_library(TRACE_LIB NAMES ${LF_TRACE_PLUGIN} HINTS "${LF_ROOT}")
if (NOT TRACE_LIB)
message(FATAL_ERROR "The trace plugin library ${LF_TRACE_PLUGIN} not found")
endif()
# We also link with libdl because it is needed for some platforms.
# TODO: Figure out why this is the case and how to avoid it.
target_link_libraries(reactor-c PRIVATE ${TRACE_LIB} dl)
else()
# If not, use the default implementation
message(STATUS "Linking with default trace implementation")
include(${LF_ROOT}/trace/impl/CMakeLists.txt)
target_link_libraries(reactor-c PRIVATE lf::trace-impl)
endif()
message(STATUS "linking trace plugin library ${LF_TRACE_PLUGIN}")
target_link_libraries(reactor-c PUBLIC lf::trace-api)
target_link_libraries(reactor-c PRIVATE "${LF_TRACE_PLUGIN}")
else()
include(${LF_ROOT}/trace/api/types/CMakeLists.txt)
target_link_libraries(reactor-c PUBLIC lf::trace-api-types)
endif()

include(${LF_ROOT}/version/api/CMakeLists.txt)
Expand Down Expand Up @@ -109,7 +122,7 @@ if(DEFINED FEDERATED_AUTHENTICATED)
target_link_libraries(reactor-c PUBLIC OpenSSL::SSL)
endif()

if(DEFINED _LF_CLOCK_SYNC_ON)
if(DEFINED FEDERATED)
find_library(MATH_LIBRARY m)
if(MATH_LIBRARY)
target_link_libraries(reactor-c PUBLIC ${MATH_LIBRARY})
Expand All @@ -128,8 +141,9 @@ target_compile_definitions(reactor-c PRIVATE INITIAL_EVENT_QUEUE_SIZE=${INITIAL_
target_compile_definitions(reactor-c PRIVATE INITIAL_REACT_QUEUE_SIZE=${INITIAL_REACT_QUEUE_SIZE})
target_compile_definitions(reactor-c PUBLIC PLATFORM_${CMAKE_SYSTEM_NAME})

# Macro for translating a command-line argument into compile definition for
# reactor-c lib
# If variable X is defined in cMake (set using SET()) or passed in as a command-line
# argument using -DX=<value>, then make it a compiler flag for reactor-c so that X
# is also defined in the C code for reactor-c.
macro(define X)
if(DEFINED ${X})
message(STATUS ${X}=${${X}})
Expand All @@ -142,9 +156,9 @@ message(STATUS "Applying preprocessor definitions...")
define(_LF_CLOCK_SYNC_ATTENUATION)
define(_LF_CLOCK_SYNC_COLLECT_STATS)
define(_LF_CLOCK_SYNC_EXCHANGES_PER_INTERVAL)
define(_LF_CLOCK_SYNC_INITIAL)
define(_LF_CLOCK_SYNC_ON)
define(LF_CLOCK_SYNC) # 1 for OFF, 2 for INIT and 3 for ON.
define(_LF_CLOCK_SYNC_PERIOD_NS)
define(_LF_FEDERATE_NAMES_COMMA_SEPARATED)
define(ADVANCE_MESSAGE_INTERVAL)
define(EXECUTABLE_PREAMBLE)
define(FEDERATED_CENTRALIZED)
Expand Down
23 changes: 11 additions & 12 deletions core/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
#include "clock.h"
#include "low_level_platform.h"

#if defined(_LF_CLOCK_SYNC_ON)
// If we are federated, include clock-sync API (and implementation)
#if defined(FEDERATED)
#include "clock-sync.h"
#endif
#else
// In the unfederated case, just provide empty implementations.
void clock_sync_add_offset(instant_t* t) { (void)t; }
void clock_sync_subtract_offset(instant_t* t) { (void)t; }
#endif // defined(FEDERATED)

static instant_t last_read_physical_time = NEVER;

Expand All @@ -20,9 +25,7 @@ int lf_clock_gettime(instant_t* now) {
if (res != 0) {
return -1;
}
#if defined(_LF_CLOCK_SYNC_ON)
clock_sync_apply_offset(now);
#endif
clock_sync_add_offset(now);
do {
// Atomically fetch the last read value. This is done with
// atomics to guarantee that it works on 32bit platforms as well.
Expand All @@ -42,19 +45,15 @@ int lf_clock_gettime(instant_t* now) {
}

int lf_clock_interruptable_sleep_until_locked(environment_t* env, instant_t wakeup_time) {
#if defined(_LF_CLOCK_SYNC_ON)
// Remove any clock sync offset and call the Platform API.
clock_sync_remove_offset(&wakeup_time);
#endif
clock_sync_subtract_offset(&wakeup_time);
return _lf_interruptable_sleep_until_locked(env, wakeup_time);
}

#if !defined(LF_SINGLE_THREADED)
int lf_clock_cond_timedwait(lf_cond_t* cond, instant_t wakeup_time) {
#if defined(_LF_CLOCK_SYNC_ON)
// Remove any clock sync offset and call the Platform API.
clock_sync_remove_offset(&wakeup_time);
#endif
clock_sync_subtract_offset(&wakeup_time);
return _lf_cond_timedwait(cond, wakeup_time);
}
#endif
#endif // !defined(LF_SINGLE_THREADED)
31 changes: 5 additions & 26 deletions core/environment.c
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
/**
* @file
* @author Erling R. Jellum ([email protected])
* @author Erling R. Jellum
* @copyright (c) 2023-2024, The Norwegian University of Science and Technology.
* License: <a href="https://github.com/lf-lang/reactor-c/blob/main/LICENSE.md">BSD 2-clause</a>
*
* @section LICENSE
* Copyright (c) 2023, The Norwegian University of Science and Technology.
*
* 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.
*
* @section DESCRIPTION Functions intitializing and freeing memory for environments.
* See environment.h for docs.
* This file defines functions intitializing and freeing memory for environments.
* See environment.h for docs.
*/

#include "environment.h"
Expand Down
Loading

0 comments on commit 59d4279

Please sign in to comment.