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

Update CI/CD for new tests #320

Merged
merged 20 commits into from
Sep 18, 2024
Merged
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
109 changes: 106 additions & 3 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ on:
permissions:
contents: read

env:
CCACHE_DIR: ${{ github.workspace }}/.ccache

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
clang-tidy:
runs-on: ubuntu-latest
Expand All @@ -20,7 +27,7 @@ jobs:
- name: Prepare
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Configure
run: cmake -DCMAKE_BUILD_TYPE=Debug -S . -B build
run: cmake -S . -B build
- name: Clang-tidy
run: run-clang-tidy -j`nproc` -p=build -header-filter=`pwd`/include/ src/*.cpp src/**/*.cpp

Expand All @@ -33,7 +40,82 @@ jobs:
- name: Run clang-format
run: clang-format include/**/*.hpp src/*.cpp src/**/*.cpp --verbose --dry-run --Werror
- name: Run cppcheck
run: cppcheck -Iinclude/ src --verbose --enable=all --error-exitcode=1 --std=c++14 --language=c++ --suppressions-list=cppcheckSuppressions.txt --inline-suppr
run: cppcheck -Iinclude/ src --verbose --enable=all --error-exitcode=1 --std=c++14 --language=c++ --suppressions-list=cppcheckSuppressions.txt --inline-suppr --check-level=exhaustive

memleak:
runs-on: ubuntu-latest
container: egecetinn/ubuntu2204
steps:
- name: Checkout Code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
submodules: recursive
- name: Prepare
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Restore ccache
id: ccache-restore
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: |
${{ env.CCACHE_DIR }}
key: memleak-ccache-${{ github.run_id }}
restore-keys: |
memleak-ccache
- name: Install Test Requirements
run: pip3 install -r tests/data/requirements.txt
- name: Configure
run: cmake -DXXX_ENABLE_MEMLEAK_CHECK=ON -S . -B build
- name: Build
run: cmake --build build --parallel
- name: Run tests
run: ctest --output-on-failure --test-dir build
- name: Save ccache
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ${{ env.CCACHE_DIR }}
key: ${{ steps.ccache-restore.outputs.cache-primary-key }}

fuzzer:
runs-on: ubuntu-latest
container: egecetinn/ubuntu2204
strategy:
matrix:
sanitizer: [ASAN, USAN]
steps:
- name: Checkout Code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
submodules: recursive
- name: Prepare
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Restore ccache
id: ccache-restore
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: |
${{ env.CCACHE_DIR }}
key: ${{ matrix.sanitizer }}-ccache-${{ github.run_id }}
restore-keys: |
${{ matrix.sanitizer }}-ccache
- name: Install Test Requirements
run: pip3 install -r tests/data/requirements.txt
- name: Configure
run: cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DXXX_BUILD_UNITTESTS=OFF -DXXX_BUILD_FUZZTESTS=ON -DXXX_ENABLE_${{ matrix.sanitizer }}=ON -S . -B build
- name: Build
run: cmake --build build --parallel
- name: Run tests
run: ctest --output-on-failure --test-dir build
- name: Save ccache
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ${{ env.CCACHE_DIR }}
key: ${{ steps.ccache-restore.outputs.cache-primary-key }}
- name: Upload regressions
if: failure()
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
with:
name: regressions-${{ matrix.sanitizer }}
path: build/tests/fuzztests/crash*

rockylinux:
runs-on: ubuntu-latest
Expand All @@ -43,8 +125,10 @@ jobs:
include:
- image: rockylinux8
- image: rockylinux8-icx
additional-flags: -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
- image: rockylinux9
- image: rockylinux9-icx
additional-flags: -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx

steps:
- name: Checkout Code
Expand All @@ -53,12 +137,31 @@ jobs:
submodules: recursive
- name: Prepare
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Setup Intel Compiler variables
if: contains(matrix.image, 'icx')
run: |
. /opt/intel/oneapi/setvars.sh
printenv >> $GITHUB_ENV
- name: Restore ccache
id: ccache-restore
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: |
${{ env.CCACHE_DIR }}
key: ${{ matrix.image }}-ccache-${{ github.run_id }}
restore-keys: |
${{ matrix.image }}-ccache
- name: Install Test Requirements
run: pip3 install -r tests/data/requirements.txt
- name: Configure
run: cmake -DCMAKE_BUILD_TYPE=Release -DXXX_ENABLE_ASAN=ON -DXXX_ENABLE_USAN=ON -S . -B build
run: cmake ${{ matrix.additional-flags }} -S . -B build
- name: Build
run: cmake --build build --parallel
- name: Run Tests
id: test-step
run: ctest --output-on-failure --test-dir build
- name: Save ccache
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ${{ env.CCACHE_DIR }}
key: ${{ steps.ccache-restore.outputs.cache-primary-key }}
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# Use ccache if available
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
message(STATUS "ccache found!")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_PROGRAM}")
else()
message(STATUS "ccache not found!")
endif()

