Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ IncludeCategories:
FixNamespaceComments: true
ReflowComments: true # Automatically wraps long comments to ColumnLimit
CommentPragmas: '^.*A2Lfactory:'
InsertNewlineAtEOF: true

Language: Cpp
Standard: c++17
4 changes: 2 additions & 2 deletions .github/workflows/code_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ on:

jobs:
cpp:
uses: eclipse-score/cicd-workflows/.github/workflows/cpp-coverage.yml@ea19fcae9aeeb4ac678b750c6c197eaf75414f39 # v0.0.0
uses: eclipse-score/cicd-workflows/.github/workflows/cpp-coverage.yml@main

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we should use the branch. I think in general people use the commit tag so that CI is stable even when template is changed.
So if we need newer stuff I would just get the commit tag of main that we need.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, but I’d prefer an automatic update. In the example main is used:
C++ Coverage Workflow
Fail early fail often.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NicolasFussberger Deciding vote?

Think that failing early is good for our code, a major change in the template would mean we are blocked from PRs on our repo until we fix the CI

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pinning to a specific commit is also recommended to avoid supply chain attacks, although debatable whether that matters between our own repos. That page is a good read either way 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I would also favor the fixed commits, with either a bot that updates this regularly or we have to update this manually regularly.

With directly using main, when they roll out breaking changes it would just break our pipelines and we cannot distinguish between minor changes and major changes.
Would be great if we could pin to version 1.x.x or something like that so that we get the latest as long as its not a breaking change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right then, I’ll pin that version. I think we should check every now and then to see if there are any newer versions.

with:
bazel-target: "//score/..."
bazel-config: "x86_64-linux"
Expand All @@ -33,7 +33,7 @@ jobs:
retention-days: 10
min-coverage: 76
rust:
uses: eclipse-score/cicd-workflows/.github/workflows/rust-coverage.yml@ea19fcae9aeeb4ac678b750c6c197eaf75414f39 # v0.0.0
uses: eclipse-score/cicd-workflows/.github/workflows/rust-coverage.yml@main
with:
bazel-test-targets: "//score/..."
bazel-test-config-flags: "--config=x86_64-linux --config=ferrocene-coverage --lockfile_mode=error --test_lang_filters=-cc,-miri"
Expand Down
11 changes: 1 addition & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,9 @@ repos:
hooks:
- id: clang-format
name: clang-format
entry: ./scripts/run_clang_format_precommit.sh
entry: bazel run //:format.fix_C++_with_clang-format
language: system
files: '\.(c|cc|cpp|h|hpp)$'
# all relevant files are currently excluded the format is not
# clarified yet, so we don't want to run clang-format on any files
exclude: |
(?x)^(
externals/|
examples/|
tests/|
score/
)
- id: clang-tidy
name: clang-tidy
# Run through a wrapper that sanitizes unsupported linker flags in
Expand Down
8 changes: 7 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ dash_license_checker(
)

# Add target for formatting checks
use_format_targets()
use_format_targets(languages = [
"python",
"rust",
"starlark",
"yaml",
"cpp",
])

