qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4] tests/qtest: add qtests for npcm7xx sdhci


From: Peter Maydell
Subject: Re: [PATCH v4] tests/qtest: add qtests for npcm7xx sdhci
Date: Fri, 25 Feb 2022 11:44:40 +0000

On Thu, 24 Feb 2022 at 19:03, Hao Wu <wuhaotsh@google.com> wrote:
>
> From: Shengtan Mao <stmao@google.com>
>
> Reviewed-by: Hao Wu <wuhaotsh@google.com>
> Reviewed-by: Chris Rauer <crauer@google.com>
> Signed-off-by: Shengtan Mao <stmao@google.com>
> Signed-off-by: Patrick Venture <venture@google.com>
> Signed-off-by: Hao Wu <wuhaotsh@google.com>
> ---
> v4:
>  * use strncmp to compare fixed length strings
> v3:
>  * fixup compilation from missing macro value
> v2:
>  * update copyright year
>  * check result of open
>  * use g_free instead of free
>  * move declarations to the top
>  * use g_file_open_tmp
> ---

> +static void write_sdread(QTestState *qts, const char *msg)
> +{
> +    int fd, ret;
> +    size_t len = strlen(msg);
> +    char *rmsg = g_malloc(len);
> +
> +    /* write message to sd */
> +    fd = open(sd_path, O_WRONLY);
> +    g_assert(fd >= 0);
> +    ret = write(fd, msg, len);
> +    close(fd);
> +    g_assert(ret == len);
> +
> +    /* read message using sdhci */
> +    ret = sdhci_read_cmd(qts, NPCM7XX_MMC_BA, rmsg, len);
> +    g_assert(ret == len);
> +    g_assert(!strncmp(rmsg, msg, len));

We always know we want to compare exactly 'len' bytes here, and we know
the buffers in each case are at least that large. The right function
for that is memcmp(), I think.

thanks
-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]