test: tmpd: Populate path members under struct mbox_context

Change-Id: I9d18bd108d1c0972a5fefa384152757a2483c103
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 98d474b..09f481d 100644
--- a/test/vpnor/create_pnor_partition_table.cpp
+++ b/test/vpnor/create_pnor_partition_table.cpp
@@ -20,7 +20,9 @@
 
 int main()
 {
-    test::VpnorRoot root(toc, BLOCK_SIZE);
+    struct mbox_context _ctx, *ctx = &_ctx;
+
+    test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
 
     const openpower::virtual_pnor::partition::Table table(root.ro(), BLOCK_SIZE,
                                                           PNOR_SIZE);
diff --git a/test/vpnor/create_read_window_vpnor.cpp b/test/vpnor/create_read_window_vpnor.cpp
index 5adb044..87deb9c 100644
--- a/test/vpnor/create_read_window_vpnor.cpp
+++ b/test/vpnor/create_read_window_vpnor.cpp
@@ -65,24 +65,17 @@
 
 int main()
 {
-    fs::path path;
-    const char *cpath;
-
-    test::VpnorRoot root(toc, BLOCK_SIZE);
-    root.write("HBB", data, sizeof(data));
-
-    path = root.ro();
-    cpath = path.c_str();
+    struct mbox_context *ctx;
 
     system_set_reserved_size(MEM_SIZE);
     system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
 
-    struct mbox_context *ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
-    strcpy(ctx->paths.ro_loc, cpath);
-    strcpy(ctx->paths.rw_loc, cpath);
-    strcpy(ctx->paths.prsv_loc, cpath);
+    ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
 
-    vpnor_create_partition_table_from_path(ctx, cpath);
+    test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
+    root.write("HBB", data, sizeof(data));
+
+    vpnor_create_partition_table_from_path(ctx, root.ro().c_str());
 
     int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
     assert(rc == 1);
diff --git a/test/vpnor/tmpd.hpp b/test/vpnor/tmpd.hpp
index 28d27c9..8ff40ad 100644
--- a/test/vpnor/tmpd.hpp
+++ b/test/vpnor/tmpd.hpp
@@ -8,6 +8,7 @@
 #include <experimental/filesystem>
 
 #include "config.h"
+#include "mbox.h"
 #include "pnor_partition_table.hpp"
 
 namespace openpower
@@ -23,7 +24,8 @@
 {
   public:
     template <std::size_t N>
-    VpnorRoot(const std::string (&toc)[N], size_t blockSize)
+    VpnorRoot(struct mbox_context* ctx, const std::string (&toc)[N],
+              size_t blockSize)
     {
         char tmplt[] = "/tmp/vpnor_root.XXXXXX";
         char* tmpdir = mkdtemp(tmplt);
@@ -51,6 +53,15 @@
             /* Update the ToC if the partition file was created */
             std::ofstream(tocFilePath, std::ofstream::app) << line << "\n";
         }
+
+        strncpy(ctx->paths.ro_loc, ro().c_str(), PATH_MAX - 1);
+        ctx->paths.ro_loc[PATH_MAX - 1] = '\0';
+        strncpy(ctx->paths.rw_loc, rw().c_str(), PATH_MAX - 1);
+        ctx->paths.rw_loc[PATH_MAX - 1] = '\0';
+        strncpy(ctx->paths.prsv_loc, prsv().c_str(), PATH_MAX - 1);
+        ctx->paths.prsv_loc[PATH_MAX - 1] = '\0';
+        strncpy(ctx->paths.patch_loc, patch().c_str(), PATH_MAX - 1);
+        ctx->paths.patch_loc[PATH_MAX - 1] = '\0';
     }
 
     VpnorRoot(const VpnorRoot&) = delete;
diff --git a/test/vpnor/write_flash_vpnor.cpp b/test/vpnor/write_flash_vpnor.cpp
index 384c13a..c53e8da 100644
--- a/test/vpnor/write_flash_vpnor.cpp
+++ b/test/vpnor/write_flash_vpnor.cpp
@@ -80,11 +80,6 @@
     ctx->block_size_shift = BLOCK_SIZE_SHIFT;
     ctx->flash_bmap = reinterpret_cast<uint8_t*>(
         calloc(MEM_SIZE >> ctx->erase_size_shift, sizeof(*ctx->flash_bmap)));
-
-    strcpy(ctx->paths.ro_loc, root.ro().c_str());
-    strcpy(ctx->paths.rw_loc, root.rw().c_str());
-    strcpy(ctx->paths.prsv_loc, root.prsv().c_str());
-    strcpy(ctx->paths.patch_loc, root.patch().c_str());
 }
 
 int main(void)
@@ -97,7 +92,7 @@
     struct mbox_context* ctx = &context;
     memset(ctx, 0, sizeof(mbox_context));
 
-    test::VpnorRoot root(toc, BLOCK_SIZE);
+    test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
 
     // Initialize the context before running the test case.
     init(ctx, root);