# Rust coverage report generation target
rust_coverage_report(
Expand Down
6 changes: 3 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bazel_dep(name = "google_benchmark", version = "1.9.5", dev_dependency = True)

bazel_dep(name = "score_bazel_platforms", version = "0.1.2", dev_dependency = True)
bazel_dep(name = "score_docs_as_code", version = "4.6.0", dev_dependency = True)
bazel_dep(name = "score_tooling", version = "1.2.0", dev_dependency = True)
bazel_dep(name = "score_tooling", version = "1.3.1", dev_dependency = True)
bazel_dep(name = "score_rust_policies", version = "0.0.5", dev_dependency = True)
bazel_dep(name = "score_cpp_policies", version = "0.0.1", dev_dependency = True)
bazel_dep(name = "score_process", version = "1.6.0", dev_dependency = True)
Expand Down Expand Up @@ -88,9 +88,9 @@ use_repo(
# LLVM toolchain (used for clang-format and clang-tidy)
bazel_dep(name = "toolchains_llvm", version = "1.4.0", dev_dependency = True)

llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm", dev_dependency = True)
llvm.toolchain(
llvm_version = "15.0.2",
llvm_version = "19.1.1",
stdlib = {"linux-x86_64": "stdc++"},
)
use_repo(llvm, "llvm_toolchain")
Expand Down
1,700 changes: 1,019 additions & 681 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions examples/control_application/control.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@

#include <cstddef>

struct RunTargetInfo {
struct RunTargetInfo
{
char runTargetName[1024]{};
};

static constexpr char const* control_socket_path = "/sm_control";
static constexpr const char* control_socket_path = "/sm_control";
static constexpr std::size_t control_socket_capacity = 32;

#endif
15 changes: 10 additions & 5 deletions examples/control_application/control_app_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,33 @@
********************************************************************************/
#include <iostream>

#include "ipc_dropin/socket.hpp"
#include "control.hpp"
#include "ipc_dropin/socket.hpp"

int main(int argc, char** argv)
{
if(argc <= 1) {
if (argc <= 1)
{
std::cout << "Usage: " << argv[0] << " MyRunTargetName" << std::endl;
return EXIT_FAILURE;
}

ipc_dropin::Socket<static_cast<size_t>(sizeof(RunTargetInfo)), control_socket_capacity> sm_control_socket{};
if (sm_control_socket.connect(control_socket_path) != ipc_dropin::ReturnCode::kOk) {
if (sm_control_socket.connect(control_socket_path) != ipc_dropin::ReturnCode::kOk)
{
std::cerr << "Could not connect to control socket" << std::endl;
return EXIT_FAILURE;
}

RunTargetInfo info{};
std::strncpy(info.runTargetName, argv[1], sizeof(info.runTargetName) - 1);
if(ipc_dropin::ReturnCode::kOk == sm_control_socket.trySend(info)) {
if (ipc_dropin::ReturnCode::kOk == sm_control_socket.trySend(info))
{
std::cout << "Successfully sent request" << std::endl;
return EXIT_SUCCESS;
} else {
}
else
{
std::cerr << "Request could not be sent" << std::endl;
return EXIT_FAILURE;
}
Expand Down
43 changes: 27 additions & 16 deletions examples/control_application/control_daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,60 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#include <atomic>
#include <csignal>
#include <thread>
#include <chrono>
#include <csignal>
#include <iostream>
#include <thread>

#include <score/mw/lifecycle/report_running.h>
#include <score/mw/lifecycle/control_client.h>
#include "ipc_dropin/socket.hpp"
#include "control.hpp"
#include "ipc_dropin/socket.hpp"
#include <score/mw/lifecycle/control_client.h>
#include <score/mw/lifecycle/report_running.h>

std::atomic<bool> exitRequested{false};
void signalHandler(int) {
void signalHandler(int)
{
exitRequested = true;
}

int main() {
int main()
{
signal(SIGINT, signalHandler);
signal(SIGTERM, signalHandler);

score::mw::lifecycle::report_running();

ipc_dropin::Socket<static_cast<size_t>(sizeof(RunTargetInfo)), control_socket_capacity> sm_control_socket{};
if (sm_control_socket.create(control_socket_path, 600) != ipc_dropin::ReturnCode::kOk) {
if (sm_control_socket.create(control_socket_path, 600) != ipc_dropin::ReturnCode::kOk)
{
std::cerr << "Could not create control socket" << std::endl;
return EXIT_FAILURE;
}

score::mw::lifecycle::ControlClient client;

score::safecpp::Scope<> scope{};
while (!exitRequested) {
while (!exitRequested)
{
RunTargetInfo info{};
if (ipc_dropin::ReturnCode::kOk == sm_control_socket.tryReceive(info)) {
if (ipc_dropin::ReturnCode::kOk == sm_control_socket.tryReceive(info))
{

std::string runTargetName{info.runTargetName};
std::cout << "Activating Run Target: " << runTargetName << std::endl;
client.ActivateRunTarget(runTargetName).Then({scope, [runTargetName](auto& result) noexcept {
if (!result) {
std::cerr << "Activating Run Target " << runTargetName << " failed with error: " << result.error().Message() << std::endl;
} else {
std::cout << "Activating Run Target " << runTargetName << " succeeded" << std::endl;
}
}});
if (!result)
{
std::cerr << "Activating Run Target " << runTargetName
<< " failed with error: "
<< result.error().Message() << std::endl;
}
else
{
std::cout << "Activating Run Target " << runTargetName
<< " succeeded" << std::endl;
}
}});
}

std::this_thread::sleep_for(std::chrono::milliseconds(100));
Expand Down
92 changes: 45 additions & 47 deletions examples/cpp_lifecycle_app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

#include <optional>
#include <unistd.h>
#include <iostream>
#include <chrono>
#include <ctime>
#include <iostream>
#include <optional>
#include <string>
#include <chrono>
#include <vector>

#ifdef __linux__
#include <linux/prctl.h>
#include <sys/prctl.h>
#include <linux/prctl.h>
#include <sys/prctl.h>
#endif

#include <score/mw/lifecycle/application.h>
Expand All @@ -31,55 +31,55 @@
struct Config
{
std::int32_t responseTimeInMs{100};
bool crashRequested{false};
bool crashRequested{false};
std::int32_t crashTimeInMs{1000};
bool failToStart{false};
bool verbose{false};
bool failToStart{false};
bool verbose{false};
};

std::string helpSstring =
"Usage:\n\
"Usage:\n\
-r <response time in ms> Worst case response time to SIGTERM signal in milliseconds.\n\
-c <crash time in ms> Simulate crash of the application, after specified time in milliseconds.\n\
-s Simulate failure during start-up of the application.\n\
-v Run in verbose mode.\n";

std::optional<Config> parseOptions(int argc, char *const *argv) noexcept
std::optional<Config> parseOptions(int argc, char* const* argv) noexcept
{
Config config{};
int c;
while ((c = getopt(argc, argv, ":r:c:svh")) != -1)
{
switch (static_cast<char>(c))
{
case 'r':
config.responseTimeInMs = std::stoi(optarg);
break;

case 'c':
config.crashRequested = true;
config.crashTimeInMs = std::stoi(optarg);
break;

case 's':
config.failToStart = true;
break;

case 'h':
std::cout << helpSstring;
return std::nullopt;

case 'v':
config.verbose = true;
break;

case '?':
std::cout << "Unrecognized option: -" << static_cast<char>(optopt) << std::endl;
std::cout << helpSstring;
return std::nullopt;

default:
break;
case 'r':
config.responseTimeInMs = std::stoi(optarg);
break;

case 'c':
config.crashRequested = true;
config.crashTimeInMs = std::stoi(optarg);
break;

case 's':
config.failToStart = true;
break;

case 'h':
std::cout << helpSstring;
return std::nullopt;

case 'v':
config.verbose = true;
break;

case '?':
std::cout << "Unrecognized option: -" << static_cast<char>(optopt) << std::endl;
std::cout << helpSstring;
return std::nullopt;

default:
break;
}
}
return config;
Expand All @@ -90,23 +90,23 @@ void set_process_name()
const char* identifier = getenv("PROCESSIDENTIFIER");
if (identifier != nullptr)
{
#ifdef __QNXNTO__
#ifdef __QNXNTO__
if (pthread_setname_np(pthread_self(), identifier) != 0)
{
std::cerr << "Failed to set QNX thread name" << std::endl;
}
#elif defined(__linux__)
#elif defined(__linux__)
if (prctl(PR_SET_NAME, identifier) < 0)
{
std::cerr << "Failed to set process name to " << identifier << std::endl;
}
#endif
#endif
}
}

class LifecycleApp final : public score::mw::lifecycle::Application
{
public:
public:
std::int32_t Initialize(const score::mw::lifecycle::ApplicationContext& appCtx) override
{
set_process_name();
Expand Down Expand Up @@ -158,8 +158,7 @@ class LifecycleApp final : public score::mw::lifecycle::Application

timespec req{
static_cast<time_t>(m_config.responseTimeInMs / 1000),
static_cast<long>((m_config.responseTimeInMs % 1000) * 1000000L)
};
static_cast<long>((m_config.responseTimeInMs % 1000) * 1000000L)};

auto timeLastVerboseLog = std::chrono::steady_clock::now();

Expand All @@ -176,8 +175,7 @@ class LifecycleApp final : public score::mw::lifecycle::Application
{
timespec crash_req{
static_cast<time_t>(timeTillCrash / 1000),
static_cast<long>((timeTillCrash % 1000) * 1000000L)
};
static_cast<long>((timeTillCrash % 1000) * 1000000L)};
nanosleep(&crash_req, nullptr);
}

Expand All @@ -201,7 +199,7 @@ class LifecycleApp final : public score::mw::lifecycle::Application
return EXIT_SUCCESS;
}

private:
private:
Config m_config{};
std::vector<char*> m_argvStorage{};
};
Expand Down
Loading
Loading