You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by rb...@apache.org on 2002/11/26 17:02:37 UTC
cvs commit: apr/test Makefile.in test_apr.h testall.c testproc.c
rbb 2002/11/26 08:02:37
Modified: test Makefile.in test_apr.h testall.c testproc.c
Log:
Migrate testproc to the new test suite.
Revision Changes Path
1.115 +9 -17 apr/test/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apr/test/Makefile.in,v
retrieving revision 1.114
retrieving revision 1.115
diff -u -r1.114 -r1.115
--- Makefile.in 26 Nov 2002 10:25:11 -0000 1.114
+++ Makefile.in 26 Nov 2002 16:02:37 -0000 1.115
@@ -12,7 +12,6 @@
server@EXEEXT@ \
testnames@EXEEXT@ \
testflock@EXEEXT@ \
- testproc@EXEEXT@ \
testsock@EXEEXT@ \
testthread@EXEEXT@ \
testlock@EXEEXT@ \
@@ -21,12 +20,10 @@
testshmproducer@EXEEXT@ \
testshmconsumer@EXEEXT@ \
testpipe@EXEEXT@ \
- testoc@EXEEXT@ \
testsockopt@EXEEXT@ \
testpoll@EXEEXT@ \
testhash@EXEEXT@ \
testuser@EXEEXT@ \
- testdup@EXEEXT@ \
testatomic@EXEEXT@ \
testmutexscope@EXEEXT@ \
testall@EXEEXT@
@@ -39,7 +36,7 @@
LOCAL_LIBS=../lib@APR_LIBNAME@.la
-CLEAN_TARGETS = testfile.tmp testdso@EXEEXT@ mod_test.slo
+CLEAN_TARGETS = testfile.tmp mod_test.slo proc_child@EXEEXT@
INCDIR=../include
INCLUDES=-I$(INCDIR)
@@ -64,12 +61,12 @@
testflock@EXEEXT@: testflock.lo $(LOCAL_LIBS)
$(LINK) testflock.lo $(LOCAL_LIBS) $(ALL_LIBS)
-testdso@EXEEXT@: testdso.lo mod_test.la libmod_test.la $(LOCAL_LIBS)
- $(LINK) testdso.lo $(LOCAL_LIBS) $(ALL_LIBS)
-
occhild@EXEEXT@: occhild.lo $(LOCAL_LIBS)
$(LINK) occhild.lo $(LOCAL_LIBS) $(ALL_LIBS)
+proc_child@EXEEXT@: proc_child.lo $(LOCAL_LIBS)
+ $(LINK) proc_child.lo $(LOCAL_LIBS) $(ALL_LIBS)
+
# FIXME: -prefer-pic is only supported with libtool-1.4+
mod_test.slo: mod_test.c
$(LIBTOOL) --mode=compile $(COMPILE) -prefer-pic -c mod_test.c && touch $@
@@ -83,9 +80,6 @@
testargs@EXEEXT@: testargs.lo $(LOCAL_LIBS)
$(LINK) testargs.lo $(LOCAL_LIBS) $(ALL_LIBS)
-testproc@EXEEXT@: testproc.lo $(LOCAL_LIBS)
- $(LINK) testproc.lo $(LOCAL_LIBS) $(ALL_LIBS)
-
testthread@EXEEXT@: testthread.lo $(LOCAL_LIBS)
$(LINK) testthread.lo $(LOCAL_LIBS) $(ALL_LIBS)
@@ -140,22 +134,20 @@
testatomic@EXEEXT@: testatomic.lo $(LOCAL_LIBS)
$(LINK) testatomic.lo $(LOCAL_LIBS) $(ALL_LIBS)
-testdup@EXEEXT@: testdup.lo $(LOCAL_LIBS)
- $(LINK) testdup.lo $(LOCAL_LIBS) $(ALL_LIBS)
-
testmutexscope@EXEEXT@: testmutexscope.lo $(LOCAL_LIBS)
$(LINK) testmutexscope.lo $(LOCAL_LIBS) $(ALL_LIBS)
testall: testall.lo testtime.lo teststr.lo testvsn.lo testipsub.lo \
testmmap.lo testud.lo testtable.lo testsleep.lo testpools.lo \
testfmt.lo testfile.lo testdir.lo testfileinfo.lo testrand.lo \
- testdso.lo testoc.lo testdup.lo testsockets.lo CuTest.lo mod_test.la \
- libmod_test.la occhild@EXEEXT@ $(LOCAL_LIBS)
+ testdso.lo testoc.lo testdup.lo testsockets.lo testproc.lo \
+ CuTest.lo mod_test.la libmod_test.la occhild@EXEEXT@ \
+ proc_child@EXEEXT@ $(LOCAL_LIBS)
$(LINK) testall.lo testtime.lo teststr.lo testvsn.lo testipsub.lo \
testmmap.lo testud.lo testtable.lo testsleep.lo testpools.lo \
testfmt.lo testfile.lo testdir.lo testfileinfo.lo testrand.lo \
- testdso.lo testoc.lo testdup.lo testsockets.lo CuTest.lo \
- $(LOCAL_LIBS) $(ALL_LIBS)
+ testdso.lo testoc.lo testdup.lo testsockets.lo testproc.lo \
+ CuTest.lo $(LOCAL_LIBS) $(ALL_LIBS)
# DO NOT REMOVE
1.27 +1 -0 apr/test/test_apr.h
Index: test_apr.h
===================================================================
RCS file: /home/cvs/apr/test/test_apr.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- test_apr.h 24 Nov 2002 06:54:55 -0000 1.26
+++ test_apr.h 26 Nov 2002 16:02:37 -0000 1.27
@@ -84,6 +84,7 @@
CuSuite *testoc(void);
CuSuite *testdup(void);
CuSuite *testsockets(void);
+CuSuite *testproc(void);
1.25 +1 -0 apr/test/testall.c
Index: testall.c
===================================================================
RCS file: /home/cvs/apr/test/testall.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- testall.c 24 Nov 2002 06:54:55 -0000 1.24
+++ testall.c 26 Nov 2002 16:02:37 -0000 1.25
@@ -82,6 +82,7 @@
{"testdso", testdso},
{"testoc", testoc},
{"testsockets", testsockets},
+ {"testproc", testproc},
{"LastTest", NULL}
};
1.38 +110 -174 apr/test/testproc.c
Index: testproc.c
===================================================================
RCS file: /home/cvs/apr/test/testproc.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- testproc.c 11 Oct 2002 12:21:42 -0000 1.37
+++ testproc.c 26 Nov 2002 16:02:37 -0000 1.38
@@ -57,19 +57,8 @@
#include "apr_general.h"
#include "apr_lib.h"
#include "apr_strings.h"
-#include <errno.h>
-#if APR_HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <string.h>
#include "test_apr.h"
-int test_filedel(void);
-int testdirs(void);
-
/* XXX I'm sure there has to be a better way to do this ... */
#ifdef WIN32
#define EXTENSION ".exe"
@@ -77,197 +66,144 @@
#define EXTENSION
#endif
-int main(int argc, char *argv[])
+#define TESTSTR "This is a test"
+
+static apr_proc_t newproc;
+
+static void test_create_proc(CuTest *tc)
{
- apr_pool_t *pool;
- apr_proc_t newproc;
+ const char *args[2];
apr_procattr_t *attr;
apr_file_t *testfile = NULL;
- apr_file_t *testout = NULL;
- apr_file_t *testerr = NULL;
+ apr_status_t rv;
apr_size_t length;
- apr_off_t offset;
char *buf;
- char msgbuf[120];
- const char *args[3];
- char *teststr;
- apr_status_t rv;
- if (apr_initialize() != APR_SUCCESS){
- printf("Failed to initialize APR\n");
- exit(-1);
- }
- atexit(apr_terminate);
- apr_pool_create(&pool, NULL);
-
- if (argc > 1) {
- teststr = apr_palloc(pool, 256);
- teststr = fgets(teststr, 256, stdin);
- printf("%s", teststr);
- if (!strcmp("--to-stderr", argv[1]))
- fprintf(stderr, "%s", teststr);
- exit(1);
- }
- teststr = apr_pstrdup(pool, "Whooo Hoooo\n");
-
- printf("APR Process Test\n================\n\n");
-
- STD_TEST_NEQ("Creating directory \"proctest\" for later use",
- apr_dir_make("proctest", APR_UREAD | APR_UWRITE | APR_UEXECUTE, pool))
+ rv = apr_procattr_create(&attr, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+
+ rv = apr_procattr_io_set(attr, APR_FULL_BLOCK, APR_FULL_BLOCK,
+ APR_NO_PIPE);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
- /* =================================================================== */
+ rv = apr_procattr_dir_set(attr, "data");
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
- printf("\nTesting process pipes ...\n\n");
+ rv = apr_procattr_cmdtype_set(attr, APR_PROGRAM);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
- STD_TEST_NEQ("Creating procattr", apr_procattr_create(&attr, pool))
- STD_TEST_NEQ("Setting attr pipes, all three", apr_procattr_io_set(attr, APR_FULL_BLOCK,
- APR_CHILD_BLOCK, APR_NO_PIPE))
- STD_TEST_NEQ("Setting attr dir", apr_procattr_dir_set(attr, "proctest"))
- STD_TEST_NEQ("Setting attr cmd type", apr_procattr_cmdtype_set(attr, APR_PROGRAM))
-
- args[0] = "testproc";
- args[1] = "-X";
- args[2] = NULL;
+ args[0] = "proc_child";
+ args[1] = NULL;
- STD_TEST_NEQ("Creating a new process", apr_proc_create(&newproc,
- "../testproc" EXTENSION, args, NULL, attr, pool))
+ rv = apr_proc_create(&newproc, "../proc_child" EXTENSION, args, NULL,
+ attr, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
- printf("%-60s","Grabbing child's stdin");
testfile = newproc.in;
- printf("OK\n");
- length = strlen(teststr);
- printf("%-60s", "Writing the data to child");
- if ((rv = apr_file_write(testfile, teststr, &length)) == APR_SUCCESS) {
- printf("OK\n");
- }
- else {
- printf("Write failed: (%d) %s.\n",
- rv, apr_strerror(rv, msgbuf, sizeof msgbuf));
- }
+ length = strlen(TESTSTR);
+ rv = apr_file_write(testfile, TESTSTR, &length);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertIntEquals(tc, strlen(TESTSTR), length);
- printf("%-60s", "Grabbing child's stdout");
testfile = newproc.out;
- printf("OK\n");
-
length = 256;
- printf("%-60s", "Checking the data read from pipe to child");
- buf = apr_pcalloc(pool, length);
- if ((rv = apr_file_read(testfile, buf, &length)) == APR_SUCCESS) {
- if (!strcmp(buf, teststr))
- printf("OK\n");
- else {
- printf( "Uh-Oh\n");
- printf(" (I actually got %s)\n", buf);
- }
- }
- else {
- printf("Read failed - (%d) %s\n",
- rv, apr_strerror(rv, msgbuf, sizeof msgbuf));
- }
-
- TEST_NEQ("Waiting for child to die",
- apr_proc_wait(&newproc, NULL, NULL, APR_WAIT),
- APR_CHILD_DONE, "OK", "Failed")
+ buf = apr_pcalloc(p, length);
+ rv = apr_file_read(testfile, buf, &length);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertStrEquals(tc, TESTSTR, buf);
+}
- /* =================================================================== */
+static void test_proc_wait(CuTest *tc)
+{
+ apr_status_t rv;
- printf("\nTesting file redirection ...\n\n");
+ rv = apr_proc_wait(&newproc, NULL, NULL, APR_WAIT);
+ CuAssertIntEquals(tc, APR_CHILD_DONE, rv);
+}
+
+static void test_file_redir(CuTest *tc)
+{
+ apr_file_t *testout = NULL;
+ apr_file_t *testerr = NULL;
+ apr_off_t offset;
+ apr_status_t rv;
+ const char *args[2];
+ apr_procattr_t *attr;
+ apr_file_t *testfile = NULL;
+ apr_size_t length;
+ char *buf;
testfile = NULL;
- STD_TEST_NEQ("Creating input file",
- apr_file_open(&testfile, "proctest/stdin",
- APR_READ | APR_WRITE | APR_CREATE | APR_EXCL,
- APR_OS_DEFAULT, pool))
- STD_TEST_NEQ("Creating output file",
- apr_file_open(&testout, "proctest/stdout",
- APR_READ | APR_WRITE | APR_CREATE | APR_EXCL,
- APR_OS_DEFAULT, pool))
- STD_TEST_NEQ("Creating error file",
- apr_file_open(&testerr, "proctest/stderr",
- APR_READ | APR_WRITE | APR_CREATE | APR_EXCL,
- APR_OS_DEFAULT, pool))
-
- length = strlen(teststr);
- STD_TEST_NEQ("Writing input file",
- apr_file_write(testfile, teststr, &length))
+ rv = apr_file_open(&testfile, "data/stdin",
+ APR_READ | APR_WRITE | APR_CREATE | APR_EXCL,
+ APR_OS_DEFAULT, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ rv = apr_file_open(&testout, "data/stdout",
+ APR_READ | APR_WRITE | APR_CREATE | APR_EXCL,
+ APR_OS_DEFAULT, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ rv = apr_file_open(&testerr, "data/stderr",
+ APR_READ | APR_WRITE | APR_CREATE | APR_EXCL,
+ APR_OS_DEFAULT, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+
+ length = strlen(TESTSTR);
+ apr_file_write(testfile, TESTSTR, &length);
offset = 0;
- STD_TEST_NEQ("Rewinding input file",
- apr_file_seek(testfile, APR_SET, &offset))
+ rv = apr_file_seek(testfile, APR_SET, &offset);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertIntEquals(tc, 0, offset);
+
+ rv = apr_procattr_create(&attr, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ rv = apr_procattr_child_in_set(attr, testfile, NULL);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ rv = apr_procattr_child_out_set(attr, testout, NULL);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ rv = apr_procattr_child_err_set(attr, testerr, NULL);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ rv = apr_procattr_dir_set(attr, "data");
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ rv = apr_procattr_cmdtype_set(attr, APR_PROGRAM);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+
+ args[0] = "proc_child";
+ args[1] = NULL;
+
+ rv = apr_proc_create(&newproc, "../proc_child" EXTENSION, args, NULL,
+ attr, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
- STD_TEST_NEQ("Creating procattr", apr_procattr_create(&attr, pool))
- STD_TEST_NEQ("Setting attr input file",
- apr_procattr_child_in_set(attr, testfile, NULL))
- STD_TEST_NEQ("Setting attr output file",
- apr_procattr_child_out_set(attr, testout, NULL))
- STD_TEST_NEQ("Setting attr error file",
- apr_procattr_child_err_set(attr, testerr, NULL))
- STD_TEST_NEQ("Setting attr dir", apr_procattr_dir_set(attr, "proctest"))
- STD_TEST_NEQ("Setting attr cmd type", apr_procattr_cmdtype_set(attr, APR_PROGRAM))
-
- args[0] = "testproc";
- args[1] = "--to-stderr";
- args[2] = NULL;
-
- STD_TEST_NEQ("Creating a new process", apr_proc_create(&newproc,
- "../testproc" EXTENSION, args, NULL, attr, pool))
-
- TEST_NEQ("Waiting for child to die",
- apr_proc_wait(&newproc, NULL, NULL, APR_WAIT),
- APR_CHILD_DONE, "OK", "Failed")
+ rv = apr_proc_wait(&newproc, NULL, NULL, APR_WAIT);
+ CuAssertIntEquals(tc, APR_CHILD_DONE, rv);
offset = 0;
- STD_TEST_NEQ("Rewinding output file",
- apr_file_seek(testout, APR_SET, &offset))
- length = 256;
- printf("%-60s", "Checking the data read from child's stdout");
- buf = apr_pcalloc(pool, length);
- if ((rv = apr_file_read(testout, buf, &length)) == APR_SUCCESS) {
- if (!strcmp(buf, teststr))
- printf("OK\n");
- else {
- printf( "Uh-Oh\n");
- printf(" (I actually got %s_\n", buf);
- }
- }
- else {
- printf("Read failed - (%d) %s\n",
- rv, apr_strerror(rv, msgbuf, sizeof msgbuf));
- }
+ rv = apr_file_seek(testout, APR_SET, &offset);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
- offset = 0;
- STD_TEST_NEQ("Rewinding error file",
- apr_file_seek(testerr, APR_SET, &offset))
length = 256;
- printf("%-60s", "Checking the data read from child's stderr");
- buf = apr_pcalloc(pool, length);
- if ((rv = apr_file_read(testerr, buf, &length)) == APR_SUCCESS) {
- if (!strcmp(buf, teststr))
- printf("OK\n");
- else {
- printf( "Uh-Oh\n");
- printf(" (I actually got %s_\n", buf);
- }
- }
- else {
- printf("Read failed - (%d) %s\n",
- rv, apr_strerror(rv, msgbuf, sizeof msgbuf));
- }
-
- STD_TEST_NEQ("Closing input file", apr_file_close(testfile));
- STD_TEST_NEQ("Closing output file", apr_file_close(testout));
- STD_TEST_NEQ("Closing error file", apr_file_close(testerr));
-
- STD_TEST_NEQ("Removing input file", apr_file_remove("proctest/stdin", pool));
- STD_TEST_NEQ("Removing output file", apr_file_remove("proctest/stdout", pool));
- STD_TEST_NEQ("Removing error file", apr_file_remove("proctest/stderr", pool));
+ buf = apr_pcalloc(p, length);
+ rv = apr_file_read(testout, buf, &length);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertStrEquals(tc, TESTSTR, buf);
+
+ rv = apr_file_remove("data/stdin", p);;
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ rv = apr_file_remove("data/stdout", p);;
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ rv = apr_file_remove("data/stderr", p);;
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+}
- /* =================================================================== */
+CuSuite *testproc(void)
+{
+ CuSuite *suite = CuSuiteNew("Process control");
- printf("\n");
- STD_TEST_NEQ("Removing directory", apr_dir_remove("proctest", pool))
+ SUITE_ADD_TEST(suite, test_create_proc);
+ SUITE_ADD_TEST(suite, test_proc_wait);
+ SUITE_ADD_TEST(suite, test_file_redir);
- printf("\nTest completed succesfully\n");
- return 0;
+ return suite;
}