From cbd6c45887a177bd9279ce9198da0712a6417248 Mon Sep 17 00:00:00 2001 From: TazyFoundSoup Date: Mon, 18 May 2026 10:31:15 +1000 Subject: ci(coverage): Add repo coverage with codecov --- .github/workflows/coverage.yaml | 27 +++++++++++++++++++++++++++ .gitignore | 7 +++++++ Makefile | 14 +++++++++++--- src/format/image/png.c | 18 +++++++++--------- 4 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/coverage.yaml diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml new file mode 100644 index 0000000..527aa20 --- /dev/null +++ b/.github/workflows/coverage.yaml @@ -0,0 +1,27 @@ +name: Coverage + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + coverage: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install lcov + run: sudo apt-get update && sudo apt-get install lcov + + - name: Generate coverage report + run: make coverage + + - name: Upload coverage report to Codecov + uses: codecov/codecov-action@v5 + with: + files: coverage.info + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: true \ No newline at end of file diff --git a/.gitignore b/.gitignore index 40d3802..14c982f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,10 @@ tests/logs/* # Ignore generated book from mdbook docs/book/ docs/book/* + +# Coverage outputs +.coverage +coverage/ +*.gcda +*.gcov +*.lcov \ No newline at end of file diff --git a/Makefile b/Makefile index cca0169..1716671 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ OUTDIR = build BENCH_OUT = $(OUTDIR)/bench LIB = libtinyff.a -ALL_CFLAGS = -Wall -Wextra -Werror -std=c11 -Iinclude +ALL_CFLAGS = -Wall -Wextra -Werror -std=c11 -Iinclude --coverage DEBUG_FLAGS = -g -O0 -fno-omit-frame-pointer RELEASE_FLAGS = -O2 @@ -37,7 +37,7 @@ $(OUTDIR)/%.o: %.c $(CC) $(ALL_CFLAGS) $(CFLAGS) -c $< -o $@ clean: - rm -rf $(OUTDIR) png_test + rm -rf $(OUTDIR) png_test coverage.info .coverage debug: CFLAGS = $(DEBUG_FLAGS) debug: $(OUTDIR)/$(LIB) @@ -63,4 +63,12 @@ bench: $(OUTDIR)/$(LIB) $(CC) $(ALL_CFLAGS) $(RELEASE_FLAGS) $(BENCH_SRC) -o $(BENCH_OUT)/bench -L$(OUTDIR) -ltinyff $(BENCH_OUT)/bench -.PHONY: all clean debug release asan test test-png gdb bench \ No newline at end of file +coverage: clean + $(MAKE) USE_HOSTED=1 debug + $(CC) $(ALL_CFLAGS) $(DEBUG_FLAGS) -DUSE_HOSTED tests/format/image/png/png_open.c -o $(OUTDIR)/png_test -L$(OUTDIR) -ltinyff + ./$(OUTDIR)/png_test || true + lcov --capture --directory . --output-file coverage.info + lcov --remove coverage.info '/usr/*' --output-file coverage.info --ignore-errors unused + lcov --list coverage.info + +.PHONY: all clean debug release asan test test-png gdb bench coverage \ No newline at end of file diff --git a/src/format/image/png.c b/src/format/image/png.c index 3b1fe5c..32399c6 100644 --- a/src/format/image/png.c +++ b/src/format/image/png.c @@ -440,19 +440,19 @@ ff_result ff_png_end_handler(ff_ctx* ctx, uint8_t *buf, size_t len, ff_png_ctx * ff_result ff_png_trans_handler(ff_ctx* ctx, uint8_t *buf, size_t len, ff_png_ctx *png_ctx) { - (void)buf; // Unused (for now) - - ff_dprintf(ctx, "png: tRNS chunk received\n"); // TODO: Format + ff_dprintf(ctx, "png: tRNS chunk received\n"); - if (png_ctx->color_type == 0) { // Grayscale - if (len != 2) { - ff_dprintf(ctx, "png: invalid tRNS length for grayscale image\n"); - png_ctx->last_error = FF_RESULT_ERROR_INVALID_FILE; - return FF_RESULT_ERROR_INVALID_FILE; + if (png_ctx->color_type == 3) { // indexed + size_t count = len; + if (count > png_ctx->palette_size) + count = png_ctx->palette_size; + + for (size_t i = 0; i < count; i++) { + png_ctx->palette[i * 4 + 3] = buf[i]; } } - return FF_RESULT_WARN_NO_IMPL; + return FF_RESULT_OK; } -- cgit v1.2.3