summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2018-03-09 15:27:03 +1030
committerAndrew Jeffery <andrew@aj.id.au>2018-03-19 10:56:22 +1030
commitf34db31d768e38c3add58a83cd943609771fd212 (patch)
tree659f3f17e8405f5edd7000f251345f5c889d5a22 /test
parent25eca77fabceb86e10ac4eb0cbe32484cbf21c14 (diff)
downloadphosphor-mboxd-f34db31d768e38c3add58a83cd943609771fd212.tar.gz
phosphor-mboxd-f34db31d768e38c3add58a83cd943609771fd212.zip
Format C++ files according to OpenBMC style guide
We don't touch the C yet as upstream hasn't got such a change in place. Change-Id: Ie6cab4bf99df520bb6655b9b00ae31e762e3c57b Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Diffstat (limited to 'test')
-rw-r--r--test/create_pnor_partition_table.cpp8
-rw-r--r--test/create_read_window_vpnor.cpp44
-rw-r--r--test/write_flash_vpnor.cpp60
3 files changed, 51 insertions, 61 deletions
diff --git a/test/create_pnor_partition_table.cpp b/test/create_pnor_partition_table.cpp
index d542299..57bb675 100644
--- a/test/create_pnor_partition_table.cpp
+++ b/test/create_pnor_partition_table.cpp
@@ -30,8 +30,8 @@ int main()
partitionFile.write(empty.data(), empty.size());
partitionFile.close();
- const openpower::virtual_pnor::partition::Table
- table(fs::path{tmpdir}, 4 * 1024, 64 * 1024 * 1024);
+ const openpower::virtual_pnor::partition::Table table(
+ fs::path{tmpdir}, 4 * 1024, 64 * 1024 * 1024);
pnor_partition_table expectedTable{};
expectedTable.data.magic = PARTITION_HEADER_MAGIC;
@@ -47,8 +47,8 @@ int main()
pnor_partition expectedPartition{};
strcpy(expectedPartition.data.name, partitionName);
- expectedPartition.data.base = 0; // starts at offset 0
- expectedPartition.data.size = 1; // 1 block
+ expectedPartition.data.base = 0; // starts at offset 0
+ expectedPartition.data.size = 1; // 1 block
expectedPartition.data.actual = 0x400; // 1024 bytes
expectedPartition.data.id = 1;
expectedPartition.data.pid = PARENT_PATITION_ID;
diff --git a/test/create_read_window_vpnor.cpp b/test/create_read_window_vpnor.cpp
index 7c344f7..3ea6bb5 100644
--- a/test/create_read_window_vpnor.cpp
+++ b/test/create_read_window_vpnor.cpp
@@ -18,28 +18,24 @@ extern "C" {
constexpr auto line = "partition01=HBB,00000100,0001000,ECC,PRESERVED";
constexpr auto partition = "HBB";
char tmplt[] = "/tmp/create_read_test.XXXXXX";
-uint8_t data[8] = { 0xaa, 0x55, 0xaa, 0x66, 0x77, 0x88, 0x99, 0xab };
+uint8_t data[8] = {0xaa, 0x55, 0xaa, 0x66, 0x77, 0x88, 0x99, 0xab};
-#define BLOCK_SIZE 4096
-#define MEM_SIZE (BLOCK_SIZE *2)
-#define ERASE_SIZE BLOCK_SIZE
-#define N_WINDOWS 1
+#define BLOCK_SIZE 4096
+#define MEM_SIZE (BLOCK_SIZE * 2)
+#define ERASE_SIZE BLOCK_SIZE
+#define N_WINDOWS 1
#define WINDOW_SIZE BLOCK_SIZE
-static const uint8_t get_info[] = {
- 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
+static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00};
// offset 0x100 and size 6
-static const uint8_t create_read_window[] = {
- 0x04, 0x01, 0x01, 0x00, 0x06, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
+static const uint8_t create_read_window[] = {0x04, 0x01, 0x01, 0x00, 0x06, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00};
-static const uint8_t response[] = {
- 0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
-};
+static const uint8_t response[] = {0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
namespace fs = std::experimental::filesystem;
@@ -60,16 +56,16 @@ int main()
partitionFilePath /= partition;
std::ofstream partitionFile(partitionFilePath.c_str());
- partitionFile.write((char*)data,sizeof(data));
+ partitionFile.write((char*)data, sizeof(data));
partitionFile.close();
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,tmpdir);
- strcpy(ctx->paths.rw_loc,tmpdir);
- strcpy(ctx->paths.prsv_loc,tmpdir);
+ struct mbox_context* ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
+ strcpy(ctx->paths.ro_loc, tmpdir);
+ strcpy(ctx->paths.rw_loc, tmpdir);
+ strcpy(ctx->paths.prsv_loc, tmpdir);
vpnor_create_partition_table_from_path(ctx, tmpdir);
@@ -78,7 +74,7 @@ int main()
// send the request for partition1
rc = mbox_command_dispatch(ctx, create_read_window,
- sizeof(create_read_window));
+ sizeof(create_read_window));
assert(rc == 1);
rc = mbox_cmp(ctx, response, sizeof(response));
@@ -88,7 +84,7 @@ int main()
rc = memcmp(ctx->mem, data, 6);
assert(rc == 0);
- //TODO: Add few more test cases for read from multiple partitions(PRSV/RW)
+ // TODO: Add few more test cases for read from multiple partitions(PRSV/RW)
// Read beyond the partition file size.
// openbmc/openbmc#1868
diff --git a/test/write_flash_vpnor.cpp b/test/write_flash_vpnor.cpp
index 78b9ad8..e78c79c 100644
--- a/test/write_flash_vpnor.cpp
+++ b/test/write_flash_vpnor.cpp
@@ -37,35 +37,31 @@ extern "C" {
#include <sys/ioctl.h>
#include <fcntl.h>
+uint8_t data[8] = {0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7};
-uint8_t data[8] = { 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7 };
-
-#define BLOCK_SIZE 4096
-#define OFFSET BLOCK_SIZE
-#define MEM_SIZE (BLOCK_SIZE *2)
+#define BLOCK_SIZE 4096
+#define OFFSET BLOCK_SIZE
+#define MEM_SIZE (BLOCK_SIZE * 2)
#define DATA_SIZE sizeof(data)
#define ERASE_SIZE BLOCK_SIZE
#define BLOCK_SIZE_SHIFT 12
-
void init(struct mbox_context* ctx)
{
namespace fs = std::experimental::filesystem;
using namespace std::string_literals;
- std::string tocData = "partition01=TEST1,00001000,00001400,ECC,READONLY\n"s
- + "partition02=TEST2,00002000,00002008,ECC,READWRITE\n"s
- + "partition03=TEST3,00003000,00003400,ECC,PRESERVED"s;
-
- std::vector<std::string> templatePaths = { "/tmp/ro.XXXXXX",
- "/tmp/rw.XXXXXX" ,
- "/tmp/prsv.XXXXXX",
- "/tmp/patch.XXXXXX"
- };
+ std::string tocData =
+ "partition01=TEST1,00001000,00001400,ECC,READONLY\n"s +
+ "partition02=TEST2,00002000,00002008,ECC,READWRITE\n"s +
+ "partition03=TEST3,00003000,00003400,ECC,PRESERVED"s;
- std::vector<std::string>partitions = { "TEST1", "TEST2", "TEST3" };
+ std::vector<std::string> templatePaths = {
+ "/tmp/ro.XXXXXX", "/tmp/rw.XXXXXX", "/tmp/prsv.XXXXXX",
+ "/tmp/patch.XXXXXX"};
+ std::vector<std::string> partitions = {"TEST1", "TEST2", "TEST3"};
// create various partition directory
@@ -75,10 +71,12 @@ void init(struct mbox_context* ctx)
std::string tmpRWdir = mkdtemp(const_cast<char*>(templatePaths[1].c_str()));
assert(tmpRWdir.length() != 0);
- std::string tmpPRSVdir = mkdtemp(const_cast<char*>(templatePaths[2].c_str()));
+ std::string tmpPRSVdir =
+ mkdtemp(const_cast<char*>(templatePaths[2].c_str()));
assert(tmpPRSVdir.length() != 0);
- std::string tmpPATCHdir = mkdtemp(const_cast<char*>(templatePaths[3].c_str()));
+ std::string tmpPATCHdir =
+ mkdtemp(const_cast<char*>(templatePaths[3].c_str()));
assert(tmpPATCHdir.length() != 0);
// create the toc file
@@ -92,12 +90,11 @@ void init(struct mbox_context* ctx)
// create the partition files in the ro directory
for (auto partition : partitions)
{
- fs::path partitionFilePath {tmpROdir};
+ fs::path partitionFilePath{tmpROdir};
partitionFilePath /= partition;
std::ofstream partitionFile(partitionFilePath.c_str());
partitionFile.write(reinterpret_cast<char*>(data), sizeof(data));
partitionFile.close();
-
}
// copy partition2 file from ro to rw
@@ -112,28 +109,25 @@ void init(struct mbox_context* ctx)
ctx->erase_size_shift = BLOCK_SIZE_SHIFT;
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)));
+ calloc(MEM_SIZE >> ctx->erase_size_shift, sizeof(*ctx->flash_bmap)));
strcpy(ctx->paths.ro_loc, tmpROdir.c_str());
strcpy(ctx->paths.rw_loc, tmpRWdir.c_str());
strcpy(ctx->paths.prsv_loc, tmpPRSVdir.c_str());
strcpy(ctx->paths.patch_loc, tmpPATCHdir.c_str());
-
}
-
int main(void)
{
namespace fs = std::experimental::filesystem;
- int rc {};
- char src[DATA_SIZE] {0};
+ int rc{};
+ char src[DATA_SIZE]{0};
struct mbox_context context;
struct mbox_context* ctx = &context;
memset(ctx, 0, sizeof(mbox_context));
- //Initialize the context before running the test case.
+ // Initialize the context before running the test case.
init(ctx);
std::string tmpROdir = ctx->paths.ro_loc;
@@ -151,7 +145,7 @@ int main(void)
memset(src, 0xaa, sizeof(src));
- rc = write_flash(ctx, (OFFSET * 3) , src, sizeof(src));
+ rc = write_flash(ctx, (OFFSET * 3), src, sizeof(src));
assert(rc == 0);
auto fd = open((tmpPRSVdir + "/" + "TEST3").c_str(), O_RDONLY);
@@ -229,7 +223,7 @@ int main(void)
assert(fs::copy_file(roFile, patchFile) == true);
// Write arbitrary data
- char srcPatch[DATA_SIZE] {0};
+ char srcPatch[DATA_SIZE]{0};
memset(srcPatch, 0x33, sizeof(srcPatch));
rc = write_flash(ctx, (OFFSET * 2), srcPatch, sizeof(srcPatch));
assert(rc == 0);
@@ -258,10 +252,10 @@ int main(void)
fs::remove(patchFile);
// END Test patch location
- fs::remove_all(fs::path {tmpROdir});
- fs::remove_all(fs::path {tmpRWdir});
- fs::remove_all(fs::path {tmpPRSVdir});
- fs::remove_all(fs::path {tmpPATCHdir});
+ fs::remove_all(fs::path{tmpROdir});
+ fs::remove_all(fs::path{tmpRWdir});
+ fs::remove_all(fs::path{tmpPRSVdir});
+ fs::remove_all(fs::path{tmpPATCHdir});
destroy_vpnor(ctx);
free(ctx->flash_bmap);
OpenPOWER on IntegriCloud