Skip to content

Commit

Permalink
Merge pull request #362 from MissouriMRDT/topic/cleanup
Browse files Browse the repository at this point in the history
Cleanup GitHub Actions and Testing Framework
  • Loading branch information
Byrdman32 authored Jan 8, 2025
2 parents d96e7f5 + 1fe5612 commit d4946d5
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 125 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,29 @@ jobs:
if [ -d "build" ]; then rm -Rf build; fi
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS_MODE=ON -DBUILD_CODE_COVERAGE=ON -DBUILD_VERBOSE_MODE=ON
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS_MODE=ON -DBUILD_CODE_COVERAGE=ON -DBUILD_COVERAGE_WATCH=OFF -DBUILD_VERBOSE_MODE=ON
make -j8
- name: Test
- name: Run Tests
run: |
cd /opt/Autonomy_Software/build
ctest --output-on-failure -T Test -T Coverage
ctest --output-on-failure --output-junit Test.xml
gcovr --root .. --xml-pretty --output Coverage.xml
lcov -c -d . -o coverage.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
ctest --output-on-failure -T Test -T Coverage -R UTest --output-junit UTests.xml
ctest --output-on-failure -T Test -T Coverage -R ITest --output-junit ITests.xml
gcovr --root .. --xml-pretty --output AllCoverage.xml
- name: Upload Test Coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
root_dir: /opt/Autonomy_Software
working-directory: /opt/Autonomy_Software
verbose: true
plugin: gcov
plugins: gcov
directory: /opt/Autonomy_Software/build
file: /opt/Autonomy_Software/build/Coverage.xml

- name: Upload test results to Codecov
files: /opt/Autonomy_Software/build/AllCoverage.xml
- name: Upload Test Results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
Expand All @@ -87,7 +87,7 @@ jobs:
working-directory: /opt/Autonomy_Software/build
verbose: true
directory: /opt/Autonomy_Software/build/
file: Test.xml
files: UTests.xml, ITests.xml

- name: Cleanup Action Environment
if: always()
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@ jobs:
if: always()
run: |
cd /opt
rm -rf /opt/Autonomy_Software
rm -rf /opt/Autonomy_Software
69 changes: 49 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ option(BUILD_SIM_MODE "Enable Simulation Mode" OFF)
## Enable or Disable Code Coverage Mode
option(BUILD_CODE_COVERAGE "Enable Code Coverage Mode" OFF)

## Enable or Disable Coverage Watch Mode
option(BUILD_COVERAGE_WATCH "Enable Code Coverage Watch Mode" ON)

## Enable or Disable Verbose Makefile
option(BUILD_VERBOSE_MODE "Enable Verbose Makefile" OFF)

