vpnor: Shuffle and rework includes for sanity

Include ordering and whether or not C linkage is forced by `extern "C"`
blocks can cause headaches at link time. Ensure that all C dependencies
are included in an `extern C` block before other includes occur. Also
include the C++ versions of string.h and assert.h

Change-Id: Ia96f6044d40c8eccb907b65924efcf62ac7a89c3
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/vpnor/test/create_pnor_partition_table.cpp b/vpnor/test/create_pnor_partition_table.cpp
index ab28180..cdbe8b6 100644
--- a/vpnor/test/create_pnor_partition_table.cpp
+++ b/vpnor/test/create_pnor_partition_table.cpp
@@ -4,8 +4,8 @@
 
 #include "vpnor/pnor_partition_table.hpp"
 
-#include <assert.h>
-#include <string.h>
+#include <cassert>
+#include <cstring>
 
 extern "C" {
 #include "test/mbox.h"
diff --git a/vpnor/test/create_read_window_oob.cpp b/vpnor/test/create_read_window_oob.cpp
index 2b8fe6d..240c10e 100644
--- a/vpnor/test/create_read_window_oob.cpp
+++ b/vpnor/test/create_read_window_oob.cpp
@@ -3,11 +3,6 @@
 
 #include "config.h"
 
-#include <assert.h>
-#include <string.h>
-
-#include "vpnor/mboxd_pnor_partition_table.h"
-
 extern "C" {
 #include "test/mbox.h"
 #include "test/system.h"
@@ -15,6 +10,11 @@
 
 #include "vpnor/test/tmpd.hpp"
 
+#include <cassert>
+#include <cstring>
+
+#include "vpnor/mboxd_pnor_partition_table.h"
+
 const std::string toc[] = {
     "partition01=HBB,00001000,00002000,80,ECC,READONLY",
 };
diff --git a/vpnor/test/create_read_window_partition_exists.cpp b/vpnor/test/create_read_window_partition_exists.cpp
index f02272d..d3532ec 100644
--- a/vpnor/test/create_read_window_partition_exists.cpp
+++ b/vpnor/test/create_read_window_partition_exists.cpp
@@ -3,15 +3,6 @@
 
 #include "config.h"
 
-#include <assert.h>
-#include <string.h>
-
-#include <experimental/filesystem>
-#include <fstream>
-#include <vector>
-
-#include "vpnor/mboxd_pnor_partition_table.h"
-
 extern "C" {
 #include "test/mbox.h"
 #include "test/system.h"
@@ -19,6 +10,14 @@
 
 #include "vpnor/test/tmpd.hpp"
 
+#include <cassert>
+#include <cstring>
+#include <experimental/filesystem>
+#include <fstream>
+#include <vector>
+
+#include "vpnor/mboxd_pnor_partition_table.h"
+
 // A read window assumes that the toc is located at offset 0,
 // so create dummy partition at arbitrary offset 0x1000.
 const std::string toc[] = {
diff --git a/vpnor/test/create_read_window_partition_invalid.cpp b/vpnor/test/create_read_window_partition_invalid.cpp
index e6747c8..36431d3 100644
--- a/vpnor/test/create_read_window_partition_invalid.cpp
+++ b/vpnor/test/create_read_window_partition_invalid.cpp
@@ -3,11 +3,6 @@
 
 #include "config.h"
 
-#include <assert.h>
-#include <string.h>
-
-#include "vpnor/mboxd_pnor_partition_table.h"
-
 extern "C" {
 #include "test/mbox.h"
 #include "test/system.h"
@@ -15,6 +10,11 @@
 
 #include "vpnor/test/tmpd.hpp"
 
+#include <cassert>
+#include <cstring>
+
+#include "vpnor/mboxd_pnor_partition_table.h"
+
 const std::string toc[] = {
     "partition01=HBB,00002000,00003000,80,ECC,READONLY",
 };
diff --git a/vpnor/test/create_read_window_remap.cpp b/vpnor/test/create_read_window_remap.cpp
index c05ef02..7a11053 100644
--- a/vpnor/test/create_read_window_remap.cpp
+++ b/vpnor/test/create_read_window_remap.cpp
@@ -3,15 +3,6 @@
 
 #include "config.h"
 
-#include <assert.h>
-#include <string.h>
-
-#include <experimental/filesystem>
-#include <fstream>
-#include <vector>
-
-#include "vpnor/mboxd_pnor_partition_table.h"
-
 extern "C" {
 #include "test/mbox.h"
 #include "test/system.h"
@@ -19,6 +10,14 @@
 
 #include "vpnor/test/tmpd.hpp"
 
+#include <cassert>
+#include <cstring>
+#include <experimental/filesystem>
+#include <fstream>
+#include <vector>
+
+#include "vpnor/mboxd_pnor_partition_table.h"
+
 static const auto BLOCK_SIZE = 4096;
 static const auto ERASE_SIZE = BLOCK_SIZE;
 static const auto WINDOW_SIZE = 16 * BLOCK_SIZE;
diff --git a/vpnor/test/create_read_window_size.cpp b/vpnor/test/create_read_window_size.cpp
index 6f9a7ed..6ea11f1 100644
--- a/vpnor/test/create_read_window_size.cpp
+++ b/vpnor/test/create_read_window_size.cpp
@@ -3,18 +3,18 @@
 
 #include "config.h"
 
-#include <assert.h>
-
-#include <experimental/filesystem>
-
-#include "vpnor/mboxd_pnor_partition_table.h"
-
 extern "C" {
 #include "test/mbox.h"
 #include "test/system.h"
 }
 
 #include "vpnor/test/tmpd.hpp"
+
+#include <cassert>
+#include <experimental/filesystem>
+
+#include "vpnor/mboxd_pnor_partition_table.h"
+
 static const auto BLOCK_SIZE = 4096;
 static const auto ERASE_SIZE = BLOCK_SIZE;
 static const auto WINDOW_SIZE = 2 * BLOCK_SIZE;
diff --git a/vpnor/test/create_read_window_straddle_partitions.cpp b/vpnor/test/create_read_window_straddle_partitions.cpp
index 168598d..bc963dd 100644
--- a/vpnor/test/create_read_window_straddle_partitions.cpp
+++ b/vpnor/test/create_read_window_straddle_partitions.cpp
@@ -3,11 +3,6 @@
 
 #include "config.h"
 
-#include <assert.h>
-#include <string.h>
-
-#include "vpnor/mboxd_pnor_partition_table.h"
-
 extern "C" {
 #include "test/mbox.h"
 #include "test/system.h"
@@ -15,6 +10,11 @@
 
 #include "vpnor/test/tmpd.hpp"
 
+#include <cassert>
+#include <cstring>
+
+#include "vpnor/mboxd_pnor_partition_table.h"
+
 const std::string toc[] = {
     "partition01=ONE,00001000,00002000,80,ECC,READONLY",
     "partition02=TWO,00002000,00003000,80,ECC,READONLY",
diff --git a/vpnor/test/create_read_window_toc.cpp b/vpnor/test/create_read_window_toc.cpp
index e0a5548..fee61ca 100644
--- a/vpnor/test/create_read_window_toc.cpp
+++ b/vpnor/test/create_read_window_toc.cpp
@@ -4,10 +4,11 @@
 
 #include "vpnor/pnor_partition_table.hpp"
 
-#include <assert.h>
-#include <string.h>
 #include <sys/mman.h>
 
+#include <cassert>
+#include <cstring>
+
 extern "C" {
 #include "test/mbox.h"
 #include "test/system.h"
diff --git a/vpnor/test/create_write_window_ro_partition.cpp b/vpnor/test/create_write_window_ro_partition.cpp
index fa53003..5cc19ca 100644
--- a/vpnor/test/create_write_window_ro_partition.cpp
+++ b/vpnor/test/create_write_window_ro_partition.cpp
@@ -3,10 +3,6 @@
 
 #include "config.h"
 
-#include <assert.h>
-
-#include "vpnor/mboxd_pnor_partition_table.h"
-
 extern "C" {
 #include "test/mbox.h"
 #include "test/system.h"
@@ -14,6 +10,10 @@
 
 #include "vpnor/test/tmpd.hpp"
 
+#include <cassert>
+
+#include "vpnor/mboxd_pnor_partition_table.h"
+
 const std::string toc[] = {
     "partition01=HBB,00001000,00002000,80,ECC,READONLY",
 };
diff --git a/vpnor/test/create_write_window_rw_partition.cpp b/vpnor/test/create_write_window_rw_partition.cpp
index 896c284..879fd85 100644
--- a/vpnor/test/create_write_window_rw_partition.cpp
+++ b/vpnor/test/create_write_window_rw_partition.cpp
@@ -3,10 +3,6 @@
 
 #include "config.h"
 
-#include <assert.h>
-
-#include "vpnor/mboxd_pnor_partition_table.h"
-
 extern "C" {
 #include "test/mbox.h"
 #include "test/system.h"
@@ -14,6 +10,10 @@
 
 #include "vpnor/test/tmpd.hpp"
 
+#include <cassert>
+
+#include "vpnor/mboxd_pnor_partition_table.h"
+
 const std::string toc[] = {
     "partition01=HBB,00001000,00002000,80,ECC,READWRITE",
 };
diff --git a/vpnor/test/create_write_window_unmapped.cpp b/vpnor/test/create_write_window_unmapped.cpp
index e26749e..76694fc 100644
--- a/vpnor/test/create_write_window_unmapped.cpp
+++ b/vpnor/test/create_write_window_unmapped.cpp
@@ -3,10 +3,6 @@
 
 #include "config.h"
 
-#include <assert.h>
-
-#include "vpnor/mboxd_pnor_partition_table.h"
-
 extern "C" {
 #include "test/mbox.h"
 #include "test/system.h"
@@ -14,6 +10,10 @@
 
 #include "vpnor/test/tmpd.hpp"
 
+#include <cassert>
+
+#include "vpnor/mboxd_pnor_partition_table.h"
+
 static constexpr auto BLOCK_SIZE = 0x1000;
 static constexpr auto ERASE_SIZE = BLOCK_SIZE;
 static constexpr auto N_WINDOWS = 1;
diff --git a/vpnor/test/dump_flash.cpp b/vpnor/test/dump_flash.cpp
index 84a88d8..5179b7c 100644
--- a/vpnor/test/dump_flash.cpp
+++ b/vpnor/test/dump_flash.cpp
@@ -3,19 +3,19 @@
 
 #include "config.h"
 
-#include <assert.h>
-#include <string.h>
-
-#include "transport_mbox.h"
-#include "vpnor/mboxd_pnor_partition_table.h"
-
 extern "C" {
 #include "test/mbox.h"
 #include "test/system.h"
+#include "transport_mbox.h"
 }
 
 #include "vpnor/test/tmpd.hpp"
 
+#include <cassert>
+#include <cstring>
+
+#include "vpnor/mboxd_pnor_partition_table.h"
+
 struct test_context
 {
     uint8_t seq;
diff --git a/vpnor/test/force_readonly_toc.cpp b/vpnor/test/force_readonly_toc.cpp
index a783bc7..8d3bec1 100644
--- a/vpnor/test/force_readonly_toc.cpp
+++ b/vpnor/test/force_readonly_toc.cpp
@@ -4,11 +4,12 @@
 
 #include "vpnor/pnor_partition_table.hpp"
 
-#include <assert.h>
 #include <endian.h>
-#include <string.h>
 #include <sys/mman.h>
 
+#include <cassert>
+#include <cstring>
+
 extern "C" {
 #include "test/mbox.h"
 #include "test/system.h"
diff --git a/vpnor/test/read_patch.cpp b/vpnor/test/read_patch.cpp
index 9429d4d..631a23c 100644
--- a/vpnor/test/read_patch.cpp
+++ b/vpnor/test/read_patch.cpp
@@ -3,18 +3,18 @@
 
 #include "config.h"
 
-#include <assert.h>
-
-#include "common.h"
-#include "vpnor/mboxd_pnor_partition_table.h"
-
 extern "C" {
+#include "common.h"
 #include "test/mbox.h"
 #include "test/system.h"
 }
 
 #include "vpnor/test/tmpd.hpp"
 
+#include <cassert>
+
+#include "vpnor/mboxd_pnor_partition_table.h"
+
 static constexpr auto BLOCK_SIZE = 0x1000;
 static constexpr auto ERASE_SIZE = BLOCK_SIZE;
 static constexpr auto PART_SIZE = BLOCK_SIZE * 4;
diff --git a/vpnor/test/tmpd.hpp b/vpnor/test/tmpd.hpp
index 2239f9c..7386f2f 100644
--- a/vpnor/test/tmpd.hpp
+++ b/vpnor/test/tmpd.hpp
@@ -3,17 +3,18 @@
 
 #include "config.h"
 
+extern "C" {
+#include "mboxd.h"
+}
+
 #include "vpnor/pnor_partition_table.hpp"
 
-#include <assert.h>
-#include <string.h>
-
+#include <cassert>
+#include <cstring>
 #include <experimental/filesystem>
 #include <fstream>
 #include <vector>
 
-#include "mboxd.h"
-
 namespace openpower
 {
 namespace virtual_pnor
diff --git a/vpnor/test/toc_flags.cpp b/vpnor/test/toc_flags.cpp
index b32b6c2..13bd016 100644
--- a/vpnor/test/toc_flags.cpp
+++ b/vpnor/test/toc_flags.cpp
@@ -5,7 +5,7 @@
 
 #include "vpnor/pnor_partition_table.hpp"
 
-#include <assert.h>
+#include <cassert>
 
 #include "common.h"
 #include "vpnor/pnor_partition_defs.h"
diff --git a/vpnor/test/toc_lookup_failed.cpp b/vpnor/test/toc_lookup_failed.cpp
index 7c68c7d..bb07725 100644
--- a/vpnor/test/toc_lookup_failed.cpp
+++ b/vpnor/test/toc_lookup_failed.cpp
@@ -5,8 +5,8 @@
 #include "vpnor/pnor_partition_table.hpp"
 #include "xyz/openbmc_project/Common/error.hpp"
 
-#include <assert.h>
-#include <string.h>
+#include <cassert>
+#include <cstring>
 
 extern "C" {
 #include "test/mbox.h"
diff --git a/vpnor/test/toc_lookup_found.cpp b/vpnor/test/toc_lookup_found.cpp
index 507f6d9..fccee0c 100644
--- a/vpnor/test/toc_lookup_found.cpp
+++ b/vpnor/test/toc_lookup_found.cpp
@@ -4,8 +4,8 @@
 
 #include "vpnor/pnor_partition_table.hpp"
 
-#include <assert.h>
-#include <string.h>
+#include <cassert>
+#include <cstring>
 
 extern "C" {
 #include "test/mbox.h"
diff --git a/vpnor/test/toc_missing_file.cpp b/vpnor/test/toc_missing_file.cpp
index 117a0bf..6b7e068 100644
--- a/vpnor/test/toc_missing_file.cpp
+++ b/vpnor/test/toc_missing_file.cpp
@@ -4,8 +4,8 @@
 
 #include "vpnor/pnor_partition_table.hpp"
 
-#include <assert.h>
-#include <string.h>
+#include <cassert>
+#include <cstring>
 
 extern "C" {
 #include "test/mbox.h"
diff --git a/vpnor/test/toc_no_end.cpp b/vpnor/test/toc_no_end.cpp
index 1eff2f2..86cc0a9 100644
--- a/vpnor/test/toc_no_end.cpp
+++ b/vpnor/test/toc_no_end.cpp
@@ -5,7 +5,7 @@
 
 #include "vpnor/pnor_partition_table.hpp"
 
-#include <assert.h>
+#include <cassert>
 
 static constexpr auto BLOCK_SIZE = 4 * 1024;
 
diff --git a/vpnor/test/toc_no_name.cpp b/vpnor/test/toc_no_name.cpp
index 0415ead..2db91f4 100644
--- a/vpnor/test/toc_no_name.cpp
+++ b/vpnor/test/toc_no_name.cpp
@@ -5,7 +5,7 @@
 
 #include "vpnor/pnor_partition_table.hpp"
 
-#include <assert.h>
+#include <cassert>
 
 static constexpr auto BLOCK_SIZE = 4 * 1024;
 
diff --git a/vpnor/test/toc_no_start.cpp b/vpnor/test/toc_no_start.cpp
index e07c5d4..17b2ea0 100644
--- a/vpnor/test/toc_no_start.cpp
+++ b/vpnor/test/toc_no_start.cpp
@@ -5,7 +5,7 @@
 
 #include "vpnor/pnor_partition_table.hpp"
 
-#include <assert.h>
+#include <cassert>
 
 static constexpr auto BLOCK_SIZE = 4 * 1024;
 
diff --git a/vpnor/test/toc_no_version.cpp b/vpnor/test/toc_no_version.cpp
index 65ed071..4a712c4 100644
--- a/vpnor/test/toc_no_version.cpp
+++ b/vpnor/test/toc_no_version.cpp
@@ -5,7 +5,7 @@
 
 #include "vpnor/pnor_partition_table.hpp"
 
-#include <assert.h>
+#include <cassert>
 
 static constexpr auto BLOCK_SIZE = 4 * 1024;
 
diff --git a/vpnor/test/toc_overlap.cpp b/vpnor/test/toc_overlap.cpp
index 70a992e..a7ac20d 100644
--- a/vpnor/test/toc_overlap.cpp
+++ b/vpnor/test/toc_overlap.cpp
@@ -4,8 +4,8 @@
 
 #include "vpnor/pnor_partition_table.hpp"
 
-#include <assert.h>
-#include <string.h>
+#include <cassert>
+#include <cstring>
 
 extern "C" {
 #include "test/mbox.h"
diff --git a/vpnor/test/toc_start_gt_end.cpp b/vpnor/test/toc_start_gt_end.cpp
index ea64344..cd4a6bc 100644
--- a/vpnor/test/toc_start_gt_end.cpp
+++ b/vpnor/test/toc_start_gt_end.cpp
@@ -5,7 +5,7 @@
 
 #include "vpnor/pnor_partition_table.hpp"
 
-#include <assert.h>
+#include <cassert>
 
 static constexpr auto BLOCK_SIZE = 4 * 1024;
 
diff --git a/vpnor/test/write_patch.cpp b/vpnor/test/write_patch.cpp
index b735d10..1bf6ba9 100644
--- a/vpnor/test/write_patch.cpp
+++ b/vpnor/test/write_patch.cpp
@@ -3,23 +3,23 @@
 
 #include "config.h"
 
-#include <assert.h>
+extern "C" {
+#include "common.h"
+#include "flash.h"
+#include "mboxd.h"
+}
+
+#include "vpnor/test/tmpd.hpp"
+
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/syslog.h>
 #include <unistd.h>
 
+#include <cassert>
 #include <experimental/filesystem>
 
-#include "common.h"
-#include "mboxd.h"
-extern "C" {
-#include "flash.h"
-}
-
-#include "vpnor/test/tmpd.hpp"
-
 static constexpr auto BLOCK_SIZE = 0x1000;
 static constexpr auto DATA_SIZE = 8;
 
diff --git a/vpnor/test/write_patch_resize.cpp b/vpnor/test/write_patch_resize.cpp
index 866333f..9a6979f 100644
--- a/vpnor/test/write_patch_resize.cpp
+++ b/vpnor/test/write_patch_resize.cpp
@@ -3,7 +3,14 @@
 
 #include "config.h"
 
-#include <assert.h>
+extern "C" {
+#include "common.h"
+#include "flash.h"
+#include "mboxd.h"
+}
+
+#include "vpnor/test/tmpd.hpp"
+
 #include <fcntl.h>
 #include <stdint.h>
 #include <sys/ioctl.h>
@@ -11,17 +18,9 @@
 #include <sys/syslog.h>
 #include <unistd.h>
 
+#include <cassert>
 #include <experimental/filesystem>
 
-#include "common.h"
-#include "mboxd.h"
-
-extern "C" {
-#include "flash.h"
-}
-
-#include "vpnor/test/tmpd.hpp"
-
 static constexpr auto BLOCK_SIZE = 0x1000;
 static constexpr auto PART_SIZE = BLOCK_SIZE;
 static constexpr auto PATCH_SIZE = BLOCK_SIZE / 2;
diff --git a/vpnor/test/write_prsv.cpp b/vpnor/test/write_prsv.cpp
index 69b4989..53f3cfe 100644
--- a/vpnor/test/write_prsv.cpp
+++ b/vpnor/test/write_prsv.cpp
@@ -1,20 +1,21 @@
 // SPDX-License-Identifier: Apache-2.0
 // Copyright (C) 2018 IBM Corp.
 
-#include <assert.h>
+extern "C" {
+#include "common.h"
+#include "flash.h"
+#include "mboxd.h"
+}
+
+#include "vpnor/test/tmpd.hpp"
+
 #include <fcntl.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
 
-#include "common.h"
-#include "mboxd.h"
-extern "C" {
-#include "flash.h"
-}
-
-#include "vpnor/test/tmpd.hpp"
+#include <cassert>
 
 static constexpr auto BLOCK_SIZE = 0x1000;
 
diff --git a/vpnor/test/write_ro.cpp b/vpnor/test/write_ro.cpp
index 13c0eae..e5671b1 100644
--- a/vpnor/test/write_ro.cpp
+++ b/vpnor/test/write_ro.cpp
@@ -1,21 +1,22 @@
 // SPDX-License-Identifier: Apache-2.0
 // Copyright (C) 2018 IBM Corp.
+#include "config.h"
 
-#include <assert.h>
+extern "C" {
+#include "common.h"
+#include "flash.h"
+#include "mboxd.h"
+}
+
+#include "vpnor/test/tmpd.hpp"
+
 #include <fcntl.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
 
-#include "common.h"
-#include "mboxd.h"
-
-extern "C" {
-#include "flash.h"
-}
-
-#include "vpnor/test/tmpd.hpp"
+#include <cassert>
 
 static constexpr auto BLOCK_SIZE = 0x1000;
 
diff --git a/vpnor/test/write_rw.cpp b/vpnor/test/write_rw.cpp
index c9d2b60..e64f01e 100644
--- a/vpnor/test/write_rw.cpp
+++ b/vpnor/test/write_rw.cpp
@@ -1,20 +1,22 @@
 // SPDX-License-Identifier: Apache-2.0
 // Copyright (C) 2018 IBM Corp.
+#include "config.h"
 
-#include <assert.h>
+extern "C" {
+#include "common.h"
+#include "flash.h"
+#include "mboxd.h"
+}
+
+#include "vpnor/test/tmpd.hpp"
+
 #include <fcntl.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
 
-#include "common.h"
-#include "mboxd.h"
-extern "C" {
-#include "flash.h"
-}
-
-#include "vpnor/test/tmpd.hpp"
+#include <cassert>
 
 static constexpr auto BLOCK_SIZE = 0x1000;
 
diff --git a/vpnor/test/write_toc.cpp b/vpnor/test/write_toc.cpp
index dcf5aae..6f6b101 100644
--- a/vpnor/test/write_toc.cpp
+++ b/vpnor/test/write_toc.cpp
@@ -4,10 +4,11 @@
 
 #include "vpnor/pnor_partition_table.hpp"
 
-#include <assert.h>
-#include <string.h>
 #include <sys/mman.h>
 
+#include <cassert>
+#include <cstring>
+
 extern "C" {
 #include "test/mbox.h"
 #include "test/system.h"