test: tmpd: Replace createVpnorRoot() with VpnorRoot class
The VpnorRoot class prepares a temporary directory for use as a VPNOR
backing store. Implementing it as a class allows us to use RAII to get
it to clean up after itself.
Change-Id: Ia5a839e751f8dc2126a4c0b474e9a7b8593cfd57
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/test/vpnor/create_pnor_partition_table.cpp b/test/vpnor/create_pnor_partition_table.cpp
index 1d4b126..fb371cb 100644
--- a/test/vpnor/create_pnor_partition_table.cpp
+++ b/test/vpnor/create_pnor_partition_table.cpp
@@ -19,18 +19,14 @@
constexpr auto partitionName = "HBB";
namespace fs = std::experimental::filesystem;
+namespace test = openpower::virtual_pnor::test;
int main()
{
- char tmplt[] = "/tmp/vpnor_partitions.XXXXXX";
- char* tmpdir = mkdtemp(tmplt);
- assert(tmpdir != nullptr);
- fs::path root{tmpdir};
-
- openpower::virtual_pnor::test::createVpnorTree(root, toc, BLOCK_SIZE);
+ test::VpnorRoot root(toc, BLOCK_SIZE);
const openpower::virtual_pnor::partition::Table table(
- fs::path{tmpdir}, BLOCK_SIZE, PNOR_SIZE);
+ fs::path{root.path()}, BLOCK_SIZE, PNOR_SIZE);
pnor_partition_table expectedTable{};
expectedTable.data.magic = PARTITION_HEADER_MAGIC;
@@ -61,8 +57,6 @@
const pnor_partition_table& result = table.getNativeTable();
- fs::remove_all(fs::path{tmpdir});
-
auto rc = memcmp(&expectedTable, &result, sizeof(pnor_partition_table));
assert(rc == 0);