On 10/7/21 8:26 PM, Hao Wu wrote:
+static void write_sdread(QTestState *qts, const char *msg) +{ + size_t len = strlen(msg); + char *rmsg = g_malloc(len); + + /* write message to sd */ + int fd = open(sd_path, O_WRONLY); + int ret; + + g_assert(fd > 0); + ret = write(fd, msg, len); + g_assert(ret == len); + ret = close(fd); + g_assert(ret == 0); + + /* read message using sdhci */ + ret = sdhci_read_cmd(qts, NPCM7XX_MMC_BA, rmsg, len); + g_assert(ret == len); + g_assert(!strcmp(rmsg, msg));
Test case bug: you're not including the terminating 0 in len, which means that strcmp cannot be expected to work.
Either use memcmp or add 1 to len at the top.
+static void sdwrite_read(QTestState *qts, const char *msg) +{ + size_t len = strlen(msg); + char *rmsg = g_malloc(len); + + /* write message using sdhci */ + sdhci_write_cmd(qts, NPCM7XX_MMC_BA, msg, len, NPCM7XX_BLK_SIZE); + + /* read message from sd */ + int fd = open(sd_path, O_RDONLY); + int ret; + + g_assert(fd > 0); + ret = read(fd, rmsg, len); + g_assert(ret == len); + ret = close(fd); + g_assert(ret == 0); + + g_assert(!strcmp(rmsg, msg));
Likewise. https://app.travis-ci.com/gitlab/qemu-project/qemu/jobs/546307442#L9369 r~