/
githubmirror
/
cmssw
Обзор
Документация
Войти
/
githubmirror
/
cmssw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
PhysicsTools/TensorFlow/test/testBase.h
66 строк
2 KB
Davide Valsecchi
Check CUDA device from ResourceInformation service. Separated CUDA tests
02 фев 2023, 12:44
02 фев 2023, 12:44
ebf6c6a
Код
Авторство
О чём код?
/* * Base class for tests. * * Author: Marcel Rieger */ #ifndef PHYSICSTOOLS_TENSORFLOW_TEST_TESTBASE_H #define PHYSICSTOOLS_TENSORFLOW_TEST_TESTBASE_H #include <boost/filesystem.hpp> #include <filesystem> #include <cppunit/extensions/HelperMacros.h> #include <stdexcept> class testBase : public CppUnit::TestFixture { public: std::string dataPath_; void setUp(); void tearDown(); std::string cmsswPath(std::string path); virtual void test() = 0; virtual std::string pyScript() const = 0; }; void testBase::setUp() { dataPath_ = cmsswPath("/test/" + std::string(std::getenv("SCRAM_ARCH")) + "/" + boost::filesystem::unique_path().string()); // create the graph std::string testPath = cmsswPath("/src/PhysicsTools/TensorFlow/test"); std::string cmd = "python3 -W ignore " + testPath + "/" + pyScript() + " " + dataPath_; std::array<char, 128> buffer; std::string result; std::shared_ptr<FILE> pipe(popen(cmd.c_str(), "r"), pclose); if (!pipe) { throw std::runtime_error("popen() failed!"); } while (!feof(pipe.get())) { if (fgets(buffer.data(), 128, pipe.get()) != NULL) { result += buffer.data(); } } std::cout << std::endl << result << std::endl; } void testBase::tearDown() { if (std::filesystem::exists(dataPath_)) { std::filesystem::remove_all(dataPath_); } } std::string testBase::cmsswPath(std::string path) { if (path.size() > 0 && path.substr(0, 1) != "/") { path = "/" + path; } std::string base = std::string(std::getenv("CMSSW_BASE")); std::string releaseBase = std::string(std::getenv("CMSSW_RELEASE_BASE")); return (std::filesystem::exists(base.c_str()) ? base : releaseBase) + path; } #endif // PHYSICSTOOLS_TENSORFLOW_TEST_TESTBASE_H