From: Thomas Huth <thuth@redhat.com>
To: Gustavo Romero <gustavo.romero@linaro.org>,
qemu-devel@nongnu.org, philmd@linaro.org
Cc: lvivier@redhat.com, qemu-arm@nongnu.org, alex.bennee@linaro.org,
pbonzini@redhat.com, anton.kochkov@proton.me,
richard.henderson@linaro.org, peter.maydell@linaro.org
Subject: Re: [PATCH 5/6] tests/qtest: Reorganize common code in ivshmem-test
Date: Mon, 26 Feb 2024 08:56:37 +0100 [thread overview]
Message-ID: <ef2f00bc-e920-485f-ba6c-c94c5aa5d615@redhat.com> (raw)
In-Reply-To: <20240222222218.2261956-6-gustavo.romero@linaro.org>
On 22/02/2024 23.22, Gustavo Romero wrote:
> This commit reorganizes the ivshmem-test qtest by moving common structs,
> functions, and code that can be utilized by other ivshmem qtests into
> two new files: ivshmem-utils.h and ivshmem-utils.c.
>
> Enum Reg, struct ServerThread, and mktempshm() have been relocated to
> these new files. Two new functions have been introduced to handle the
> ivshmem server start/stop: test_ivshmem_server_{start,stop}.
>
> To accommodate the new way for starting/stopping the ivshmem server,
> struct ServerThread now includes two new members: 'server', previously
> present but not a member of any struct; and 'status', a new member of a
> new type, ServerStartStatus, used to track and handle service
> termination properly.
>
> Additionally, a new function, mktempsocket(), has been added to help
> create a unix socket filename, similar to what mktempshm() does for the
> creation of a shm file.
>
> Finally, the ivshmem-test qtest has been adapted to use the new ivhsmem
> utils. Adjustments in that sense have also been made to meson.build;
> also 'rt' have been removed as a lib dependency for ivhsmem-test.c.
>
> Two lines unrelated to these changes have had their line indentation
> also fixed in meson.build.
>
> Message-ID: <20231127052024.435743-3-gustavo.romero@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
> ---
...
> diff --git a/tests/qtest/ivshmem-utils.c b/tests/qtest/ivshmem-utils.c
> new file mode 100644
> index 0000000000..c2fc3463dd
> --- /dev/null
> +++ b/tests/qtest/ivshmem-utils.c
> @@ -0,0 +1,156 @@
> +/*
> + * Common utilities for testing ivshmem devices
> + *
> + * SPDX-FileCopyrightText: 2012 SUSE LINUX Products GmbH
> + * SPDX-FileCopyrightText: 2021 Red Hat, Inc.
> + * SPDX-FileCopyrightText: 2023 Linaro Ltd.
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + *
> + */
> +
> +#include "ivshmem-utils.h"
> +
> +gchar *mktempshm(int size, int *fd)
> +{
> + while (true) {
> + /* Relative path to the shm filesystem, e.g. '/dev/shm'. */
> + gchar *shm_rel_path;
> +
> + shm_rel_path = g_strdup_printf("/ivshmem_qtest-%u-%u", getpid(),
> + g_test_rand_int());
> + *fd = shm_open(shm_rel_path, O_CREAT | O_RDWR | O_EXCL,
> + S_IRWXU | S_IRWXG | S_IRWXO);
> + if (*fd > 0) {
> + g_assert(ftruncate(*fd, size) == 0);
> + return shm_rel_path;
> + }
> +
> + g_free(shm_rel_path);
> +
> + if (errno != EEXIST) {
> + perror("shm_open");
> + return NULL;
> + }
> + }
> +}
> +
> +gchar *mktempsocket(void)
> +{
> + gchar *server_socket_path;
> +
> + server_socket_path = g_strdup_printf("%s/ivshmem_socket_qtest-%u-%u",
> + g_get_tmp_dir(), getpid(),
> + g_test_rand_int());
> + return server_socket_path;
> +}
You could simplify that to:
return g_strdup_printf("%s/ivshmem_socket_qtest-%u-%u",
g_get_tmp_dir(), getpid(),
g_test_rand_int());
Anyway:
Acked-by: Thomas Huth <thuth@redhat.com>
next prev parent reply other threads:[~2024-02-26 7:57 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-22 22:22 [PATCH 0/6] Add ivshmem-flat device Gustavo Romero
2024-02-22 22:22 ` [PATCH 1/6] hw/misc/ivshmem: " Gustavo Romero
2024-02-22 22:22 ` [PATCH 2/6] hw/misc/ivshmem-flat: Allow device to wire itself on sysbus Gustavo Romero
2024-02-22 22:22 ` [PATCH 3/6] hw/arm: Allow some machines to use the ivshmem-flat device Gustavo Romero
2024-02-22 22:22 ` [PATCH 4/6] hw/misc/ivshmem: Rename ivshmem to ivshmem-pci Gustavo Romero
2024-02-22 22:22 ` [PATCH 5/6] tests/qtest: Reorganize common code in ivshmem-test Gustavo Romero
2024-02-26 7:56 ` Thomas Huth [this message]
2024-02-22 22:22 ` [PATCH 6/6] tests/qtest: Add ivshmem-flat test Gustavo Romero
2024-02-26 8:00 ` Thomas Huth
2024-02-28 6:29 ` [PATCH 0/6] Add ivshmem-flat device Markus Armbruster
2024-04-22 16:47 ` Gustavo Romero
2024-04-23 10:39 ` Markus Armbruster
2024-04-23 16:00 ` Bill Mills
2024-04-25 11:58 ` Markus Armbruster
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=ef2f00bc-e920-485f-ba6c-c94c5aa5d615@redhat.com \
--to=thuth@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=anton.kochkov@proton.me \
--cc=gustavo.romero@linaro.org \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/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).