Skip to contentSkip to conversation

tests/qtest: add qtests for npcm7xx sdhci

PATCH Superseded Hao Wu 3 participants 4 messages Feb 24, 2022 – Feb 25, 2022 Arm/Amlogic Meson SoC support

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Hao Wu

author
#0 lore raw

PATCH v4 1/1 tests/qtest: add qtests for npcm7xx sdhci

From: Shengtan Mao <[email protected]>

---
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

---
 tests/qtest/meson.build          |   1 +
 tests/qtest/npcm7xx_sdhci-test.c | 215 +++++++++++++++++++++++++++++++
 2 files changed, 216 insertions(+)
 create mode 100644 tests/qtest/npcm7xx_sdhci-test.c
tests/qtest/meson.build +1 -0
index 842b1df420..2b566999cd 100644
@@ -189,6 +189,7 @@ qtests_npcm7xx = \
    'npcm7xx_gpio-test',
    'npcm7xx_pwm-test',
    'npcm7xx_rng-test',
+   'npcm7xx_sdhci-test',
    'npcm7xx_smbus-test',
    'npcm7xx_timer-test',
    'npcm7xx_watchdog_timer-test'] + \
tests/qtest/npcm7xx_sdhci-test.c new file +26 -0
new file mode 100644
index 0000000000..7de28f900b
@@ -0,0 +1,215 @@
+/*
+ * QTests for NPCM7xx SD-3.0 / MMC-4.51 Host Controller
+ *
+ * Copyright (c) 2022 Google LLC
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/sd/npcm7xx_sdhci.h"
+
+#include "libqos/libqtest.h"
+#include "libqtest-single.h"
+#include "libqos/sdhci-cmd.h"
+
+#define NPCM7XX_REG_SIZE 0x100
+#define NPCM7XX_MMC_BA 0xF0842000
+#define NPCM7XX_BLK_SIZE 512
---
 tests/qtest/meson.build          |   1 +
 tests/qtest/npcm7xx_sdhci-test.c | 215 +++++++++++++++++++++++++++++++
 2 files changed, 216 insertions(+)
 create mode 100644 tests/qtest/npcm7xx_sdhci-test.c
tests/qtest/meson.build +1 -0
index f33d84d19b..721eafad12 100644
@@ -190,6 +190,7 @@ qtests_npcm7xx = \
    'npcm7xx_gpio-test',
    'npcm7xx_pwm-test',
    'npcm7xx_rng-test',
+   'npcm7xx_sdhci-test',
    'npcm7xx_smbus-test',
    'npcm7xx_timer-test',
    'npcm7xx_watchdog_timer-test'] + \
tests/qtest/npcm7xx_sdhci-test.c new file +215 -0

215 lines not on this page · raw message

Signature · 1 line
2.35.1.574.g5d30c73bfb-goog
#1 lore raw
Quoted 28 lines · Hao Wu

From: Shengtan Mao <[email protected]>

---
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
---

tests/qtest/npcm7xx_sdhci-test.c new file +7 -0
+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 */

tests/qtest/npcm7xx_sdhci-test.c line 69

Quoted 10 lines
tests/qtest/npcm7xx_sdhci-test.c new file +10 -0
+    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

author
#2 lore raw

I have sent an updated version that uses memcmp()

Quoted 47 lines · Peter Maydell
Quoted 28 lines · Hao Wu

From: Shengtan Mao <[email protected]>

---
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
---

tests/qtest/npcm7xx_sdhci-test.c new file +7 -0
+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 */

tests/qtest/npcm7xx_sdhci-test.c line 69

Quoted 10 lines
tests/qtest/npcm7xx_sdhci-test.c new file +10 -0
+    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

#3 lore raw
Quoted 50 lines · Hao Wu

I have sent an updated version that uses memcmp()

Quoted 44 lines · Peter Maydell
Quoted 28 lines · Hao Wu

From: Shengtan Mao <[email protected]>

---
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
---

tests/qtest/npcm7xx_sdhci-test.c new file +7 -0
+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 */

tests/qtest/npcm7xx_sdhci-test.c line 69

Quoted 10 lines
tests/qtest/npcm7xx_sdhci-test.c new file +10 -0
+    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 Hao for picking this up :)

Quoted 5 lines
Quoted 4 lines

thanks
-- PMM