From 2c553cc9a24dd7bcc7dab092fbe13cb9c737c6e7 Mon Sep 17 00:00:00 2001 From: John Boehr Date: Sun, 7 Apr 2024 12:25:35 -0700 Subject: [PATCH] Add coverage to nix matrix --- .github/workflows/ci.yml | 23 ++++++++++++++++++++--- config.m4 | 8 ++++++++ flake.nix | 21 ++++++++++++++++++--- nix/derivation.nix | 35 +++++++++++++++++++++++++++++++---- 4 files changed, 77 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f012a4..6dc0b5f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -176,7 +176,7 @@ jobs: with: file: coverage.info token: ${{ secrets.CODECOV_TOKEN }} - slug: jbboehr/php-perf + slug: jbboehr/php-perfifidous - name: Coveralls uses: coverallsapp/github-action@v2 @@ -187,7 +187,9 @@ jobs: parallel: true finish: - needs: coverage + needs: + - coverage + - nix if: ${{ always() }} runs-on: ubuntu-latest steps: @@ -244,7 +246,22 @@ jobs: - run: nix build -L ".#${{ matrix.attr }}" - # - run: nix flake check -L + - name: Upload coverage reports to Codecov + if: ${{ hashFiles('result-coverage') != '' }} + uses: codecov/codecov-action@v4 + with: + file: result-coverage/coverage.info + token: ${{ secrets.CODECOV_TOKEN }} + slug: jbboehr/php-perfifidous + + - name: Coveralls + if: ${{ hashFiles('result-coverage') != '' }} + uses: coverallsapp/github-action@v2 + continue-on-error: true + with: + file: result-coverage/coverage.info + format: lcov + parallel: true - name: Export Nix Store Cache shell: bash diff --git a/config.m4 b/config.m4 index 7712517..6afb7c4 100644 --- a/config.m4 +++ b/config.m4 @@ -21,6 +21,9 @@ PHP_ARG_ENABLE(perfidious, whether to enable perfidious, PHP_ARG_ENABLE(perfidious-debug, whether to enable perfidious debug support, [AS_HELP_STRING([--enable-perfidious-debug], [Enable perfidious debug support])], [no], [no]) +PHP_ARG_ENABLE(perfidious-coverage, whether to enable perfidious coverage support, +[AS_HELP_STRING([--enable-perfidious-coverage], [Enable perfidious coverage support])], [no], [no]) + AC_DEFUN([PHP_PERFIDIOUS_ADD_SOURCES], [ PHP_PERFIDIOUS_SOURCES="$PHP_PERFIDIOUS_SOURCES $1" ]) @@ -53,6 +56,11 @@ if test "$PHP_PERFIDIOUS" != "no"; then AC_DEFINE([NDEBUG], [1], [Disable debug support]) fi + if test "$PHP_PERFIDIOUS_COVERAGE" == "yes"; then + CFLAGS="-fprofile-arcs -ftest-coverage $CFLAGS" + LDFLAGS="--coverage $LDFLAGS" + fi + PHP_ADD_LIBRARY(cap, , PERFIDIOUS_SHARED_LIBADD) PHP_ADD_LIBRARY(pfm, , PERFIDIOUS_SHARED_LIBADD) diff --git a/flake.nix b/flake.nix index a972977..ced8b4d 100644 --- a/flake.nix +++ b/flake.nix @@ -80,11 +80,12 @@ php ? pkgs.php, libpfm ? pkgs.libpfm, debugSupport ? false, + coverageSupport ? false, }: pkgs.callPackage ./nix/derivation.nix { inherit src; inherit stdenv php libpfm; - inherit debugSupport; + inherit debugSupport coverageSupport; buildPecl = pkgs.callPackage (nixpkgs + "/pkgs/build-support/php/build-pecl.nix") { inherit php stdenv; }; @@ -212,6 +213,7 @@ # "musl" ]; libpfm = ["libpfm" "libpfm-unstable"]; + coverageSupport = [false]; }) ++ [ { @@ -220,13 +222,21 @@ libpfm = "libpfm"; debugSupport = true; } - ]; + ] + ++ (lib.cartesianProductOfSets { + php = ["php81" "php82" "php83"]; + stdenv = ["gcc"]; + libpfm = ["libpfm"]; + debugSupport = [false true]; + coverageSupport = [true]; + }); buildFn = { php, libpfm, stdenv, debugSupport ? false, + coverageSupport ? false, }: lib.nameValuePair (lib.concatStringsSep "-" (lib.filter (v: v != "") [ @@ -243,13 +253,18 @@ then "debug" else "" ) + ( + if coverageSupport + then "coverage" + else "" + ) ])) ( makePackage { php = matrix.php.${php}; libpfm = matrix.libpfm.${libpfm}; stdenv = matrix.stdenv.${stdenv}; - inherit debugSupport; + inherit debugSupport coverageSupport; } ); diff --git a/nix/derivation.nix b/nix/derivation.nix index 61bf534..885446a 100644 --- a/nix/derivation.nix +++ b/nix/derivation.nix @@ -9,10 +9,12 @@ autoreconfHook, buildPecl, src, + lcov, checkSupport ? false, debugSupport ? false, WerrorSupport ? checkSupport, valgrindSupport ? true, + coverageSupport ? false, }: (buildPecl rec { pname = "perfidious"; @@ -24,7 +26,8 @@ buildInputs = [libcap libpfm]; nativeBuildInputs = [php.unwrapped.dev pkg-config] - ++ lib.optional valgrindSupport valgrind; + ++ lib.optional valgrindSupport valgrind + ++ lib.optional coverageSupport lcov; passthru = { inherit php libpfm stdenv; @@ -34,19 +37,43 @@ [] ++ lib.optional WerrorSupport "--enable-compile-warnings=error" ++ lib.optionals (!WerrorSupport) ["--enable-compile-warnings=yes" "--disable-Werror"] - ++ lib.optional debugSupport "--enable-perfidious-debug"; + ++ lib.optional debugSupport "--enable-perfidious-debug" + ++ lib.optional coverageSupport ["--enable-perfidious-coverage"]; makeFlags = ["phpincludedir=$(dev)/include"]; - outputs = ["out" "dev"]; + outputs = + lib.optional (checkSupport && coverageSupport) "coverage" + ++ ["out" "dev"]; doCheck = checkSupport; theRealFuckingCheckPhase = '' + runHook preCheck REPORT_EXIT_STATUS=1 NO_INTERACTION=1 make test TEST_PHP_ARGS="-n" || (find tests -name '*.log' | xargs cat ; exit 1) '' + (lib.optionalString valgrindSupport '' USE_ZEND_ALLOC=0 REPORT_EXIT_STATUS=1 NO_INTERACTION=1 make test TEST_PHP_ARGS="-n -m" || (find tests -name '*.mem' | xargs cat ; exit 1) - ''); + '') + + '' + runHook postCheck + ''; + + preBuild = lib.optionalString coverageSupport '' + lcov --directory . --zerocounters + lcov --directory . --capture --compat-libtool --initial --output-file coverage.info + ''; + + postCheck = lib.optionalString coverageSupport '' + lcov --no-checksum --directory . --capture --no-markers --compat-libtool --output-file coverage.info + set -o noglob + lcov --remove coverage.info '${builtins.storeDir}/*' \ + --compat-libtool \ + --output-file coverage.info + set +o noglob + mkdir -p $coverage + cp coverage.info $coverage/coverage.info + genhtml coverage.info -o $coverage/html/ + ''; #TEST_PHP_DETAILED = 1; })