diff options
author | Andrew Jeffery <andrew@aj.id.au> | 2018-02-21 21:19:00 +1030 |
---|---|---|
committer | Andrew Jeffery <andrew@aj.id.au> | 2018-03-24 13:59:32 +1030 |
commit | d083efd2d1425dead6e049b7e1a5dc4dcc7e29e2 (patch) | |
tree | 58949cc3b6fe3b0922d7dd58e46813196fd0dbba /test | |
parent | 9ecef7963f211d279cd82eb5e47b92bdb640a0a9 (diff) | |
download | phosphor-mboxd-d083efd2d1425dead6e049b7e1a5dc4dcc7e29e2.tar.gz phosphor-mboxd-d083efd2d1425dead6e049b7e1a5dc4dcc7e29e2.zip |
test: Add temporary directory helper for virtual PNOR tests
Move the createVpnorTree() helper function out from the
create_pnor_partition_table test case into its own header. This way
multiple tests can make use of its function.
Change-Id: Ieb4149e736c7ff87ecdbf7aa586b58baf936cd97
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Diffstat (limited to 'test')
-rw-r--r-- | test/vpnor/create_pnor_partition_table.cpp | 34 | ||||
-rw-r--r-- | test/vpnor/tmpd.hpp | 54 |
2 files changed, 57 insertions, 31 deletions
diff --git a/test/vpnor/create_pnor_partition_table.cpp b/test/vpnor/create_pnor_partition_table.cpp index 6b47bb9..1d4b126 100644 --- a/test/vpnor/create_pnor_partition_table.cpp +++ b/test/vpnor/create_pnor_partition_table.cpp @@ -8,6 +8,8 @@ #include <fstream> #include <experimental/filesystem> +#include "test/vpnor/tmpd.hpp" + static const auto BLOCK_SIZE = 4 * 1024; static const auto PNOR_SIZE = 64 * 1024 * 1024; @@ -18,36 +20,6 @@ constexpr auto partitionName = "HBB"; namespace fs = std::experimental::filesystem; -template <std::size_t N> -static 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()); - - for (const std::string& line : toc) - { - pnor_partition 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(); - - /* Update the ToC if the partition file was created */ - tocFile.write(line.c_str(), line.length()); - tocFile.write("\n", 1); - } - - tocFile.close(); -} - int main() { char tmplt[] = "/tmp/vpnor_partitions.XXXXXX"; @@ -55,7 +27,7 @@ int main() assert(tmpdir != nullptr); fs::path root{tmpdir}; - createVpnorTree(root, toc, BLOCK_SIZE); + openpower::virtual_pnor::test::createVpnorTree(root, toc, BLOCK_SIZE); const openpower::virtual_pnor::partition::Table table( fs::path{tmpdir}, BLOCK_SIZE, PNOR_SIZE); diff --git a/test/vpnor/tmpd.hpp b/test/vpnor/tmpd.hpp new file mode 100644 index 0000000..ab27377 --- /dev/null +++ b/test/vpnor/tmpd.hpp @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/* Copyright (C) 2018 IBM Corp. */ + +#include <assert.h> +#include <string.h> +#include <vector> +#include <fstream> +#include <experimental/filesystem> + +#include "config.h" +#include "pnor_partition_table.hpp" + +namespace fs = std::experimental::filesystem; + +namespace openpower +{ +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()); + + for (const std::string &line : toc) + { + pnor_partition 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(); + + /* Update the ToC if the partition file was created */ + tocFile.write(line.c_str(), line.length()); + tocFile.write("\n", 1); + } + + tocFile.close(); +} + +} // test +} // virtual_pnor +} // openpower |