Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cppcheck into ci #291

Merged
merged 28 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
76b118b
get cppcheck suppressions file
xygyo77 Jun 19, 2024
b0b015d
change NOLINT->cppcheck-suppress
xygyo77 Jun 19, 2024
5de7f01
NOLINT->cppcheck-suppress
xygyo77 Jun 20, 2024
b08a628
add cppcheck-all-files and remove clang-tidy-differential
xygyo77 Jun 20, 2024
5d90577
add NOLINT
xygyo77 Jun 20, 2024
e020db9
move suppression comments
xygyo77 Jun 20, 2024
67e3858
move suppression comments
xygyo77 Jun 20, 2024
5ddb07b
move suppression comments
xygyo77 Jun 20, 2024
36e41cf
move suppression comments
xygyo77 Jun 20, 2024
0bc36aa
move suppression comments
xygyo77 Jun 20, 2024
dd0bf8a
move suppression comments
xygyo77 Jun 20, 2024
af553f2
Update cppcheck-differential.yaml
xygyo77 Jun 20, 2024
158afa4
Update trace_node.cpp
xygyo77 Jun 20, 2024
8b462aa
temporary change
xygyo77 Jun 21, 2024
9ac3e80
change .cppcheck-suppressions download timing
xygyo77 Jun 21, 2024
c0576e1
add LF to build-and-test-differential.yaml
xygyo77 Jun 21, 2024
794d37e
ci(pre-commit): autofix
pre-commit-ci[bot] Jun 21, 2024
11d6de5
modify cppcheck-differential
xygyo77 Jun 21, 2024
7baa5e9
formatting cppcheck-differential
xygyo77 Jun 21, 2024
fbf0dd5
modify cppcheck-differential
xygyo77 Jun 21, 2024
1d56226
add install snapd
xygyo77 Jun 21, 2024
91acb11
fix workflow version
xygyo77 Jun 21, 2024
8a70fe1
cppcheck is installed via apt-get
xygyo77 Jun 21, 2024
da721ff
remove snapd and ros2 container
xygyo77 Jun 21, 2024
07f0307
fix files variable setting
xygyo77 Jun 21, 2024
5b4f355
fix files variable setting
xygyo77 Jun 21, 2024
2ce2617
Merge branch 'main' into add_cppcheck_ci
xygyo77 Jun 26, 2024
30be6bb
restore clang-tidy-differential
xygyo77 Jun 26, 2024
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
63 changes: 63 additions & 0 deletions .github/workflows/cppcheck-all-files.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: cppcheck-all-files

on:
pull_request:
workflow_dispatch:

jobs:
cppcheck-all-files:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y wget

# cppcheck from apt does not yet support --check-level args, and thus install from snap
- name: Install Cppcheck from snap
run: |
sudo snap install cppcheck

# Download the cppcheck suppression file
- name: Download cppcheck suppression file
run: |
wget https://raw.githubusercontent.com/autowarefoundation/autoware.universe/main/.cppcheck_suppressions -O .cppcheck_suppressions

- name: Get all C++ files
id: all-files
run: |
find . -type f \( -name "*.cpp" -o -name "*.hpp" \) > all_files.txt
cat all_files.txt

- name: Run Cppcheck on all files
continue-on-error: true
id: cppcheck
run: |
files=$(cat all_files.txt)
if [ -n "$files" ]; then
echo "Running Cppcheck on all files: $files"
cppcheck --inline-suppr --enable=all --inconclusive --check-level=exhaustive --error-exitcode=1 --suppressions-list=.cppcheck_suppressions $files 2> cppcheck-report.txt
else
echo "No C++ files found."
touch cppcheck-report.txt
fi
shell: bash

- name: Show cppcheck-report result
run: |
cat cppcheck-report.txt

- name: Upload Cppcheck report
uses: actions/upload-artifact@v4
with:
name: cppcheck-report
path: cppcheck-report.txt

- name: Fail the job if Cppcheck failed
if: ${{ steps.cppcheck.outcome == 'failure' }}
run: exit 1
83 changes: 83 additions & 0 deletions .github/workflows/cppcheck-differential.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: cppcheck-differential

on:
pull_request:

jobs:
cppcheck-differential:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y wget

# cppcheck from apt does not yet support --check-level args, and thus install from snap
- name: Install Cppcheck from snap
run: |
sudo snap install cppcheck

# Download the cppcheck suppression file
- name: Download cppcheck suppression file
run: |
wget https://raw.githubusercontent.com/autowarefoundation/autoware.universe/main/.cppcheck_suppressions -O .cppcheck_suppressions

- name: Remove exec_depend
uses: autowarefoundation/autoware-github-actions/remove-exec-depend@v1

- name: Get modified packages
id: get-modified-packages
uses: autowarefoundation/autoware-github-actions/get-modified-packages@v1

# Display the modified packages
- name: Show modified packages
run: |
echo "Modified packages:"
echo "${{ steps.get-modified-packages.outputs.modified_packages }}"

