test: vpnor: Extract write_ro from write_flash_vpnor

Change-Id: I10b82d84cd40d52b0a489dc834269eec1a0d5240
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/test/vpnor/write_ro.cpp b/test/vpnor/write_ro.cpp
new file mode 100644
index 0000000..fe934dd
--- /dev/null
+++ b/test/vpnor/write_ro.cpp
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright (C) 2018 IBM Corp.
+
+#include <assert.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "mbox.h"
+#include "mboxd_flash.h"
+
+#include "test/vpnor/tmpd.hpp"
+
+static constexpr auto BLOCK_SIZE = 0x1000;
+
+const std::string toc[] = {
+    "partition01=TEST1,00001000,00002000,80,ECC,READONLY",
+};
+
+int main(void)
+{
+    namespace fs = std::experimental::filesystem;
+    namespace test = openpower::virtual_pnor::test;
+
+    struct mbox_context _ctx, *ctx = &_ctx;
+    uint8_t src[8] = {0};
+    int rc;
+
+    /* Setup */
+    memset(ctx, 0, sizeof(mbox_context));
+
+    mbox_vlog = &mbox_log_console;
+    verbosity = (verbose)2;
+
+    test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
+    vpnor_create_partition_table_from_path(ctx, root.ro().c_str());
+
+    /* Test */
+    rc = write_flash(ctx, 0x1000, src, sizeof(src));
+
+    /* Verify we can't write to RO partitions */
+    assert(rc != 0);
+
+    destroy_vpnor(ctx);
+
+    return 0;
+}