From dbe8e52bde8194d52adc5d7b28a51ac4b5b30a63 Mon Sep 17 00:00:00 2001 From: Emmanuel Fleury Date: Thu, 24 Feb 2022 11:54:14 +0100 Subject: [PATCH 1/4] Convert tests/gio-test.c to g_test framework --- tests/gio-test.c | 525 ++++++++++++++++++++++++----------------------- 1 file changed, 268 insertions(+), 257 deletions(-) diff --git a/tests/gio-test.c b/tests/gio-test.c index d203d0b27..3bab515eb 100644 --- a/tests/gio-test.c +++ b/tests/gio-test.c @@ -19,9 +19,6 @@ * Just run it. Optional parameter is number of sub-processes. */ -#undef G_DISABLE_ASSERT -#undef G_LOG_DOMAIN - #include "config.h" #include @@ -47,11 +44,11 @@ static int nrunning; static GMainLoop *main_loop; -#define BUFSIZE 5000 /* Larger than the circular buffer in - * giowin32.c on purpose. - */ +/* Larger than the circular buffer in giowin32.c on purpose */ +#define BUFSIZE 5000 static int nkiddies; +static char *exec_name; static struct { int fd; @@ -60,10 +57,10 @@ static struct { static GIOError read_all (int fd, - GIOChannel *channel, - char *buffer, - guint nbytes, - guint *bytes_read) + GIOChannel *channel, + char *buffer, + guint nbytes, + guint *bytes_read) { guint left = nbytes; gsize nb; @@ -77,16 +74,16 @@ read_all (int fd, while (left) { error = g_io_channel_read (channel, bufp, left, &nb); - + if (error != G_IO_ERROR_NONE) - { - g_print ("gio-test: ...from %d: %d\n", fd, error); - if (error == G_IO_ERROR_AGAIN) - continue; - break; - } + { + g_print ("gio-test: ...from %d: %d\n", fd, error); + if (error == G_IO_ERROR_AGAIN) + continue; + break; + } if (nb == 0) - return error; + return error; left -= nb; bufp += nb; *bytes_read += nb; @@ -101,23 +98,23 @@ shutdown_source (gpointer data) { nrunning--; if (nrunning == 0) - g_main_loop_quit (main_loop); + g_main_loop_quit (main_loop); } } static gboolean recv_message (GIOChannel *channel, - GIOCondition cond, - gpointer data) + GIOCondition cond, + gpointer data) { gint fd = g_io_channel_unix_get_fd (channel); gboolean retval = TRUE; g_debug ("gio-test: ...from %d:%s%s%s%s", fd, - (cond & G_IO_ERR) ? " ERR" : "", - (cond & G_IO_HUP) ? " HUP" : "", - (cond & G_IO_IN) ? " IN" : "", - (cond & G_IO_PRI) ? " PRI" : ""); + (cond & G_IO_ERR) ? " ERR" : "", + (cond & G_IO_HUP) ? " HUP" : "", + (cond & G_IO_IN) ? " IN" : "", + (cond & G_IO_PRI) ? " PRI" : ""); if (cond & (G_IO_ERR | G_IO_HUP)) { @@ -133,96 +130,93 @@ recv_message (GIOChannel *channel, guint j; int i, seq; GIOError error; - + error = read_all (fd, channel, (gchar *) &seq, sizeof (seq), &nb); if (error == G_IO_ERROR_NONE) - { - if (nb == 0) - { - g_debug ("gio-test: ...from %d: EOF", fd); - shutdown_source (data); - return FALSE; - } - - g_assert (nb == sizeof (nbytes)); + { + if (nb == 0) + { + g_debug ("gio-test: ...from %d: EOF", fd); + shutdown_source (data); + return FALSE; + } + g_assert_cmpuint (nb, ==, sizeof (nbytes)); - for (i = 0; i < nkiddies; i++) - if (seqtab[i].fd == fd) - { + for (i = 0; i < nkiddies; i++) + if (seqtab[i].fd == fd) + { g_assert_cmpint (seq, ==, seqtab[i].seq); - seqtab[i].seq++; - break; - } + seqtab[i].seq++; + break; + } - error = read_all (fd, channel, (gchar *) &nbytes, sizeof (nbytes), &nb); - } + error = + read_all (fd, channel, (gchar *) &nbytes, sizeof (nbytes), &nb); + } if (error != G_IO_ERROR_NONE) - return FALSE; - - if (nb == 0) - { - g_debug ("gio-test: ...from %d: EOF", fd); - shutdown_source (data); - return FALSE; - } - - g_assert (nb == sizeof (nbytes)); + return FALSE; - g_assert_cmpint (nbytes, <, BUFSIZE); - g_assert (nbytes < BUFSIZE); + if (nb == 0) + { + g_debug ("gio-test: ...from %d: EOF", fd); + shutdown_source (data); + return FALSE; + } + g_assert_cmpuint (nb, ==, sizeof (nbytes)); + + g_assert_cmpuint (nbytes, <, BUFSIZE); g_debug ("gio-test: ...from %d: %d bytes", fd, nbytes); if (nbytes > 0) - { - error = read_all (fd, channel, buf, nbytes, &nb); + { + error = read_all (fd, channel, buf, nbytes, &nb); - if (error != G_IO_ERROR_NONE) - return FALSE; + if (error != G_IO_ERROR_NONE) + return FALSE; - if (nb == 0) - { - g_debug ("gio-test: ...from %d: EOF", fd); - shutdown_source (data); - return FALSE; - } - - for (j = 0; j < nbytes; j++) - g_assert (buf[j] == ' ' + (char) ((nbytes + j) % 95)); - g_debug ("gio-test: ...from %d: OK", fd); - } + if (nb == 0) + { + g_debug ("gio-test: ...from %d: EOF", fd); + shutdown_source (data); + return FALSE; + } + + for (j = 0; j < nbytes; j++) + g_assert_cmpint (buf[j], ==, ' ' + (char) ((nbytes + j) % 95)); + g_debug ("gio-test: ...from %d: OK", fd); + } } return retval; } #ifdef G_OS_WIN32 - static gboolean recv_windows_message (GIOChannel *channel, - GIOCondition cond, - gpointer data) + GIOCondition cond, + gpointer data) { GIOError error; MSG msg; gsize nb; - + while (1) { error = g_io_channel_read (channel, (gchar *) &msg, sizeof (MSG), &nb); - + if (error != G_IO_ERROR_NONE) - { - g_print ("gio-test: ...reading Windows message: G_IO_ERROR_%s\n", - (error == G_IO_ERROR_AGAIN ? "AGAIN" : - (error == G_IO_ERROR_INVAL ? "INVAL" : - (error == G_IO_ERROR_UNKNOWN ? "UNKNOWN" : "???")))); - if (error == G_IO_ERROR_AGAIN) - continue; - } + { + g_print ("gio-test: ...reading Windows message: G_IO_ERROR_%s\n", + (error == G_IO_ERROR_AGAIN ? "AGAIN" : + (error == G_IO_ERROR_INVAL ? "INVAL" : + (error == G_IO_ERROR_UNKNOWN ? "UNKNOWN" : "???")))); + if (error == G_IO_ERROR_AGAIN) + continue; + } break; } g_print ("gio-test: ...Windows message for 0x%p: %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT "\n", - msg.hwnd, msg.message, msg.wParam, (gintptr)msg.lParam); + msg.hwnd, msg.message, msg.wParam, (gintptr) msg.lParam); return TRUE; } @@ -232,190 +226,207 @@ LRESULT CALLBACK window_procedure (HWND hwnd, WPARAM wparam, LPARAM lparam); -LRESULT CALLBACK +LRESULT CALLBACK window_procedure (HWND hwnd, - UINT message, - WPARAM wparam, - LPARAM lparam) + UINT message, + WPARAM wparam, + LPARAM lparam) { g_print ("gio-test: window_procedure for 0x%p: %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT "\n", - hwnd, message, wparam, (gintptr)lparam); + hwnd, message, wparam, (gintptr) lparam); return DefWindowProc (hwnd, message, wparam, lparam); } - #endif +static void +spawn_process (int children_nb) +{ + GIOChannel *my_read_channel; + gchar *cmdline; + int i; + +#ifdef G_OS_WIN32 + GTimeVal start, end; + GPollFD pollfd; + int pollresult; + ATOM klass; + static WNDCLASS wcl; + HWND hwnd; + GIOChannel *windows_messages_channel; + + wcl.style = 0; + wcl.lpfnWndProc = window_procedure; + wcl.cbClsExtra = 0; + wcl.cbWndExtra = 0; + wcl.hInstance = GetModuleHandle (NULL); + wcl.hIcon = NULL; + wcl.hCursor = NULL; + wcl.hbrBackground = NULL; + wcl.lpszMenuName = NULL; + wcl.lpszClassName = "gio-test"; + + klass = RegisterClass (&wcl); + + if (!klass) + { + g_print ("gio-test: RegisterClass failed\n"); + exit (1); + } + + hwnd = CreateWindow (MAKEINTATOM(klass), "gio-test", 0, 0, 0, 10, 10, + NULL, NULL, wcl.hInstance, NULL); + if (!hwnd) + { + g_print ("gio-test: CreateWindow failed\n"); + exit (1); + } + + windows_messages_channel = + g_io_channel_win32_new_messages ((guint) (guintptr) hwnd); + g_io_add_watch (windows_messages_channel, G_IO_IN, recv_windows_message, 0); +#endif + + nkiddies = (children_nb > 0 ? children_nb : 1); + seqtab = g_malloc (nkiddies * 2 * sizeof (int)); + + for (i = 0; i < nkiddies; i++) + { + guint *id; + int pipe_to_sub[2], pipe_from_sub[2]; + + if (pipe (pipe_to_sub) == -1 || pipe (pipe_from_sub) == -1) + { + perror ("pipe"); + exit (1); + } + + seqtab[i].fd = pipe_from_sub[0]; + seqtab[i].seq = 0; + + my_read_channel = g_io_channel_unix_new (pipe_from_sub[0]); + + id = g_new (guint, 1); + *id = g_io_add_watch_full (my_read_channel, + G_PRIORITY_DEFAULT, + G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP, + recv_message, + id, g_free); + nrunning++; + +#ifdef G_OS_WIN32 + /* Spawn new Win32 process */ + cmdline = + g_strdup_printf ("%d:%d:0x%p", pipe_to_sub[0], pipe_from_sub[1], hwnd); + _spawnl (_P_NOWAIT, exec_name, exec_name, "--child", cmdline, NULL); +#else + /* Spawn new Unix process */ + cmdline = g_strdup_printf ("%s --child %d:%d &", + exec_name, pipe_to_sub[0], pipe_from_sub[1]); + system (cmdline); +#endif + g_free (cmdline); + + /* Closing pipes */ + close (pipe_to_sub[0]); + close (pipe_from_sub[1]); + +#ifdef G_OS_WIN32 + g_get_current_time (&start); + g_io_channel_win32_make_pollfd (my_read_channel, G_IO_IN, &pollfd); + pollresult = g_io_channel_win32_poll (&pollfd, 1, 100); + g_get_current_time (&end); + if (end.tv_usec < start.tv_usec) + end.tv_sec--, end.tv_usec += 1000000; + g_print ("gio-test: had to wait %ld.%03ld s, result:%d\n", + end.tv_sec - start.tv_sec, + (end.tv_usec - start.tv_usec) / 1000, pollresult); +#endif + + g_io_channel_unref (my_read_channel); + } + + main_loop = g_main_loop_new (NULL, FALSE); + g_main_loop_run (main_loop); + + g_main_loop_unref (main_loop); + g_free (seqtab); +} + +static void +run_process (int argc, char *argv[]) +{ + int readfd, writefd; + GTimeVal tv; + char buf[BUFSIZE]; + int buflen, i, j, n; +#ifdef G_OS_WIN32 + HWND hwnd; +#endif + + g_get_current_time (&tv); + + /* Extract parameters */ + sscanf (argv[2], "%d:%d%n", &readfd, &writefd, &n); +#ifdef G_OS_WIN32 + sscanf (argv[2] + n, ":0x%p", &hwnd); +#endif + + srand (tv.tv_sec ^ (tv.tv_usec / 1000) ^ readfd ^ (writefd << 4)); + + for (i = 0; i < 20 + rand () % 10; i++) + { + g_usleep ((100 + rand () % 10) * 2500); + buflen = rand () % BUFSIZE; + for (j = 0; j < buflen; j++) + buf[j] = ' ' + ((buflen + j) % 95); + g_debug ("gio-test: child writing %d+%d bytes to %d", + (int) (sizeof (i) + sizeof (buflen)), buflen, writefd); + write (writefd, &i, sizeof (i)); + write (writefd, &buflen, sizeof (buflen)); + write (writefd, buf, buflen); + +#ifdef G_OS_WIN32 + if (i % 10 == 0) + { + int msg = WM_USER + (rand () % 100); + WPARAM wparam = rand (); + LPARAM lparam = rand (); + g_print ("gio-test: child posting message %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT " to 0x%p\n", + msg, wparam, (gintptr) lparam, hwnd); + PostMessage (hwnd, msg, wparam, lparam); + } +#endif + } + g_debug ("gio-test: child exiting, closing %d", writefd); + close (writefd); +} + +static void +test_io_basics (void) +{ + spawn_process (1); +#ifndef G_OS_WIN32 + spawn_process (5); +#endif +} + int -main (int argc, - char **argv) +main (int argc, char *argv[]) { - if (argc < 3) + /* Get executable name */ + exec_name = argv[0]; + + /* Run the tests */ + g_test_init (&argc, &argv, NULL); + + /* Run subprocess, if it is the case */ + if (argc > 2) { - /* Parent */ - - GIOChannel *my_read_channel; - gchar *cmdline; - int i; -#ifdef G_OS_WIN32 - GTimeVal start, end; - GPollFD pollfd; - int pollresult; - ATOM klass; - static WNDCLASS wcl; - HWND hwnd; - GIOChannel *windows_messages_channel; -#endif - - nkiddies = (argc == 1 ? 1 : atoi(argv[1])); - seqtab = g_malloc (nkiddies * 2 * sizeof (int)); - -#ifdef G_OS_WIN32 - wcl.style = 0; - wcl.lpfnWndProc = window_procedure; - wcl.cbClsExtra = 0; - wcl.cbWndExtra = 0; - wcl.hInstance = GetModuleHandle (NULL); - wcl.hIcon = NULL; - wcl.hCursor = NULL; - wcl.hbrBackground = NULL; - wcl.lpszMenuName = NULL; - wcl.lpszClassName = "gio-test"; - - klass = RegisterClass (&wcl); - - if (!klass) - { - g_print ("gio-test: RegisterClass failed\n"); - exit (1); - } - - hwnd = CreateWindow (MAKEINTATOM(klass), "gio-test", 0, 0, 0, 10, 10, - NULL, NULL, wcl.hInstance, NULL); - if (!hwnd) - { - g_print ("gio-test: CreateWindow failed\n"); - exit (1); - } - - windows_messages_channel = g_io_channel_win32_new_messages ((guint) (guintptr) hwnd); - g_io_add_watch (windows_messages_channel, G_IO_IN, recv_windows_message, 0); -#endif - - for (i = 0; i < nkiddies; i++) - { - int pipe_to_sub[2], pipe_from_sub[2]; - guint *id; - - if (pipe (pipe_to_sub) == -1 || - pipe (pipe_from_sub) == -1) - perror ("pipe"), exit (1); - - seqtab[i].fd = pipe_from_sub[0]; - seqtab[i].seq = 0; - - my_read_channel = g_io_channel_unix_new (pipe_from_sub[0]); - - id = g_new (guint, 1); - *id = - g_io_add_watch_full (my_read_channel, - G_PRIORITY_DEFAULT, - G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP, - recv_message, - id, g_free); - - nrunning++; - -#ifdef G_OS_WIN32 - cmdline = g_strdup_printf ("%d:%d:0x%p", - pipe_to_sub[0], - pipe_from_sub[1], - hwnd); - _spawnl (_P_NOWAIT, argv[0], argv[0], "--child", cmdline, NULL); -#else - cmdline = g_strdup_printf ("%s --child %d:%d &", argv[0], - pipe_to_sub[0], pipe_from_sub[1]); - - system (cmdline); - g_free (cmdline); -#endif - close (pipe_to_sub[0]); - close (pipe_from_sub [1]); - -#ifdef G_OS_WIN32 - g_get_current_time (&start); - g_io_channel_win32_make_pollfd (my_read_channel, G_IO_IN, &pollfd); - pollresult = g_io_channel_win32_poll (&pollfd, 1, 100); - g_get_current_time (&end); - if (end.tv_usec < start.tv_usec) - end.tv_sec--, end.tv_usec += 1000000; - g_print ("gio-test: had to wait %ld.%03ld s, result:%d\n", - end.tv_sec - start.tv_sec, - (end.tv_usec - start.tv_usec) / 1000, - pollresult); -#endif - g_io_channel_unref (my_read_channel); - } - - main_loop = g_main_loop_new (NULL, FALSE); - - g_main_loop_run (main_loop); - - g_main_loop_unref (main_loop); - g_free (seqtab); + run_process (argc, argv); + return 0; } - else if (argc == 3) - { - /* Child */ - - int readfd, writefd; -#ifdef G_OS_WIN32 - HWND hwnd; -#endif - int i, j; - char buf[BUFSIZE]; - int buflen; - GTimeVal tv; - int n; - - g_get_current_time (&tv); - - sscanf (argv[2], "%d:%d%n", &readfd, &writefd, &n); -#ifdef G_OS_WIN32 - sscanf (argv[2] + n, ":0x%p", &hwnd); -#endif - - srand (tv.tv_sec ^ (tv.tv_usec / 1000) ^ readfd ^ (writefd << 4)); - - for (i = 0; i < 20 + rand() % 20; i++) - { - g_usleep (100 + (rand() % 10) * 5000); - buflen = rand() % BUFSIZE; - for (j = 0; j < buflen; j++) - buf[j] = ' ' + ((buflen + j) % 95); - g_debug ("gio-test: child writing %d+%d bytes to %d", - (int)(sizeof(i) + sizeof(buflen)), buflen, writefd); - write (writefd, &i, sizeof (i)); - write (writefd, &buflen, sizeof (buflen)); - write (writefd, buf, buflen); + g_test_add_func ("/gio/io-basics", test_io_basics); -#ifdef G_OS_WIN32 - if (rand() % 100 < 5) - { - int msg = WM_USER + (rand() % 100); - WPARAM wparam = rand (); - LPARAM lparam = rand (); - g_print ("gio-test: child posting message %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT " to 0x%p\n", - msg, wparam, (gintptr)lparam, hwnd); - PostMessage (hwnd, msg, wparam, lparam); - } -#endif - } - g_debug ("gio-test: child exiting, closing %d", writefd); - close (writefd); - } - else - g_print ("Huh?\n"); - - return 0; + return g_test_run (); } From 38e0781ba75972b38650176106b4a1624cee8321 Mon Sep 17 00:00:00 2001 From: Emmanuel Fleury Date: Wed, 9 Mar 2022 18:27:02 +0100 Subject: [PATCH 2/4] Convert deprecated GTimeVal to GDateTime in tests/gio-test.c --- tests/gio-test.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/tests/gio-test.c b/tests/gio-test.c index 3bab515eb..e26ebdb3d 100644 --- a/tests/gio-test.c +++ b/tests/gio-test.c @@ -24,9 +24,6 @@ #include #include -#include -#include -#include #ifdef G_OS_WIN32 #include @@ -246,7 +243,7 @@ spawn_process (int children_nb) int i; #ifdef G_OS_WIN32 - GTimeVal start, end; + gint64 start, end; GPollFD pollfd; int pollresult; ATOM klass; @@ -331,17 +328,14 @@ spawn_process (int children_nb) close (pipe_from_sub[1]); #ifdef G_OS_WIN32 - g_get_current_time (&start); + start = g_get_monotonic_time(); g_io_channel_win32_make_pollfd (my_read_channel, G_IO_IN, &pollfd); pollresult = g_io_channel_win32_poll (&pollfd, 1, 100); - g_get_current_time (&end); - if (end.tv_usec < start.tv_usec) - end.tv_sec--, end.tv_usec += 1000000; - g_print ("gio-test: had to wait %ld.%03ld s, result:%d\n", - end.tv_sec - start.tv_sec, - (end.tv_usec - start.tv_usec) / 1000, pollresult); -#endif + end = g_get_monotonic_time(); + g_print ("gio-test: had to wait %" G_GINT64_FORMAT "s, result:%d\n", + (end - start) / 1000000, pollresult); +#endif g_io_channel_unref (my_read_channel); } @@ -356,22 +350,21 @@ static void run_process (int argc, char *argv[]) { int readfd, writefd; - GTimeVal tv; + gint64 dt; char buf[BUFSIZE]; int buflen, i, j, n; #ifdef G_OS_WIN32 HWND hwnd; #endif - g_get_current_time (&tv); - /* Extract parameters */ sscanf (argv[2], "%d:%d%n", &readfd, &writefd, &n); #ifdef G_OS_WIN32 sscanf (argv[2] + n, ":0x%p", &hwnd); #endif - srand (tv.tv_sec ^ (tv.tv_usec / 1000) ^ readfd ^ (writefd << 4)); + dt = g_get_monotonic_time(); + srand (dt ^ (dt / 1000) ^ readfd ^ (writefd << 4)); for (i = 0; i < 20 + rand () % 10; i++) { From 4589ff080d153968977557249679ddeb46501d35 Mon Sep 17 00:00:00 2001 From: Emmanuel Fleury Date: Sun, 13 Mar 2022 10:57:32 +0100 Subject: [PATCH 3/4] Move test/gio-test.c to glib/test/io-channel-basic.c Helps issue #1434 --- .../tests/io-channel-basic.c | 43 +++++++++++-------- glib/tests/meson.build | 1 + tests/meson.build | 1 - 3 files changed, 25 insertions(+), 20 deletions(-) rename tests/gio-test.c => glib/tests/io-channel-basic.c (86%) diff --git a/tests/gio-test.c b/glib/tests/io-channel-basic.c similarity index 86% rename from tests/gio-test.c rename to glib/tests/io-channel-basic.c index e26ebdb3d..4e3b9fea7 100644 --- a/tests/gio-test.c +++ b/glib/tests/io-channel-basic.c @@ -19,6 +19,11 @@ * Just run it. Optional parameter is number of sub-processes. */ +/* We are using g_io_channel_read() which is deprecated */ +#ifndef GLIB_DISABLE_DEPRECATION_WARNINGS +#define GLIB_DISABLE_DEPRECATION_WARNINGS +#endif + #include "config.h" #include @@ -74,7 +79,7 @@ read_all (int fd, if (error != G_IO_ERROR_NONE) { - g_print ("gio-test: ...from %d: %d\n", fd, error); + g_print ("io-channel-basic: ...from %d: %d\n", fd, error); if (error == G_IO_ERROR_AGAIN) continue; break; @@ -107,7 +112,7 @@ recv_message (GIOChannel *channel, gint fd = g_io_channel_unix_get_fd (channel); gboolean retval = TRUE; - g_debug ("gio-test: ...from %d:%s%s%s%s", fd, + g_debug ("io-channel-basic: ...from %d:%s%s%s%s", fd, (cond & G_IO_ERR) ? " ERR" : "", (cond & G_IO_HUP) ? " HUP" : "", (cond & G_IO_IN) ? " IN" : "", @@ -133,7 +138,7 @@ recv_message (GIOChannel *channel, { if (nb == 0) { - g_debug ("gio-test: ...from %d: EOF", fd); + g_debug ("io-channel-basic: ...from %d: EOF", fd); shutdown_source (data); return FALSE; } @@ -156,14 +161,14 @@ recv_message (GIOChannel *channel, if (nb == 0) { - g_debug ("gio-test: ...from %d: EOF", fd); + g_debug ("io-channel-basic: ...from %d: EOF", fd); shutdown_source (data); return FALSE; } g_assert_cmpuint (nb, ==, sizeof (nbytes)); g_assert_cmpuint (nbytes, <, BUFSIZE); - g_debug ("gio-test: ...from %d: %d bytes", fd, nbytes); + g_debug ("io-channel-basic: ...from %d: %d bytes", fd, nbytes); if (nbytes > 0) { error = read_all (fd, channel, buf, nbytes, &nb); @@ -173,14 +178,14 @@ recv_message (GIOChannel *channel, if (nb == 0) { - g_debug ("gio-test: ...from %d: EOF", fd); + g_debug ("io-channel-basic: ...from %d: EOF", fd); shutdown_source (data); return FALSE; } for (j = 0; j < nbytes; j++) g_assert_cmpint (buf[j], ==, ' ' + (char) ((nbytes + j) % 95)); - g_debug ("gio-test: ...from %d: OK", fd); + g_debug ("io-channel-basic: ...from %d: OK", fd); } } return retval; @@ -202,7 +207,7 @@ recv_windows_message (GIOChannel *channel, if (error != G_IO_ERROR_NONE) { - g_print ("gio-test: ...reading Windows message: G_IO_ERROR_%s\n", + g_print ("io-channel-basic: ...reading Windows message: G_IO_ERROR_%s\n", (error == G_IO_ERROR_AGAIN ? "AGAIN" : (error == G_IO_ERROR_INVAL ? "INVAL" : (error == G_IO_ERROR_UNKNOWN ? "UNKNOWN" : "???")))); @@ -212,7 +217,7 @@ recv_windows_message (GIOChannel *channel, break; } - g_print ("gio-test: ...Windows message for 0x%p: %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT "\n", + g_print ("io-channel-basic: ...Windows message for 0x%p: %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT "\n", msg.hwnd, msg.message, msg.wParam, (gintptr) msg.lParam); return TRUE; @@ -229,7 +234,7 @@ window_procedure (HWND hwnd, WPARAM wparam, LPARAM lparam) { - g_print ("gio-test: window_procedure for 0x%p: %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT "\n", + g_print ("io-channel-basic: window_procedure for 0x%p: %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT "\n", hwnd, message, wparam, (gintptr) lparam); return DefWindowProc (hwnd, message, wparam, lparam); } @@ -260,21 +265,21 @@ spawn_process (int children_nb) wcl.hCursor = NULL; wcl.hbrBackground = NULL; wcl.lpszMenuName = NULL; - wcl.lpszClassName = "gio-test"; + wcl.lpszClassName = "io-channel-basic"; klass = RegisterClass (&wcl); if (!klass) { - g_print ("gio-test: RegisterClass failed\n"); + g_print ("io-channel-basic: RegisterClass failed\n"); exit (1); } - hwnd = CreateWindow (MAKEINTATOM(klass), "gio-test", 0, 0, 0, 10, 10, + hwnd = CreateWindow (MAKEINTATOM(klass), "io-channel-basic", 0, 0, 0, 10, 10, NULL, NULL, wcl.hInstance, NULL); if (!hwnd) { - g_print ("gio-test: CreateWindow failed\n"); + g_print ("io-channel-basic: CreateWindow failed\n"); exit (1); } @@ -333,8 +338,8 @@ spawn_process (int children_nb) pollresult = g_io_channel_win32_poll (&pollfd, 1, 100); end = g_get_monotonic_time(); - g_print ("gio-test: had to wait %" G_GINT64_FORMAT "s, result:%d\n", - (end - start) / 1000000, pollresult); + g_print ("io-channel-basic: had to wait %" G_GINT64_FORMAT "s, result:%d\n", + g_date_time_difference (end, start) / 1000000, pollresult); #endif g_io_channel_unref (my_read_channel); } @@ -372,7 +377,7 @@ run_process (int argc, char *argv[]) buflen = rand () % BUFSIZE; for (j = 0; j < buflen; j++) buf[j] = ' ' + ((buflen + j) % 95); - g_debug ("gio-test: child writing %d+%d bytes to %d", + g_debug ("io-channel-basic: child writing %d+%d bytes to %d", (int) (sizeof (i) + sizeof (buflen)), buflen, writefd); write (writefd, &i, sizeof (i)); write (writefd, &buflen, sizeof (buflen)); @@ -384,13 +389,13 @@ run_process (int argc, char *argv[]) int msg = WM_USER + (rand () % 100); WPARAM wparam = rand (); LPARAM lparam = rand (); - g_print ("gio-test: child posting message %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT " to 0x%p\n", + g_print ("io-channel-basic: child posting message %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT " to 0x%p\n", msg, wparam, (gintptr) lparam, hwnd); PostMessage (hwnd, msg, wparam, lparam); } #endif } - g_debug ("gio-test: child exiting, closing %d", writefd); + g_debug ("io-channel-basic: child exiting, closing %d", writefd); close (writefd); } diff --git a/glib/tests/meson.build b/glib/tests/meson.build index 07490a079..557806f94 100644 --- a/glib/tests/meson.build +++ b/glib/tests/meson.build @@ -45,6 +45,7 @@ glib_tests = { 'hmac' : {}, 'hook' : {}, 'hostutils' : {}, + 'io-channel-basic' : {}, 'io-channel' : {}, 'keyfile' : {}, 'list' : {}, diff --git a/tests/meson.build b/tests/meson.build index 9c8821132..a74453d6d 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -16,7 +16,6 @@ subdir('gobject') subdir('refcount') tests = { - 'gio-test' : {}, 'slice-threadinit' : { 'dependencies' : [libgthread_dep], }, From 87a4cea9e486c000bce5f2d08a5d575ede362801 Mon Sep 17 00:00:00 2001 From: Emmanuel Fleury Date: Wed, 11 May 2022 07:54:03 +0200 Subject: [PATCH 4/4] Convert g_printf() to g_test_message() to capture messages on TAP --- glib/tests/io-channel-basic.c | 37 ++++++++++++----------------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/glib/tests/io-channel-basic.c b/glib/tests/io-channel-basic.c index 4e3b9fea7..70b3a9dfc 100644 --- a/glib/tests/io-channel-basic.c +++ b/glib/tests/io-channel-basic.c @@ -79,7 +79,7 @@ read_all (int fd, if (error != G_IO_ERROR_NONE) { - g_print ("io-channel-basic: ...from %d: %d\n", fd, error); + g_test_message ("io-channel-basic: ...from %d: %d", fd, error); if (error == G_IO_ERROR_AGAIN) continue; break; @@ -207,18 +207,16 @@ recv_windows_message (GIOChannel *channel, if (error != G_IO_ERROR_NONE) { - g_print ("io-channel-basic: ...reading Windows message: G_IO_ERROR_%s\n", - (error == G_IO_ERROR_AGAIN ? "AGAIN" : - (error == G_IO_ERROR_INVAL ? "INVAL" : - (error == G_IO_ERROR_UNKNOWN ? "UNKNOWN" : "???")))); + g_test_message ("io-channel-basic: ...reading Windows message: G_IO_ERROR_%s", + (error == G_IO_ERROR_AGAIN ? "AGAIN" : (error == G_IO_ERROR_INVAL ? "INVAL" : (error == G_IO_ERROR_UNKNOWN ? "UNKNOWN" : "???")))); if (error == G_IO_ERROR_AGAIN) continue; } break; } - g_print ("io-channel-basic: ...Windows message for 0x%p: %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT "\n", - msg.hwnd, msg.message, msg.wParam, (gintptr) msg.lParam); + g_test_message ("io-channel-basic: ...Windows message for 0x%p: %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT, + msg.hwnd, msg.message, msg.wParam, (gintptr) msg.lParam); return TRUE; } @@ -234,8 +232,8 @@ window_procedure (HWND hwnd, WPARAM wparam, LPARAM lparam) { - g_print ("io-channel-basic: window_procedure for 0x%p: %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT "\n", - hwnd, message, wparam, (gintptr) lparam); + g_test_message ("io-channel-basic: window_procedure for 0x%p: %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT, + hwnd, message, wparam, (gintptr) lparam); return DefWindowProc (hwnd, message, wparam, lparam); } #endif @@ -268,20 +266,11 @@ spawn_process (int children_nb) wcl.lpszClassName = "io-channel-basic"; klass = RegisterClass (&wcl); - - if (!klass) - { - g_print ("io-channel-basic: RegisterClass failed\n"); - exit (1); - } + g_assert_cmpint (klass, !=, 0); hwnd = CreateWindow (MAKEINTATOM(klass), "io-channel-basic", 0, 0, 0, 10, 10, NULL, NULL, wcl.hInstance, NULL); - if (!hwnd) - { - g_print ("io-channel-basic: CreateWindow failed\n"); - exit (1); - } + g_assert_nonnull (hwnd); windows_messages_channel = g_io_channel_win32_new_messages ((guint) (guintptr) hwnd); @@ -338,8 +327,8 @@ spawn_process (int children_nb) pollresult = g_io_channel_win32_poll (&pollfd, 1, 100); end = g_get_monotonic_time(); - g_print ("io-channel-basic: had to wait %" G_GINT64_FORMAT "s, result:%d\n", - g_date_time_difference (end, start) / 1000000, pollresult); + g_test_message ("io-channel-basic: had to wait %" G_GINT64_FORMAT "s, result:%d", + (end - start) / 1000000, pollresult); #endif g_io_channel_unref (my_read_channel); } @@ -389,8 +378,8 @@ run_process (int argc, char *argv[]) int msg = WM_USER + (rand () % 100); WPARAM wparam = rand (); LPARAM lparam = rand (); - g_print ("io-channel-basic: child posting message %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT " to 0x%p\n", - msg, wparam, (gintptr) lparam, hwnd); + g_test_message ("io-channel-basic: child posting message %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT " to 0x%p", + msg, wparam, (gintptr) lparam, hwnd); PostMessage (hwnd, msg, wparam, lparam); } #endif