[PATCH v2 22/39] test: mbr: Use a constant for the block size

Ilias Apalodimas ilias.apalodimas at linaro.org
Thu Aug 8 12:15:16 CEST 2024


Hi Simon

On Tue, 6 Aug 2024 at 15:59, Simon Glass <sjg at chromium.org> wrote:
>
> 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 <sjg at chromium.org>
> ---
>
> (no changes since v1)
>
>  test/cmd/mbr.c | 37 ++++++++++++++++++++-----------------
>  1 file changed, 20 insertions(+), 17 deletions(-)
>
> diff --git a/test/cmd/mbr.c b/test/cmd/mbr.c
> index 8a4d61b2928..bab92c3ba00 100644
> --- a/test/cmd/mbr.c
> +++ b/test/cmd/mbr.c
> @@ -18,6 +18,9 @@
>  #include <test/ut.h>
>
>  DECLARE_GLOBAL_DATA_PTR;
> +
> +#define BLKSZ  0x200   /* block size */

We already have definitions for that. I prefer SZ_512

Thanks
/Ilias
> +
>  /*
>   * Requirements for running test manually:
>   * mmc6.img - File size needs to be at least 12 MiB
> @@ -228,7 +231,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 +260,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));
> @@ -269,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__);
> @@ -277,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_assertok(console_record_reset_enable());
>         ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
>         ut_assertok(run_commandf("mbr write mmc 6"));
> @@ -290,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_assertok(ut_check_console_end(uts));
>         /*
>         000001b0  00 00 00 00 00 00 00 00  78 56 34 12 00 00 80 05  |........xV4.....|
> @@ -313,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_assertok(console_record_reset_enable());
>         ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
>         ut_assertok(run_commandf("mbr write mmc 6"));
> @@ -326,7 +329,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_assertok(ut_check_console_end(uts));
>         /*
>         000001b0  00 00 00 00 00 00 00 00  78 56 34 12 00 00 80 05  |........xV4.....|
> @@ -349,11 +352,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_assertok(console_record_reset_enable());
>         ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
>         ut_assertok(run_commandf("mbr write mmc 6"));
> @@ -362,7 +365,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_assertok(ut_check_console_end(uts));
>         /*
>         000001b0  00 00 00 00 00 00 00 00  78 56 34 12 00 00 80 05  |........xV4.....|
> @@ -385,11 +388,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_assertok(console_record_reset_enable());
>         ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
>         ut_assertok(run_commandf("mbr write mmc 6"));
> @@ -398,7 +401,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_assertok(ut_check_console_end(uts));
>         /*
>         000001b0  00 00 00 00 00 00 00 00  78 56 34 12 00 00 80 05  |........xV4.....|
> @@ -421,11 +424,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_assertok(console_record_reset_enable());
>         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);
> --
> 2.34.1
>


More information about the U-Boot mailing list