* [PATCH v2] tests: Trying fixes test-replication.c on msys2.
@ 2020-09-03 22:06 Yonggang Luo
2020-09-04 7:58 ` Paolo Bonzini
2020-09-04 13:07 ` Thomas Huth
0 siblings, 2 replies; 5+ messages in thread
From: Yonggang Luo @ 2020-09-03 22:06 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Yonggang Luo
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
tests/test-replication.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/tests/test-replication.c b/tests/test-replication.c
index 9ab3666a90..d0e06f8d77 100644
--- a/tests/test-replication.c
+++ b/tests/test-replication.c
@@ -23,14 +23,18 @@
/* primary */
#define P_ID "primary-id"
-static char p_local_disk[] = "/tmp/p_local_disk.XXXXXX";
+#define P_LOCAL_DISK "%s/p_local_disk.XXXXXX"
+static char p_local_disk[PATH_MAX];
/* secondary */
#define S_ID "secondary-id"
#define S_LOCAL_DISK_ID "secondary-local-disk-id"
-static char s_local_disk[] = "/tmp/s_local_disk.XXXXXX";
-static char s_active_disk[] = "/tmp/s_active_disk.XXXXXX";
-static char s_hidden_disk[] = "/tmp/s_hidden_disk.XXXXXX";
+#define S_LOCAL_DISK "%s/s_local_disk.XXXXXX"
+static char s_local_disk[PATH_MAX];
+#define S_ACTIVE_DISK "%s/s_active_disk.XXXXXX"
+static char s_active_disk[PATH_MAX];
+#define S_HIDDEN_DISK "%s/s_hidden_disk.XXXXXX"
+static char s_hidden_disk[PATH_MAX];
/* FIXME: steal from blockdev.c */
QemuOptsList qemu_drive_opts = {
@@ -571,7 +575,12 @@ static void setup_sigabrt_handler(void)
int main(int argc, char **argv)
{
int ret;
+ const char *tmpdir = g_get_tmp_dir();
qemu_init_main_loop(&error_fatal);
+ sprintf(p_local_disk, P_LOCAL_DISK, tmpdir);
+ sprintf(s_local_disk, S_LOCAL_DISK, tmpdir);
+ sprintf(s_active_disk, S_ACTIVE_DISK, tmpdir);
+ sprintf(s_hidden_disk, S_HIDDEN_DISK, tmpdir);
bdrv_init();
g_test_init(&argc, &argv, NULL);
--
2.28.0.windows.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] tests: Trying fixes test-replication.c on msys2.
2020-09-03 22:06 [PATCH v2] tests: Trying fixes test-replication.c on msys2 Yonggang Luo
@ 2020-09-04 7:58 ` Paolo Bonzini
2020-09-04 13:07 ` Thomas Huth
1 sibling, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2020-09-04 7:58 UTC (permalink / raw)
To: Yonggang Luo, qemu-devel; +Cc: qemu block
On 04/09/20 00:06, Yonggang Luo wrote:
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
> tests/test-replication.c | 17 +++++++++++++----
> 1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/tests/test-replication.c b/tests/test-replication.c
> index 9ab3666a90..d0e06f8d77 100644
> --- a/tests/test-replication.c
> +++ b/tests/test-replication.c
> @@ -23,14 +23,18 @@
>
> /* primary */
> #define P_ID "primary-id"
> -static char p_local_disk[] = "/tmp/p_local_disk.XXXXXX";
> +#define P_LOCAL_DISK "%s/p_local_disk.XXXXXX"
> +static char p_local_disk[PATH_MAX];
>
> /* secondary */
> #define S_ID "secondary-id"
> #define S_LOCAL_DISK_ID "secondary-local-disk-id"
> -static char s_local_disk[] = "/tmp/s_local_disk.XXXXXX";
> -static char s_active_disk[] = "/tmp/s_active_disk.XXXXXX";
> -static char s_hidden_disk[] = "/tmp/s_hidden_disk.XXXXXX";
> +#define S_LOCAL_DISK "%s/s_local_disk.XXXXXX"
> +static char s_local_disk[PATH_MAX];
> +#define S_ACTIVE_DISK "%s/s_active_disk.XXXXXX"
> +static char s_active_disk[PATH_MAX];
> +#define S_HIDDEN_DISK "%s/s_hidden_disk.XXXXXX"
> +static char s_hidden_disk[PATH_MAX];
>
> /* FIXME: steal from blockdev.c */
> QemuOptsList qemu_drive_opts = {
> @@ -571,7 +575,12 @@ static void setup_sigabrt_handler(void)
> int main(int argc, char **argv)
> {
> int ret;
> + const char *tmpdir = g_get_tmp_dir();
> qemu_init_main_loop(&error_fatal);
> + sprintf(p_local_disk, P_LOCAL_DISK, tmpdir);
> + sprintf(s_local_disk, S_LOCAL_DISK, tmpdir);
> + sprintf(s_active_disk, S_ACTIVE_DISK, tmpdir);
> + sprintf(s_hidden_disk, S_HIDDEN_DISK, tmpdir);
> bdrv_init();
>
> g_test_init(&argc, &argv, NULL);
>
Cc: qemu-block@nongnu.org
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] tests: Trying fixes test-replication.c on msys2.
2020-09-03 22:06 [PATCH v2] tests: Trying fixes test-replication.c on msys2 Yonggang Luo
2020-09-04 7:58 ` Paolo Bonzini
@ 2020-09-04 13:07 ` Thomas Huth
2020-09-05 3:11 ` 罗勇刚(Yonggang Luo)
1 sibling, 1 reply; 5+ messages in thread
From: Thomas Huth @ 2020-09-04 13:07 UTC (permalink / raw)
To: Yonggang Luo, qemu-devel; +Cc: Paolo Bonzini, Xie Changlong, Wen Congyang
On 04/09/2020 00.06, Yonggang Luo wrote:
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
> tests/test-replication.c | 17 +++++++++++++----
> 1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/tests/test-replication.c b/tests/test-replication.c
> index 9ab3666a90..d0e06f8d77 100644
> --- a/tests/test-replication.c
> +++ b/tests/test-replication.c
> @@ -23,14 +23,18 @@
>
> /* primary */
> #define P_ID "primary-id"
> -static char p_local_disk[] = "/tmp/p_local_disk.XXXXXX";
> +#define P_LOCAL_DISK "%s/p_local_disk.XXXXXX"
> +static char p_local_disk[PATH_MAX];
>
> /* secondary */
> #define S_ID "secondary-id"
> #define S_LOCAL_DISK_ID "secondary-local-disk-id"
> -static char s_local_disk[] = "/tmp/s_local_disk.XXXXXX";
> -static char s_active_disk[] = "/tmp/s_active_disk.XXXXXX";
> -static char s_hidden_disk[] = "/tmp/s_hidden_disk.XXXXXX";
> +#define S_LOCAL_DISK "%s/s_local_disk.XXXXXX"
> +static char s_local_disk[PATH_MAX];
> +#define S_ACTIVE_DISK "%s/s_active_disk.XXXXXX"
> +static char s_active_disk[PATH_MAX];
> +#define S_HIDDEN_DISK "%s/s_hidden_disk.XXXXXX"
> +static char s_hidden_disk[PATH_MAX];
>
> /* FIXME: steal from blockdev.c */
> QemuOptsList qemu_drive_opts = {
> @@ -571,7 +575,12 @@ static void setup_sigabrt_handler(void)
> int main(int argc, char **argv)
> {
> int ret;
> + const char *tmpdir = g_get_tmp_dir();
> qemu_init_main_loop(&error_fatal);
> + sprintf(p_local_disk, P_LOCAL_DISK, tmpdir);
> + sprintf(s_local_disk, S_LOCAL_DISK, tmpdir);
> + sprintf(s_active_disk, S_ACTIVE_DISK, tmpdir);
> + sprintf(s_hidden_disk, S_HIDDEN_DISK, tmpdir);
Sounds like the right way to go, but I think I'd do it without the
#defines and simply use the strings directly here, what do you think?
Thomas
PS: Please use scripts/get_maintainer.pl (or the MAINTAINERS file
directly) on your patches to find out the right maintainers that you
should put on CC: for every patch.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] tests: Trying fixes test-replication.c on msys2.
2020-09-04 13:07 ` Thomas Huth
@ 2020-09-05 3:11 ` 罗勇刚(Yonggang Luo)
2020-09-05 7:25 ` Thomas Huth
0 siblings, 1 reply; 5+ messages in thread
From: 罗勇刚(Yonggang Luo) @ 2020-09-05 3:11 UTC (permalink / raw)
To: Thomas Huth; +Cc: Paolo Bonzini, Xie Changlong, qemu-level, Wen Congyang
[-- Attachment #1: Type: text/plain, Size: 2415 bytes --]
On Fri, Sep 4, 2020 at 9:07 PM Thomas Huth <thuth@redhat.com> wrote:
> On 04/09/2020 00.06, Yonggang Luo wrote:
> > Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> > ---
> > tests/test-replication.c | 17 +++++++++++++----
> > 1 file changed, 13 insertions(+), 4 deletions(-)
> >
> > diff --git a/tests/test-replication.c b/tests/test-replication.c
> > index 9ab3666a90..d0e06f8d77 100644
> > --- a/tests/test-replication.c
> > +++ b/tests/test-replication.c
> > @@ -23,14 +23,18 @@
> >
> > /* primary */
> > #define P_ID "primary-id"
> > -static char p_local_disk[] = "/tmp/p_local_disk.XXXXXX";
> > +#define P_LOCAL_DISK "%s/p_local_disk.XXXXXX"
> > +static char p_local_disk[PATH_MAX];
> >
> > /* secondary */
> > #define S_ID "secondary-id"
> > #define S_LOCAL_DISK_ID "secondary-local-disk-id"
> > -static char s_local_disk[] = "/tmp/s_local_disk.XXXXXX";
> > -static char s_active_disk[] = "/tmp/s_active_disk.XXXXXX";
> > -static char s_hidden_disk[] = "/tmp/s_hidden_disk.XXXXXX";
> > +#define S_LOCAL_DISK "%s/s_local_disk.XXXXXX"
> > +static char s_local_disk[PATH_MAX];
> > +#define S_ACTIVE_DISK "%s/s_active_disk.XXXXXX"
> > +static char s_active_disk[PATH_MAX];
> > +#define S_HIDDEN_DISK "%s/s_hidden_disk.XXXXXX"
> > +static char s_hidden_disk[PATH_MAX];
> >
> > /* FIXME: steal from blockdev.c */
> > QemuOptsList qemu_drive_opts = {
> > @@ -571,7 +575,12 @@ static void setup_sigabrt_handler(void)
> > int main(int argc, char **argv)
> > {
> > int ret;
> > + const char *tmpdir = g_get_tmp_dir();
> > qemu_init_main_loop(&error_fatal);
> > + sprintf(p_local_disk, P_LOCAL_DISK, tmpdir);
> > + sprintf(s_local_disk, S_LOCAL_DISK, tmpdir);
> > + sprintf(s_active_disk, S_ACTIVE_DISK, tmpdir);
> > + sprintf(s_hidden_disk, S_HIDDEN_DISK, tmpdir);
>
> Sounds like the right way to go, but I think I'd do it without the
> #defines and simply use the strings directly here, what do you think?
>
I place them at the same place by define is for easily readable, if I
directly place at sprintf,
then the code are harder to read
>
> Thomas
>
>
> PS: Please use scripts/get_maintainer.pl (or the MAINTAINERS file
> directly) on your patches to find out the right maintainers that you
> should put on CC: for every patch.
>
>
--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo
[-- Attachment #2: Type: text/html, Size: 3488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] tests: Trying fixes test-replication.c on msys2.
2020-09-05 3:11 ` 罗勇刚(Yonggang Luo)
@ 2020-09-05 7:25 ` Thomas Huth
0 siblings, 0 replies; 5+ messages in thread
From: Thomas Huth @ 2020-09-05 7:25 UTC (permalink / raw)
To: luoyonggang; +Cc: Paolo Bonzini, Xie Changlong, qemu-level, Wen Congyang
On 05/09/2020 05.11, 罗勇刚(Yonggang Luo) wrote:
>
>
> On Fri, Sep 4, 2020 at 9:07 PM Thomas Huth <thuth@redhat.com
> <mailto:thuth@redhat.com>> wrote:
>
> On 04/09/2020 00.06, Yonggang Luo wrote:
> > Signed-off-by: Yonggang Luo <luoyonggang@gmail.com
> <mailto:luoyonggang@gmail.com>>
> > ---
> > tests/test-replication.c | 17 +++++++++++++----
> > 1 file changed, 13 insertions(+), 4 deletions(-)
> >
> > diff --git a/tests/test-replication.c b/tests/test-replication.c
> > index 9ab3666a90..d0e06f8d77 100644
> > --- a/tests/test-replication.c
> > +++ b/tests/test-replication.c
> > @@ -23,14 +23,18 @@
> >
> > /* primary */
> > #define P_ID "primary-id"
> > -static char p_local_disk[] = "/tmp/p_local_disk.XXXXXX";
> > +#define P_LOCAL_DISK "%s/p_local_disk.XXXXXX"
> > +static char p_local_disk[PATH_MAX];
> >
> > /* secondary */
> > #define S_ID "secondary-id"
> > #define S_LOCAL_DISK_ID "secondary-local-disk-id"
> > -static char s_local_disk[] = "/tmp/s_local_disk.XXXXXX";
> > -static char s_active_disk[] = "/tmp/s_active_disk.XXXXXX";
> > -static char s_hidden_disk[] = "/tmp/s_hidden_disk.XXXXXX";
> > +#define S_LOCAL_DISK "%s/s_local_disk.XXXXXX"
> > +static char s_local_disk[PATH_MAX];
> > +#define S_ACTIVE_DISK "%s/s_active_disk.XXXXXX"
> > +static char s_active_disk[PATH_MAX];
> > +#define S_HIDDEN_DISK "%s/s_hidden_disk.XXXXXX"
> > +static char s_hidden_disk[PATH_MAX];
> >
> > /* FIXME: steal from blockdev.c */
> > QemuOptsList qemu_drive_opts = {
> > @@ -571,7 +575,12 @@ static void setup_sigabrt_handler(void)
> > int main(int argc, char **argv)
> > {
> > int ret;
> > + const char *tmpdir = g_get_tmp_dir();
> > qemu_init_main_loop(&error_fatal);
> > + sprintf(p_local_disk, P_LOCAL_DISK, tmpdir);
> > + sprintf(s_local_disk, S_LOCAL_DISK, tmpdir);
> > + sprintf(s_active_disk, S_ACTIVE_DISK, tmpdir);
> > + sprintf(s_hidden_disk, S_HIDDEN_DISK, tmpdir);
>
> Sounds like the right way to go, but I think I'd do it without the
> #defines and simply use the strings directly here, what do you think?
>
> I place them at the same place by define is for easily readable, if I
> directly place at sprintf, then the code are harder to read
IMHO it's easier to read the code the other way round: For understanding
the sprintf and its arguments, you have to know the format string, e.g.
will the "tmpdir" be handled via "%s", or "%p" or maybe something
completely different? If you then have to look up a macro first, it is a
cumbersome indirection. #defines are certainly fine for things that are
used multiple times, but here the strings are only used once, so the
indirection is really not needed.
Thomas
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-09-05 7:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-03 22:06 [PATCH v2] tests: Trying fixes test-replication.c on msys2 Yonggang Luo
2020-09-04 7:58 ` Paolo Bonzini
2020-09-04 13:07 ` Thomas Huth
2020-09-05 3:11 ` 罗勇刚(Yonggang Luo)
2020-09-05 7:25 ` Thomas Huth
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).