diff --git a/.gitignore b/.gitignore index b97b08f..57b6c38 100644 --- a/.gitignore +++ b/.gitignore @@ -6,9 +6,6 @@ /docs/guided_examples/*/build* /docs/guided_examples/flake.lock -# Avoid adding symlinks -/support/ides/clion/* - # Products of SimoSim Simo.log statistics.yaml diff --git a/flake.nix b/flake.nix index c39ed77..8c7daa0 100644 --- a/flake.nix +++ b/flake.nix @@ -87,9 +87,9 @@ }; derivationAttributes = { - default = pkgs.clangStdenv.mkDerivation simoBaseAttributes; - clang = pkgs.clangStdenv.mkDerivation simoBaseAttributes; - gcc = pkgs.gccStdenv.mkDerivation simoBaseAttributes; + default = pkgs.clangStdenv.mkDerivation simoBaseAttributes; + clang = pkgs.clangStdenv.mkDerivation simoBaseAttributes; + gcc = pkgs.gccStdenv.mkDerivation simoBaseAttributes; }; in { @@ -106,11 +106,16 @@ { inputsFrom = [ derivationAttributes.default ]; packages = with pkgs; [ + git + bashInteractive clang-tools ast-grep # For llvm-cov llvmPackages.llvm ]; + shellHook = '' + export SHELL="${pkgs.bashInteractive}/bin/bash" + ''; }; } ); diff --git a/include/Simo/port/Port.h b/include/Simo/port/Port.h index 1772d13..7a8f36b 100644 --- a/include/Simo/port/Port.h +++ b/include/Simo/port/Port.h @@ -89,6 +89,19 @@ class SIMO_PUBLIC OutPort : public Port { std::abort(); } + SEND_OUTCOME send(Payload& payload) { + storage = payload; + switch (state_) { + case PORT_STATE::EMPTY: + state_ = PORT_STATE::FILLED; + return SEND_OUTCOME::NEW; + case PORT_STATE::FILLED: + state_ = PORT_STATE::FILLED; + return SEND_OUTCOME::REPLACED; + } + std::abort(); + } + void clear() { state_ = PORT_STATE::EMPTY; } PORT_STATE state() const { return state_; } @@ -172,6 +185,10 @@ class SIMO_PUBLIC BidirectionalPortTyped : public Port { return out_port.send(std::move(payload)); } + OutPort::SEND_OUTCOME send_out(OutPayload& payload) { + return out_port.send(payload); + } + void clear_out() { out_port.clear(); } void clear_in() { in_port.clear(); } diff --git a/support/ides/clion/README.md b/support/ides/clion/README.md index 66678d1..0c964f2 100644 --- a/support/ides/clion/README.md +++ b/support/ides/clion/README.md @@ -1,11 +1,10 @@ # Use Nix packages in CLion -Based on [this](https://gist.github.com/pmenke-de/2fed80213c48c2fe80891678f4fa3b42), -but reworked to use flakes. +From the terminal, open a development environment with `nix develop`. -1. Run `support/ides/clion/setup-symlinks.sh` to expose some nix binaries -2. In `Settings` -> `Build, Execution, Deployment` -> `Toolchains`, create a new toolchain -3. Set CMake executable to `support/ides/clion/nix-cmake.sh` and the other elements of the -toolchain to the symlinks created in step 1. +Inside the development environment, launch CLion. -Note it is important to set the symlink of ctest to be able to run unit-tests from CLion. \ No newline at end of file +On macOS, this can be done with `open -na "CLion.app"`. + +One issue is that the integrated terminal may complain about `bash: bind: command not found` +and show escape symbol. The solution is to run `nix develop` in the terminal. \ No newline at end of file diff --git a/support/ides/clion/nix-cmake.sh b/support/ides/clion/nix-cmake.sh deleted file mode 100755 index d5fcb49..0000000 --- a/support/ides/clion/nix-cmake.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env sh -# -# Copyright 2026 Matteo Fusi and Contributors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# Use the cmakeFlags set by Nix - this doesn't work with --build -#FLAGS=$(echo "$@" | grep -e '--build' > /dev/null || echo "$cmakeFlags") -#"$(dirname "$0")"/nix-run.sh cmake ${FLAGS:+"$FLAGS"} "$@" - - -SCRIPT_DIR=$(cd -- "$(dirname -- "$0")" && pwd) -PROJECT_DIR=$SCRIPT_DIR/../../../ -set -x -nix develop "$PROJECT_DIR" --command "$SCRIPT_DIR/nix-run.sh" cmake "$@" -exit $? - - diff --git a/support/ides/clion/nix-run.sh b/support/ides/clion/nix-run.sh deleted file mode 100755 index 2486b78..0000000 --- a/support/ides/clion/nix-run.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env sh -# -# Copyright 2026 Matteo Fusi and Contributors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -set -x -"$@" \ No newline at end of file diff --git a/support/ides/clion/setup-symlinks.sh b/support/ides/clion/setup-symlinks.sh deleted file mode 100755 index 2d426a7..0000000 --- a/support/ides/clion/setup-symlinks.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env sh -# -# Copyright 2026 Matteo Fusi and Contributors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -SCRIPT_DIR=$(cd -- "$(dirname -- "$0")" && pwd) - -# Run bash inside dev shell to create symlinks -nix develop --command bash -c " - ln -sf $(which ninja) $SCRIPT_DIR/ - ln -sf $(which clang) $SCRIPT_DIR/ - ln -sf $(which clang++) $SCRIPT_DIR/ - ln -sf $(which ctest) $SCRIPT_DIR/ -" diff --git a/tests/Simo/MainLoopTests.cc b/tests/Simo/MainLoopTests.cc index 1baa879..6cdc6c2 100644 --- a/tests/Simo/MainLoopTests.cc +++ b/tests/Simo/MainLoopTests.cc @@ -17,6 +17,7 @@ #include "support/BoostInclude.h" +namespace Simo::Tests { class TestModule : public Simo::Module { public: Simo::InitializationStatus initialize(Simo::Context& ctx, @@ -97,3 +98,4 @@ BOOST_AUTO_TEST_CASE(InitializationFailure) { ss << initialize_success; BOOST_CHECK_EQUAL(ss.str(), initialization_success_str); } +} // namespace Simo::Tests diff --git a/tests/Simo/SimulationContextTest.cc b/tests/Simo/SimulationContextTest.cc index 22fb28d..7492042 100644 --- a/tests/Simo/SimulationContextTest.cc +++ b/tests/Simo/SimulationContextTest.cc @@ -22,6 +22,7 @@ #include "support/BoostInclude.h" +namespace Simo::Tests { class InitTrackingModule final : public Simo::Module { public: Simo::InitializationStatus initialize( @@ -263,3 +264,4 @@ BOOST_AUTO_TEST_CASE(ModuleParametersGetSubtreeHitAndMiss) { auto missing = params.get_subtree("missing"); BOOST_CHECK_EQUAL(missing.has_value(), false); } +} // namespace Simo::Tests diff --git a/tests/collection/CollectionTest.cc b/tests/collection/CollectionTest.cc index 4c44f22..134a9d6 100644 --- a/tests/collection/CollectionTest.cc +++ b/tests/collection/CollectionTest.cc @@ -28,6 +28,7 @@ #define DYNLIB_EXT "so" #endif +namespace Simo::Tests { namespace { std::filesystem::path collection_library_path() { // Assuming tests are run from the build folder @@ -264,3 +265,4 @@ BOOST_AUTO_TEST_CASE(collection_with_lib_move_assignment_and_self_move) { BOOST_CHECK_EQUAL(destination.get_collection(), source_collection); } +} // namespace Simo::Tests diff --git a/tests/core/RadixHeap/RadixHeapTest.cc b/tests/core/RadixHeap/RadixHeapTest.cc index f2370cf..cd35ab8 100644 --- a/tests/core/RadixHeap/RadixHeapTest.cc +++ b/tests/core/RadixHeap/RadixHeapTest.cc @@ -17,7 +17,8 @@ #include "support/BoostInclude.h" -using Simo::Internal::RadixHeap; +namespace Simo::Tests { +using Internal::RadixHeap; BOOST_AUTO_TEST_CASE(pushElements) { RadixHeap heap; @@ -96,3 +97,4 @@ BOOST_AUTO_TEST_CASE(pushElementReorder) { BOOST_CHECK_EQUAL(heap.peek(), 0); BOOST_CHECK_EQUAL(heap.size(), 1); } +} // namespace Simo::Tests diff --git a/tests/core/TimePeriod/TimePeriodTest.cc b/tests/core/TimePeriod/TimePeriodTest.cc index 7cb903b..b43ac78 100644 --- a/tests/core/TimePeriod/TimePeriodTest.cc +++ b/tests/core/TimePeriod/TimePeriodTest.cc @@ -20,6 +20,7 @@ #include "Simo/Simo.h" #include "support/BoostInclude.h" +namespace Simo::Tests { BOOST_AUTO_TEST_CASE(TimeUnitConversions) { using Simo::Time; @@ -110,3 +111,4 @@ BOOST_AUTO_TEST_CASE(TimeJsonSerializationAndParsing) { BOOST_CHECK(invalid_error); BOOST_CHECK_EQUAL(unchanged.to_picoseconds(), 99U); } +} // namespace Simo::Tests diff --git a/tests/module/ModuleTest.cc b/tests/module/ModuleTest.cc index f190dab..9461d4a 100644 --- a/tests/module/ModuleTest.cc +++ b/tests/module/ModuleTest.cc @@ -24,6 +24,7 @@ namespace fs = std::filesystem; +namespace Simo::Tests { namespace { [[nodiscard]] std::string read_file_contents( @@ -121,3 +122,4 @@ BOOST_AUTO_TEST_CASE(ModuleChild) { BOOST_CHECK_EQUAL(child_status.success(), true); BOOST_CHECK_EQUAL(p_child.name(), "root/child"); } +} // namespace Simo::Tests diff --git a/tests/parameter/ParameterTest.cc b/tests/parameter/ParameterTest.cc index c6ee045..98a1e60 100644 --- a/tests/parameter/ParameterTest.cc +++ b/tests/parameter/ParameterTest.cc @@ -21,6 +21,7 @@ #include "support/BoostInclude.h" +namespace Simo::Tests { BOOST_AUTO_TEST_CASE(ParameterTyped_default_constructor_and_setters) { using Simo::Parameter::ParameterTyped; @@ -172,3 +173,4 @@ BOOST_AUTO_TEST_CASE(ParameterTrie_subtrie_lookup_branches) { BOOST_CHECK_EQUAL(nested_value, &value_param); BOOST_CHECK_CLOSE(nested_value->value(), 3.14, 0.0001); } +} // namespace Simo::Tests \ No newline at end of file diff --git a/tests/statistics/StatisticsTest.cc b/tests/statistics/StatisticsTest.cc index 3736e96..a837cc3 100644 --- a/tests/statistics/StatisticsTest.cc +++ b/tests/statistics/StatisticsTest.cc @@ -29,6 +29,7 @@ #include "support/BoostInclude.h" +namespace Simo::Tests { namespace { class NamedPort final : public Simo::Port { @@ -467,3 +468,4 @@ BOOST_AUTO_TEST_CASE(CollectorInitializeFailsWithInvalidParameters) { BOOST_CHECK_EQUAL(collector.initialize(sim_ctx, params).success(), false); } +} // namespace Simo::Tests