diff mbox series

[1/3] qga: test: Use absolute path to test data

Message ID d4b8f60e02ae9f6fd12f2d05feae3c903cfe9e82.1677197937.git.dxu@dxuuu.xyz
State New
Headers show
Series qga: Add optional `merge-output` flag to guest-exec QAPI | expand

Commit Message

Daniel Xu Feb. 24, 2023, 12:21 a.m. UTC
It looks like qga's working directory is in a tempdir. So the relative
path that the test case gives qga through the QGA_OS_RELEASE=
env variable does not resolve correctly.

Fix by doing a poor man's path canonicalization of the test data file.

Note we cannot use g_canonicalize_filename() b/c that helper was only
introduced in glib 2.58 and the current GLIB_VERSION_MAX_ALLOWED is
pinned to 2.56.

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
---
 tests/unit/test-qga.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Marc-André Lureau Feb. 27, 2023, 8:16 a.m. UTC | #1
Hi

On Fri, Feb 24, 2023 at 8:31 AM Daniel Xu <dxu@dxuuu.xyz> wrote:
>
> It looks like qga's working directory is in a tempdir. So the relative
> path that the test case gives qga through the QGA_OS_RELEASE=
> env variable does not resolve correctly.
>
> Fix by doing a poor man's path canonicalization of the test data file.
>
> Note we cannot use g_canonicalize_filename() b/c that helper was only
> introduced in glib 2.58 and the current GLIB_VERSION_MAX_ALLOWED is
> pinned to 2.56.
>
> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>

This breaks "meson test test-qga" for me. How do you run the tests?

> ---
>  tests/unit/test-qga.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c
> index b4e0a14573..9d8e1d1cd3 100644
> --- a/tests/unit/test-qga.c
> +++ b/tests/unit/test-qga.c
> @@ -881,13 +881,16 @@ static void test_qga_guest_get_osinfo(gconstpointer data)
>  {
>      TestFixture fixture;
>      const gchar *str;
> +    g_autofree const gchar *cwd;

const is not appropriate here, interesting I don't get a warning

>      g_autoptr(QDict) ret = NULL;
>      char *env[2];
>      QDict *val;
>
> +    cwd = g_get_current_dir();
>      env[0] = g_strdup_printf(
> -        "QGA_OS_RELEASE=%s%c..%cdata%ctest-qga-os-release",
> -        g_test_get_dir(G_TEST_DIST), G_DIR_SEPARATOR, G_DIR_SEPARATOR, G_DIR_SEPARATOR);
> +        "QGA_OS_RELEASE=%s%c%s%c..%cdata%ctest-qga-os-release",
> +        cwd, G_DIR_SEPARATOR, g_test_get_dir(G_TEST_DIST), G_DIR_SEPARATOR,
> +        G_DIR_SEPARATOR, G_DIR_SEPARATOR);
>      env[1] = NULL;
>      fixture_setup(&fixture, NULL, env);
>
> --
> 2.39.1
>
>
Daniel Xu Feb. 28, 2023, 1 a.m. UTC | #2
Hi Marc-André,

Thanks for reviewing the series.

On Mon, Feb 27, 2023, at 1:16 AM, Marc-André Lureau wrote:
> Hi
>
> On Fri, Feb 24, 2023 at 8:31 AM Daniel Xu <dxu@dxuuu.xyz> wrote:
>>
>> It looks like qga's working directory is in a tempdir. So the relative
>> path that the test case gives qga through the QGA_OS_RELEASE=
>> env variable does not resolve correctly.
>>
>> Fix by doing a poor man's path canonicalization of the test data file.
>>
>> Note we cannot use g_canonicalize_filename() b/c that helper was only
>> introduced in glib 2.58 and the current GLIB_VERSION_MAX_ALLOWED is
>> pinned to 2.56.
>>
>> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
>
> This breaks "meson test test-qga" for me. How do you run the tests?

Ah, thanks for the hint. I was running the qga tests in build/ with:

        $ ./tests/unit/test-qga

Using meson to drive the tests fixed it for me. I will drop this patch.

[...]

Thanks,
Daniel
diff mbox series

Patch

diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c
index b4e0a14573..9d8e1d1cd3 100644
--- a/tests/unit/test-qga.c
+++ b/tests/unit/test-qga.c
@@ -881,13 +881,16 @@  static void test_qga_guest_get_osinfo(gconstpointer data)
 {
     TestFixture fixture;
     const gchar *str;
+    g_autofree const gchar *cwd;
     g_autoptr(QDict) ret = NULL;
     char *env[2];
     QDict *val;
 
+    cwd = g_get_current_dir();
     env[0] = g_strdup_printf(
-        "QGA_OS_RELEASE=%s%c..%cdata%ctest-qga-os-release",
-        g_test_get_dir(G_TEST_DIST), G_DIR_SEPARATOR, G_DIR_SEPARATOR, G_DIR_SEPARATOR);
+        "QGA_OS_RELEASE=%s%c%s%c..%cdata%ctest-qga-os-release",
+        cwd, G_DIR_SEPARATOR, g_test_get_dir(G_TEST_DIST), G_DIR_SEPARATOR,
+        G_DIR_SEPARATOR, G_DIR_SEPARATOR);
     env[1] = NULL;
     fixture_setup(&fixture, NULL, env);