From 43551b72d709d6487317f2b936e54fe67be8fcce Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Wed, 26 Feb 2025 14:04:37 +0300 Subject: [PATCH] Merge pull request #26948 from mshabunin:fix-videoio-test-params videoio: print test params instead of indexes #26948 _videoio_ test names changed - use string instead of index. E.g. `videoio_read.threads/0` is now `videoio_read.threads/h264_0_RAW`. It allows to filter tests independently of the platform. **Notes:** - not all tests has been updated - only simpler ones and those which have varying parameters depending on platform --- modules/videoio/test/test_audio.cpp | 22 ++++- modules/videoio/test/test_ffmpeg.cpp | 45 +++++++++- modules/videoio/test/test_gstreamer.cpp | 9 +- modules/videoio/test/test_mfx.cpp | 5 +- modules/videoio/test/test_orientation.cpp | 9 +- modules/videoio/test/test_precomp.hpp | 34 +++++++- modules/videoio/test/test_video_io.cpp | 101 ++++++++++++++++++++-- 7 files changed, 205 insertions(+), 20 deletions(-) diff --git a/modules/videoio/test/test_audio.cpp b/modules/videoio/test/test_audio.cpp index bf2b4bad68..e3041e6eaf 100644 --- a/modules/videoio/test/test_audio.cpp +++ b/modules/videoio/test/test_audio.cpp @@ -135,7 +135,16 @@ TEST_P(Audio, audio) doTest(); } -INSTANTIATE_TEST_CASE_P(/**/, Audio, testing::ValuesIn(audioParams)); +inline static std::string Audio_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream out; + out << getExtensionSafe(get<0>(info.param)) << "_" + << get<1>(info.param) << "CN" << "_" + << getBackendNameSafe(get<4>(info.param)); + return out.str(); +} + +INSTANTIATE_TEST_CASE_P(/**/, Audio, testing::ValuesIn(audioParams), Audio_name_printer); class MediaTestFixture : public AudioBaseTest, public testing::TestWithParam { @@ -283,7 +292,16 @@ const paramCombination mediaParams[] = #endif // _WIN32 }; -INSTANTIATE_TEST_CASE_P(/**/, Media, testing::ValuesIn(mediaParams)); +inline static std::string Media_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream out; + out << getExtensionSafe(get<0>(info.param)) << "_" + << get<1>(info.param) << "CN" << "_" + << getBackendNameSafe(get<10>(info.param)); + return out.str(); +} + +INSTANTIATE_TEST_CASE_P(/**/, Media, testing::ValuesIn(mediaParams), Media_name_printer); TEST(AudioOpenCheck, bad_arg_invalid_audio_stream) { diff --git a/modules/videoio/test/test_ffmpeg.cpp b/modules/videoio/test/test_ffmpeg.cpp index 588b286ec1..03e41bd8f0 100644 --- a/modules/videoio/test/test_ffmpeg.cpp +++ b/modules/videoio/test/test_ffmpeg.cpp @@ -78,7 +78,16 @@ const FourCC_Ext_Size entries[] = make_tuple("FFV1", "mkv", bigSize) }; -INSTANTIATE_TEST_CASE_P(videoio, videoio_ffmpeg, testing::ValuesIn(entries)); +inline static std::string videoio_ffmpeg_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream os; + const string & fourcc = get<0>(info.param); + const Size sz = get<2>(info.param); + os << (fourcc.size() == 0 ? "NONE" : fourcc) << "_" << get<1>(info.param) << "_" << sz.height << "p"; + return os.str(); +} + +INSTANTIATE_TEST_CASE_P(videoio, videoio_ffmpeg, testing::ValuesIn(entries), videoio_ffmpeg_name_printer); //========================================================================== @@ -143,9 +152,19 @@ const videoio_read_params_t videoio_read_params[] = //videoio_read_params_t("video/big_buck_bunny.wmv", 125, true), }; +inline static std::string videoio_read_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream out; + out << getExtensionSafe(get<0>(get<0>(info.param))) << "_" + << get<1>(info.param) << "_" + << (get<2>(info.param) ? "RAW" : "ENC"); + return out.str(); +} + INSTANTIATE_TEST_CASE_P(/**/, videoio_read, testing::Combine(testing::ValuesIn(videoio_read_params), testing::Values(0, 1, 2, 50), - testing::Values(true, false))); + testing::Values(true, false)), + videoio_read_name_printer); //========================================================================== @@ -720,7 +739,15 @@ const ffmpeg_get_fourcc_param_t ffmpeg_get_fourcc_param[] = ffmpeg_get_fourcc_param_t("video/sample_322x242_15frames.yuv420p.libx264.mp4", "h264") }; -INSTANTIATE_TEST_CASE_P(videoio, ffmpeg_get_fourcc, testing::ValuesIn(ffmpeg_get_fourcc_param)); +inline static std::string ffmpeg_get_fourcc_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream os; + const string & fourcc = get<1>(info.param); + os << info.index << "_" << (fourcc.size() == 0 ? "NONE" : fourcc); + return os.str(); +} + +INSTANTIATE_TEST_CASE_P(videoio, ffmpeg_get_fourcc, testing::ValuesIn(ffmpeg_get_fourcc_param), ffmpeg_get_fourcc_name_printer); static void ffmpeg_check_read_raw(VideoCapture& cap) { @@ -914,6 +941,16 @@ const FourCC_Ext_Color_Support sixteen_bit_modes[] = }; -INSTANTIATE_TEST_CASE_P(/**/, videoio_ffmpeg_16bit, testing::ValuesIn(sixteen_bit_modes)); +inline static std::string videoio_ffmpeg_16bit_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream os; + os << get<0>(info.param) << "_" + << get<1>(info.param) << "_" + << (get<2>(info.param) ? "COLOR" : "GRAY") << "_" + << (get<3>(info.param) ? "SUP" : "NOT"); + return os.str(); +} + +INSTANTIATE_TEST_CASE_P(/**/, videoio_ffmpeg_16bit, testing::ValuesIn(sixteen_bit_modes), videoio_ffmpeg_16bit_name_printer); }} // namespace diff --git a/modules/videoio/test/test_gstreamer.cpp b/modules/videoio/test/test_gstreamer.cpp index ef9a6765a8..2ac06b6a20 100644 --- a/modules/videoio/test/test_gstreamer.cpp +++ b/modules/videoio/test/test_gstreamer.cpp @@ -218,7 +218,14 @@ static const string bunny_params[] = { string("mjpg.avi") }; -INSTANTIATE_TEST_CASE_P(videoio, gstreamer_bunny, testing::ValuesIn(bunny_params)); +inline static std::string gstreamer_bunny_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream out; + out << extToStringSafe(info.param); + return out.str(); +} + +INSTANTIATE_TEST_CASE_P(videoio, gstreamer_bunny, testing::ValuesIn(bunny_params), gstreamer_bunny_name_printer); }} // namespace diff --git a/modules/videoio/test/test_mfx.cpp b/modules/videoio/test/test_mfx.cpp index 032d5a96e0..c244d1c853 100644 --- a/modules/videoio/test/test_mfx.cpp +++ b/modules/videoio/test/test_mfx.cpp @@ -160,8 +160,9 @@ inline static std::string videoio_mfx_name_printer(const testing::TestParamInfo< { std::ostringstream out; const Size sz = get<0>(info.param); - const std::string ext = get<2>(info.param); - out << sz.width << "x" << sz.height << "x" << get<1>(info.param) << "x" << ext.substr(1, ext.size() - 1); + out << sz.height << "p" << "_" + << get<1>(info.param) << "FPS" << "_" + << extToStringSafe(get<2>(info.param)); return out.str(); } diff --git a/modules/videoio/test/test_orientation.cpp b/modules/videoio/test/test_orientation.cpp index ccff7391b0..7ebabc02b2 100644 --- a/modules/videoio/test/test_orientation.cpp +++ b/modules/videoio/test/test_orientation.cpp @@ -80,7 +80,14 @@ static cv::VideoCaptureAPIs supported_backends[] = { CAP_FFMPEG }; -INSTANTIATE_TEST_CASE_P(videoio, VideoCaptureAPITests, testing::ValuesIn(supported_backends)); +inline static std::string VideoCaptureAPITests_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream out; + out << getBackendNameSafe(info.param); + return out.str(); +} + +INSTANTIATE_TEST_CASE_P(videoio, VideoCaptureAPITests, testing::ValuesIn(supported_backends), VideoCaptureAPITests_name_printer); #endif // WIN32 diff --git a/modules/videoio/test/test_precomp.hpp b/modules/videoio/test/test_precomp.hpp index b17a2f0ab7..205d8f92bd 100644 --- a/modules/videoio/test/test_precomp.hpp +++ b/modules/videoio/test/test_precomp.hpp @@ -63,7 +63,8 @@ inline std::string fourccToStringSafe(int fourcc) { std::string res = fourccToString(fourcc); // TODO: return hex values for invalid characters - std::transform(res.begin(), res.end(), res.begin(), [](char c) -> char { return (c >= '0' && c <= 'z') ? c : (c == ' ' ? '_' : 'x'); }); + std::transform(res.begin(), res.end(), res.begin(), + [](char c) -> char { return (c >= '0' && c <= 'z') ? c : (c == ' ' ? '_' : 'x'); }); return res; } @@ -73,6 +74,37 @@ inline int fourccFromString(const std::string &fourcc) return cv::VideoWriter::fourcc(fourcc[0], fourcc[1], fourcc[2], fourcc[3]); } +inline std::string extToStringSafe(const std::string & ext) +{ + std::string res; + const bool start_with_dot = (ext.size() > 0) && (ext[0] == '.'); + std::transform(start_with_dot ? ext.begin() + 1 : ext.begin(), ext.end(), std::back_inserter(res), + [](char c) -> char { return (c >= '0' && c <= 'z') ? c : ((c == ' ' || c == '.') ? '_' : 'x'); }); + return res; +} + +inline std::string getExtensionSafe(const std::string & fname) +{ + std::string fext(std::find(fname.begin(), fname.end(), '.'), fname.end()); + if (fext.size() == 0) + return std::string("NOEXT"); + else + return extToStringSafe(fext); +} + +inline std::string getBackendNameSafe(const cv::VideoCaptureAPIs & api) +{ + const std::string res = cv::videoio_registry::getBackendName(api); + if (res.substr(0, 7) == "Unknown") + { + std::ostringstream os; os << "BACKEND_" << (size_t)api; return os.str(); + } + else + { + return res; + } +} + inline void generateFrame(int i, int FRAME_COUNT, cv::Mat & frame) { using namespace cv; diff --git a/modules/videoio/test/test_video_io.cpp b/modules/videoio/test/test_video_io.cpp index f3c0862999..03d69dfe5b 100644 --- a/modules/videoio/test/test_video_io.cpp +++ b/modules/videoio/test/test_video_io.cpp @@ -383,10 +383,20 @@ TEST_P(videoio_bunny, frame_count) { doFrameCountTest(); } TEST_P(videoio_bunny, frame_timestamp) { doTimestampTest(); } +inline static std::string videoio_bunny_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream os; + os << extToStringSafe(get<0>(info.param)) << "_" + << getBackendNameSafe(get<1>(info.param)); + return os.str(); +} + INSTANTIATE_TEST_CASE_P(videoio, videoio_bunny, testing::Combine( testing::ValuesIn(bunny_params), - testing::ValuesIn(backend_params))); + testing::ValuesIn(backend_params)), + videoio_bunny_name_printer); + inline static std::ostream &operator<<(std::ostream &out, const Ext_Fourcc_PSNR &p) @@ -446,10 +456,23 @@ Size all_sizes[] = { TEST_P(videoio_synthetic, write_read_position) { doTest(); } +inline static std::string videoio_synthetic_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream os; + const Size sz = get<0>(info.param); + const Ext_Fourcc_PSNR & param = get<1>(info.param); + os << sz.height << "p" << "_" + << param.ext << "_" + << param.fourcc << "_" + << getBackendNameSafe(param.api); + return os.str(); +} + INSTANTIATE_TEST_CASE_P(videoio, videoio_synthetic, testing::Combine( testing::ValuesIn(all_sizes), - testing::ValuesIn(synthetic_params))); + testing::ValuesIn(synthetic_params)), + videoio_synthetic_name_printer); struct Ext_Fourcc_API { @@ -531,7 +554,19 @@ static vector generate_Ext_Fourcc_API() return result; } -INSTANTIATE_TEST_CASE_P(videoio, Videoio_Writer, testing::ValuesIn(generate_Ext_Fourcc_API())); +inline static std::string Videoio_Writer_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream os; + std::string ext(info.param.ext); + if (info.param.api == CAP_GSTREAMER && info.param.fourcc[0] == '\0') // gstreamer pipeline instead of extension + os << getExtensionSafe(info.param.ext) << "_" << "NONE"; + else + os << info.param.ext << "_" << info.param.fourcc; + os << "_" << getBackendNameSafe(info.param.api); + return os.str(); +} + +INSTANTIATE_TEST_CASE_P(videoio, Videoio_Writer, testing::ValuesIn(generate_Ext_Fourcc_API()), Videoio_Writer_name_printer); TEST(Videoio, exceptions) @@ -610,7 +645,7 @@ static vector generate_Ext_Fourcc_API_nocrash() return result; } -INSTANTIATE_TEST_CASE_P(videoio, Videoio_Writer_bad_fourcc, testing::ValuesIn(generate_Ext_Fourcc_API_nocrash())); +INSTANTIATE_TEST_CASE_P(videoio, Videoio_Writer_bad_fourcc, testing::ValuesIn(generate_Ext_Fourcc_API_nocrash()), Videoio_Writer_name_printer); typedef testing::TestWithParam safe_capture; @@ -643,7 +678,15 @@ TEST_P(safe_capture, frames_independency) } static VideoCaptureAPIs safe_apis[] = {CAP_FFMPEG, CAP_GSTREAMER, CAP_MSMF,CAP_AVFOUNDATION}; -INSTANTIATE_TEST_CASE_P(videoio, safe_capture, testing::ValuesIn(safe_apis)); + +inline static std::string safe_capture_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream os; + os << getBackendNameSafe(info.param); + return os.str(); +} + +INSTANTIATE_TEST_CASE_P(videoio, safe_capture, testing::ValuesIn(safe_apis), safe_capture_name_printer); //================================================================================================== // TEST_P(videocapture_acceleration, ...) @@ -836,12 +879,22 @@ static bool hw_use_umat[] = { true }; +inline static std::string videocapture_acceleration_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream os; + os << getExtensionSafe(get<0>(info.param).filename) << "_" + << getBackendNameSafe(get<1>(info.param)) << "_" + << get<2>(info.param) << "_" + << (get<3>(info.param) ? "UMAT" : "MAT"); + return os.str(); +} + INSTANTIATE_TEST_CASE_P(videoio, videocapture_acceleration, testing::Combine( testing::ValuesIn(hw_filename), testing::ValuesIn(hw_backends), testing::ValuesIn(hw_types), testing::ValuesIn(hw_use_umat) -)); +), videocapture_acceleration_name_printer); ////////////////////////////////////////// TEST_P(video_acceleration, write_read) @@ -1019,11 +1072,23 @@ static Ext_Fourcc_PSNR hw_codecs[] = { #endif }; +inline static std::string videowriter_acceleration_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream os; + const Ext_Fourcc_PSNR & param = get<0>(info.param); + os << extToStringSafe(param.ext) << "_" + << param.fourcc << "_" + << getBackendNameSafe(param.api) << "_" + << get<1>(info.param) << "_" + << (get<2>(info.param) ? "UMAT" : "MAT"); + return os.str(); +} + INSTANTIATE_TEST_CASE_P(videoio, videowriter_acceleration, testing::Combine( testing::ValuesIn(hw_codecs), testing::ValuesIn(hw_types), testing::ValuesIn(hw_use_umat) -)); +), videowriter_acceleration_name_printer); class BufferStream : public cv::IStreamReader { @@ -1094,10 +1159,20 @@ TEST_P(stream_capture, read) for(int i = 0; i < numFrames; i++) EXPECT_EQ(0, cv::norm(frames[i], hardCopies[i], NORM_INF)) << i; } + +inline static std::string stream_capture_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream os; + os << extToStringSafe(get<0>(info.param)) << "_" + << getBackendNameSafe(get<1>(info.param)); + return os.str(); +} + INSTANTIATE_TEST_CASE_P(videoio, stream_capture, testing::Combine( testing::ValuesIn(bunny_params), - testing::ValuesIn(backend_params))); + testing::ValuesIn(backend_params)), + stream_capture_name_printer); // This test for stream input for container format (See test_ffmpeg/videoio_container.read test) typedef testing::TestWithParam stream_capture_ffmpeg; @@ -1152,6 +1227,14 @@ TEST_P(stream_capture_ffmpeg, raw) EXPECT_EQ(0, cv::norm(frame, frameRef, NORM_INF)) << i; } } -INSTANTIATE_TEST_CASE_P(videoio, stream_capture_ffmpeg, testing::Values("h264", "h265", "mjpg.avi")); + +inline static std::string stream_capture_ffmpeg_name_printer(const testing::TestParamInfo& info) +{ + std::ostringstream os; + os << extToStringSafe(info.param); + return os.str(); +} + +INSTANTIATE_TEST_CASE_P(videoio, stream_capture_ffmpeg, testing::Values("h264", "h265", "mjpg.avi"), stream_capture_ffmpeg_name_printer); } // namespace