From 44a280a6b3a0d75ece661c1198b71fb660921efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Thu, 13 Apr 2023 08:54:24 -0400 Subject: [PATCH 1/8] Adding a method to clear the processor cache. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- include/OpenColorIO/OpenColorIO.h | 3 +++ src/OpenColorIO/Config.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/include/OpenColorIO/OpenColorIO.h b/include/OpenColorIO/OpenColorIO.h index a7d073f788..9d13bab69b 100644 --- a/include/OpenColorIO/OpenColorIO.h +++ b/include/OpenColorIO/OpenColorIO.h @@ -1318,6 +1318,9 @@ class OCIOEXPORT Config const ConstConfigRcPtr & dstConfig, const char * dstColorSpaceName, const char * dstInterchangeName); + + /// \brief Clears the caches ids and processor cache. + void clearProcessorCache(); /// Set the ConfigIOProxy object used to provision the config and LUTs from somewhere other /// than the file system. (This is set on the config's embedded Context object.) diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index 665d522390..14b6eb4256 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -4967,6 +4967,11 @@ ConstProcessorRcPtr Config::GetProcessorFromBuiltinColorSpace(const char * built TRANSFORM_DIR_INVERSE); } +void Config::clearProcessorCache() +{ + getImpl()->resetCacheIDs(); +} + std::ostream& operator<< (std::ostream& os, const Config& config) { config.serialize(os); From c14d40d24fbd66a3634ae20e60ab40a00685c2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Thu, 13 Apr 2023 08:56:55 -0400 Subject: [PATCH 2/8] Do not clear the cache when enabling the cache Adding test for the cache enable/disable cycle Adding test to test clearProcessorCache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- src/OpenColorIO/Caching.h | 5 -- tests/cpu/Caching_tests.cpp | 93 ++++++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 6 deletions(-) diff --git a/src/OpenColorIO/Caching.h b/src/OpenColorIO/Caching.h index 6dd60f31b9..9d4c595f89 100644 --- a/src/OpenColorIO/Caching.h +++ b/src/OpenColorIO/Caching.h @@ -54,11 +54,6 @@ class GenericCache AutoMutex lock(m_mutex); m_enabled = enable; - - if (!isEnabled()) - { - m_entries.clear(); - } } inline bool isEnabled() const noexcept { return !m_envDisableAllCaches && m_enabled; } diff --git a/tests/cpu/Caching_tests.cpp b/tests/cpu/Caching_tests.cpp index 27841fa965..d8d35bb62b 100644 --- a/tests/cpu/Caching_tests.cpp +++ b/tests/cpu/Caching_tests.cpp @@ -5,6 +5,7 @@ #include "Caching.cpp" #include "testutils/UnitTest.h" +#include "UnitTestUtils.h" namespace OCIO = OCIO_NAMESPACE; @@ -115,6 +116,29 @@ OCIO_ADD_TEST(Caching, processor_cache) OCIO_CHECK_ASSERT(cache.isEnabled()); } + // Test that the content of the cache stays the same after disabling and enabling the cache. + { + OCIO::ProcessorCache cache; + OCIO_CHECK_ASSERT(cache.isEnabled()); + + // The lock control is useless here but useful as a good example to copy & paste. + { + OCIO::AutoMutex m(cache.lock()); + DataRcPtr entry1 = std::make_shared(); + cache["entry1"] = entry1; + } + + cache.enable(false); + + // Expecting failure because the cache is disabled. + OCIO_CHECK_ASSERT(!cache.exists("entry1")); + + cache.enable(true); + + // The data with the key "entry1" still exists after enabling the cache. + OCIO_CHECK_ASSERT(cache.exists("entry1")); + } + { // Disable all the caches. Guard guard; @@ -137,5 +161,72 @@ OCIO_ADD_TEST(Caching, processor_cache) OCIO::GenericCache cache2; OCIO_CHECK_ASSERT(cache2.isEnabled()); } -} + // Test the processor cache reset. + { + static const std::string CONFIG = + "ocio_profile_version: 2\n" + "\n" + "search_path: " + OCIO::GetTestFilesDir() + "\n" + "\n" + "environment: {CS3: lut1d_green.ctf}\n" + "\n" + "roles:\n" + " default: cs1\n" + "\n" + "displays:\n" + " disp1:\n" + " - ! {name: view1, colorspace: cs3}\n" + " - ! {name: view2, colorspace: cs3, looks: look1}\n" + "\n" + "looks:\n" + " - !\n" + " name: look1\n" + " process_space: cs2\n" + " transform: ! {src: $LOOK1}\n" + "\n" + "\n" + "colorspaces:\n" + " - !\n" + " name: cs1\n" + "\n" + " - !\n" + " name: cs2\n" + " from_scene_reference: ! {offset: [0.11, 0.12, 0.13, 0]}\n" + "\n" + " - !\n" + " name: cs3\n" + " from_scene_reference: ! {src: $CS3}\n"; + + std::istringstream iss; + iss.str(CONFIG); + + OCIO::ConstConfigRcPtr config; + OCIO_CHECK_NO_THROW(config = OCIO::Config::CreateFromStream(iss)); + + // Creating a editable config to clear the processor cache later in the test. + OCIO::ConfigRcPtr cfg = config->createEditableCopy(); + + // Create two processors and confirm that it is the same object as expected. + OCIO::ConstProcessorRcPtr procA = cfg->getProcessor("cs3", + "disp1", + "view1", + OCIO::TRANSFORM_DIR_FORWARD); + OCIO::ConstProcessorRcPtr procB = cfg->getProcessor("cs3", + "disp1", + "view1", + OCIO::TRANSFORM_DIR_FORWARD); + OCIO_CHECK_EQUAL(procA, procB); + + // Clear the processor cache. + cfg->clearProcessorCache(); + + // Create a third processor and confirm that it is different from the previous two as the + // the processor cache was cleared. + OCIO::ConstProcessorRcPtr procC = cfg->getProcessor("cs3", + "disp1", + "view1", + OCIO::TRANSFORM_DIR_FORWARD); + OCIO_CHECK_NE(procC, procA); + } +} \ No newline at end of file From 1f968d6057ff35e11f867064c37b8fe821146ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Thu, 13 Apr 2023 08:57:53 -0400 Subject: [PATCH 3/8] Unrelated: Changing zlib version to 1.2.8 (adding it to this PR to minimize PRs) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- share/cmake/modules/FindExtPackages.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/cmake/modules/FindExtPackages.cmake b/share/cmake/modules/FindExtPackages.cmake index 870b039bfc..37659eb23d 100644 --- a/share/cmake/modules/FindExtPackages.cmake +++ b/share/cmake/modules/FindExtPackages.cmake @@ -101,7 +101,7 @@ ocio_handle_dependency( Imath REQUIRED ALLOW_INSTALL # See https://nvd.nist.gov/vuln/detail/CVE-2022-37434 # See https://github.com/madler/zlib/releases/tag/v1.2.13 ocio_handle_dependency( ZLIB REQUIRED ALLOW_INSTALL - MIN_VERSION 1.2.10 + MIN_VERSION 1.2.8 RECOMMENDED_VERSION 1.2.13 RECOMMENDED_VERSION_REASON "CVE fixes" VERSION_VARS ZLIB_VERSION_STRING ZLIB_VERSION ) From 85e49d1b16a5f811a0bc0073254586f1e19e88aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Tue, 18 Apr 2023 10:01:47 -0400 Subject: [PATCH 4/8] Documentations Tweak unit tests FIx implementation for clearProcessorCache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- include/OpenColorIO/OpenColorIO.h | 14 +++-- src/OpenColorIO/Config.cpp | 9 ++-- tests/cpu/Caching_tests.cpp | 86 ++++++++++++++++++------------- 3 files changed, 66 insertions(+), 43 deletions(-) diff --git a/include/OpenColorIO/OpenColorIO.h b/include/OpenColorIO/OpenColorIO.h index 9d13bab69b..1c35b222db 100644 --- a/include/OpenColorIO/OpenColorIO.h +++ b/include/OpenColorIO/OpenColorIO.h @@ -126,8 +126,9 @@ class OCIOEXPORT ExceptionMissingFile : public Exception * such as designing OCIO profiles, and wanting to re-read luts without restarting. * * \note The method does not apply to instance specific caches such as the processor cache in a - * config instance or the GPU and CPU processor caches in a processor instance. Here deleting the - * instance flushes the cache. + * config instance or the GPU and CPU processor caches in a processor instance. + * Calling clearProcessorCache on the Config instance is helpful in that case. Note that this must + * be done if any LUT files have been changed after the Processors were created. */ extern OCIOEXPORT void ClearAllCaches(); @@ -1319,7 +1320,14 @@ class OCIOEXPORT Config const char * dstColorSpaceName, const char * dstInterchangeName); - /// \brief Clears the caches ids and processor cache. + /** + * \brief Clears this config's cache of Processor, CPUProcessor, and GPUProcessor instances. + * + * This must be done if any of the LUT files used by these Processors have been modified. + * Note that setProcessorCacheFlags(PROCESSOR_CACHE_OFF) turns off caching but does not clear + * any existing cache. + * + */ void clearProcessorCache(); /// Set the ConfigIOProxy object used to provision the config and LUTs from somewhere other diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index 14b6eb4256..c9af481fa4 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -4967,11 +4967,6 @@ ConstProcessorRcPtr Config::GetProcessorFromBuiltinColorSpace(const char * built TRANSFORM_DIR_INVERSE); } -void Config::clearProcessorCache() -{ - getImpl()->resetCacheIDs(); -} - std::ostream& operator<< (std::ostream& os, const Config& config) { config.serialize(os); @@ -5074,6 +5069,10 @@ void Config::setProcessorCacheFlags(ProcessorCacheFlags flags) noexcept getImpl()->setProcessorCacheFlags(flags); } +void Config::clearProcessorCache() +{ + getImpl()->m_processorCache.clear(); +} /////////////////////////////////////////////////////////////////////////// // Config::Impl diff --git a/tests/cpu/Caching_tests.cpp b/tests/cpu/Caching_tests.cpp index d8d35bb62b..5d6ef06fb0 100644 --- a/tests/cpu/Caching_tests.cpp +++ b/tests/cpu/Caching_tests.cpp @@ -121,12 +121,8 @@ OCIO_ADD_TEST(Caching, processor_cache) OCIO::ProcessorCache cache; OCIO_CHECK_ASSERT(cache.isEnabled()); - // The lock control is useless here but useful as a good example to copy & paste. - { - OCIO::AutoMutex m(cache.lock()); - DataRcPtr entry1 = std::make_shared(); - cache["entry1"] = entry1; - } + DataRcPtr entry1 = std::make_shared(); + cache["entry1"] = entry1; cache.enable(false); @@ -177,14 +173,6 @@ OCIO_ADD_TEST(Caching, processor_cache) "displays:\n" " disp1:\n" " - ! {name: view1, colorspace: cs3}\n" - " - ! {name: view2, colorspace: cs3, looks: look1}\n" - "\n" - "looks:\n" - " - !\n" - " name: look1\n" - " process_space: cs2\n" - " transform: ! {src: $LOOK1}\n" - "\n" "\n" "colorspaces:\n" " - !\n" @@ -207,26 +195,54 @@ OCIO_ADD_TEST(Caching, processor_cache) // Creating a editable config to clear the processor cache later in the test. OCIO::ConfigRcPtr cfg = config->createEditableCopy(); - // Create two processors and confirm that it is the same object as expected. - OCIO::ConstProcessorRcPtr procA = cfg->getProcessor("cs3", - "disp1", - "view1", - OCIO::TRANSFORM_DIR_FORWARD); - OCIO::ConstProcessorRcPtr procB = cfg->getProcessor("cs3", - "disp1", - "view1", - OCIO::TRANSFORM_DIR_FORWARD); - OCIO_CHECK_EQUAL(procA, procB); - - // Clear the processor cache. - cfg->clearProcessorCache(); - - // Create a third processor and confirm that it is different from the previous two as the - // the processor cache was cleared. - OCIO::ConstProcessorRcPtr procC = cfg->getProcessor("cs3", - "disp1", - "view1", - OCIO::TRANSFORM_DIR_FORWARD); - OCIO_CHECK_NE(procC, procA); + { + // Test that clearProcessorCache clears the Processor cache. + + // Create two processors and confirm that it is the same object as expected. + OCIO::ConstProcessorRcPtr procA = cfg->getProcessor("cs3", + "disp1", + "view1", + OCIO::TRANSFORM_DIR_FORWARD); + OCIO::ConstProcessorRcPtr procB = cfg->getProcessor("cs3", + "disp1", + "view1", + OCIO::TRANSFORM_DIR_FORWARD); + + // Comparing the address of both Processor objects to confirm if they are the same or not. + OCIO_CHECK_EQUAL(procA, procB); + + // Clear the processor cache. + cfg->clearProcessorCache(); + + // Create a third processor and confirm that it is different from the previous two as the + // the processor cache was cleared. + OCIO::ConstProcessorRcPtr procC = cfg->getProcessor("cs3", + "disp1", + "view1", + OCIO::TRANSFORM_DIR_FORWARD); + + OCIO_CHECK_NE(procC, procA); + } + + { + // Test that disable and re-enable the cache, using setProcessorCacheFlags, does not + // clear the Processor cache. + + OCIO::ConstProcessorRcPtr procA = cfg->getProcessor("cs3", + "disp1", + "view1", + OCIO::TRANSFORM_DIR_FORWARD); + + // Disable and re-enable the processor cache. + cfg->setProcessorCacheFlags(OCIO::PROCESSOR_CACHE_OFF); + cfg->setProcessorCacheFlags(OCIO::PROCESSOR_CACHE_ENABLED); + + // Confirm that the processor is the same. + OCIO::ConstProcessorRcPtr procB = cfg->getProcessor("cs3", + "disp1", + "view1", + OCIO::TRANSFORM_DIR_FORWARD); + OCIO_CHECK_EQUAL(procA, procB); + } } } \ No newline at end of file From f9997963b0c7a190f7e3d7a4e5a0fb530474bb5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Wed, 19 Apr 2023 08:34:06 -0400 Subject: [PATCH 5/8] Documentations reverting zlib version and will do it in another PR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- include/OpenColorIO/OpenColorIO.h | 23 ++++++++++++----------- share/cmake/modules/FindExtPackages.cmake | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/OpenColorIO/OpenColorIO.h b/include/OpenColorIO/OpenColorIO.h index 1c35b222db..14161ecf14 100644 --- a/include/OpenColorIO/OpenColorIO.h +++ b/include/OpenColorIO/OpenColorIO.h @@ -125,10 +125,11 @@ class OCIOEXPORT ExceptionMissingFile : public Exception * Under normal usage, this is not necessary, but it can be helpful in particular instances, * such as designing OCIO profiles, and wanting to re-read luts without restarting. * - * \note The method does not apply to instance specific caches such as the processor cache in a - * config instance or the GPU and CPU processor caches in a processor instance. - * Calling clearProcessorCache on the Config instance is helpful in that case. Note that this must - * be done if any LUT files have been changed after the Processors were created. + * \note + * This method does not apply to instance-specific caches such as the Processor cache in + * a Config instance or the GPU and CPU Processor caches in a Processor instance. So in case + * where you still have a Config instance after calling ClearAllCaches, you should also call + * the Config's clearProcessorCache method. */ extern OCIOEXPORT void ClearAllCaches(); @@ -1319,7 +1320,12 @@ class OCIOEXPORT Config const ConstConfigRcPtr & dstConfig, const char * dstColorSpaceName, const char * dstInterchangeName); - + + /// Control the caching of processors in the config instance. By default, caching is on. + /// The flags allow turning caching off entirely or only turning it off if dynamic + /// properties are being used by the processor. + void setProcessorCacheFlags(ProcessorCacheFlags flags) noexcept; + /** * \brief Clears this config's cache of Processor, CPUProcessor, and GPUProcessor instances. * @@ -1328,7 +1334,7 @@ class OCIOEXPORT Config * any existing cache. * */ - void clearProcessorCache(); + void clearProcessorCache() noexcept; /// Set the ConfigIOProxy object used to provision the config and LUTs from somewhere other /// than the file system. (This is set on the config's embedded Context object.) @@ -1392,11 +1398,6 @@ class OCIOEXPORT Config /// Do not use (needed only for pybind11). ~Config(); - /// Control the caching of processors in the config instance. By default, caching is on. - /// The flags allow turning caching off entirely or only turning it off if dynamic - /// properties are being used by the processor. - void setProcessorCacheFlags(ProcessorCacheFlags flags) noexcept; - private: Config(); diff --git a/share/cmake/modules/FindExtPackages.cmake b/share/cmake/modules/FindExtPackages.cmake index 37659eb23d..870b039bfc 100644 --- a/share/cmake/modules/FindExtPackages.cmake +++ b/share/cmake/modules/FindExtPackages.cmake @@ -101,7 +101,7 @@ ocio_handle_dependency( Imath REQUIRED ALLOW_INSTALL # See https://nvd.nist.gov/vuln/detail/CVE-2022-37434 # See https://github.com/madler/zlib/releases/tag/v1.2.13 ocio_handle_dependency( ZLIB REQUIRED ALLOW_INSTALL - MIN_VERSION 1.2.8 + MIN_VERSION 1.2.10 RECOMMENDED_VERSION 1.2.13 RECOMMENDED_VERSION_REASON "CVE fixes" VERSION_VARS ZLIB_VERSION_STRING ZLIB_VERSION ) From 19360b12e1ff6636279cd05094142f242b01389c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Thu, 20 Apr 2023 10:29:38 -0400 Subject: [PATCH 6/8] Documentation and python binding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- include/OpenColorIO/OpenColorIO.h | 3 +-- src/bindings/python/PyConfig.cpp | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/OpenColorIO/OpenColorIO.h b/include/OpenColorIO/OpenColorIO.h index 14161ecf14..ec2a8bb871 100644 --- a/include/OpenColorIO/OpenColorIO.h +++ b/include/OpenColorIO/OpenColorIO.h @@ -127,7 +127,7 @@ class OCIOEXPORT ExceptionMissingFile : public Exception * * \note * This method does not apply to instance-specific caches such as the Processor cache in - * a Config instance or the GPU and CPU Processor caches in a Processor instance. So in case + * a Config instance or the GPU and CPU Processor caches in a Processor instance. So in cases * where you still have a Config instance after calling ClearAllCaches, you should also call * the Config's clearProcessorCache method. */ @@ -1332,7 +1332,6 @@ class OCIOEXPORT Config * This must be done if any of the LUT files used by these Processors have been modified. * Note that setProcessorCacheFlags(PROCESSOR_CACHE_OFF) turns off caching but does not clear * any existing cache. - * */ void clearProcessorCache() noexcept; diff --git a/src/bindings/python/PyConfig.cpp b/src/bindings/python/PyConfig.cpp index 48270f2eca..b90d6e8b5d 100644 --- a/src/bindings/python/PyConfig.cpp +++ b/src/bindings/python/PyConfig.cpp @@ -777,6 +777,8 @@ void bindPyConfig(py::module & m) DOC(Config, GetProcessorFromConfigs, 4)) .def("setProcessorCacheFlags", &Config::setProcessorCacheFlags, "flags"_a, DOC(Config, setProcessorCacheFlags)) + .def("clearProcessorCache", &Config::clearProcessorCache, + DOC(Config, setProcessorCacheFlags)) // Archiving .def("isArchivable", &Config::isArchivable, DOC(Config, isArchivable)) From 85db1089e7a4a9c47b9f55c647bbe57ae7ccf9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Thu, 20 Apr 2023 14:23:05 -0400 Subject: [PATCH 7/8] Adding python unit tests and minor fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- src/OpenColorIO/Config.cpp | 2 +- tests/cpu/Caching_tests.cpp | 1 - tests/python/OpenColorIOTestSuite.py | 2 + tests/python/ProcessorCacheTest.py | 72 ++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 tests/python/ProcessorCacheTest.py diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index c9af481fa4..2643076cee 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -5069,7 +5069,7 @@ void Config::setProcessorCacheFlags(ProcessorCacheFlags flags) noexcept getImpl()->setProcessorCacheFlags(flags); } -void Config::clearProcessorCache() +void Config::clearProcessorCache() noexcept { getImpl()->m_processorCache.clear(); } diff --git a/tests/cpu/Caching_tests.cpp b/tests/cpu/Caching_tests.cpp index 5d6ef06fb0..94f93ba238 100644 --- a/tests/cpu/Caching_tests.cpp +++ b/tests/cpu/Caching_tests.cpp @@ -211,7 +211,6 @@ OCIO_ADD_TEST(Caching, processor_cache) // Comparing the address of both Processor objects to confirm if they are the same or not. OCIO_CHECK_EQUAL(procA, procB); - // Clear the processor cache. cfg->clearProcessorCache(); // Create a third processor and confirm that it is different from the previous two as the diff --git a/tests/python/OpenColorIOTestSuite.py b/tests/python/OpenColorIOTestSuite.py index 995706f0a4..159d5eca81 100755 --- a/tests/python/OpenColorIOTestSuite.py +++ b/tests/python/OpenColorIOTestSuite.py @@ -80,6 +80,7 @@ import NamedTransformTest import OCIOZArchiveTest import OpenColorIOTest +import ProcessorCacheTest import ProcessorTest import RangeTransformTest import TransformsTest @@ -137,6 +138,7 @@ def suite(): suite.addTest(loader.loadTestsFromModule(NamedTransformTest)) suite.addTest(loader.loadTestsFromModule(OCIOZArchiveTest)) suite.addTest(loader.loadTestsFromModule(OpenColorIOTest)) + suite.addTest(loader.loadTestsFromModule(ProcessorCacheTest)) suite.addTest(loader.loadTestsFromModule(ProcessorTest)) suite.addTest(loader.loadTestsFromModule(RangeTransformTest)) suite.addTest(loader.loadTestsFromModule(TransformsTest)) diff --git a/tests/python/ProcessorCacheTest.py b/tests/python/ProcessorCacheTest.py new file mode 100644 index 0000000000..f890ea4a0a --- /dev/null +++ b/tests/python/ProcessorCacheTest.py @@ -0,0 +1,72 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. + +import unittest, os, sys +import PyOpenColorIO as OCIO + +from UnitTestUtils import (TEST_DATAFILES_DIR) + +class CacheTest(unittest.TestCase): + def test_processor_cache(self): + CONFIG = """ocio_profile_version: 2 + +search_path: """ + TEST_DATAFILES_DIR + """ +strictparsing: true +luma: [0.2126, 0.7152, 0.0722] + +environment: {CS3: lut1d_green.ctf} + +roles: + default: cs1 + +displays: + disp1: + - ! {name: view1, colorspace: cs3} + +colorspaces: + - ! + name: cs1 + + - ! + name: cs2 + from_scene_reference: ! {offset: [0.11, 0.12, 0.13, 0]} + + - ! + name: cs3 + from_scene_reference: ! {src: $CS3} +""" + + cfg = OCIO.Config.CreateFromStream(CONFIG) + cfg.validate() + + # Test that clearProcessorCache clears the Processor cache. + + # Create two processors and confirm that it is the same object as expected + procA = cfg.getProcessor("cs3", "disp1", "view1", OCIO.TRANSFORM_DIR_FORWARD) + procB = cfg.getProcessor("cs3", "disp1", "view1", OCIO.TRANSFORM_DIR_FORWARD) + + # Comparing the address of both Processor objects to confirm if they are the same or not. + self.assertEqual(procA, procB) + + cfg.clearProcessorCache() + + # Create a third processor and confirm that it is different from the previous two as the + # the processor cache was cleared. + procC = cfg.getProcessor("cs3", "disp1", "view1", OCIO.TRANSFORM_DIR_FORWARD) + + self.assertNotEqual(procC, procA) + + + # Test that disable and re-enable the cache, using setProcessorCacheFlags, does not + # clear the Processor cache. + + procD = cfg.getProcessor("cs3", "disp1", "view1", OCIO.TRANSFORM_DIR_FORWARD) + + # Disable and re-enable the processor cache. + cfg.setProcessorCacheFlags(OCIO.PROCESSOR_CACHE_OFF) + cfg.setProcessorCacheFlags(OCIO.PROCESSOR_CACHE_ENABLED) + + # Confirm that the processor is the same. + procE = cfg.getProcessor("cs3", "disp1", "view1", OCIO.TRANSFORM_DIR_FORWARD) + + self.assertEqual(procD, procE) \ No newline at end of file From 5bbfb21228383a4c484356ee69b84dfa186f908a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Thu, 20 Apr 2023 14:32:00 -0400 Subject: [PATCH 8/8] Missing change from last commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- tests/python/ProcessorCacheTest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python/ProcessorCacheTest.py b/tests/python/ProcessorCacheTest.py index f890ea4a0a..4f65a1232d 100644 --- a/tests/python/ProcessorCacheTest.py +++ b/tests/python/ProcessorCacheTest.py @@ -6,7 +6,7 @@ from UnitTestUtils import (TEST_DATAFILES_DIR) -class CacheTest(unittest.TestCase): +class ProcessorCacheTest(unittest.TestCase): def test_processor_cache(self): CONFIG = """ocio_profile_version: 2