From fe2dc948a5a226eded995858996c4d779aad93dd Mon Sep 17 00:00:00 2001 From: Ananth Bhaskararaman Date: Thu, 17 Oct 2024 00:03:19 +0530 Subject: [PATCH] Move GPU LUT files into the tests dir Instead of creating temporary LUT files for GPU tests, read them from the testdata directory instead. This removes the need to clean them up after each run. Signed-off-by: Ananth Bhaskararaman --- tests/cpu/Context_tests.cpp | 8 +- tests/data/files/lut3d_arbitrary.csp | 22 +++ tests/data/files/lut3d_blu-only.csp | 22 +++ tests/data/files/lut3d_grn-only.csp | 22 +++ tests/data/files/lut3d_red-only.csp | 22 +++ tests/gpu/CDLOp_test.cpp | 1 - tests/gpu/CMakeLists.txt | 1 - tests/gpu/GPUHelpers.cpp | 58 -------- tests/gpu/GPUHelpers.h | 16 --- tests/gpu/Lut1DOp_test.cpp | 1 - tests/gpu/Lut3DOp_test.cpp | 203 ++++----------------------- tests/gpu/RangeOp_test.cpp | 1 - 12 files changed, 122 insertions(+), 255 deletions(-) create mode 100644 tests/data/files/lut3d_arbitrary.csp create mode 100644 tests/data/files/lut3d_blu-only.csp create mode 100644 tests/data/files/lut3d_grn-only.csp create mode 100644 tests/data/files/lut3d_red-only.csp delete mode 100644 tests/gpu/GPUHelpers.cpp delete mode 100644 tests/gpu/GPUHelpers.h diff --git a/tests/cpu/Context_tests.cpp b/tests/cpu/Context_tests.cpp index c8d4052ffd..3372d8f36f 100644 --- a/tests/cpu/Context_tests.cpp +++ b/tests/cpu/Context_tests.cpp @@ -119,8 +119,8 @@ OCIO_ADD_TEST(Context, use_searchpaths) const std::string res1 = searchPath1 + "/Context.cpp"; OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), SanitizePath(res1.c_str()).c_str()) == 0); - OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("GPUHelpers.h")); - const std::string res2 = searchPath2 + "/GPUHelpers.h"; + OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("GPUUnitTest.h")); + const std::string res2 = searchPath2 + "/GPUUnitTest.h"; OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), SanitizePath(res2.c_str()).c_str()) == 0); } @@ -141,8 +141,8 @@ OCIO_ADD_TEST(Context, use_searchpaths_workingdir) const std::string res1 = ociodir + "/" + searchPath1 + "/Context.cpp"; OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), SanitizePath(res1.c_str()).c_str()) == 0); - OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("GPUHelpers.h")); - const std::string res2 = ociodir + "/" + searchPath2 + "/GPUHelpers.h"; + OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("GPUUnitTest.h")); + const std::string res2 = ociodir + "/" + searchPath2 + "/GPUUnitTest.h"; OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), SanitizePath(res2.c_str()).c_str()) == 0); } diff --git a/tests/data/files/lut3d_arbitrary.csp b/tests/data/files/lut3d_arbitrary.csp new file mode 100644 index 0000000000..7babf7c08b --- /dev/null +++ b/tests/data/files/lut3d_arbitrary.csp @@ -0,0 +1,22 @@ +CSPLUTV100 +3D + +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 + +2 2 2 +0.100000 0.100000 0.100000 +1.100000 0.100000 0.100000 +0.100000 1.100000 0.100000 +1.100000 1.100000 0.100000 +0.100000 0.100000 1.100000 +1.100000 0.100000 1.100000 +0.100000 1.100000 1.100000 +1.100000 1.100000 1.100000 diff --git a/tests/data/files/lut3d_blu-only.csp b/tests/data/files/lut3d_blu-only.csp new file mode 100644 index 0000000000..e9f68bee8c --- /dev/null +++ b/tests/data/files/lut3d_blu-only.csp @@ -0,0 +1,22 @@ +CSPLUTV100 +3D + +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 + +2 2 2 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 1.0 +0.0 0.0 1.0 +0.0 0.0 1.0 +0.0 0.0 1.0 diff --git a/tests/data/files/lut3d_grn-only.csp b/tests/data/files/lut3d_grn-only.csp new file mode 100644 index 0000000000..e62fa8fce6 --- /dev/null +++ b/tests/data/files/lut3d_grn-only.csp @@ -0,0 +1,22 @@ +CSPLUTV100 +3D + +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 + +2 2 2 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 1.0 0.0 +0.0 1.0 0.0 +0.0 1.0 0.0 +0.0 1.0 0.0 diff --git a/tests/data/files/lut3d_red-only.csp b/tests/data/files/lut3d_red-only.csp new file mode 100644 index 0000000000..7a08c38d81 --- /dev/null +++ b/tests/data/files/lut3d_red-only.csp @@ -0,0 +1,22 @@ +CSPLUTV100 +3D + +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 + +2 2 2 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +1.0 0.0 0.0 +1.0 0.0 0.0 +1.0 0.0 0.0 +1.0 0.0 0.0 diff --git a/tests/gpu/CDLOp_test.cpp b/tests/gpu/CDLOp_test.cpp index 9f32d0d42a..ddf1b43eeb 100644 --- a/tests/gpu/CDLOp_test.cpp +++ b/tests/gpu/CDLOp_test.cpp @@ -9,7 +9,6 @@ #include #include "GPUUnitTest.h" -#include "GPUHelpers.h" namespace OCIO = OCIO_NAMESPACE; diff --git a/tests/gpu/CMakeLists.txt b/tests/gpu/CMakeLists.txt index 4e16243bfd..2c56f2948b 100644 --- a/tests/gpu/CMakeLists.txt +++ b/tests/gpu/CMakeLists.txt @@ -12,7 +12,6 @@ set(SOURCES ECOp_test.cpp FixedFunctionOp_test.cpp GammaOp_test.cpp - GPUHelpers.cpp GPUUnitTest.cpp GradingPrimaryOp_test.cpp GradingRGBCurveOp_test.cpp diff --git a/tests/gpu/GPUHelpers.cpp b/tests/gpu/GPUHelpers.cpp deleted file mode 100644 index 317e772461..0000000000 --- a/tests/gpu/GPUHelpers.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// Copyright Contributors to the OpenColorIO Project. - - -#include -#include - -#if !defined(_WIN32) -#include -#include -#include -#endif - -#include - -#include "GPUHelpers.h" - -namespace OCIO = OCIO_NAMESPACE; - - -// TODO: Make OCIO::Platform::CreateTempFilename() public so it could be used here. - -std::string createTempFile(const std::string& fileExt, const std::string& fileContent) -{ - // Note: because of security issue, tmpnam could not be used - - std::string filename; - -#ifdef _WIN32 - - char tmpFilename[L_tmpnam]; - if(tmpnam_s(tmpFilename)) - { - throw OCIO::Exception("Could not create a temporary file"); - } - - // Note that when a file name is pre-pended with a backslash and no path information, such as \fname21, this - // indicates that the name is valid for the current working directory. - filename = tmpFilename[0] == '\\' ? tmpFilename + 1 : tmpFilename; - filename += fileExt; - -#else - - std::stringstream ss; - ss << "/tmp/ocio"; - ss << std::rand(); - ss << fileExt; - - filename = ss.str(); - -#endif - - std::ofstream ofs(filename.c_str(), std::ios_base::out); - ofs << fileContent; - ofs.close(); - - return filename; -} diff --git a/tests/gpu/GPUHelpers.h b/tests/gpu/GPUHelpers.h deleted file mode 100644 index e49be0e1d3..0000000000 --- a/tests/gpu/GPUHelpers.h +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// Copyright Contributors to the OpenColorIO Project. - - -#ifndef OPENCOLORIO_GPU_HELPERS_H -#define OPENCOLORIO_GPU_HELPERS_H - - -#include - -// FIXME: Duplicate function implemented in `src/OpenColorIO/Platform.h and cpp`. -// Implement a function or class for temporary file creation useable by all tests. -std::string createTempFile(const std::string& fileExt, const std::string& fileContent); - - -#endif \ No newline at end of file diff --git a/tests/gpu/Lut1DOp_test.cpp b/tests/gpu/Lut1DOp_test.cpp index 91d13446bb..cb76697619 100644 --- a/tests/gpu/Lut1DOp_test.cpp +++ b/tests/gpu/Lut1DOp_test.cpp @@ -9,7 +9,6 @@ #include #include "GPUUnitTest.h" -#include "GPUHelpers.h" namespace OCIO = OCIO_NAMESPACE; diff --git a/tests/gpu/Lut3DOp_test.cpp b/tests/gpu/Lut3DOp_test.cpp index d5fc45a0b6..d1ee3aa3de 100644 --- a/tests/gpu/Lut3DOp_test.cpp +++ b/tests/gpu/Lut3DOp_test.cpp @@ -7,47 +7,43 @@ #include -#include "GPUHelpers.h" #include "GPUUnitTest.h" namespace OCIO = OCIO_NAMESPACE; +#ifndef OCIO_UNIT_TEST_FILES_DIR +#error Expecting OCIO_UNIT_TEST_FILES_DIR to be defined for tests. Check relevant CMakeLists.txt +#endif + + +// For explanation, refer to https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html +#define _STR(x) #x +#define STR(x) _STR(x) + +static const std::string ocioTestFilesDir(STR(OCIO_UNIT_TEST_FILES_DIR)); + + +namespace +{ +OCIO::FileTransformRcPtr GetFileTransform(const std::string & filename) +{ + const std::string filepath(ocioTestFilesDir + std::string("/") + filename); + + OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); + file->setSrc(filepath.c_str()); + + return file; +} +} + OCIO_ADD_GPU_TEST(Lut3DOp, red_only_using_CSP_file_legacy_shader) { // Any other 3D LUT file format would have been good also. - std::ostringstream content; - content << "CSPLUTV100" << "\n"; - content << "3D" << "\n"; - content << "" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "" << "\n"; - content << "2 2 2" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "1.0 0.0 0.0" << "\n"; - content << "1.0 0.0 0.0" << "\n"; - content << "1.0 0.0 0.0" << "\n"; - content << "1.0 0.0 0.0" << "\n"; - - - const std::string filename = createTempFile(".csp", content.str()); - // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filename.c_str()); + OCIO::FileTransformRcPtr file = GetFileTransform("lut3d_red-only.csp"); file->setInterpolation(OCIO::INTERP_LINEAR); test.setProcessor(file); @@ -60,37 +56,9 @@ OCIO_ADD_GPU_TEST(Lut3DOp, green_only_using_CSP_file_legacy_shader) { // Any other 3D LUT file format would have been good also. - std::ostringstream content; - content << "CSPLUTV100" << "\n"; - content << "3D" << "\n"; - content << "" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "" << "\n"; - content << "2 2 2" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 1.0 0.0" << "\n"; - content << "0.0 1.0 0.0" << "\n"; - content << "0.0 1.0 0.0" << "\n"; - content << "0.0 1.0 0.0" << "\n"; - - - const std::string filename = createTempFile(".csp", content.str()); - // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filename.c_str()); + OCIO::FileTransformRcPtr file = GetFileTransform("lut3d_grn-only.csp"); file->setInterpolation(OCIO::INTERP_LINEAR); test.setProcessor(file); @@ -103,37 +71,10 @@ OCIO_ADD_GPU_TEST(Lut3DOp, blue_only_using_CSP_file_legacy_shader) { // Any other 3D LUT file format would have been good also. - std::ostringstream content; - content << "CSPLUTV100" << "\n"; - content << "3D" << "\n"; - content << "" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "" << "\n"; - content << "2 2 2" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 1.0" << "\n"; - content << "0.0 0.0 1.0" << "\n"; - content << "0.0 0.0 1.0" << "\n"; - content << "0.0 0.0 1.0" << "\n"; - - - const std::string filename = createTempFile(".csp", content.str()); // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filename.c_str()); + OCIO::FileTransformRcPtr file = GetFileTransform("lut3d_blu-only.csp"); file->setInterpolation(OCIO::INTERP_LINEAR); test.setProcessor(file); @@ -147,37 +88,9 @@ OCIO_ADD_GPU_TEST(Lut3DOp, arbitrary_using_CSP_file_legacy_shader) { // Any other 3D LUT file format would have been good also. - std::ostringstream content; - content << "CSPLUTV100" << "\n"; - content << "3D" << "\n"; - content << "" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "" << "\n"; - content << "2 2 2" << "\n"; - content << "0.100000 0.100000 0.100000" << "\n"; - content << "1.100000 0.100000 0.100000" << "\n"; - content << "0.100000 1.100000 0.100000" << "\n"; - content << "1.100000 1.100000 0.100000" << "\n"; - content << "0.100000 0.100000 1.100000" << "\n"; - content << "1.100000 0.100000 1.100000" << "\n"; - content << "0.100000 1.100000 1.100000" << "\n"; - content << "1.100000 1.100000 1.100000" << "\n"; - - - const std::string filename = createTempFile(".csp", content.str()); - // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filename.c_str()); + OCIO::FileTransformRcPtr file = GetFileTransform("lut3d_arbitrary.csp"); file->setInterpolation(OCIO::INTERP_LINEAR); test.setProcessor(file); @@ -189,37 +102,9 @@ OCIO_ADD_GPU_TEST(Lut3DOp, arbitrary_using_CSP_file_legacy_shader) OCIO_ADD_GPU_TEST(Lut3DOp, arbitrary_using_CSP_file) { - std::ostringstream content; - content << "CSPLUTV100" << "\n"; - content << "3D" << "\n"; - content << "" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "" << "\n"; - content << "2 2 2" << "\n"; - content << "0.100000 0.100000 0.100000" << "\n"; - content << "1.100000 0.100000 0.100000" << "\n"; - content << "0.100000 1.100000 0.100000" << "\n"; - content << "1.100000 1.100000 0.100000" << "\n"; - content << "0.100000 0.100000 1.100000" << "\n"; - content << "1.100000 0.100000 1.100000" << "\n"; - content << "0.100000 1.100000 1.100000" << "\n"; - content << "1.100000 1.100000 1.100000" << "\n"; - - - const std::string filename = createTempFile(".csp", content.str()); - // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filename.c_str()); + OCIO::FileTransformRcPtr file = GetFileTransform("lut3d_arbitrary.csp"); file->setInterpolation(OCIO::INTERP_LINEAR); test.setProcessor(file); @@ -232,33 +117,6 @@ OCIO_ADD_GPU_TEST(Lut3DOp, arbitrary_using_CSP_file) } - -#ifndef OCIO_UNIT_TEST_FILES_DIR -#error Expecting OCIO_UNIT_TEST_FILES_DIR to be defined for tests. Check relevant CMakeLists.txt -#endif - - -// For explanation, refer to https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html -#define _STR(x) #x -#define STR(x) _STR(x) - -static const std::string ocioTestFilesDir(STR(OCIO_UNIT_TEST_FILES_DIR)); - - -namespace -{ -OCIO::FileTransformRcPtr GetFileTransform(const std::string & filename) -{ - const std::string filepath(ocioTestFilesDir + std::string("/") + filename); - - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filepath.c_str()); - - return file; -} -} - - OCIO_ADD_GPU_TEST(Lut3DOp, 3dlut_file_legacy_shader) { OCIO::FileTransformRcPtr file = GetFileTransform("lut3d_1.spi3d"); @@ -389,4 +247,3 @@ OCIO_ADD_GPU_TEST(Lut3DOp, 3dlut_biggest_supported) test.setErrorThreshold(1e-4f); } - diff --git a/tests/gpu/RangeOp_test.cpp b/tests/gpu/RangeOp_test.cpp index c94906cfe9..3ae2c90012 100644 --- a/tests/gpu/RangeOp_test.cpp +++ b/tests/gpu/RangeOp_test.cpp @@ -7,7 +7,6 @@ #include -#include "GPUHelpers.h" #include "GPUUnitTest.h" namespace OCIO = OCIO_NAMESPACE;