opencv.passthru.tests.opencv4-tests: refactor and fix CUDA tests

Signed-off-by: Connor Baker <ConnorBaker01@gmail.com>
This commit is contained in:
Connor Baker 2025-07-03 20:42:49 +00:00
parent f779eea4a2
commit f4fe5e45a0

View File

@ -1,85 +1,131 @@
{ {
opencv4,
testDataSrc,
stdenv,
lib,
runCommand,
gst_all_1,
runAccuracyTests,
runPerformanceTests,
enableGStreamer, enableGStreamer,
enableGtk2, enableGtk2,
enableGtk3, enableGtk3,
gst_all_1,
lib,
opencv4,
runAccuracyTests,
runCommand,
runPerformanceTests,
stdenv,
testDataSrc,
writableTmpDirAsHomeHook,
xvfb-run, xvfb-run,
}: }:
let let
testNames = inherit (lib) getExe optionals optionalString;
[ inherit (opencv4.passthru) cudaSupport;
inherit (stdenv.hostPlatform) isAarch64 isDarwin;
in
runCommand "opencv4-tests"
{
__structuredAttrs = true;
strictDeps = true;
nativeBuildInputs =
[ writableTmpDirAsHomeHook ]
++ optionals enableGStreamer (
with gst_all_1;
[
gstreamer
gst-plugins-base
gst-plugins-good
]
);
ignoredTests =
[
"AsyncAPICancelation/cancel*"
"Photo_CalibrateDebevec.regression"
]
++ optionals cudaSupport [
# opencv4-tests> /build/source/modules/photo/test/test_denoising.cuda.cpp:115: Failure
# opencv4-tests> The max difference between matrices "bgr_gold" and "dbgr" is 2 at (339, 486), which exceeds "1", where "bgr_gold" at (339, 486) evaluates to (182, 239, 239), "dbgr" at (339, 486) evaluates to (184, 239, 239), "1" evaluates to 1
# opencv4-tests> [ FAILED ] CUDA_FastNonLocalMeans.Regression (48 ms)
"CUDA_FastNonLocalMeans.Regression"
];
inherit runAccuracyTests;
accuracyTestNames =
[
"calib3d"
"core"
"features2d"
"flann"
"imgcodecs"
"imgproc"
"ml"
"objdetect"
"photo"
"stitching"
"video"
#"videoio" # - a lot of GStreamer warnings and failed tests
#"dnn" #- some caffe tests failed, probably because github workflow also downloads additional models
]
++ optionals (!isAarch64 && enableGStreamer) [ "gapi" ]
++ optionals (enableGtk2 || enableGtk3) [ "highgui" ];
inherit runPerformanceTests;
performanceTestNames = [
"calib3d" "calib3d"
"core" "core"
"features2d" "features2d"
"flann"
"imgcodecs" "imgcodecs"
"imgproc" "imgproc"
"ml"
"objdetect" "objdetect"
"photo" "photo"
"stitching" "stitching"
"video" "video"
#"videoio" # - a lot of GStreamer warnings and failed tests ] ++ optionals (!isAarch64 && enableGStreamer) [ "gapi" ];
#"dnn" #- some caffe tests failed, probably because github workflow also downloads additional models
] testRunner = optionalString (!isDarwin) "${getExe xvfb-run} -a ";
++ lib.optionals (!stdenv.hostPlatform.isAarch64 && enableGStreamer) [ "gapi" ]
++ lib.optionals (enableGtk2 || enableGtk3) [ "highgui" ]; requiredSystemFeatures = optionals cudaSupport [ "cuda" ];
perfTestNames = [ }
"calib3d" ''
"core" set -euo pipefail
"features2d"
"imgcodecs"
"imgproc"
"objdetect"
"photo"
"stitching"
"video"
] ++ lib.optionals (!stdenv.hostPlatform.isAarch64 && enableGStreamer) [ "gapi" ];
testRunner = lib.optionalString (!stdenv.hostPlatform.isDarwin) "${lib.getExe xvfb-run} -a ";
testsPreparation = ''
touch $out
# several tests want a write access, so we have to copy files # several tests want a write access, so we have to copy files
tmpPath="$(mktemp -d "/tmp/opencv_extra_XXXXXX")" nixLog "Preparing test data"
cp -R ${testDataSrc} $tmpPath/opencv_extra cp -R "${testDataSrc}" "$HOME/opencv_extra"
chmod -R +w $tmpPath/opencv_extra chmod -R +w "$HOME/opencv_extra"
export OPENCV_TEST_DATA_PATH="$tmpPath/opencv_extra/testdata" export OPENCV_TEST_DATA_PATH="$HOME/opencv_extra/testdata"
export OPENCV_SAMPLES_DATA_PATH="${opencv4.package_tests}/samples/data" export OPENCV_SAMPLES_DATA_PATH="${opencv4.package_tests}/samples/data"
# ignored tests because of gtest error - "Test code is not available due to compilation error with GCC 11" # ignored tests because of gtest error - "Test code is not available due to compilation error with GCC 11"
# ignore test due to numerical instability # ignore test due to numerical instability
export GTEST_FILTER="-AsyncAPICancelation/cancel*:Photo_CalibrateDebevec.regression" if [[ -n ''${ignoredTests+x} ]]; then
''; export GTEST_FILTER="-$(concatStringsSep ":" ignoredTests)"
accuracyTests = lib.optionalString runAccuracyTests '' nixLog "Using GTEST_FILTER: $GTEST_FILTER"
${builtins.concatStringsSep "\n" ( fi
map (
test: if [[ -n $runAccuracyTests ]]; then
"${testRunner}${opencv4.package_tests}/opencv_test_${test} --test_threads=$NIX_BUILD_CORES --gtest_filter=$GTEST_FILTER" nixLog "Running accuracy tests"
) testNames for testName in "''${accuracyTestNames[@]}"; do
)} nixLog "Running accuracy test: $testName"
''; ''${testRunner}${opencv4.package_tests}/opencv_test_''${testName} \
performanceTests = lib.optionalString runPerformanceTests '' --test_threads=$NIX_BUILD_CORES
${builtins.concatStringsSep "\n" ( done
map ( nixLog "Finished running accuracy tests"
test: fi
"${testRunner}${opencv4.package_tests}/opencv_perf_${test} --perf_impl=plain --perf_min_samples=10 --perf_force_samples=10 --perf_verify_sanity --skip_unstable=1 --gtest_filter=$GTEST_FILTER"
) perfTestNames if [[ -n $runPerformanceTests ]]; then
)} nixLog "Running performance tests"
''; for testName in "''${performanceTestNames[@]}"; do
in nixLog "Running performance test: $testName"
runCommand "opencv4-tests" { ''${testRunner}${opencv4.package_tests}/opencv_perf_''${testName} \
nativeBuildInputs = lib.optionals enableGStreamer ( --perf_impl=plain \
with gst_all_1; --perf_min_samples=10 \
[ --perf_force_samples=10 \
gstreamer --perf_verify_sanity \
gst-plugins-base --skip_unstable=1
gst-plugins-good done
] nixLog "Finished running performance tests"
); fi
} (testsPreparation + accuracyTests + performanceTests)
nixLog "Finished running tests"
touch "$out"
''