1{
2 enableGStreamer,
3 enableGtk2,
4 enableGtk3,
5 gst_all_1,
6 lib,
7 opencv4,
8 runAccuracyTests,
9 runCommand,
10 runPerformanceTests,
11 stdenv,
12 testDataSrc,
13 writableTmpDirAsHomeHook,
14 xvfb-run,
15}:
16let
17 inherit (lib) getExe optionals optionalString;
18 inherit (opencv4.passthru) cudaSupport;
19 inherit (stdenv.hostPlatform) isAarch64 isDarwin;
20in
21runCommand "opencv4-tests"
22 {
23 __structuredAttrs = true;
24 strictDeps = true;
25
26 nativeBuildInputs = [
27 writableTmpDirAsHomeHook
28 ]
29 ++ optionals enableGStreamer (
30 with gst_all_1;
31 [
32 gstreamer
33 gst-plugins-base
34 gst-plugins-good
35 ]
36 );
37
38 ignoredTests = [
39 "AsyncAPICancelation/cancel*"
40 "Photo_CalibrateDebevec.regression"
41 ]
42 ++ optionals cudaSupport [
43 # opencv4-tests> /build/source/modules/photo/test/test_denoising.cuda.cpp:115: Failure
44 # 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
45 # opencv4-tests> [ FAILED ] CUDA_FastNonLocalMeans.Regression (48 ms)
46 "CUDA_FastNonLocalMeans.Regression"
47 ];
48
49 inherit runAccuracyTests;
50
51 accuracyTestNames = [
52 "calib3d"
53 "core"
54 "features2d"
55 "flann"
56 "imgcodecs"
57 "imgproc"
58 "ml"
59 "objdetect"
60 "photo"
61 "stitching"
62 "video"
63 #"videoio" # - a lot of GStreamer warnings and failed tests
64 #"dnn" #- some caffe tests failed, probably because github workflow also downloads additional models
65 ]
66 ++ optionals (!isAarch64 && enableGStreamer) [ "gapi" ]
67 ++ optionals (enableGtk2 || enableGtk3) [ "highgui" ];
68
69 inherit runPerformanceTests;
70
71 performanceTestNames = [
72 "calib3d"
73 "core"
74 "features2d"
75 "imgcodecs"
76 "imgproc"
77 "objdetect"
78 "photo"
79 "stitching"
80 "video"
81 ]
82 ++ optionals (!isAarch64 && enableGStreamer) [ "gapi" ];
83
84 testRunner = optionalString (!isDarwin) "${getExe xvfb-run} -a ";
85
86 requiredSystemFeatures = optionals cudaSupport [ "cuda" ];
87 }
88 ''
89 set -euo pipefail
90
91 # several tests want a write access, so we have to copy files
92 nixLog "Preparing test data"
93 cp -R "${testDataSrc}" "$HOME/opencv_extra"
94 chmod -R +w "$HOME/opencv_extra"
95 export OPENCV_TEST_DATA_PATH="$HOME/opencv_extra/testdata"
96 export OPENCV_SAMPLES_DATA_PATH="${opencv4.package_tests}/samples/data"
97
98 # ignored tests because of gtest error - "Test code is not available due to compilation error with GCC 11"
99 # ignore test due to numerical instability
100 if [[ -n ''${ignoredTests+x} ]]; then
101 export GTEST_FILTER="-$(concatStringsSep ":" ignoredTests)"
102 nixLog "Using GTEST_FILTER: $GTEST_FILTER"
103 fi
104
105 if [[ -n $runAccuracyTests ]]; then
106 nixLog "Running accuracy tests"
107 for testName in "''${accuracyTestNames[@]}"; do
108 nixLog "Running accuracy test: $testName"
109 ''${testRunner}${opencv4.package_tests}/opencv_test_''${testName} \
110 --test_threads=$NIX_BUILD_CORES
111 done
112 nixLog "Finished running accuracy tests"
113 fi
114
115 if [[ -n $runPerformanceTests ]]; then
116 nixLog "Running performance tests"
117 for testName in "''${performanceTestNames[@]}"; do
118 nixLog "Running performance test: $testName"
119 ''${testRunner}${opencv4.package_tests}/opencv_perf_''${testName} \
120 --perf_impl=plain \
121 --perf_min_samples=10 \
122 --perf_force_samples=10 \
123 --perf_verify_sanity \
124 --skip_unstable=1
125 done
126 nixLog "Finished running performance tests"
127 fi
128
129 nixLog "Finished running tests"
130 touch "$out"
131 ''