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
106 changes: 106 additions & 0 deletions .github/workflows/build_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Build and test

on:
workflow_dispatch:

push:
branches:
- main
- develop
- feature*

pull_request_target:
types:
- edited
- opened
- reopened
- synchronize

branches:
- main
- develop
- feature*

jobs:
build:
runs-on: ubuntu-22.04
permissions: read-all
container:
image: ghcr.io/aosedge/aos-core-build-base:latest
options: "--entrypoint /usr/bin/bash"
credentials:
username: ${{ github.actor }}
password: ${{ github.token }}

env:
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory

steps:
# Apply solution to "HOME is overridden for containers" problem: https://github.com/actions/runner/issues/863
- name: Preserve $HOME set in the container
run: echo HOME=/root >> "$GITHUB_ENV"

- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
fetch-depth: 0

- name: Install Build Wrapper
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v4

- name: Build using SonarQube Build Wrapper
run: |
mkdir build

conan profile detect --force

conan install ./conan/ --output-folder build --settings=build_type=Debug --build=missing
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DWITH_TEST=ON -DWITH_COVERAGE=ON -DWITH_VCHAN=OFF -G "Unix Makefiles" \
-DWITH_MBEDTLS=OFF -DWITH_OPENSSL=ON -DCMAKE_TOOLCHAIN_FILE=./conan_toolchain.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build ./build/ --config Debug --parallel

- name: Run Tests
run: |
cd build
make coverage

# - name: Static analysis
# run: |
# cppcheck --enable=all --inline-suppr -I src --std=c++17 --error-exitcode=1 \
# --suppressions-list=./suppressions.txt --project=build/compile_commands.json --file-filter='src/*'

- name: Upload codecov report
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./build/coverage.total

- name: SonarCloud Scan on push
if: github.event_name == 'push'
uses: SonarSource/sonarqube-scan-action@v4
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

with:
args: >
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"
--define sonar.coverageReportPaths=build/coverage_sonarqube.xml

- name: SonarCloud Scan on pull request
if: github.event_name == 'pull_request_target'
uses: SonarSource/sonarqube-scan-action@v4
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

with:
projectBaseDir: "."
args: >
--define sonar.scm.revision=${{ github.event.pull_request.head.sha }}
--define sonar.pullrequest.key=${{ github.event.pull_request.number }}
--define sonar.pullrequest.branch=${{ github.event.pull_request.head.ref }}
--define sonar.pullrequest.base=${{ github.event.pull_request.base.ref }}
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"
--define sonar.coverageReportPaths=build/coverage_sonarqube.xml
29 changes: 29 additions & 0 deletions .github/workflows/check_format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Check formatting

on:
push:
branches:
- main

pull_request:
branches:
- develop
- feature_*

jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Run clang-format style check
uses: jidicula/clang-format-action@v4.11.0
with:
clang-format-version: "15"

- name: Run cmake-format style check
run: |
python -m pip install --upgrade pip
pip install cmake_format
find . \( \( -not -path '*/build/*' \) -name '*.cmake' -or -name 'CMakeLists.txt' \) \
-exec cmake-format --check {} +;
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ if(WITH_COVERAGE)

append_coverage_compiler_flags()

set(COVERAGE_EXCLUDES "build/*" "tests/*" "/usr/*")
set(COVERAGE_EXCLUDES "build/*" "/usr/*")
set(GCOVR_ADDITIONAL_ARGS --gcov-ignore-parse-errors negative_hits.warn)

