Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
lib/*
build/*
CoverageReport-*/
LastCoverageResults.log
62 changes: 50 additions & 12 deletions build.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,57 @@ if [ "${COVERAGE}" = "ON" ]; then
echo "Running unit tests..."
BUILD_DIR="$(pwd)/build"
(cd "${BUILD_DIR}" && ctest --output-on-failure) || { echo "Tests failed."; exit 1; }

echo "Tests passed. Generating coverage report..."
COVERAGE_DIR="${BUILD_DIR}/coverage"
mkdir -p ${COVERAGE_DIR}

lcov --directory "${BUILD_DIR}" --capture --output-file ${COVERAGE_DIR}/coverage.info \
--rc branch_coverage=1 --exclude '/usr/*' --exclude '*/tests/*' --exclude '*/_deps/*' \
--quiet

genhtml --output-directory ${COVERAGE_DIR}/html --title "Event Loop Code Coverage" \
--prefix "${PWD}" --rc branch_coverage=1 --quiet ${COVERAGE_DIR}/coverage.info

echo "Coverage report generated at: ${COVERAGE_DIR}/html/index.html"
mkdir -p "${COVERAGE_DIR}"

OS="$(uname -s)"
if [[ "${OS}" == MINGW* ]] || [[ "${OS}" == MSYS* ]] || [[ "${OS}" == CYGWIN* ]]; then
# ── Windows: OpenCppCoverage ──────────────────────────────────────────
if ! command -v OpenCppCoverage &>/dev/null; then
echo "WARNING: OpenCppCoverage not found on PATH. Skipping Windows coverage report."
echo "Install it with: winget install OpenCppCoverage"
else
# Support both multi-config generators (MSVC) and single-config (Ninja/MinGW).
# Multi-config puts binaries under build/tests/<BuildType>/; single-config does not.
if [ -f "${BUILD_DIR}/tests/${BUILD_TYPE}/EventLoopTests.exe" ]; then
TEST_EXE="${BUILD_DIR}/tests/${BUILD_TYPE}/EventLoopTests.exe"
LIB_DLL="${BUILD_DIR}/${BUILD_TYPE}/EventLoop.dll"
else
TEST_EXE="${BUILD_DIR}/tests/EventLoopTests.exe"
LIB_DLL="${BUILD_DIR}/EventLoop.dll"
fi

echo "Generating Windows coverage report with OpenCppCoverage..."
OpenCppCoverage \
--sources "${PWD}/src" \
--sources "${PWD}/include" \
--modules "${LIB_DLL}" \
--export_type "html:${COVERAGE_DIR}/html" \
--export_type "cobertura:${COVERAGE_DIR}/coverage.xml" \
-- "${TEST_EXE}"

echo "Coverage report generated at: ${COVERAGE_DIR}/html/index.html"
fi
else
# ── Linux / macOS: lcov + genhtml ─────────────────────────────────────
# --ignore-errors unused: suppresses harmless warning when _deps/ does not
# exist (e.g. when gtest is installed system-wide instead of via FetchContent)
lcov --directory "${BUILD_DIR}" --capture \
--output-file "${COVERAGE_DIR}/coverage.info" \
--rc branch_coverage=1 \
--exclude '/usr/*' --exclude '*/tests/*' --exclude '*/_deps/*' \
--ignore-errors mismatch,empty,unused \
--quiet

genhtml --output-directory "${COVERAGE_DIR}/html" \
--title "Event Loop Code Coverage" \
--prefix "${PWD}" --rc branch_coverage=1 --quiet \
"${COVERAGE_DIR}/coverage.info"

echo "Coverage report generated at: ${COVERAGE_DIR}/html/index.html"
fi
fi

if [ ${TARGET} = "clean" ]; then
Expand All @@ -80,4 +118,4 @@ if [ ${TARGET} = "clean" ]; then
if [ -d ${PWD}/lib ]; then
rm -rf lib/*
fi
fi
fi
9 changes: 9 additions & 0 deletions src/EventManager.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ void EventManager::start()
{
try
{
// A previous run's threads may still be joinable here (stop() signals
// shutdown but does not join). Reassigning a std::thread that already
// represents a joinable thread calls std::terminate(), so clean those
// up first to allow the loop to be safely restarted after a Halt().
if (m_mainLoop.joinable())
m_mainLoop.join();
if (m_scheduler.joinable())
m_scheduler.join();

m_shutdown = false;
m_scheduler = std::thread(&EventManager::eventScheduler, this);
if (m_blockPrimary)
Expand Down
Loading