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

Cleanup GitHub Actions #360

Closed
wants to merge 13 commits into from
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
66 changes: 46 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,68 @@ 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)

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.*)
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.*)
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
13 changes: 4 additions & 9 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ coverage:
project:
default:
target: auto
threshold: 5%
patch:
default:
target: auto
informational: true
threshold: 5%
changes: false

ignore:
Expand All @@ -21,14 +24,6 @@ ignore:
- "**/build/*"
- "/usr/include/*"

flags:
unit_tests:
paths:
- "tests/Unit/**"
integration_tests:
paths:
- "tests/Integration/**"

component_management:
individual_components:
- component_id: algorithms
Expand Down Expand Up @@ -67,7 +62,7 @@ component_management:
- src/*.cpp

comment:
layout: "header, diff, flags, files, components"
layout: "header, diff, files, 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
20 changes: 3 additions & 17 deletions src/AutonomyLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
******************************************************************************/

#include "AutonomyLogging.h"
#include "./util/TimeOperations.hpp"
#include "AutonomyNetworking.h"

/// \cond
Expand Down Expand Up @@ -57,28 +58,13 @@ namespace logging
******************************************************************************/
void InitializeLoggers(std::string szLoggingOutputPath)
{
// 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 = timeops::GetTimestamp();

// 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
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;

Check warning on line 55 in src/util/TimeOperations.hpp

View check run for this annotation

Codecov / codecov/patch

src/util/TimeOperations.hpp#L55

Added line #L55 was not covered by tests
}

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

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

This file was deleted.

35 changes: 0 additions & 35 deletions tests/Unit/main.cc

This file was deleted.

Loading
Loading