Skip to content

Commit bd6dff7

Browse files
committed
Add tests for PES parser
1 parent 0ce8215 commit bd6dff7

7 files changed

Lines changed: 616 additions & 3 deletions

File tree

.github/workflows/c-cpp.yml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
jobs:
1313
build:
1414
runs-on: ubuntu-latest
15-
15+
1616
steps:
1717
- name: Install build dependencies
1818
run: |
@@ -21,6 +21,8 @@ jobs:
2121
build-essential \
2222
pkg-config \
2323
git \
24+
catch2 \
25+
lcov \
2426
gettext \
2527
libavcodec-dev \
2628
libavfilter-dev \
@@ -57,9 +59,32 @@ jobs:
5759
path: vdr/PLUGINS/src/softhddevice-drm-gles/libvdr-softhddevice-drm-gles.so
5860
if-no-files-found: error
5961

62+
- name: Run unit tests
63+
run: |
64+
cd vdr/PLUGINS/src/softhddevice-drm-gles/tests
65+
make test
66+
continue-on-error: false
67+
68+
- name: Publish test results
69+
uses: EnricoMi/publish-unit-test-result-action@v2
70+
with:
71+
files: vdr/PLUGINS/src/softhddevice-drm-gles/tests/test-results.xml
72+
check_name: Unit Test Results
73+
74+
- name: Generate coverage report
75+
run: |
76+
cd vdr/PLUGINS/src/softhddevice-drm-gles/tests
77+
make coverage-html
78+
79+
- name: Upload coverage HTML report
80+
uses: actions/upload-artifact@v4
81+
with:
82+
name: coverage-html-report
83+
path: vdr/PLUGINS/src/softhddevice-drm-gles/tests/coverage-html/
84+
6085
build-without-gles:
6186
runs-on: ubuntu-latest
62-
87+
6388
steps:
6489
- name: Install build dependencies
6590
run: |

