1111 * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
1212 * Portions Copyright (c) 1994, Regents of the University of California
1313 *
14- * $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.6 2006/07/2001:16:57 tgl Exp $
14+ * $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.7 2006/07/2002:10:00 tgl Exp $
1515 *
1616 *-------------------------------------------------------------------------
1717 */
@@ -919,47 +919,70 @@ results_differ(const char *testname)
919919
920920/*
921921 * Wait for specified subprocesses to finish
922+ *
923+ * If names isn't NULL, report each subprocess as it finishes
924+ *
925+ * Note: it's OK to scribble on the pids array, but not on the names array
922926 */
923927static void
924- wait_for_tests (PID_TYPE * pids ,int num_tests )
928+ wait_for_tests (PID_TYPE * pids ,char * * names , int num_tests )
925929{
926- #ifndef WIN32
927930int tests_left ;
928931int i ;
929932
933+ #ifdef WIN32
934+ PID_TYPE * active_pids = malloc (num_tests * sizeof (PID_TYPE ));
935+
936+ memcpy (active_pids ,pids ,num_tests * sizeof (PID_TYPE ));
937+ #endif
938+
930939tests_left = num_tests ;
931940while (tests_left > 0 )
932941{
933- pid_t p = wait ( NULL ) ;
942+ PID_TYPE p ;
934943
935- if (p == -1 )
944+ #ifndef WIN32
945+ p = wait (NULL );
946+
947+ if (p == INVALID_PID )
936948{
937- fprintf (stderr ,_ ("could not wait(): %s\n" ),strerror (errno ));
949+ fprintf (stderr ,_ ("failed to wait for subprocesses: %s\n" ),
950+ strerror (errno ));
938951exit_nicely (2 );
939952}
953+ #else
954+ int r ;
955+
956+ r = WaitForMultipleObjects (tests_left ,active_pids , FALSE,INFINITE );
957+ if (r < WAIT_OBJECT_0 || r >=WAIT_OBJECT_0 + tests_left )
958+ {
959+ fprintf (stderr ,_ ("failed to wait for subprocesses: %lu\n" ),
960+ GetLastError ());
961+ exit_nicely (2 );
962+ }
963+ p = active_pids [r - WAIT_OBJECT_0 ];
964+ /* compact the active_pids array */
965+ active_pids [r - WAIT_OBJECT_0 ]= active_pids [tests_left - 1 ];
966+ #endif /* WIN32 */
967+
940968for (i = 0 ;i < num_tests ;i ++ )
941969{
942- /* Make sure we only count the processes we explicitly started */
943970if (p == pids [i ])
944971{
945- pids [i ]= -1 ;
972+ #ifdef WIN32
973+ CloseHandle (pids [i ]);
974+ #endif
975+ pids [i ]= INVALID_PID ;
976+ if (names )
977+ status (" %s" ,names [i ]);
946978tests_left -- ;
979+ break ;
947980}
948981}
949982}
950- #else
951- int r ;
952- int i ;
953983
954- r = WaitForMultipleObjects (num_tests ,pids , TRUE,INFINITE );
955- if (r != WAIT_OBJECT_0 )
956- {
957- fprintf (stderr ,_ ("could not wait for commands to finish: %lu\n" ),
958- GetLastError ());
959- exit_nicely (2 );
960- }
961- for (i = 0 ;i < num_tests ;i ++ )
962- CloseHandle (pids [i ]);
984+ #ifdef WIN32
985+ free (active_pids );
963986#endif
964987}
965988
@@ -1059,7 +1082,7 @@ run_schedule(const char *schedule)
10591082{
10601083status (_ ("test %-20s ... " ),tests [0 ]);
10611084pids [0 ]= psql_start_test (tests [0 ]);
1062- wait_for_tests (pids ,1 );
1085+ wait_for_tests (pids ,NULL , 1 );
10631086/* status line is finished below */
10641087}
10651088else if (max_connections > 0 && max_connections < num_tests )
@@ -1072,24 +1095,22 @@ run_schedule(const char *schedule)
10721095{
10731096if (i - oldest >=max_connections )
10741097{
1075- wait_for_tests (pids + oldest ,i - oldest );
1098+ wait_for_tests (pids + oldest ,tests + oldest , i - oldest );
10761099oldest = i ;
10771100}
1078- status (" %s" ,tests [i ]);
10791101pids [i ]= psql_start_test (tests [i ]);
10801102}
1081- wait_for_tests (pids + oldest ,i - oldest );
1103+ wait_for_tests (pids + oldest ,tests + oldest , i - oldest );
10821104status_end ();
10831105}
10841106else
10851107{
10861108status (_ ("parallel group (%d tests): " ),num_tests );
10871109for (i = 0 ;i < num_tests ;i ++ )
10881110{
1089- status (" %s" ,tests [i ]);
10901111pids [i ]= psql_start_test (tests [i ]);
10911112}
1092- wait_for_tests (pids ,num_tests );
1113+ wait_for_tests (pids ,tests , num_tests );
10931114status_end ();
10941115}
10951116
@@ -1146,7 +1167,7 @@ run_single_test(const char *test)
11461167
11471168status (_ ("test %-20s ... " ),test );
11481169pid = psql_start_test (test );
1149- wait_for_tests (& pid ,1 );
1170+ wait_for_tests (& pid ,NULL , 1 );
11501171
11511172if (results_differ (test ))
11521173{