From 261f61a1747a9ebf092d4f426e891ff94ad33ffc Mon Sep 17 00:00:00 2001 From: Andrew Jeffery Date: Thu, 14 Mar 2019 09:57:28 +1030 Subject: [PATCH] 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 --- vpnor/test/create_pnor_partition_table.cpp | 4 ++-- vpnor/test/create_read_window_oob.cpp | 10 +++++----- .../create_read_window_partition_exists.cpp | 17 ++++++++--------- .../create_read_window_partition_invalid.cpp | 10 +++++----- vpnor/test/create_read_window_remap.cpp | 17 ++++++++--------- vpnor/test/create_read_window_size.cpp | 12 ++++++------ ...create_read_window_straddle_partitions.cpp | 10 +++++----- vpnor/test/create_read_window_toc.cpp | 5 +++-- .../test/create_write_window_ro_partition.cpp | 8 ++++---- .../test/create_write_window_rw_partition.cpp | 8 ++++---- vpnor/test/create_write_window_unmapped.cpp | 8 ++++---- vpnor/test/dump_flash.cpp | 12 ++++++------ vpnor/test/force_readonly_toc.cpp | 5 +++-- vpnor/test/read_patch.cpp | 10 +++++----- vpnor/test/tmpd.hpp | 11 ++++++----- vpnor/test/toc_flags.cpp | 2 +- vpnor/test/toc_lookup_failed.cpp | 4 ++-- vpnor/test/toc_lookup_found.cpp | 4 ++-- vpnor/test/toc_missing_file.cpp | 4 ++-- vpnor/test/toc_no_end.cpp | 2 +- vpnor/test/toc_no_name.cpp | 2 +- vpnor/test/toc_no_start.cpp | 2 +- vpnor/test/toc_no_version.cpp | 2 +- vpnor/test/toc_overlap.cpp | 4 ++-- vpnor/test/toc_start_gt_end.cpp | 2 +- vpnor/test/write_patch.cpp | 18 +++++++++--------- vpnor/test/write_patch_resize.cpp | 19 +++++++++---------- vpnor/test/write_prsv.cpp | 17 +++++++++-------- vpnor/test/write_ro.cpp | 19 ++++++++++--------- vpnor/test/write_rw.cpp | 18 ++++++++++-------- vpnor/test/write_toc.cpp | 5 +++-- 31 files changed, 138 insertions(+), 133 deletions(-) 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 -#include +#include +#include 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 -#include - -#include "vpnor/mboxd_pnor_partition_table.h" - extern "C" { #include "test/mbox.h" #include "test/system.h" @@ -15,6 +10,11 @@ extern "C" { #include "vpnor/test/tmpd.hpp" +#include +#include + +#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 -#include - -#include -#include -#include - -#include "vpnor/mboxd_pnor_partition_table.h" - extern "C" { #include "test/mbox.h" #include "test/system.h" @@ -19,6 +10,14 @@ extern "C" { #include "vpnor/test/tmpd.hpp" +#include +#include +#include +#include +#include + +#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 -#include - -#include "vpnor/mboxd_pnor_partition_table.h" - extern "C" { #include "test/mbox.h" #include "test/system.h" @@ -15,6 +10,11 @@ extern "C" { #include "vpnor/test/tmpd.hpp" +#include +#include + +#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 -#include - -#include -#include -#include - -#include "vpnor/mboxd_pnor_partition_table.h" - extern "C" { #include "test/mbox.h" #include "test/system.h" @@ -19,6 +10,14 @@ extern "C" { #include "vpnor/test/tmpd.hpp" +#include +#include +#include +#include +#include + +#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 - -#include - -#include "vpnor/mboxd_pnor_partition_table.h" - extern "C" { #include "test/mbox.h" #include "test/system.h" } #include "vpnor/test/tmpd.hpp" + +#include +#include + +#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 -#include - -#include "vpnor/mboxd_pnor_partition_table.h" - extern "C" { #include "test/mbox.h" #include "test/system.h" @@ -15,6 +10,11 @@ extern "C" { #include "vpnor/test/tmpd.hpp" +#include +#include + +#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 -#include #include +#include +#include + 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 - -#include "vpnor/mboxd_pnor_partition_table.h" - extern "C" { #include "test/mbox.h" #include "test/system.h" @@ -14,6 +10,10 @@ extern "C" { #include "vpnor/test/tmpd.hpp" +#include + +#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 - -#include "vpnor/mboxd_pnor_partition_table.h" - extern "C" { #include "test/mbox.h" #include "test/system.h" @@ -14,6 +10,10 @@ extern "C" { #include "vpnor/test/tmpd.hpp" +#include + +#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 - -#include "vpnor/mboxd_pnor_partition_table.h" - extern "C" { #include "test/mbox.h" #include "test/system.h" @@ -14,6 +10,10 @@ extern "C" { #include "vpnor/test/tmpd.hpp" +#include + +#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 -#include - -#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 +#include + +#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 #include -#include #include +#include +#include + 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 - -#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 + +#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" -#include "vpnor/pnor_partition_table.hpp" +extern "C" { +#include "mboxd.h" +} -#include -#include +#include "vpnor/pnor_partition_table.hpp" +#include +#include #include #include #include -#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 +#include #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 -#include +#include +#include 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 -#include +#include +#include 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 -#include +#include +#include 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 +#include 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 +#include 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 +#include 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 +#include 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 -#include +#include +#include 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 +#include 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 +extern "C" { +#include "common.h" +#include "flash.h" +#include "mboxd.h" +} + +#include "vpnor/test/tmpd.hpp" + #include #include #include #include #include +#include #include -#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 +extern "C" { +#include "common.h" +#include "flash.h" +#include "mboxd.h" +} + +#include "vpnor/test/tmpd.hpp" + #include #include #include @@ -11,17 +18,9 @@ #include #include +#include #include -#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 +extern "C" { +#include "common.h" +#include "flash.h" +#include "mboxd.h" +} + +#include "vpnor/test/tmpd.hpp" + #include #include #include #include #include -#include "common.h" -#include "mboxd.h" -extern "C" { -#include "flash.h" -} - -#include "vpnor/test/tmpd.hpp" +#include 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" + +extern "C" { +#include "common.h" +#include "flash.h" +#include "mboxd.h" +} + +#include "vpnor/test/tmpd.hpp" -#include #include #include #include #include #include -#include "common.h" -#include "mboxd.h" - -extern "C" { -#include "flash.h" -} - -#include "vpnor/test/tmpd.hpp" +#include 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" + +extern "C" { +#include "common.h" +#include "flash.h" +#include "mboxd.h" +} + +#include "vpnor/test/tmpd.hpp" -#include #include #include #include #include #include -#include "common.h" -#include "mboxd.h" -extern "C" { -#include "flash.h" -} - -#include "vpnor/test/tmpd.hpp" +#include 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 -#include #include +#include +#include + extern "C" { #include "test/mbox.h" #include "test/system.h" -- 2.30.2