diff options
Diffstat (limited to 'test/vpnor/tmpd.hpp')
-rw-r--r-- | test/vpnor/tmpd.hpp | 73 |
1 files changed, 49 insertions, 24 deletions
diff --git a/test/vpnor/tmpd.hpp b/test/vpnor/tmpd.hpp index ab27377..d684706 100644 --- a/test/vpnor/tmpd.hpp +++ b/test/vpnor/tmpd.hpp @@ -10,8 +10,6 @@ #include "config.h" #include "pnor_partition_table.hpp" -namespace fs = std::experimental::filesystem; - namespace openpower { namespace virtual_pnor @@ -19,35 +17,62 @@ namespace virtual_pnor namespace test { -template <std::size_t N> -void createVpnorTree(fs::path &root, const std::string (&toc)[N], - size_t blockSize) -{ - fs::path tocFilePath{root}; - tocFilePath /= PARTITION_TOC_FILE; - std::ofstream tocFile(tocFilePath.c_str()); +namespace fs = std::experimental::filesystem; - for (const std::string &line : toc) +class VpnorRoot +{ + public: + template <std::size_t N> + VpnorRoot(const std::string (&toc)[N], size_t blockSize) { - pnor_partition part; + char tmplt[] = "/tmp/vpnor_root.XXXXXX"; + char* tmpdir = mkdtemp(tmplt); + root = fs::path{tmpdir}; + + fs::path tocFilePath{root}; + tocFilePath /= PARTITION_TOC_FILE; + std::ofstream tocFile(tocFilePath.c_str()); + + for (const std::string& line : toc) + { + pnor_partition part; - openpower::virtual_pnor::parseTocLine(line, blockSize, part); + openpower::virtual_pnor::parseTocLine(line, blockSize, part); - /* Populate the partition in the tree */ - fs::path partitionFilePath{root}; - partitionFilePath /= part.data.name; - std::ofstream partitionFile(partitionFilePath.c_str()); - std::vector<char> empty(part.data.size, 0); - partitionFile.write(empty.data(), empty.size()); - partitionFile.close(); + /* Populate the partition in the tree */ + fs::path partitionFilePath{root}; + partitionFilePath /= part.data.name; + std::ofstream partitionFile(partitionFilePath.c_str()); + std::vector<char> empty(part.data.size, 0); + partitionFile.write(empty.data(), empty.size()); + partitionFile.close(); - /* Update the ToC if the partition file was created */ - tocFile.write(line.c_str(), line.length()); - tocFile.write("\n", 1); + /* Update the ToC if the partition file was created */ + tocFile.write(line.c_str(), line.length()); + tocFile.write("\n", 1); + } + + tocFile.close(); + } + + VpnorRoot(const VpnorRoot&) = delete; + VpnorRoot& operator=(const VpnorRoot&) = delete; + VpnorRoot(VpnorRoot&&) = delete; + VpnorRoot& operator=(VpnorRoot&&) = delete; + + ~VpnorRoot() + { + fs::remove_all(root); + } + const fs::path& path() + { + return root; } + size_t write(const std::string& name, const void* data, size_t len); - tocFile.close(); -} + private: + fs::path root; +}; } // test } // virtual_pnor |