From 7a382438aa5a521473ecc740319d92d69e5f45ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 6 Jul 2022 16:06:12 +0200 Subject: [PATCH] glib/tests: Ensure that calls to write, system, symlink and pipe are checked Assert that calls to such system calls are returning the expected values --- glib/tests/fileutils.c | 12 ++++++------ glib/tests/io-channel-basic.c | 8 ++++---- glib/tests/mainloop.c | 4 ++-- glib/tests/spawn-multithreaded.c | 8 ++++---- glib/tests/unix.c | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/glib/tests/fileutils.c b/glib/tests/fileutils.c index 819700958..2f38a3282 100644 --- a/glib/tests/fileutils.c +++ b/glib/tests/fileutils.c @@ -1469,7 +1469,7 @@ test_file_test (void) fd = g_file_open_tmp (NULL, &name, &error); g_assert_no_error (error); - write (fd, "a", 1); + g_assert_cmpint (write (fd, "a", 1), ==, 1); g_assert_cmpint (g_fsync (fd), ==, 0); close (fd); @@ -1477,7 +1477,7 @@ test_file_test (void) result = g_file_test (name, G_FILE_TEST_IS_SYMLINK); g_assert_false (result); - symlink (name, "symlink"); + g_assert_no_errno (symlink (name, "symlink")); result = g_file_test ("symlink", G_FILE_TEST_IS_SYMLINK); g_assert_true (result); unlink ("symlink"); @@ -1500,7 +1500,7 @@ test_set_contents (void) fd = g_file_open_tmp (NULL, &name, &error); g_assert_no_error (error); - write (fd, "a", 1); + g_assert_cmpint (write (fd, "a", 1), ==, 1); g_assert_cmpint (g_fsync (fd), ==, 0); close (fd); @@ -1593,7 +1593,7 @@ test_set_contents_full (void) fd = g_file_open_tmp (NULL, &file_name, &error); g_assert_no_error (error); - write (fd, "a", 1); + g_assert_cmpint (write (fd, "a", 1), ==, 1); g_assert_no_errno (g_fsync (fd)); close (fd); @@ -1726,7 +1726,7 @@ test_set_contents_full_read_only_file (void) * existing file permissions. */ fd = g_file_open_tmp (NULL, &file_name, &error); g_assert_no_error (error); - write (fd, "a", 1); + g_assert_cmpint (write (fd, "a", 1), ==, 1); g_assert_no_errno (g_fsync (fd)); close (fd); g_assert_no_errno (g_chmod (file_name, 0400)); /* S_IREAD */ @@ -1800,7 +1800,7 @@ test_set_contents_full_read_only_directory (void) file_name = g_build_filename (dir_name, "file", NULL); fd = g_open (file_name, O_CREAT | O_RDWR, 0644); g_assert_cmpint (fd, >=, 0); - write (fd, "a", 1); + g_assert_cmpint (write (fd, "a", 1), ==, 1); g_assert_no_errno (g_fsync (fd)); close (fd); diff --git a/glib/tests/io-channel-basic.c b/glib/tests/io-channel-basic.c index 142e38bec..c1a46cd07 100644 --- a/glib/tests/io-channel-basic.c +++ b/glib/tests/io-channel-basic.c @@ -320,7 +320,7 @@ spawn_process (int children_nb) /* Spawn new Unix process */ cmdline = g_strdup_printf ("%s --child %d:%d &", exec_name, pipe_to_sub[0], pipe_from_sub[1]); - system (cmdline); + g_assert_no_errno (system (cmdline)); #endif g_free (cmdline); @@ -375,9 +375,9 @@ run_process (int argc, char *argv[]) buf[j] = ' ' + ((buflen + j) % 95); 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)); - write (writefd, buf, buflen); + g_assert_cmpint (write (writefd, &i, sizeof (i)), ==, sizeof (i)); + g_assert_cmpint (write (writefd, &buflen, sizeof (buflen)), ==, sizeof (buflen)); + g_assert_cmpint (write (writefd, buf, buflen), ==, buflen); #ifdef G_OS_WIN32 if (i % 10 == 0) diff --git a/glib/tests/mainloop.c b/glib/tests/mainloop.c index fd3cac1b9..105bec87e 100644 --- a/glib/tests/mainloop.c +++ b/glib/tests/mainloop.c @@ -1467,8 +1467,8 @@ test_source_unix_fd_api (void) gint fds_a[2]; gint fds_b[2]; - pipe (fds_a); - pipe (fds_b); + g_assert_cmpint (pipe (fds_a), ==, 0); + g_assert_cmpint (pipe (fds_b), ==, 0); source_a = g_source_new (&no_funcs, sizeof (FlagSource)); source_b = g_source_new (&no_funcs, sizeof (FlagSource)); diff --git a/glib/tests/spawn-multithreaded.c b/glib/tests/spawn-multithreaded.c index 8dbc7bfbb..9e399b43d 100644 --- a/glib/tests/spawn-multithreaded.c +++ b/glib/tests/spawn-multithreaded.c @@ -157,9 +157,9 @@ test_spawn_childs (void) main_loop = g_main_loop_new (NULL, FALSE); #ifdef G_OS_WIN32 - system ("cd ."); + g_assert_no_errno (system ("cd .")); #else - system ("true"); + g_assert_no_errno (system ("true")); #endif n_alive = 2; @@ -200,9 +200,9 @@ test_spawn_childs_threads (void) main_loop = g_main_loop_new (NULL, FALSE); #ifdef G_OS_WIN32 - system ("cd ."); + g_assert_no_errno (system ("cd .")); #else - system ("true"); + g_assert_no_errno (system ("true")); #endif n_alive = 2; diff --git a/glib/tests/unix.c b/glib/tests/unix.c index 7639d066a..2112cab6b 100644 --- a/glib/tests/unix.c +++ b/glib/tests/unix.c @@ -40,7 +40,7 @@ test_pipe (void) g_assert (res); g_assert_no_error (error); - write (pipefd[1], "hello", sizeof ("hello")); + g_assert_cmpint (write (pipefd[1], "hello", sizeof ("hello")), ==, sizeof ("hello")); memset (buf, 0, sizeof (buf)); bytes_read = read (pipefd[0], buf, sizeof(buf) - 1); g_assert_cmpint (bytes_read, >, 0);