# Disable/Enable options of subprojects
set(CPPZMQ_BUILD_TESTS OFF CACHE BOOL "")
set(ENABLE_TESTING OFF CACHE BOOL "") # prometheus-cpp
Expand Down
2 changes: 1 addition & 1 deletion include/connection/Http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class HTTP {
* Gets the host address of the object
* @return The host address
*/
std::string getHostAddress() const { return _hostAddr; }
const std::string &getHostAddress() const { return _hostAddr; }

/**
* Sends a GET request
Expand Down
2 changes: 1 addition & 1 deletion include/connection/RawSocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class RawSocket {
* Returns the binded ethernet interface
* @return std::string Name of the interface
*/
std::string getInterfaceName() const { return _iFace; }
const std::string &getInterfaceName() const { return _iFace; }

/**
* Writes data to the interface
Expand Down
4 changes: 2 additions & 2 deletions include/telnet/TelnetServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ class TelnetServer : public std::enable_shared_from_this<TelnetServer> {
void tabCallback(FPTR_TabCallback func) { m_tabCallback = std::move(func); }
FPTR_TabCallback tabCallback() const { return m_tabCallback; }

VEC_SP_TelnetSession sessions() const { return m_sessions; }
const VEC_SP_TelnetSession &sessions() const { return m_sessions; }

bool interactivePrompt() const { return m_promptString.length() > 0; }
void promptString(const std::string &prompt) { m_promptString = prompt; }
std::string promptString() const { return m_promptString; }
const std::string &promptString() const { return m_promptString; }

private:
// Called after the telnet session is initialised. function(SP_TelnetSession) {}
Expand Down
4 changes: 2 additions & 2 deletions include/utils/Hasher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

/**
* Calculates the compile-time hash value of a string.
* @param[in] s The input string.
* @param[in] s The input string. Must be null-terminated.
* @return The hash value of the input string.
*/
constexpr size_t constHasher(const char *s) { return *s ? *s + 33 * constHasher(s + 1) : 5381; }
constexpr size_t constHasher(const char *s) { return (s && *s) ? (*s + 33 * constHasher(s + 1)) : 5381; }

/**
* Generates entropy using the input string and an initial value.
Expand Down
20 changes: 12 additions & 8 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,27 @@ option(XXX_ENABLE_TSAN "Enables Thread Sanitizer for XXX" OFF)

# Sanitizers
if(XXX_ENABLE_ASAN)
target_compile_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=address")
target_link_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=address")
message(STATUS "Enabling Address Sanitizer")
target_compile_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=address")
target_link_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=address")
endif()

if(XXX_ENABLE_MSAN)
target_compile_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=memory")
target_link_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=memory")
message(STATUS "Enabling Memory Sanitizer")
target_compile_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=memory")
target_link_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=memory")
endif()

if(XXX_ENABLE_USAN)
target_compile_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=undefined")
target_link_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=undefined")
message(STATUS "Enabling Undefined Behaviour Sanitizer")
target_compile_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=undefined")
target_link_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=undefined")
endif()

if(XXX_ENABLE_TSAN)
target_compile_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=thread")
target_link_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=thread")
message(STATUS "Enabling Thread Sanitizer")
target_compile_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=thread")
target_link_options("${PROJECT_NAME}-lib" PUBLIC "-fsanitize=thread")
endif()

if(XXX_BUILD_UNITTESTS)
Expand Down
10 changes: 5 additions & 5 deletions tests/fuzztests/Hasher_FuzzTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
char seederBuffer[4096] = {'\0'};
char buffer[4096] = {'\0'};

std::string dataStr(reinterpret_cast<const char *>(data), size);
constHasher(dataStr.c_str());
memcpy(buffer, data, size > 4095 ? 4095 : size);
constHasher(buffer);

memcpy(seederBuffer, data, size > 4096 ? 4096 : size);
constSeeder(seederBuffer);
memcpy(buffer, data, size > 4096 ? 4096 : size);
constSeeder(buffer);

return 0;
}
20 changes: 0 additions & 20 deletions tests/fuzztests/Telnet_FuzzTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,6 @@

#define TELNET_SERVER_PORT 9001

// Parse fuzzer arguments
std::string findOptionValue(const std::string &option, int argc, char **argv)
{
for (int idx = 0; idx < argc; ++idx)
{
const std::string argument = argv[idx];
auto pos = argument.find("=");
if (pos != std::string::npos)
{
const std::string key = argument.substr(1, pos - 1);
if (key == option)
{
return argument.substr(pos + 1);
}
}
}

return "";
}

class SocketWrapper {
private:
int sockFd{-1};
Expand Down