setup_target_for_coverage_lcov(
NAME
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[![ci](https://github.com/aosedge/aos_core_cpp/actions/workflows/build_test.yaml/badge.svg)](https://github.com/aosedge/aos_core_cpp/actions/workflows/build_test.yaml)
[![codecov](https://codecov.io/gh/aosedge/aos_core_cpp/graph/badge.svg?token=MknkthRkpf)](https://codecov.io/gh/aosedge/aos_core_cpp)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=aosedge_aos_core_cpp&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=aosedge_aos_core_cpp)

# AosCore C++ implementation

## Prepare build environment
Expand Down
Empty file added dummy.txt
Empty file.
12 changes: 12 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sonar.projectKey=aosedge_aos_core_cpp
sonar.organization=aosedge

sonar.sources=src/
sonar.exclusions=**/tests/**

sonar.tests=src/
sonar.test.inclusions=**/tests/**

sonar.coverage.exclusions=**/tests/**

sonar.cfamily.compile-commands=build/compile_commands.json
2 changes: 2 additions & 0 deletions src/common/jsonprovider/jsonprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ AlertRulePercents AlertRulePercentsFromJSON(const utils::CaseInsensitiveObjectWr
if (const auto minTimeout = object.GetOptionalValue<std::string>("minTimeout"); minTimeout.has_value()) {
Error err;

// cppcheck-suppress unusedScopedObject
Tie(percents.mMinTimeout, err) = utils::ParseDuration(minTimeout->c_str());
AOS_ERROR_CHECK_AND_THROW(err, "min timeout parsing error");
}
Expand All @@ -271,6 +272,7 @@ AlertRulePoints AlertRulePointsFromJSON(const utils::CaseInsensitiveObjectWrappe
if (const auto minTimeout = object.GetOptionalValue<std::string>("minTimeout"); minTimeout.has_value()) {
Error err;

// cppcheck-suppress unusedScopedObject
Tie(points.mMinTimeout, err) = utils::ParseDuration(minTimeout->c_str());
AOS_ERROR_CHECK_AND_THROW(err, "min timeout parsing error");
}
Expand Down
1 change: 1 addition & 0 deletions src/common/logger/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define AOS_COMMON_LOGGER_LOGGER_HPP_

#include <mutex>
#include <string>

#include <aos/common/tools/log.hpp>

Expand Down
2 changes: 1 addition & 1 deletion src/common/migration/tests/migration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ TEST_F(MigrationTest, MergeMigration)

WriteMigrationScript(secondDownSql, "CREATE TABLE IF NOT EXISTS test2 (id INTEGER PRIMARY KEY);", cMigrationDir);

aos::common::migration::Migration migration {*mSession, cMigrationDir, cMergedMigrationDir};
[[maybe_unused]] aos::common::migration::Migration migration {*mSession, cMigrationDir, cMergedMigrationDir};

EXPECT_TRUE(fs::exists(fs::path(cMergedMigrationDir) / firstUpSql));
EXPECT_TRUE(fs::exists(fs::path(cMergedMigrationDir) / secondUpSql));
Expand Down
5 changes: 3 additions & 2 deletions src/common/network/interfacemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ Error InterfaceManager::GetAddrList(const String& ifname, int family, Array<IPAd
IPAddr ipAddr;
ipAddr.mFamily = rtnl_addr_get_family(addr);

if (auto local = rtnl_addr_get_local(addr); local) {
if (const auto* local = rtnl_addr_get_local(addr); local) {
char buf[INET6_ADDRSTRLEN];

nl_addr2str(local, buf, sizeof(buf));
Expand Down Expand Up @@ -468,7 +468,7 @@ Error InterfaceManager::GetRouteList(Array<RouteInfo>& routes) const
info.mLinkIndex = rtnl_route_nh_get_ifindex(nh);

if (rtnl_route_get_table(route) == RT_TABLE_MAIN) {
if (auto* dst = rtnl_route_get_dst(route); dst && nl_addr_get_prefixlen(dst) > 0) {
if (const auto* dst = rtnl_route_get_dst(route); dst && nl_addr_get_prefixlen(dst) > 0) {
char buf[INET6_ADDRSTRLEN];

nl_addr2str(dst, buf, sizeof(buf));
Expand Down Expand Up @@ -550,6 +550,7 @@ Error InterfaceManager::CreateVlan(const String& name, uint64_t vlanId)
vlanAttrs.mName = name.CStr();
vlanAttrs.mParentIndex = masterIndex;

// cppcheck-suppress unusedScopedObject
if (Tie(vlanAttrs.mMac, err) = GenerateMACAddress(*mRandom); !err.IsNone()) {
return err;
}
Expand Down
1 change: 1 addition & 0 deletions src/common/ocispec/imagespec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Error OCISpec::LoadImageSpec(const String& path, aos::oci::ImageSpec& imageSpec)
imageSpec.mVariant = variant.c_str();

if (const auto created = wrapper.GetOptionalValue<std::string>("created"); created.has_value()) {
// cppcheck-suppress unusedScopedObject
Tie(imageSpec.mCreated, err) = utils::FromUTCString(created->c_str());
AOS_ERROR_CHECK_AND_THROW(err, "created time parsing error");
}
Expand Down
6 changes: 6 additions & 0 deletions src/common/ocispec/serviceconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ void RunParametersFromJSON(const utils::CaseInsensitiveObjectWrapper& object, Ru
Error err;

if (const auto startInterval = object.GetOptionalValue<std::string>("startInterval"); startInterval.has_value()) {
// cppcheck-suppress unusedScopedObject
Tie(params.mStartInterval, err) = utils::ParseDuration(*startInterval);
AOS_ERROR_CHECK_AND_THROW(err, "start interval parsing error");
}

if (const auto restartInterval = object.GetOptionalValue<std::string>("restartInterval");
restartInterval.has_value()) {
// cppcheck-suppress unusedScopedObject
Tie(params.mRestartInterval, err) = utils::ParseDuration(*restartInterval);
AOS_ERROR_CHECK_AND_THROW(err, "restart interval parsing error");
}
Expand Down Expand Up @@ -302,6 +304,7 @@ AlertRulePercents AlertRulePercentsFromJSON(const utils::CaseInsensitiveObjectWr
if (const auto minTimeout = object.GetOptionalValue<std::string>("minTimeout"); minTimeout.has_value()) {
Error err;

// cppcheck-suppress unusedScopedObject
Tie(percents.mMinTimeout, err) = utils::ParseDuration(minTimeout->c_str());
AOS_ERROR_CHECK_AND_THROW(err, "min timeout parsing error");
}
Expand All @@ -319,6 +322,7 @@ AlertRulePoints AlertRulePointsFromJSON(const utils::CaseInsensitiveObjectWrappe
if (const auto minTimeout = object.GetOptionalValue<std::string>("minTimeout"); minTimeout.has_value()) {
Error err;

// cppcheck-suppress unusedScopedObject
Tie(points.mMinTimeout, err) = utils::ParseDuration(minTimeout->c_str());
AOS_ERROR_CHECK_AND_THROW(err, "min timeout parsing error");
}
Expand Down Expand Up @@ -442,6 +446,7 @@ Error OCISpec::LoadServiceConfig(const String& path, aos::oci::ServiceConfig& se
utils::CaseInsensitiveObjectWrapper wrapper(object);

if (const auto created = wrapper.GetOptionalValue<std::string>("created"); created.has_value()) {
// cppcheck-suppress unusedScopedObject
Tie(serviceConfig.mCreated, err) = utils::FromUTCString(created->c_str());
AOS_ERROR_CHECK_AND_THROW(err, "created time parsing error");
}
Expand Down Expand Up @@ -474,6 +479,7 @@ Error OCISpec::LoadServiceConfig(const String& path, aos::oci::ServiceConfig& se
}

if (const auto offlineTTLStr = wrapper.GetOptionalValue<std::string>("offlineTTL"); offlineTTLStr.has_value()) {
// cppcheck-suppress unusedScopedObject
Tie(serviceConfig.mOfflineTTL, err) = utils::ParseDuration(*offlineTTLStr);
AOS_ERROR_CHECK_AND_THROW(err, "offlineTTL parsing error");
}
Expand Down
7 changes: 3 additions & 4 deletions src/common/tests/utils/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <filesystem>
#include <iostream>
#include <numeric>
#include <sstream>

#include <Poco/String.h>
Expand Down Expand Up @@ -132,10 +133,8 @@ RetWithError<std::vector<PartInfo>> FormatDisk(const std::string& loopDev, const
RetWithError<TestDisk> NewTestDisk(const std::string& path, const std::vector<PartDesc>& desc)
{
// skip 1M for GPT table etc. and add 1M after device
uint64_t totalSize = 2;

for (auto const& p : desc)
totalSize += p.mSize;
uint64_t totalSize = std::accumulate(
desc.begin(), desc.end(), uint64_t {2}, [](uint64_t sum, const PartDesc& p) { return sum + p.mSize; });

TestDisk disk(path);

Expand Down
1 change: 1 addition & 0 deletions src/common/utils/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ RetWithError<Duration> ParseISO8601Duration(const std::string& duration)

totalDuration += delta;

// cppcheck-suppress unusedScopedObject
Tie(delta, err) = ParseISO8601DurationTime(match[2].str());
if (!err.IsNone()) {
return {{}, AOS_ERROR_WRAP(err)};
Expand Down
5 changes: 4 additions & 1 deletion src/iam/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ IAMClientConfig ParseIAMClientConfig(const common::utils::CaseInsensitiveObjectW
config.mMainIAMProtectedServerURL = object.GetValue<std::string>("mainIAMProtectedServerURL");
auto nodeReconnectInterval = object.GetOptionalValue<std::string>("nodeReconnectInterval").value_or("10s");

Error err = ErrorEnum::eNone;
Error err = ErrorEnum::eNone;

// cppcheck-suppress unusedScopedObject
Tie(config.mNodeReconnectInterval, err) = common::utils::ParseDuration(nodeReconnectInterval);
AOS_ERROR_CHECK_AND_THROW(err, "nodeReconnectInterval parse error");

Expand Down Expand Up @@ -261,6 +263,7 @@ RetWithError<VISIdentifierModuleParams> ParseVISIdentifierModuleParams(Poco::Dyn
Error err;

Tie(moduleParams.mWebSocketTimeout, err)
// cppcheck-suppress unusedScopedObject
= common::utils::ParseDuration(object.GetValue<std::string>("webSocketTimeout", "120s"));
AOS_ERROR_CHECK_AND_THROW(err, "failed to parse webSocketTimeout");
} catch (const std::exception& e) {
Expand Down
2 changes: 1 addition & 1 deletion src/iam/fileidentifier/fileidentifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Error FileIdentifier::Init(const config::IdentifierConfig& config, identhandler:

try {
Error err;

// cppcheck-suppress unusedScopedObject
Tie(mConfig, err) = config::ParseFileIdentifierModuleParams(config.mParams);
if (!err.IsNone()) {
return err;
Expand Down
Loading
Loading