Skip to content

Commit

Permalink
Add asan build option and create asan github action
Browse files Browse the repository at this point in the history
Signed-off-by: RaulSanchez <raul@eprosima.com>
  • Loading branch information
rsanchez15 committed Oct 27, 2022
1 parent 2c777cf commit 3cf463e
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 4 deletions.
25 changes: 25 additions & 0 deletions .github/actions/install-apt-packages copy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 'install-apt-packages'
description: 'Install necessary apt packages'
runs:
using: "composite"
steps:
- id: install-apt-packages
run: |
sudo apt update && sudo apt -y install \
clang-tidy \
curl \
doxygen \
graphviz \
grep \
imagemagick \
libasio-dev \
libtinyxml2-dev \
libyaml-cpp-dev \
lcov \
python3 \
python3-pip \
python3-sphinxcontrib.spelling \
python3-venv \
software-properties-common \
wget
shell: bash
21 changes: 21 additions & 0 deletions .github/actions/install-gtest-linux/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Install GTest
description: Install and setup GTest for linking and building test application in Linux
runs:
using: composite
steps:
- run: sudo apt install libgtest-dev libgmock-dev
shell: bash
- run: (cd /usr/src/gtest && sudo `which cmake` .)
shell: bash
- run: sudo make -j $(nproc) -C /usr/src/gtest
shell: bash
- run: sudo ln -s /usr/src/gtest/libgtest.a /usr/lib/libgtest.a
shell: bash
- run: sudo ln -s /usr/src/gtest/libgtest_main.a /usr/lib/libgtest_main.a
shell: bash
- run: (cd /usr/src/googletest/googlemock && sudo `which cmake` .)
shell: bash
- run: sudo make -j $(nproc) -C /usr/src/googletest/googlemock
shell: bash
- run: sudo ln -s /usr/src/googletest/googlemock/libgmock.a /usr/lib/libgmock.a
shell: bash
3 changes: 2 additions & 1 deletion .github/actions/install-python-packages/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ runs:
colcon-mixin \
vcstool \
setuptools \
gcovr
gcovr \
tomark
shell: bash
70 changes: 70 additions & 0 deletions .github/workflows/asan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Address Sanitizer analysis

on:
workflow_dispatch:
pull_request:
push:
branches:
- main
schedule:
- cron: '0 1 * * *'

jobs:

asan-test:
runs-on: ubuntu-20.04

steps:
- name: Sync eProsima/Fast-DDS repository
uses: actions/checkout@v3
with:
path: src/Fast-DDS

- name: Install apt packages
uses: ./src/Fast-DDS/.github/actions/install-apt-packages

- name: Install GTest
uses: ./src/Fast-DDS/.github/actions/install-gtest-linux

- name: Install Python packages
uses: ./src/Fast-DDS/.github/actions/install-python-packages

- name: Update colcon mixin
run: |
colcon mixin add default \
https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml
colcon mixin update default
continue-on-error: true

- name: Fetch Fast DDS dependencies
uses: ./src/Fast-DDS/.github/actions/fetch-fastdds-repos

- name: Build workspace
run: |
cat src/Fast-DDS/.github/workflows/asan_colcon.meta
colcon build \
--event-handlers=console_direct+ \
--metas src/Fast-DDS/.github/workflows/asan_colcon.meta
- name: Run tests Fast DDS
run: |
source install/setup.bash && \
colcon test \
--packages-select fastrtps \
--event-handlers=console_direct+ \
--return-code-on-test-failure \
--ctest-args --timeout 60
- name: Upload Logs
uses: actions/upload-artifact@v1
with:
name: asan-logs
path: log/
if: always()

