@@ -596,6 +596,16 @@ template <sycl::backend Backend = backend::opencl> class UrMock {
596596
597597 sycl::detail::ur::initializeUr (UrLoaderConfig);
598598 urLoaderConfigRelease (UrLoaderConfig);
599+
600+ // We clear platform cache for each test run, so that tests can have a
601+ // different backend. This forces platforms to be reconstructed (and thus
602+ // queries about UR backend info to be called again) This also erases each
603+ // platform's devices (normally done in the library shutdown) so that
604+ // platforms/devices' lifetimes could work in unittests scenario. In SYCL,
605+ // this is normally done at shutdown, but between Win/Lin and static/shared
606+ // differences, there is no correct parallel in the ~UrMock destructor.
607+ // Instead we do it here. Simple and clean.
608+ detail::GlobalHandler::instance ().getPlatformCache ().clear ();
599609 }
600610
601611 UrMock (UrMock<Backend> &&Other) = delete ;
@@ -606,18 +616,8 @@ template <sycl::backend Backend = backend::opencl> class UrMock {
606616 // these between tests
607617 detail::GlobalHandler::instance ().prepareSchedulerToRelease (true );
608618 detail::GlobalHandler::instance ().releaseDefaultContexts ();
609- #ifndef WIN32
610- // Clear platform cache in case subsequent tests want a different backend.
611- // This forces platforms to be reconstructed (and thus queries about UR
612- // backend info to be called again) This also erases each platform's devices
613- // (normally done in the library shutdown) so that platforms/devices'
614- // lifetimes could work in unittests scenario. But on Windows, because the
615- // shutdown/teardown timing is slightly different, doing this now can cause
616- // a race which will cause errors. At the moment, skipping this on Windows
617- // is fine. If, in the future, we really need to clear this, do it in the
618- // UrMock constructor.
619- detail::GlobalHandler::instance ().getPlatformCache ().clear ();
620- #endif // !WIN32
619+ // the platform cache is cleared at the BEGINING of the mock.
620+
621621 mock::getCallbacks ().resetCallbacks ();
622622 }
623623
0 commit comments