From: Li Qiang <liq3ea@gmail.com>
To: Laszlo Ersek <lersek@redhat.com>
Cc: "Li Qiang" <liq3ea@163.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
lvivier@redhat.com, "Paolo Bonzini" <pbonzini@redhat.com>,
"Qemu Developers" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH 1/2] tests: fw_cfg: add a function to get the fw_cfg file entry
Date: Tue, 22 Jan 2019 09:21:06 +0800 [thread overview]
Message-ID: <CAKXe6SLAxE1Qv3MX4=Crgju+ApRsiDKwY84KU5ZMH-f+aNBjmg@mail.gmail.com> (raw)
In-Reply-To: <66f7e560-2e3e-0efc-6a80-9a44dff71324@redhat.com>
Laszlo Ersek <lersek@redhat.com> 于2019年1月22日周二 上午5:32写道:
> On 01/20/19 08:13, Li Qiang wrote:
> > This is useful to write qtest about fw_cfg file entry.
> >
> > Signed-off-by: Li Qiang <liq3ea@163.com>
> > ---
> > tests/libqos/fw_cfg.c | 33 +++++++++++++++++++++++++++++++++
> > tests/libqos/fw_cfg.h | 2 ++
> > 2 files changed, 35 insertions(+)
> >
> > diff --git a/tests/libqos/fw_cfg.c b/tests/libqos/fw_cfg.c
> > index d0889d1e22..e2b0cae7cd 100644
> > --- a/tests/libqos/fw_cfg.c
> > +++ b/tests/libqos/fw_cfg.c
> > @@ -16,6 +16,7 @@
> > #include "libqos/fw_cfg.h"
> > #include "libqtest.h"
> > #include "qemu/bswap.h"
> > +#include "standard-headers/linux/qemu_fw_cfg.h"
> >
> > void qfw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
> > {
> > @@ -54,6 +55,38 @@ uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key)
> > return le64_to_cpu(value);
> > }
> >
> > +size_t qfw_cfg_get_file(QFWCFG *fw_cfg, const char *filename,
> > + void *data, size_t buflen)
> > +{
> > + uint32_t count;
> > + uint32_t i;
> > + unsigned char *filesbuf = NULL;
> > + uint32_t dsize;
>
> dsize should be size_t
>
>
OK.
> > + struct fw_cfg_file *p;
>
> Please use a better variable name, such as "dir_entry" or similar.
>
>
OK.
> > + size_t filesize = 0;
> > +
> > + qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, &count, sizeof(count));
> > + count = be32_to_cpu(count);
> > + dsize = sizeof(uint32_t) + count * sizeof(struct fw_cfg_file);
>
> where does "struct fw_cfg_file" come from?
>
>
>From include/standard-headers/linux/qemu_fw_cfg.h
> ... more precisely: why use it over the "FWCfgFile" typedef? (applies to
> the declaration of "p" as well).
>
>
Ok, I think we should use include/hw/nvram/fw_cfg.h.
Thanks,
Li Qiang
> > + filesbuf = g_malloc0(dsize);
> > + qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, filesbuf, dsize);
> > + p = (struct fw_cfg_file *)(filesbuf + sizeof(uint32_t));
> > + for (i = 0; i < count; ++i, ++p) {
> > + if (!strcmp(p->name, filename)) {
> > + uint32_t len = be32_to_cpu(p->size);
> > + uint16_t sel = be16_to_cpu(p->select);
> > + filesize = len;
> > + if (len > buflen) {
> > + len = buflen;
> > + }
> > + qfw_cfg_get(fw_cfg, sel, data, len);
> > + break;
> > + }
> > + }
> > + g_free(filesbuf);
> > + return filesize;
> > +}
> > +
> > static void mm_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
> > {
> > qtest_writew(fw_cfg->qts, fw_cfg->base, key);
> > diff --git a/tests/libqos/fw_cfg.h b/tests/libqos/fw_cfg.h
> > index 0353416af0..de73722e67 100644
> > --- a/tests/libqos/fw_cfg.h
> > +++ b/tests/libqos/fw_cfg.h
> > @@ -31,6 +31,8 @@ void qfw_cfg_get(QFWCFG *fw_cfg, uint16_t key, void
> *data, size_t len);
> > uint16_t qfw_cfg_get_u16(QFWCFG *fw_cfg, uint16_t key);
> > uint32_t qfw_cfg_get_u32(QFWCFG *fw_cfg, uint16_t key);
> > uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key);
> > +size_t qfw_cfg_get_file(QFWCFG *fw_cfg, const char *filename,
> > + void *data, size_t buflen);
> >
> > QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base);
> > QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base);
> >
>
> Looks OK to me otherwise.
>
> Thanks,
> Laszlo
>
next prev parent reply other threads:[~2019-01-22 1:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-20 7:13 [Qemu-devel] [PATCH 0/2] tests: fw_cfg: add reboot-timeout test case Li Qiang
2019-01-20 7:13 ` [Qemu-devel] [PATCH 1/2] tests: fw_cfg: add a function to get the fw_cfg file entry Li Qiang
2019-01-21 21:32 ` Laszlo Ersek
2019-01-22 1:21 ` Li Qiang [this message]
2019-01-20 7:13 ` [Qemu-devel] [PATCH 2/2] tests: fw_cfg: add reboot_timeout test case Li Qiang
2019-01-21 21:38 ` Laszlo Ersek
2019-01-22 1:28 ` Li Qiang
2019-01-22 12:10 ` Laszlo Ersek
-- strict thread matches above, loose matches on Subject: below --
2018-10-28 12:40 [Qemu-devel] [PATCH 0/2] test: fw_cfg: add reboot-timeout " Li Qiang
2018-10-28 12:40 ` [Qemu-devel] [PATCH 1/2] tests: fw_cfg: add a function to get the fw_cfg file entry Li Qiang
2018-10-29 23:46 ` Philippe Mathieu-Daudé
2018-10-30 1:45 ` li qiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAKXe6SLAxE1Qv3MX4=Crgju+ApRsiDKwY84KU5ZMH-f+aNBjmg@mail.gmail.com' \
--to=liq3ea@gmail.com \
--cc=kraxel@redhat.com \
--cc=lersek@redhat.com \
--cc=liq3ea@163.com \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).