- name: Report ASAN errors
if: always()
run: |
echo -n "**ASAN Errors**: " >> $GITHUB_STEP_SUMMARY
echo $(sed 's/==.*==ERROR:/==.*==ERROR:\n/g' log/latest_test/fastrtps/stdout_stderr.log | grep -c "==.*==ERROR:") >> $GITHUB_STEP_SUMMARY
python3 src/Fast-DDS/.github/workflows/asan_log_parser.py
22 changes: 22 additions & 0 deletions .github/workflows/asan_colcon.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"names":
{
"fastrtps":
{
"cmake-args":
[
"-DCMAKE_BUILD_TYPE=Debug",
"-DEPROSIMA_BUILD_TESTS=ON",
"-DGTEST_INDIVIDUAL=ON",
"-DRTPS_API_TESTS=ON",
"-DFASTRTPS_API_TESTS=ON",
"-DFASTDDS_PIM_API_TESTS=ON",
"-DPERFORMANCE_TESTS=ON",
"-DSECURITY=ON",
"-DFASTDDS_STATISTICS=ON",
"-DASAN_BUILD=ON",
"-DCMAKE_CXX_FLAGS='-Werror'"
]
}
}
}
53 changes: 53 additions & 0 deletions .github/workflows/asan_log_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# 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 to parse the colcon test output file."

import re
import os

from tomark import Tomark

# Python summary file saved in GITHUB_STEP_SUMMARY environment variable
SUMMARY_FILE = os.getenv('GITHUB_STEP_SUMMARY')
LOG_FILE = 'log/latest_test/fastrtps/stdout_stderr.log'

# Save the lines with failed tests
saved_lines = []
with open(LOG_FILE, 'r') as file:
for line in reversed(file.readlines()):
saved_lines.append(line)
if (re.search('.*The following tests FAILED:.*', line)):
break

# Exit if no test failed
if (not saved_lines):
exit(0)

failed_tests = []
for test in saved_lines:
match = re.search('\d* - .* \(Failed\)', test)
if (match):
split_test = match.group().split()
failed_tests.insert(
0,
dict({'ID': split_test[0], 'Name': split_test[2]}))

# Convert python dict to markdown table
md_table = Tomark.table(failed_tests)
print(md_table)

# Save table of failed test to GitHub action summary file
with open(SUMMARY_FILE, 'a') as file:
file.write(f'\n{md_table}')
32 changes: 29 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if(MSVC OR MSVC_IDE)
endif()

# make visual studio more gcc and clang like.
# C4101 'identifier' : unreferenced local variable
# C4101 'identifier' : unreferenced local variable
# C4189 'identifier' : local variable is initialized but not referenced
# C4555 expression has no effect; expected expression with side-effect
# C4715: 'Test': not all control paths return a value
Expand Down Expand Up @@ -103,6 +103,32 @@ check_stdcxx(${FORCE_CXX})

check_endianness()

###############################################################################
# Activate Address sanitizer
###############################################################################
option(ASAN_BUILD "Activate address sanitizer flags" OFF)

if (ASAN_BUILD)
# Warning/Error messages
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
message(WARNING "Address sanitizer results with an optimized (non-Debug) build may be misleading")
endif()

if("${CMAKE_C_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
message(STATUS "Building with llvm Address sanitizer Tools")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
elseif(CMAKE_COMPILER_IS_GNUCXX)
message(STATUS "Building with Address sanitizer Tools")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
else()
message(FATAL_ERROR "Address sanitizer requires Clang or GCC. Aborting.")
endif()
endif()

###############################################################################
# Installation paths
###############################################################################
Expand Down Expand Up @@ -298,7 +324,7 @@ option(FASTDDS_STATISTICS "Enable Fast DDS Statistics Module" OFF)
add_subdirectory(src/cpp)

###############################################################################
# Add http://optionparser.sourceforge.net/ as unified cli parser
# Add http://optionparser.sourceforge.net/ as unified cli parser
###############################################################################
add_subdirectory(thirdparty/optionparser)

Expand Down Expand Up @@ -425,7 +451,7 @@ if(BUILD_DOCUMENTATION)
configure_file(${CMAKE_CURRENT_BINARY_DIR}/readthedocs_custom_template.cmake ${CMAKE_CURRENT_BINARY_DIR}/readthedocs_custom.cmake)

add_custom_target(readthedocs
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/readthedocs_custom.cmake
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/readthedocs_custom.cmake
)

add_dependencies(readthedocs docdirs)
Expand Down

0 comments on commit 3cf463e

Please sign in to comment.