- name: Get modified files
id: get-modified-files
uses: tj-actions/changed-files@v44
with:
files: |
**/*.cpp
**/*.hpp

# Display the modified files
- name: Show modified files
run: |
echo "Modified files:"
echo "${{ steps.get-modified-files.outputs.all_changed_files }}"

- name: Run Cppcheck on changed files
continue-on-error: true
id: cppcheck
run: |
files=$(echo ${{ steps.get-modified-files.outputs.all_changed_files }})
if [ -n "$files" ]; then
echo "Running Cppcheck on changed files: $files"
cppcheck --inline-suppr --enable=all --inconclusive --check-level=exhaustive --error-exitcode=1 --suppressions-list=.cppcheck_suppressions $files 2> cppcheck-report.txt
else
echo "No C++ files changed."
touch cppcheck-report.txt
fi
shell: bash

- name: Show cppcheck-report result
run: |
cat cppcheck-report.txt

- name: Upload Cppcheck report
uses: actions/upload-artifact@v4
with:
name: cppcheck-report
path: cppcheck-report.txt

- name: Fail the job if Cppcheck failed
if: steps.cppcheck.outcome == 'failure'
run: exit 1
ymski marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 3 additions & 3 deletions CARET_trace/include/caret_trace/data_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ class DataContainer : public DataContainerInterface
std::shared_ptr<RclcppIpbToSubscription::KeysT> rclcpp_ipb_to_subscription,
std::shared_ptr<RmwImplementation::KeysT> rmw_implementation);

bool record(uint64_t loop_count = 1);
bool record(uint64_t loop_count = 1) override;

void start_recording();
void start_recording() override;

void reset();
void reset() override;

/// @brief Store data for add_callback_group trace points.
/// @tparam ...Args Data types to be stored.
Expand Down
6 changes: 3 additions & 3 deletions CARET_trace/include/caret_trace/lttng_session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ class LttngSessionImpl : public LttngSession
public:
LttngSessionImpl() : started_session_running_(is_session_running()) {}

~LttngSessionImpl() {}
~LttngSessionImpl() override {}

bool is_session_running() const;
bool started_session_running() const;
bool is_session_running() const override;
bool started_session_running() const override;

private:
mutable std::mutex mtx_;
Expand Down
2 changes: 1 addition & 1 deletion CARET_trace/include/caret_trace/trace_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class TraceNode : public rclcpp::Node, public TraceNodeInterface
rclcpp::Logger::Level level = rclcpp::Logger::Level::Info, bool use_log = false,
bool execute_timer_on_run = true);

~TraceNode();
~TraceNode() override;

/// @brief Check whther current status allows recording.
/// @return True if recording is allowed, false otherwise.
Expand Down
2 changes: 2 additions & 0 deletions CARET_trace/src/trace_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,14 @@ bool TraceNode::is_recording_allowed() const
bool TraceNode::is_recording_allowed_init() const
{
return true;
#if 0 // ignore following
std::shared_lock<std::shared_mutex> lock(mutex_);

// NOTE: Since PREPARE to RECORD is a continuous state transition
// with a return value of TRUE, no mutex is required.
// On the other hand, the transition to the PREPARE state is a boundary, so a mutex is required.
return status_ == TRACE_STATUS::RECORD || status_ == TRACE_STATUS::PREPARE;
#endif
}

const TRACE_STATUS & TraceNode::get_status() const
Expand Down
6 changes: 6 additions & 0 deletions CARET_trace/test/test_scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ using rclcpp::Logger;

void add_data(DataContainer & container, int loop)
{
// cppcheck-suppress-begin nullPointerArithmetic
char * ptr = nullptr;
for (auto i = 0; i < loop; i++) {
ptr++;
container.store_rcl_init(ptr, 0);
}
// cppcheck-suppress-end nullPointerArithmetic
}

void record_data(DataContainer & container, int loop)
Expand All @@ -66,11 +68,13 @@ TEST(ScenarioTest, TestSingleThread)

auto loop = 1000;

// cppcheck-suppress-begin nullPointerArithmetic
char * ptr = nullptr;
for (auto i = 0; i < loop; i++) {
ptr++;
EXPECT_CALL(rcl_init_mock, Call(ptr, 0)).Times(1);
}
// cppcheck-suppress-end nullPointerArithmetic

add_data(container, loop);
container.record(loop);
Expand All @@ -92,11 +96,13 @@ TEST(ScenarioTest, TestMultiThread)

auto loop = 1000;

// cppcheck-suppress-begin nullPointerArithmetic
char * ptr = nullptr;
for (auto i = 0; i < loop; i++) {
ptr++;
EXPECT_CALL(rcl_init_mock, Call(ptr, 0)).WillRepeatedly(Return());
}
// cppcheck-suppress-end nullPointerArithmetic

// NOTE: Ensure recording data. Avoid container.record() before add_data() is called.
add_data(container, 1);
Expand Down
Loading