Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / development / libraries / opencv / tests.nix
blobd1966b1a4aa82cc40bee1b415d0f4da31d29fda5
1 { opencv4
2 , testDataSrc
3 , stdenv
4 , lib
5 , runCommand
6 , gst_all_1
7 , runAccuracyTests
8 , runPerformanceTests
9 , enableGStreamer
10 , enableGtk2
11 , enableGtk3
12 , xvfb-run
14 let
15   testNames = [
16     "calib3d"
17     "core"
18     "features2d"
19     "flann"
20     "imgcodecs"
21     "imgproc"
22     "ml"
23     "objdetect"
24     "photo"
25     "stitching"
26     "video"
27     #"videoio" # - a lot of GStreamer warnings and failed tests
28     #"dnn" #- some caffe tests failed, probably because github workflow also downloads additional models
29   ] ++ lib.optionals (!stdenv.isAarch64 && enableGStreamer) [ "gapi" ]
30   ++ lib.optionals (enableGtk2 || enableGtk3) [ "highgui" ];
31   perfTestNames = [
32     "calib3d"
33     "core"
34     "features2d"
35     "imgcodecs"
36     "imgproc"
37     "objdetect"
38     "photo"
39     "stitching"
40     "video"
41   ] ++ lib.optionals (!stdenv.isAarch64 && enableGStreamer) [ "gapi" ];
42   testRunner = lib.optionalString (!stdenv.isDarwin) "${lib.getExe xvfb-run} -a ";
43   testsPreparation = ''
44     touch $out
45     # several tests want a write access, so we have to copy files
46     tmpPath="$(mktemp -d "/tmp/opencv_extra_XXXXXX")"
47     cp -R ${testDataSrc} $tmpPath/opencv_extra
48     chmod -R +w $tmpPath/opencv_extra
49     export OPENCV_TEST_DATA_PATH="$tmpPath/opencv_extra/testdata"
50     export OPENCV_SAMPLES_DATA_PATH="${opencv4.package_tests}/samples/data"
52     #ignored tests because of gtest error - "Test code is not available due to compilation error with GCC 11"
53     export GTEST_FILTER="-AsyncAPICancelation/cancel*"
54   '';
55   accuracyTests = lib.optionalString runAccuracyTests ''
56     ${ builtins.concatStringsSep "\n"
57       (map (test: "${testRunner}${opencv4.package_tests}/opencv_test_${test} --test_threads=$NIX_BUILD_CORES --gtest_filter=$GTEST_FILTER" ) testNames)
58     }
59   '';
60   performanceTests = lib.optionalString runPerformanceTests ''
61     ${ builtins.concatStringsSep "\n"
62       (map (test: "${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)
63     }
64   '';
66 runCommand "opencv4-tests"
68   nativeBuildInputs = lib.optionals enableGStreamer (with gst_all_1; [ gstreamer gst-plugins-base gst-plugins-good ]);
70   (testsPreparation + accuracyTests + performanceTests)