From: Simon Glass Date: Sun, 1 Sep 2024 22:26:32 +0000 (-0600) Subject: test: mbr: Use a constant for the block size X-Git-Url: http://git.dujemihanovic.xyz/img/%7B%7B?a=commitdiff_plain;h=e9d899591c7b1cf9661a22a66e0f1c41f37eaeb9;p=u-boot.git test: mbr: Use a constant for the block size It isn't that important to factor out constants in tests, but in this case we have 0x200 and 512 used. The commands don't use the constant as they use a block count ('1'). It doesn't create more code to use a constant, so create one. Signed-off-by: Simon Glass --- diff --git a/test/cmd/mbr.c b/test/cmd/mbr.c index e750875ea4..e67e777c99 100644 --- a/test/cmd/mbr.c +++ b/test/cmd/mbr.c @@ -14,10 +14,14 @@ #include #include #include +#include #include #include DECLARE_GLOBAL_DATA_PTR; + +#define BLKSZ SZ_512 /* block size */ + /* * Requirements for running test manually: * mmc6.img - File size needs to be at least 12 MiB @@ -228,7 +232,7 @@ static unsigned build_mbr_parts(char *buf, size_t buf_size, unsigned num_parts) static int mbr_test_run(struct unit_test_state *uts) { struct blk_desc *mmc_dev_desc; - unsigned char mbr_wbuf[512], ebr_wbuf[512], rbuf[512]; + unsigned char mbr_wbuf[BLKSZ], ebr_wbuf[BLKSZ], rbuf[BLKSZ]; char mbr_parts_buf[256]; ulong mbr_wa, ebr_wa, ra, ebr_blk, mbr_parts_max; struct udevice *dev; @@ -257,7 +261,7 @@ static int mbr_test_run(struct unit_test_state *uts) mbr_wa = map_to_sysmem(mbr_wbuf); ebr_wa = map_to_sysmem(ebr_wbuf); ra = map_to_sysmem(rbuf); - ebr_blk = (ulong)0xb00000 / 0x200; + ebr_blk = (ulong)0xb00000 / BLKSZ; /* Make sure mmc6 exists */ ut_asserteq(6, blk_get_device_by_str("mmc", "6", &mmc_dev_desc)); @@ -268,7 +272,7 @@ static int mbr_test_run(struct unit_test_state *uts) /* Make sure mmc6 is 12+ MiB in size */ ut_assertok(run_commandf("mmc read %lx %lx 1", ra, - (ulong)0xbffe00 / 0x200)); + (ulong)0xbffe00 / BLKSZ)); /* Test one MBR partition */ init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__); @@ -276,11 +280,11 @@ static int mbr_test_run(struct unit_test_state *uts) ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa)); memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra)); - ut_assertok(memcmp(mbr_wbuf, rbuf, 512)); + ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ)); ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk)); memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk)); - ut_assertok(memcmp(ebr_wbuf, rbuf, 512)); + ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ)); ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf); ut_assertok(run_commandf("mbr write mmc 6")); ut_assert_nextlinen("MMC read: dev # 6"); @@ -289,7 +293,7 @@ static int mbr_test_run(struct unit_test_state *uts) ut_assert_nextline("MBR: verify success!"); memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk)); - ut_assertok(memcmp(ebr_wbuf, rbuf, 512)); + ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ)); ut_assert_console_end(); /* 000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....| @@ -312,11 +316,11 @@ static int mbr_test_run(struct unit_test_state *uts) ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa)); memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra)); - ut_assertok(memcmp(mbr_wbuf, rbuf, 512)); + ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ)); ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk)); memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk)); - ut_assertok(memcmp(ebr_wbuf, rbuf, 512)); + ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ)); ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf); ut_assertok(run_commandf("mbr write mmc 6")); ut_assert_nextline("MBR: write success!"); @@ -324,7 +328,7 @@ static int mbr_test_run(struct unit_test_state *uts) ut_assert_nextline("MBR: verify success!"); memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk)); - ut_assertok(memcmp(ebr_wbuf, rbuf, 512)); + ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ)); ut_assert_console_end(); /* 000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....| @@ -347,11 +351,11 @@ static int mbr_test_run(struct unit_test_state *uts) ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa)); memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra)); - ut_assertok(memcmp(mbr_wbuf, rbuf, 512)); + ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ)); ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk)); memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk)); - ut_assertok(memcmp(ebr_wbuf, rbuf, 512)); + ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ)); ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf); ut_assertok(run_commandf("mbr write mmc 6")); ut_assert_nextline("MBR: write success!"); @@ -359,7 +363,7 @@ static int mbr_test_run(struct unit_test_state *uts) ut_assert_nextline("MBR: verify success!"); memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk)); - ut_assertok(memcmp(ebr_wbuf, rbuf, 512)); + ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ)); ut_assert_console_end(); /* 000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....| @@ -382,11 +386,11 @@ static int mbr_test_run(struct unit_test_state *uts) ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa)); memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra)); - ut_assertok(memcmp(mbr_wbuf, rbuf, 512)); + ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ)); ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk)); memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk)); - ut_assertok(memcmp(ebr_wbuf, rbuf, 512)); + ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ)); ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf); ut_assertok(run_commandf("mbr write mmc 6")); ut_assert_nextline("MBR: write success!"); @@ -394,7 +398,7 @@ static int mbr_test_run(struct unit_test_state *uts) ut_assert_nextline("MBR: verify success!"); memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk)); - ut_assertok(memcmp(ebr_wbuf, rbuf, 512)); + ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ)); ut_assert_console_end(); /* 000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....| @@ -417,11 +421,11 @@ static int mbr_test_run(struct unit_test_state *uts) ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa)); memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra)); - ut_assertok(memcmp(mbr_wbuf, rbuf, 512)); + ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ)); ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk)); memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk)); - ut_assertok(memcmp(ebr_wbuf, rbuf, 512)); + ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ)); ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf); ut_assertf(0 == run_commandf("mbr write mmc 6"), "Invalid partitions string: %s\n", mbr_parts_buf); ut_assert_nextline("MBR: write success!");