Expand Down Expand Up @@ -77,18 +80,6 @@ if (BUILD_CODE_COVERAGE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -fprofile-arcs -ftest-coverage --coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")

add_custom_target(run_coverage ALL
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
COMMAND gcovr --root ${CMAKE_SOURCE_DIR} --xml-pretty --output Coverage.xml
COMMAND lcov -c -d . -o coverage.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running tests and generating coverage reports..."
VERBATIM
)

# Ensure dependencies for the run_coverage target. Tests must be built first.
add_dependencies(run_coverage ${EXE_NAME}_UnitTests ${EXE_NAME}_IntegrationTests)
else()
message("-- [ ]: Code Coverage: Disabled")
endif()
Expand Down Expand Up @@ -343,33 +334,71 @@ endif()

## Tests Mode
if (BUILD_TESTS_MODE)
file(GLOB_RECURSE UnitTests_SRC CONFIGURE_DEPENDS "tests/Unit/*.cc")
file(GLOB_RECURSE IntegrationTests_SRC CONFIGURE_DEPENDS "tests/Integration/*.cc")
## Find Unit and Integration Tests
file(GLOB_RECURSE UTests_SRC CONFIGURE_DEPENDS "tests/Unit/src/*.cc")
file(GLOB_RECURSE ITests_SRC CONFIGURE_DEPENDS "tests/Integration/src/*.cc")
file(GLOB Runner_SRC CONFIGURE_DEPENDS "tests/main.cc")

## Find Source Files Required for Tests
file(GLOB_RECURSE Algorithms_SRC CONFIGURE_DEPENDS "src/algorithms/*.cpp")
file(GLOB_RECURSE Drivers_SRC CONFIGURE_DEPENDS "src/drivers/*.cpp")
file(GLOB_RECURSE Vision_SRC CONFIGURE_DEPENDS "src/vision/*.cpp")
file(GLOB Network_SRC CONFIGURE_DEPENDS "src/AutonomyNetworking.cpp")
file(GLOB Logging_SRC CONFIGURE_DEPENDS "src/AutonomyLogging.cpp")
file(GLOB Globals_SRC CONFIGURE_DEPENDS "src/AutonomyGlobals.cpp")

list(LENGTH UnitTests_SRC UnitTests_LEN)
list(LENGTH IntegrationTests_SRC IntegrationTests_LEN)
list(LENGTH UTests_SRC UnitTests_LEN)
list(LENGTH ITests_SRC IntegrationTests_LEN)

string(TIMESTAMP CURRENT_TIMESTAMP "%Y%m%d-%H%M%S")
message("-- Current Timestamp: ${CURRENT_TIMESTAMP}")

if (UnitTests_LEN GREATER 0)
add_executable(${EXE_NAME}_UnitTests ${UnitTests_SRC} ${Algorithms_SRC} ${Drivers_SRC} ${Vision_SRC} ${Network_SRC} ${Logging_SRC} ${Globals_SRC})
add_executable(${EXE_NAME}_UnitTests ${Runner_SRC} ${UTests_SRC} ${Algorithms_SRC} ${Drivers_SRC} ${Vision_SRC} ${Network_SRC} ${Logging_SRC} ${Globals_SRC})
target_link_libraries(${EXE_NAME}_UnitTests GTest::gtest GTest::gtest_main ${AUTONOMY_LIBRARIES})
add_test(Unit_Tests ${EXE_NAME}_UnitTests)

foreach(test_file ${UTests_SRC})
get_filename_component(test_name ${test_file} NAME_WE)
add_test(NAME UTest_${test_name} COMMAND ${EXE_NAME}_UnitTests --gtest_filter=${test_name}Test.* --timestamp=${CURRENT_TIMESTAMP})
endforeach()
else()
message("No Unit Tests!")
endif()

if (IntegrationTests_LEN GREATER 0)
add_executable(${EXE_NAME}_IntegrationTests ${IntegrationTests_SRC} ${Algorithms_SRC} ${Drivers_SRC} ${Vision_SRC} ${Network_SRC} ${Logging_SRC} ${Globals_SRC})
add_executable(${EXE_NAME}_IntegrationTests ${Runner_SRC} ${ITests_SRC} ${Algorithms_SRC} ${Drivers_SRC} ${Vision_SRC} ${Network_SRC} ${Logging_SRC} ${Globals_SRC})
target_link_libraries(${EXE_NAME}_IntegrationTests GTest::gtest GTest::gtest_main ${AUTONOMY_LIBRARIES})
add_test(Integration_Tests ${EXE_NAME}_IntegrationTests)

foreach(test_file ${ITests_SRC})
get_filename_component(test_name ${test_file} NAME_WE)
add_test(NAME ITest_${test_name} COMMAND ${EXE_NAME}_IntegrationTests --gtest_filter=${test_name}Test.* --timestamp=${CURRENT_TIMESTAMP})
endforeach()
else()
message("No Integration Tests!")
endif()

if (BUILD_CODE_COVERAGE AND BUILD_COVERAGE_WATCH)
add_custom_target(run_coverage ALL
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
COMMAND gcovr --root ${CMAKE_SOURCE_DIR} --xml-pretty --output Coverage.xml
COMMAND lcov -c -d . -o coverage.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running tests and generating coverage reports..."
VERBATIM
)

# Ensure dependencies for the run_coverage target. Tests must be built first.
if (UnitTests_LEN GREATER 0 AND IntegrationTests_LEN GREATER 0)
add_dependencies(run_coverage ${EXE_NAME}_UnitTests ${EXE_NAME}_IntegrationTests)
elseif (UnitTests_LEN GREATER 0)
add_dependencies(run_coverage ${EXE_NAME}_UnitTests)
elseif (IntegrationTests_LEN GREATER 0)
add_dependencies(run_coverage ${EXE_NAME}_IntegrationTests)
else()
message("No Tests to Run! run_coverage target will not be created.")
set_target_properties(run_coverage PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()
endif()
endif()

####################################################################################################################
Expand Down
11 changes: 10 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ coverage:
project:
default:
target: auto
informational: true
threshold: 5%
flags:
- unit_tests
- integration_tests
patch:
default:
target: auto
threshold: 5%
flags:
- unit_tests
- integration_tests
changes: false

ignore:
Expand Down Expand Up @@ -67,7 +76,7 @@ component_management:
- src/*.cpp

comment:
layout: "header, diff, flags, files, components"
layout: "header, diff, files, flags, components"
behavior: default
require_changes: false
require_base: false
Expand Down
1 change: 1 addition & 0 deletions data/Custom_Dictionaries/Autonomy-Dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ bytem
byteswap
CAFFE
CALIB
carryforward
CELLVOLTAGE
charconv
chromaprint
Expand Down
41 changes: 15 additions & 26 deletions src/AutonomyLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,15 @@ namespace logging
* @author Eli Byrd ([email protected])
* @date 2023-08-22
******************************************************************************/
void InitializeLoggers(std::string szLoggingOutputPath)
void InitializeLoggers(std::string szLoggingOutputPath, std::string szProgramTimeLogsDir)
{
// Retrieve the current time for the log file name
std::chrono::time_point<std::chrono::system_clock> tmCurrentTime = std::chrono::system_clock::now();
std::time_t tCurrentTime = std::chrono::system_clock::to_time_t(tmCurrentTime);

// Convert time to local time
std::tm* tLocalTime = std::localtime(&tCurrentTime);

// Format the current time in a format that can be used as a file name.
std::array<char, 80> cCurrentTime;
size_t siTimeCharacters;
siTimeCharacters = std::strftime(cCurrentTime.data(), cCurrentTime.size(), "%Y%m%d-%H%M%S", tLocalTime);
if (siTimeCharacters == 0)
{
std::cerr << "Unable to format calendar date & time (exceeds string length)" << std::endl;
}
// Store start time string in member variable.
g_szProgramStartTimeString = cCurrentTime.data();
g_szProgramStartTimeString = szProgramTimeLogsDir;

// Assemble filepath string.
std::filesystem::path szFilePath;
std::filesystem::path szFilename;
szFilePath = szLoggingOutputPath + "/"; // Main location for all recordings.
szFilePath = szLoggingOutputPath; // Main location for all recordings.
szFilePath += g_szProgramStartTimeString + "/"; // Folder for each program run.
szFilename = "console_output"; // Base file name.

Expand Down Expand Up @@ -126,22 +111,26 @@ namespace logging
szFullOutputPath.replace_extension(".log"), // Log Output Path
[]()
{
return quill::RotatingFileSinkConfig(); // Rotating File Sink Configs
quill::RotatingFileSinkConfig cfg;
cfg.set_open_mode('a');
return cfg; // Rotating File Sink Configs
}(),
szLogFilePattern, // Log Output Pattern
szTimestampPattern, // Log Timestamp Pattern
quill::Timezone::LocalTime // Log Timezone
szLogFilePattern, // Log Output Pattern
szTimestampPattern, // Log Timestamp Pattern
quill::Timezone::LocalTime // Log Timezone
);

std::shared_ptr<quill::Sink> qCSVFileSink = quill::Frontend::create_or_get_sink<MRDTRotatingFileSink>(
szFullOutputPath.replace_extension(".csv"), // Log Output Path
[]()
{
return quill::RotatingFileSinkConfig(); // Rotating File Sink Configs
quill::RotatingFileSinkConfig cfg;
cfg.set_open_mode('a');
return cfg; // Rotating File Sink Configs
}(),
szCSVFilePattern, // Log Output Pattern
szTimestampPattern, // Log Timestamp Pattern
quill::Timezone::LocalTime // Log Timezone
szCSVFilePattern, // Log Output Pattern
szTimestampPattern, // Log Timestamp Pattern
quill::Timezone::LocalTime // Log Timezone
);

std::shared_ptr<quill::Sink> qConsoleSink = quill::Frontend::create_or_get_sink<MRDTConsoleSink>("ConsoleSink", // Log Name
Expand Down
3 changes: 2 additions & 1 deletion src/AutonomyLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
/// \endcond

#include "./AutonomyConstants.h"
#include "./util/TimeOperations.hpp"

#ifndef AUTONOMY_LOGGING_H
#define AUTONOMY_LOGGING_H
Expand Down Expand Up @@ -86,7 +87,7 @@ namespace logging
// Declare namespace methods.
/////////////////////////////////////////

void InitializeLoggers(std::string szLoggingOutputPath);
void InitializeLoggers(std::string szLoggingOutputPath, std::string szProgramTimeLogsDir = timeops::GetTimestamp());

/////////////////////////////////////////
// Declare namespace callbacks.
Expand Down
62 changes: 62 additions & 0 deletions src/util/TimeOperations.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/******************************************************************************
* @brief Defines and implements functions related to operations on time and
* date within the timeops namespace.
*
* @file TimeOperations.hpp
* @author Eli Byrd ([email protected])
* @date 2025-01-07
*
* @copyright Copyright Mars Rover Design Team 2025 - All Rights Reserved
******************************************************************************/

#ifndef TIME_OPERATIONS_HPP
#define TIME_OPERATIONS_HPP

/// \cond
#include <chrono>
#include <ctime>
#include <iostream>

/// \endcond

/******************************************************************************
* @brief Namespace containing functions related to operations on time and
* date related data types.
*
* @author Eli Byrd ([email protected])
* @date 2025-01-07
******************************************************************************/
namespace timeops
{
/******************************************************************************
* @brief Accessor for getting the current time in a specified format.
*
* @param szFormat - The format to return the time in.
* @return std::string - The current time in the specified format.
*
* @author Eli Byrd ([email protected])
* @date 2025-01-07
******************************************************************************/
inline std::string GetTimestamp(std::string szFormat = "%Y%m%d-%H%M%S")
{
// Retrieve the current time for the log file name
std::chrono::time_point<std::chrono::system_clock> tmCurrentTime = std::chrono::system_clock::now();
std::time_t tCurrentTime = std::chrono::system_clock::to_time_t(tmCurrentTime);

// Convert time to local time
std::tm* tLocalTime = std::localtime(&tCurrentTime);

// Format the current time in a format that can be used as a file name.
std::array<char, 80> cCurrentTime;
size_t siTimeCharacters;
siTimeCharacters = std::strftime(cCurrentTime.data(), cCurrentTime.size(), szFormat.c_str(), tLocalTime);
if (siTimeCharacters == 0)
{
std::cerr << "Unable to format calendar date & time (exceeds string length)" << std::endl;
}

return cCurrentTime.data();
}
} // namespace timeops

#endif // TIME_OPERATIONS_HPP
28 changes: 0 additions & 28 deletions tests/Integration/main.cc

This file was deleted.

Loading

0 comments on commit d4946d5

Please sign in to comment.