Skip to contentSkip to conversation

tests/unit/test-qga: enable on FreeBSD

PATCH Superseded Roman Bogorodskiy 3 participants 3 messages Sep 16 – Sep 29 Arm/Amlogic Meson SoC support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/unit/test-qga: enable on FreeBSD

FreeBSD has all necessary commands implemented,
so enable test-qga for it.

Requires only minimal portability fixes for sockets in connect_qga().

---
 tests/unit/meson.build | 2 +-
 tests/unit/test-qga.c  | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)
tests/unit/meson.build +1 -1
index e47bc7225a..0ca0d8974e 100644
@@ -169,7 +169,7 @@ if have_system
   tests += {'test-qdev': [qom, hwcore]}
 endif
 
-if have_ga and host_os == 'linux'
+if have_ga and host_os in ['freebsd', 'linux']
   tests += {'test-qga': ['../qtest/libqmp.c', '../qtest/libqtest.c']}
   test_deps += {'test-qga': qga}
 endif
tests/unit/test-qga.c +5 -1
index 01ccf826e6..dbedfe3d5f 100644
@@ -18,7 +18,7 @@ typedef struct {
 static int connect_qga(char *path)
 {
     int s, ret, len, i = 0;
-    struct sockaddr_un remote;
+    struct sockaddr_un remote = { 0 };
 
     s = socket(AF_UNIX, SOCK_STREAM, 0);
     g_assert(s != -1);
@@ -26,7 +26,11 @@ static int connect_qga(char *path)
     remote.sun_family = AF_UNIX;
     do {
         strcpy(remote.sun_path, path);
+#ifdef SUN_LEN
+        len = SUN_LEN(&remote);
+#else
         len = strlen(remote.sun_path) + sizeof(remote.sun_family);
+#endif
         ret = connect(s, (struct sockaddr *)&remote, len);
         if (ret == -1) {
             g_usleep(G_USEC_PER_SEC);
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 54 lines · Roman Bogorodskiy

FreeBSD has all necessary commands implemented,
so enable test-qga for it.

Requires only minimal portability fixes for sockets in connect_qga().

---
 tests/unit/meson.build | 2 +-
 tests/unit/test-qga.c  | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)
tests/unit/meson.build +1 -1
index e47bc7225a..0ca0d8974e 100644
@@ -169,7 +169,7 @@ if have_system
   tests += {'test-qdev': [qom, hwcore]}
 endif
 
-if have_ga and host_os == 'linux'
+if have_ga and host_os in ['freebsd', 'linux']
   tests += {'test-qga': ['../qtest/libqmp.c', '../qtest/libqtest.c']}
   test_deps += {'test-qga': qga}
 endif
tests/unit/test-qga.c +5 -2
index 01ccf826e6..dbedfe3d5f 100644
@@ -18,7 +18,7 @@ typedef struct {
 static int connect_qga(char *path)
 {
     int s, ret, len, i = 0;
-    struct sockaddr_un remote;
+    struct sockaddr_un remote = { 0 };
 
     s = socket(AF_UNIX, SOCK_STREAM, 0);
     g_assert(s != -1);
@@ -26,7 +26,11 @@ static int connect_qga(char *path)
     remote.sun_family = AF_UNIX;
     do {
         strcpy(remote.sun_path, path);
+#ifdef SUN_LEN
+        len = SUN_LEN(&remote);
+#else
         len = strlen(remote.sun_path) + sizeof(remote.sun_family);
+#endif
         ret = connect(s, (struct sockaddr *)&remote, len);
         if (ret == -1) {
             g_usleep(G_USEC_PER_SEC);
--

2.55.0

#2 lore raw
In reply to Roman Bogorodskiy
Quoted 39 lines · Roman Bogorodskiy

FreeBSD has all necessary commands implemented,
so enable test-qga for it.

Requires only minimal portability fixes for sockets in connect_qga().

---
 tests/unit/meson.build | 2 +-
 tests/unit/test-qga.c  | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)
tests/unit/meson.build +1 -1
index e47bc7225a..0ca0d8974e 100644
@@ -169,7 +169,7 @@ if have_system
   tests += {'test-qdev': [qom, hwcore]}
 endif
 
-if have_ga and host_os == 'linux'
+if have_ga and host_os in ['freebsd', 'linux']
   tests += {'test-qga': ['../qtest/libqmp.c', '../qtest/libqtest.c']}
   test_deps += {'test-qga': qga}
 endif
tests/unit/test-qga.c +1 -1
index 01ccf826e6..dbedfe3d5f 100644
@@ -18,7 +18,7 @@ typedef struct {
 static int connect_qga(char *path)
 {
     int s, ret, len, i = 0;
-    struct sockaddr_un remote;
+    struct sockaddr_un remote = { 0 };
 
     s = socket(AF_UNIX, SOCK_STREAM, 0);
     g_assert(s != -1);

tests/unit/test-qga.c static int connect_qga(char *path) · line 33

Quoted 8 lines
tests/unit/test-qga.c +4 -0
@@ -26,7 +26,11 @@ static int connect_qga(char *path)
     remote.sun_family = AF_UNIX;
     do {
         strcpy(remote.sun_path, path);
+#ifdef SUN_LEN
+        len = SUN_LEN(&remote);
+#else
         len = strlen(remote.sun_path) + sizeof(remote.sun_family);
+#endif

This conditional shouldn't be needed, as this ought to be written as

len = sizeof(remote)

given that sun_path is NUL terminate, there's no reason to try to calculate a shorter size, only paths in the abstract namespace need special length handling.

Quoted 7 lines
tests/unit/test-qga.c +0 -0
         ret = connect(s, (struct sockaddr *)&remote, len);
         if (ret == -1) {
             g_usleep(G_USEC_PER_SEC);
Signature · 1 line
2.55.0

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|