Thomas Faber : msvcrt/tests: Show that spawn does not require locking of fds.

Alexandre Julliard julliard at winehq.org
Tue Apr 12 13:38:03 CDT 2022


Module: wine
Branch: oldstable
Commit: d1833f8ea618bcaa71ba31aa3f3fd099cfc929e7
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=d1833f8ea618bcaa71ba31aa3f3fd099cfc929e7

Author: Thomas Faber <thomas.faber at reactos.org>
Date:   Thu Nov 11 17:42:58 2021 -0500

msvcrt/tests: Show that spawn does not require locking of fds.

Signed-off-by: Thomas Faber <thomas.faber at reactos.org>
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit be0684dad50ffbc93b3ded4fbfebf1d1e4690589)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 dlls/msvcrt/tests/file.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)

diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c
index 0cf8bad124f..206c01695ca 100644
--- a/dlls/msvcrt/tests/file.c
+++ b/dlls/msvcrt/tests/file.c
@@ -1550,6 +1550,18 @@ static void test_stdout_handle( STARTUPINFOA *startup, char *cmdline, HANDLE hst
     DeleteFileA( "fdopen.err" );
 }
 
+static unsigned WINAPI read_pipe_thread(void *argument)
+{
+    unsigned char buffer[2];
+    int ret;
+    int *pipefds = argument;
+
+    ret = _read(pipefds[0], buffer, sizeof(buffer));
+    ok(ret == 1, "ret = %d\n", ret);
+    ok(buffer[0] == 'a', "%x\n", buffer[0]);
+    return 0;
+}
+
 static void test_file_inherit( const char* selfname )
 {
     int			fd;
@@ -1559,6 +1571,9 @@ static void test_file_inherit( const char* selfname )
     STARTUPINFOA startup;
     SECURITY_ATTRIBUTES sa;
     HANDLE handles[3];
+    HANDLE thread_handle;
+    int pipefds[2];
+    intptr_t ret;
 
     fd = open ("fdopen.tst", O_CREAT | O_RDWR | O_BINARY, _S_IREAD |_S_IWRITE);
     ok(fd != -1, "Couldn't create test file\n");
@@ -1567,7 +1582,8 @@ static void test_file_inherit( const char* selfname )
     arg_v[2] = "inherit";
     arg_v[3] = buffer; sprintf(buffer, "%d", fd);
     arg_v[4] = 0;
-    _spawnvp(_P_WAIT, selfname, arg_v);
+    ret = _spawnvp(_P_WAIT, selfname, arg_v);
+    ok(ret == 0, "_spawnvp returned %d, errno %d\n", ret, errno);
     ok(tell(fd) == 8, "bad position %lu expecting 8\n", tell(fd));
     lseek(fd, 0, SEEK_SET);
     ok(read(fd, buffer, sizeof (buffer)) == 8 && memcmp(buffer, "Success", 8) == 0, "Couldn't read back the data\n");
@@ -1580,12 +1596,37 @@ static void test_file_inherit( const char* selfname )
     arg_v[2] = "inherit_no";
     arg_v[3] = buffer; sprintf(buffer, "%d", fd);
     arg_v[4] = 0;
-    _spawnvp(_P_WAIT, selfname, arg_v);
+    ret = _spawnvp(_P_WAIT, selfname, arg_v);
+    ok(ret == 0, "_spawnvp returned %d, errno %d\n", ret, errno);
     ok(tell(fd) == 0, "bad position %lu expecting 0\n", tell(fd));
     ok(read(fd, buffer, sizeof (buffer)) == 0, "Found unexpected data (%s)\n", buffer);
     close (fd);
     ok(unlink("fdopen.tst") == 0, "Couldn't unlink\n");
 
+    /* Show that spawn works while a read is active */
+    ok(_pipe(pipefds, 1, O_BINARY) == 0, "_pipe() failed\n");
+    thread_handle = (HANDLE)_beginthreadex(NULL, 0, read_pipe_thread, pipefds, 0, NULL);
+    Sleep(100); /* try to make sure the thread is reading */
+    fd = open ("fdopen.tst", O_CREAT | O_RDWR | O_BINARY, _S_IREAD |_S_IWRITE);
+    ok(fd != -1, "Couldn't create test file\n");
+    arg_v[1] = "tests/file.c";
+    arg_v[2] = "inherit";
+    arg_v[3] = buffer; sprintf(buffer, "%d", fd);
+    arg_v[4] = 0;
+    ret = _spawnvp(_P_WAIT, selfname, arg_v);
+    ok(ret == 0, "_spawnvp returned %Id, errno %d\n", ret, errno);
+    ret = tell(fd);
+    ok(ret == 8, "bad position %Iu expecting 8\n", ret);
+    lseek(fd, 0, SEEK_SET);
+    ok(read(fd, buffer, sizeof (buffer)) == 8 && memcmp(buffer, "Success", 8) == 0, "Couldn't read back the data\n");
+    close (fd);
+    ok(unlink("fdopen.tst") == 0, "Couldn't unlink\n");
+    _write(pipefds[1], "a", 1);
+    WaitForSingleObject(thread_handle, INFINITE);
+    CloseHandle(thread_handle);
+    close(pipefds[0]);
+    close(pipefds[1]);
+
     /* make file handle inheritable */
     sa.nLength = sizeof(sa);
     sa.lpSecurityDescriptor = NULL;




More information about the wine-cvs mailing list