Skip to contentSkip to conversation

tests: use macros for registering char tests for sockets

PATCH Superseded Daniel P. Berrangé 2 participants 3 messages Oct 16, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests: use macros for registering char tests for sockets

The test-char.c has a couple of helper macros for registering tests that need to be repeated for both IP and UNIX sockets. One test case was not using the macro though.

---
 tests/unit/test-char.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
tests/unit/test-char.c +3 -5
index f30a39f61f..3c9f0a68e8 100644
@@ -1969,19 +1969,17 @@ int main(int argc, char **argv)
     g_test_add_data_func("/char/socket/client/reconnect-error/" # name, \
                          &client7 ##name, char_socket_client_test);     \
     g_test_add_data_func("/char/socket/client/dupid-reconnect/" # name, \
-                         &client8 ##name, char_socket_client_dupid_test)
+                         &client8 ##name, char_socket_client_dupid_test); \
+    g_test_add_data_func("/char/socket/server/two-clients/" # name,     \
+                         addr, char_socket_server_two_clients_test)
 
     if (has_ipv4) {
         SOCKET_SERVER_TEST(tcp, &tcpaddr);
         SOCKET_CLIENT_TEST(tcp, &tcpaddr);
-        g_test_add_data_func("/char/socket/server/two-clients/tcp", &tcpaddr,
-                             char_socket_server_two_clients_test);
     }
 #ifndef WIN32
     SOCKET_SERVER_TEST(unix, &unixaddr);
     SOCKET_CLIENT_TEST(unix, &unixaddr);
-    g_test_add_data_func("/char/socket/server/two-clients/unix", &unixaddr,
-                         char_socket_server_two_clients_test);
 #endif
 
     g_test_add_func("/char/udp", char_udp_test);
Signature · 1 line
2.50.1
#1 lore raw
Quoted 25 lines · Daniel P. Berrangé

The test-char.c has a couple of helper macros for registering tests that need to be repeated for both IP and UNIX sockets. One test case was not using the macro though.

---
 tests/unit/test-char.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
tests/unit/test-char.c +3 -1
index f30a39f61f..3c9f0a68e8 100644
@@ -1969,19 +1969,17 @@ int main(int argc, char **argv)
     g_test_add_data_func("/char/socket/client/reconnect-error/" # name, \
                          &client7 ##name, char_socket_client_test);     \
     g_test_add_data_func("/char/socket/client/dupid-reconnect/" # name, \
-                         &client8 ##name, char_socket_client_dupid_test)
+                         &client8 ##name, char_socket_client_dupid_test); \
+    g_test_add_data_func("/char/socket/server/two-clients/" # name,     \
+                         addr, char_socket_server_two_clients_test)
 
     if (has_ipv4) {
         SOCKET_SERVER_TEST(tcp, &tcpaddr);

tests/unit/test-char.c int main(int argc, char **argv) · line 1983

Quoted 10 lines
tests/unit/test-char.c +0 -4
         SOCKET_CLIENT_TEST(tcp, &tcpaddr);
-        g_test_add_data_func("/char/socket/server/two-clients/tcp", &tcpaddr,
-                             char_socket_server_two_clients_test);
     }
 #ifndef WIN32
     SOCKET_SERVER_TEST(unix, &unixaddr);
     SOCKET_CLIENT_TEST(unix, &unixaddr);
-    g_test_add_data_func("/char/socket/server/two-clients/unix", &unixaddr,
-                         char_socket_server_two_clients_test);
 #endif

This is a "server" test, but it looks like you've added it to the SOCKET_CLIENT_TEST macro instead of the SOCKET_SERVER_TEST macro ?

thanks
-- PMM

#2 lore raw
Quoted 24 lines · Peter Maydell
Quoted 23 lines · Daniel P. Berrangé

The test-char.c has a couple of helper macros for registering tests that need to be repeated for both IP and UNIX sockets. One test case was not using the macro though.

---
 tests/unit/test-char.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
tests/unit/test-char.c +3 -1
index f30a39f61f..3c9f0a68e8 100644
@@ -1969,19 +1969,17 @@ int main(int argc, char **argv)
     g_test_add_data_func("/char/socket/client/reconnect-error/" # name, \
                          &client7 ##name, char_socket_client_test);     \
     g_test_add_data_func("/char/socket/client/dupid-reconnect/" # name, \
-                         &client8 ##name, char_socket_client_dupid_test)
+                         &client8 ##name, char_socket_client_dupid_test); \
+    g_test_add_data_func("/char/socket/server/two-clients/" # name,     \
+                         addr, char_socket_server_two_clients_test)
 
Quoted 15 lines

tests/unit/test-char.c int main(int argc, char **argv) · line 1983

Quoted 12 lines
tests/unit/test-char.c +0 -4
     if (has_ipv4) {
         SOCKET_SERVER_TEST(tcp, &tcpaddr);
         SOCKET_CLIENT_TEST(tcp, &tcpaddr);
-        g_test_add_data_func("/char/socket/server/two-clients/tcp", &tcpaddr,
-                             char_socket_server_two_clients_test);
     }
 #ifndef WIN32
     SOCKET_SERVER_TEST(unix, &unixaddr);
     SOCKET_CLIENT_TEST(unix, &unixaddr);
-    g_test_add_data_func("/char/socket/server/two-clients/unix", &unixaddr,
-                         char_socket_server_two_clients_test);
 #endif

This is a "server" test, but it looks like you've added it to the SOCKET_CLIENT_TEST macro instead of the SOCKET_SERVER_TEST macro ?

Opps, yes, though it raises the question of why we have separate macros for server vs client tests instead of one.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|