.gitignore

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,14 @@ po/*.mo
66
po/*.pot
77
.dependencies
88
srcdoc
9-
.vscode
9+
.vscode
10+
11+
# test coverage files
12+
*.gcda
13+
*.gcno
14+
*.gcov
15+
16+
tests/test_runner
17+
tests/test-results.xml
18+
tests/coverage.info
19+
tests/coverage-html/

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ clean:
201201
@-rm -f $(PODIR)/*.mo $(PODIR)/*.pot
202202
@-rm -f $(DEPFILE) *.o *.so *.tgz core* *~
203203
@-rm -rf srcdoc
204+
@$(MAKE) -C tests clean 2>/dev/null || true
205+
206+
# Unit tests:
207+
.PHONY: test
208+
test:
209+
@$(MAKE) -C tests test
204210

205211
# Source documentation:
206212
srcdoc:

tests/Makefile

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#
2+
# Makefile for unit tests using Catch2 and coverage with lcov
3+
#
4+
5+
# Compiler settings
6+
CXX = g++
7+
CXXFLAGS = -std=c++17 -g -Wall -Wextra -I.. -isystem ../../../../include
8+
LDFLAGS =
9+
10+
# Coverage settings
11+
COVERAGE_CXXFLAGS = --coverage -fprofile-arcs -ftest-coverage
12+
COVERAGE_LDFLAGS = --coverage
13+
14+
# Add library dependencies
15+
CXXFLAGS += $(shell pkg-config --cflags libavcodec libavutil catch2)
16+
LIBS = $(shell pkg-config --libs libavcodec libavutil catch2-with-main)
17+
18+
# Source files
19+
TEST_SOURCES = catch_main.cpp test_pes.cpp
20+
SOURCE_UNDER_TEST = ../pes.cpp
21+
22+
# Object files
23+
TEST_OBJS = $(TEST_SOURCES:.cpp=.o)
24+
SOURCE_OBJS = $(SOURCE_UNDER_TEST:.cpp=.o)
25+
26+
# Test executable
27+
TEST_EXEC = test_runner
28+
29+
# Main target
30+
all: $(TEST_EXEC)
31+
32+
# Link test executable
33+
$(TEST_EXEC): $(TEST_OBJS) $(SOURCE_OBJS)
34+
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
35+
36+
# Compile test sources
37+
%.o: %.cpp
38+
$(CXX) $(CXXFLAGS) -c -o $@ $<
39+
40+
# Compile sources under test
41+
../%.o: ../%.cpp
42+
$(CXX) $(CXXFLAGS) -c -o $@ $<
43+
44+
# Run tests
45+
.PHONY: test
46+
test: $(TEST_EXEC)
47+
./$(TEST_EXEC) -r console -r junit::out=test-results.xml
48+
49+
# Clean
50+
.PHONY: clean
51+
clean:
52+
@echo "Cleaning test build artifacts..."
53+
rm -f $(TEST_OBJS) $(SOURCE_OBJS) $(TEST_EXEC) test-results.xml
54+
@echo "Cleaning coverage data..."
55+
rm -f *.gcda *.gcno ../*.gcda ../*.gcno coverage.info
56+
rm -rf coverage-html
57+
58+
# Coverage targets
59+
.PHONY: coverage
60+
coverage: CXXFLAGS += $(COVERAGE_CXXFLAGS)
61+
coverage: LDFLAGS += $(COVERAGE_LDFLAGS)
62+
coverage: clean $(TEST_EXEC)
63+
@echo "Running tests with coverage..."
64+
./$(TEST_EXEC)
65+
@echo "Generating coverage report..."
66+
lcov --capture --directory . --directory .. --output-file coverage.info
67+
lcov --remove coverage.info '/usr/*' '*/tests/*' --output-file coverage.info
68+
lcov --list coverage.info
69+
70+
.PHONY: coverage-html
71+
coverage-html: coverage
72+
@echo "Generating HTML coverage report..."
73+
genhtml coverage.info --output-directory coverage-html
74+
@echo "Coverage report generated in coverage-html/index.html"
75+
76+
.PHONY: help
77+
help:
78+
@echo "Available targets:"
79+
@echo " all - Build test executable (default)"
80+
@echo " test - Build and run tests with console output"
81+
@echo " coverage - Build with coverage, run tests, and generate coverage report"
82+
@echo " coverage-html - Generate HTML coverage report (includes coverage)"
83+
@echo " clean - Remove all build artifacts, test results, and coverage data"
84+
@echo " help - Show this help message"

tests/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Unit Tests for softhddevice-drm-gles
2+
3+
This directory contains unit tests for the softhddevice-drm-gles VDR plugin using the Catch2 testing framework.
4+
5+
## Prerequisites
6+
7+
You need to have Catch2 v3 (since Ubuntu 24.04/Debian 13) and lcov installed on your system. On Debian/Ubuntu systems:
8+
9+
```bash
10+
sudo apt-get install catch2 lcov
11+
```
12+
13+
## Building and Running Tests
14+
15+
### Run tests
16+
17+
```bash
18+
make test
19+
```
20+
21+
### Run specific tests
22+
23+
```bash
24+
./test_runner "[pes]" # Run all PES tests
25+
./test_runner "cPes - MPEG2" # Run MPEG2-related tests
26+
```
27+
28+
### List all available tests
29+
30+
```bash
31+
./test_runner --list-tests
32+
```
33+
34+
## Code Coverage
35+
36+
### Generate coverage report
37+
38+
```bash
39+
make coverage
40+
```
41+
42+
This will:
43+
1. Build the tests with coverage instrumentation
44+
2. Run all tests
45+
3. Generate a coverage report showing which lines of code were executed
46+
47+
### Generate HTML coverage report
48+
49+
```bash
50+
make coverage-html
51+
```
52+
53+
This generates an interactive HTML report in `coverage-html/index.html` that you can open in a browser to see detailed coverage information with color-coded source files.

tests/catch_main.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @file catch_main.cpp
3+
* Catch2 test runner main file
4+
*
5+
* @copyright (c) 2025 by Andreas Baierl. All Rights Reserved.
6+
*
7+
* @license{AGPLv3
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.}
18+
*/
19+
20+
#define CATCH_CONFIG_MAIN
21+
#include <catch2/catch_all.hpp>

0 commit comments

Comments
 (0)