rbb 2002/11/23 20:49:45
Modified: test Makefile.in test_apr.h testall.c testoc.c
Log:
Migrate testoc to the new test suite.
Revision Changes Path
1.110 +3 -6 apr/test/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apr/test/Makefile.in,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -r1.109 -r1.110
--- Makefile.in 23 Nov 2002 21:53:00 -0000 1.109
+++ Makefile.in 24 Nov 2002 04:49:45 -0000 1.110
@@ -25,7 +25,6 @@
[EMAIL PROTECTED]@ \
[EMAIL PROTECTED]@ \
[EMAIL PROTECTED]@ \
- [EMAIL PROTECTED]@ \
[EMAIL PROTECTED]@ \
[EMAIL PROTECTED]@ \
[EMAIL PROTECTED]@ \
@@ -69,9 +68,6 @@
[EMAIL PROTECTED]@: testdso.lo mod_test.la libmod_test.la $(LOCAL_LIBS)
$(LINK) testdso.lo $(LOCAL_LIBS) $(ALL_LIBS)
[EMAIL PROTECTED]@: testoc.lo [EMAIL PROTECTED]@ $(LOCAL_LIBS)
- $(LINK) testoc.lo $(LOCAL_LIBS) $(ALL_LIBS)
-
[EMAIL PROTECTED]@: occhild.lo $(LOCAL_LIBS)
$(LINK) occhild.lo $(LOCAL_LIBS) $(ALL_LIBS)
@@ -157,11 +153,12 @@
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 CuTest.lo mod_test.la libmod_test.la $(LOCAL_LIBS)
+ testdso.lo testoc.lo CuTest.lo mod_test.la libmod_test.la \
+ [EMAIL PROTECTED]@ $(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 CuTest.lo $(LOCAL_LIBS) $(ALL_LIBS)
+ testdso.lo testoc.lo CuTest.lo $(LOCAL_LIBS) $(ALL_LIBS)
# DO NOT REMOVE
1.24 +1 -0 apr/test/test_apr.h
Index: test_apr.h
===================================================================
RCS file: /home/cvs/apr/test/test_apr.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- test_apr.h 23 Nov 2002 21:53:00 -0000 1.23
+++ test_apr.h 24 Nov 2002 04:49:45 -0000 1.24
@@ -81,6 +81,7 @@
CuSuite *testfileinfo(void);
CuSuite *testrand(void);
CuSuite *testdso(void);
+CuSuite *testoc(void);
1.22 +1 -0 apr/test/testall.c
Index: testall.c
===================================================================
RCS file: /home/cvs/apr/test/testall.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- testall.c 23 Nov 2002 22:06:15 -0000 1.21
+++ testall.c 24 Nov 2002 04:49:45 -0000 1.22
@@ -79,6 +79,7 @@
{"testfileinfo", testfileinfo},
{"testrand", testrand},
{"testdso", testdso},
+ {"testoc", testoc},
{"LastTest", NULL}
};
1.27 +57 -69 apr/test/testoc.c
Index: testoc.c
===================================================================
RCS file: /home/cvs/apr/test/testoc.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- testoc.c 23 Nov 2002 22:07:41 -0000 1.26
+++ testoc.c 24 Nov 2002 04:49:45 -0000 1.27
@@ -52,34 +52,35 @@
* <http://www.apache.org/>.
*/
+#include "test_apr.h"
#include "apr_thread_proc.h"
#include "apr_errno.h"
#include "apr_general.h"
#include "apr_lib.h"
#include "apr_strings.h"
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#if APR_HAVE_UNISTD_H
-#include <unistd.h>
-#endif
#if APR_HAS_OTHER_CHILD
+
+static char reasonstr[256];
+
static void ocmaint(int reason, void *data, int status)
{
- fprintf(stdout,"[CHILD] Maintenance routine called....");
- fflush(stdout);
switch (reason) {
case APR_OC_REASON_DEATH:
- fprintf(stdout, "Died correctly\n");
+ apr_cpystrn(reasonstr, "APR_OC_REASON_DEATH",
+ strlen("APR_OC_REASON_DEATH") + 1);
break;
case APR_OC_REASON_LOST:
- fprintf(stdout, "APR_OC_REASON_LOST\n");
+ apr_cpystrn(reasonstr, "APR_OC_REASON_LOST",
+ strlen("APR_OC_REASON_LOST") + 1);
+ break;
case APR_OC_REASON_UNWRITABLE:
- fprintf(stdout, "APR_OC_REASON_UNWRITEABLE\n");
+ apr_cpystrn(reasonstr, "APR_OC_REASON_UNWRITEABLE",
+ strlen("APR_OC_REASON_UNWRITEABLE") + 1);
+ break;
case APR_OC_REASON_RESTART:
- fprintf(stdout, "APR_OC_REASON_RESTART\n");
- fprintf(stdout, "OC maintentance called for reason other than
death\n");
+ apr_cpystrn(reasonstr, "APR_OC_REASON_RESTART",
+ strlen("APR_OC_REASON_RESTART") + 1);
break;
}
}
@@ -89,80 +90,67 @@
#define SIGKILL 1
#endif
-int main(int argc, char *argv[])
+/* It would be great if we could stress this stuff more, and make the test
+ * more granular.
+ */
+static void test_child_kill(CuTest *tc)
{
-#if APR_HAS_OTHER_CHILD
- apr_status_t rv;
- apr_pool_t *context;
+ apr_file_t *std = NULL;
apr_proc_t newproc;
apr_procattr_t *procattr = NULL;
- apr_file_t *std = NULL;
const char *args[3];
+ apr_status_t rv;
- if (argc > 1) {
- while (1);
- }
-
- if (apr_initialize() != APR_SUCCESS) {
- fprintf(stderr, "Couldn't initialize.");
- exit(-1);
- }
- atexit(apr_terminate);
- if (apr_pool_create(&context, NULL) != APR_SUCCESS) {
- fprintf(stderr, "Couldn't allocate context.");
- exit(-1);
- }
-
- args[0] = apr_pstrdup(context, "occhild");
- args[1] = apr_pstrdup(context, "-X");
+ args[0] = apr_pstrdup(p, "occhild");
+ args[1] = apr_pstrdup(p, "-X");
args[2] = NULL;
- fprintf(stdout, "[PARENT] Creating procattr.............");
- fflush(stdout);
- if (apr_procattr_create(&procattr, context) != APR_SUCCESS) {
- fprintf(stderr, "Could not create attr\n");
- exit(-1);;
- }
- else {
- apr_procattr_io_set(procattr, APR_FULL_BLOCK, APR_NO_PIPE,
APR_NO_PIPE);
- }
- fprintf(stdout, "OK\n");
+ rv = apr_procattr_create(&procattr, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
- fprintf(stdout, "[PARENT] Starting other child..........");
- fflush(stdout);
- if (apr_proc_create(&newproc, "./occhild", args, NULL, procattr,
context)
- != APR_SUCCESS) {
- fprintf(stderr, "error starting other child\n");
- exit(-1);
- }
- fprintf(stdout, "OK\n");
+ rv = apr_procattr_io_set(procattr, APR_FULL_BLOCK, APR_NO_PIPE,
+ APR_NO_PIPE);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+
+ rv = apr_proc_create(&newproc, "./occhild", args, NULL, procattr, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertPtrNotNull(tc, newproc.in);
+ CuAssertPtrEquals(tc, NULL, newproc.out);
+ CuAssertPtrEquals(tc, NULL, newproc.err);
std = newproc.in;
- apr_proc_other_child_register(&newproc, ocmaint, NULL, std, context);
+ apr_proc_other_child_register(&newproc, ocmaint, NULL, std, p);
- fprintf(stdout, "[PARENT] Sending SIGKILL to child......");
- fflush(stdout);
apr_sleep(apr_time_from_sec(1));
- if ((rv = apr_proc_kill(&newproc, SIGKILL)) != APR_SUCCESS) {
- char msgbuf[120];
-
- fprintf(stderr,"couldn't send the signal: %d/%s!\n",
- rv, apr_strerror(rv, msgbuf, sizeof msgbuf));
- exit(-1);
- }
- fprintf(stdout,"OK\n");
+ rv = apr_proc_kill(&newproc, SIGKILL);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
/* allow time for things to settle... */
apr_sleep(apr_time_from_sec(3));
- fprintf(stdout, "[PARENT] Checking on children..........\n");
apr_proc_other_child_check();
-#else
- fprintf(stdout, "OC failed!\n");
- fprintf(stdout, "Other_child is not supported on this platform\n");
+ CuAssertStrEquals(tc, "APR_OC_REASON_DEATH", reasonstr);
+}
+
+#if !APR_HAS_OTHER_CHILD
+static void oc_not_impl(CuTest *tc)
+{
+ CuNotImpl(tc, "Other child logic not implemented on this platform");
+}
#endif
- return 0;
-}
+CuSuite *testoc(void)
+{
+ CuSuite *suite = CuSuiteNew("Test Time");
+
+#if !APR_HAS_OTHER_CHILD
+ SUITE_ADD_TEST(suite, oc_not_impl);
+#else
+
+ SUITE_ADD_TEST(suite, test_child_kill);
+
+#endif
+ return suite;
+}