diff options
Diffstat (limited to 'rubbos/app/httpd-2.0.64/srclib/apr/test')
77 files changed, 13710 insertions, 0 deletions
diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/CuTest.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/CuTest.c new file mode 100644 index 00000000..8356b9b2 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/CuTest.c @@ -0,0 +1,475 @@ +/* + * Copyright (c) 2002-2006 Asim Jalis + * + * This library is released under the zlib/libpng license as described at + * + * http://www.opensource.org/licenses/zlib-license.html + * + * Here is the statement of the license: + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the authors be held liable for any damages arising from + * the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software in a + * product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source distribution. + */ +/* + * This file has been modified from the original distribution. + */ + +#include <assert.h> +#include <setjmp.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "CuTest.h" + +static int verbose = 0; + +void CuInit(int argc, char *argv[]) +{ + int i; + + /* Windows doesn't have getopt, so we have to fake it. We can't use + * apr_getopt, because CuTest is meant to be a stand-alone test suite + */ + for (i = 0; i < argc; i++) { + if (!strcmp(argv[i], "-v")) { + verbose = 1; + } + } +} + +/*-------------------------------------------------------------------------* + * CuStr + *-------------------------------------------------------------------------*/ + +char* CuStrAlloc(int size) +{ + char* new = (char*) malloc( sizeof(char) * (size) ); + return new; +} + +char* CuStrCopy(const char* old) +{ + int len = strlen(old); + char* new = CuStrAlloc(len + 1); + strcpy(new, old); + return new; +} + +/*-------------------------------------------------------------------------* + * CuString + *-------------------------------------------------------------------------*/ + +void CuStringInit(CuString* str) +{ + str->length = 0; + str->size = STRING_MAX; + str->buffer = (char*) malloc(sizeof(char) * str->size); + str->buffer[0] = '\0'; +} + +CuString* CuStringNew(void) +{ + CuString* str = (CuString*) malloc(sizeof(CuString)); + str->length = 0; + str->size = STRING_MAX; + str->buffer = (char*) malloc(sizeof(char) * str->size); + str->buffer[0] = '\0'; + return str; +} + +void CuStringResize(CuString* str, int newSize) +{ + str->buffer = (char*) realloc(str->buffer, sizeof(char) * newSize); + str->size = newSize; +} + +void CuStringAppend(CuString* str, const char* text) +{ + int length = strlen(text); + if (str->length + length + 1 >= str->size) + CuStringResize(str, str->length + length + 1 + STRING_INC); + str->length += length; + strcat(str->buffer, text); +} + +void CuStringAppendChar(CuString* str, char ch) +{ + char text[2]; + text[0] = ch; + text[1] = '\0'; + CuStringAppend(str, text); +} + +void CuStringAppendFormat(CuString* str, const char* format, ...) +{ + va_list argp; + char buf[HUGE_STRING_LEN]; + va_start(argp, format); + vsprintf(buf, format, argp); + va_end(argp); + CuStringAppend(str, buf); +} + +void CuStringRead(CuString *str, char *path) +{ + path = strdup(str->buffer); +} + +/*-------------------------------------------------------------------------* + * CuTest + *-------------------------------------------------------------------------*/ + +void CuTestInit(CuTest* t, char* name, TestFunction function) +{ + t->name = CuStrCopy(name); + t->notimpl = 0; + t->failed = 0; + t->ran = 0; + t->message = NULL; + t->function = function; + t->jumpBuf = NULL; +} + +CuTest* CuTestNew(char* name, TestFunction function) +{ + CuTest* tc = CU_ALLOC(CuTest); + CuTestInit(tc, name, function); + return tc; +} + +void CuNotImpl(CuTest* tc, const char* message) +{ + CuString* newstr = CuStringNew(); + CuStringAppend(newstr, message); + CuStringAppend(newstr, " not implemented on this platform"); + tc->notimpl = 1; + tc->message = CuStrCopy(newstr->buffer); + if (tc->jumpBuf != 0) longjmp(*(tc->jumpBuf), 0); +} + +void CuFail(CuTest* tc, const char* message) +{ + tc->failed = 1; + tc->message = CuStrCopy(message); + if (tc->jumpBuf != 0) longjmp(*(tc->jumpBuf), 0); +} + +void CuAssert(CuTest* tc, const char* message, int condition) +{ + if (condition) return; + CuFail(tc, message); +} + +void CuAssertTrue(CuTest* tc, int condition) +{ + if (condition) return; + CuFail(tc, "assert failed"); +} + +void CuAssertStrNEquals(CuTest* tc, const char* expected, const char* actual, + int n) +{ + CuString* message; + if (strncmp(expected, actual, n) == 0) return; + message = CuStringNew(); + CuStringAppend(message, "expected\n---->\n"); + CuStringAppend(message, expected); + CuStringAppend(message, "\n<----\nbut saw\n---->\n"); + CuStringAppend(message, actual); + CuStringAppend(message, "\n<----"); + CuFail(tc, message->buffer); +} + +void CuAssertStrEquals(CuTest* tc, const char* expected, const char* actual) +{ + CuString* message; + if (strcmp(expected, actual) == 0) return; + message = CuStringNew(); + CuStringAppend(message, "expected\n---->\n"); + CuStringAppend(message, expected); + CuStringAppend(message, "\n<----\nbut saw\n---->\n"); + CuStringAppend(message, actual); + CuStringAppend(message, "\n<----"); + CuFail(tc, message->buffer); +} + +void CuAssertIntEquals(CuTest* tc, int expected, int actual) +{ + char buf[STRING_MAX]; + if (expected == actual) return; + sprintf(buf, "expected <%d> but was <%d>", expected, actual); + CuFail(tc, buf); +} + +void CuAssertPtrEquals(CuTest* tc, const void* expected, const void* actual) +{ + char buf[STRING_MAX]; + if (expected == actual) return; + sprintf(buf, "expected pointer <%p> but was <%p>", expected, actual); + CuFail(tc, buf); +} + +void CuAssertPtrNotNull(CuTest* tc, const void* pointer) +{ + char buf[STRING_MAX]; + if (pointer != NULL ) return; + sprintf(buf, "null pointer unexpected, but was <%p>", pointer); + CuFail(tc, buf); +} + +void CuTestRun(CuTest* tc) +{ + jmp_buf buf; + tc->jumpBuf = &buf; + if (setjmp(buf) == 0) + { + tc->ran = 1; + (tc->function)(tc); + } + tc->jumpBuf = 0; +} + +/*-------------------------------------------------------------------------* + * CuSuite + *-------------------------------------------------------------------------*/ + +void CuSuiteInit(CuSuite* testSuite, char *name) +{ + testSuite->name = strdup(name); + testSuite->count = 0; + testSuite->failCount = 0; + testSuite->notimplCount = 0; +} + +CuSuite* CuSuiteNew(char *name) +{ + CuSuite* testSuite = CU_ALLOC(CuSuite); + CuSuiteInit(testSuite, name); + return testSuite; +} + +void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase) +{ + assert(testSuite->count < MAX_TEST_CASES); + testSuite->list[testSuite->count] = testCase; + testSuite->count++; +} + +void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2) +{ + int i; + for (i = 0 ; i < testSuite2->count ; ++i) + { + CuTest* testCase = testSuite2->list[i]; + CuSuiteAdd(testSuite, testCase); + } +} + +void CuSuiteRun(CuSuite* testSuite) +{ + int i; + for (i = 0 ; i < testSuite->count ; ++i) + { + CuTest* testCase = testSuite->list[i]; + CuTestRun(testCase); + if (testCase->failed) { testSuite->failCount += 1; } + if (testCase->notimpl) { testSuite->notimplCount += 1; } + } +} + +void CuSuiteSummary(CuSuite* testSuite, CuString* summary) +{ + int i; + for (i = 0 ; i < testSuite->count ; ++i) + { + CuTest* testCase = testSuite->list[i]; + CuStringAppend(summary, testCase->failed ? "F" : + testCase->notimpl ? "N": "."); + } + CuStringAppend(summary, "\n"); +} + +void CuSuiteOverView(CuSuite* testSuite, CuString* details) +{ + CuStringAppendFormat(details, "%d %s run: %d passed, %d failed, " + "%d not implemented.\n", + testSuite->count, + testSuite->count == 1 ? "test" : "tests", + testSuite->count - testSuite->failCount - + testSuite->notimplCount, + testSuite->failCount, testSuite->notimplCount); +} + +void CuSuiteDetails(CuSuite* testSuite, CuString* details) +{ + int i; + int failCount = 0; + + if (testSuite->failCount != 0 && verbose) + { + CuStringAppendFormat(details, "\nFailed tests in %s:\n", testSuite->name); + for (i = 0 ; i < testSuite->count ; ++i) + { + CuTest* testCase = testSuite->list[i]; + if (testCase->failed) + { + failCount++; + CuStringAppendFormat(details, "%d) %s: %s\n", + failCount, testCase->name, testCase->message); + } + } + } + if (testSuite->notimplCount != 0 && verbose) + { + CuStringAppendFormat(details, "\nNot Implemented tests in %s:\n", testSuite->name); + for (i = 0 ; i < testSuite->count ; ++i) + { + CuTest* testCase = testSuite->list[i]; + if (testCase->notimpl) + { + failCount++; + CuStringAppendFormat(details, "%d) %s: %s\n", + failCount, testCase->name, testCase->message); + } + } + } +} + +/*-------------------------------------------------------------------------* + * CuSuiteList + *-------------------------------------------------------------------------*/ + +CuSuiteList* CuSuiteListNew(char *name) +{ + CuSuiteList* testSuite = CU_ALLOC(CuSuiteList); + testSuite->name = strdup(name); + testSuite->count = 0; + return testSuite; +} + +void CuSuiteListAdd(CuSuiteList *suites, CuSuite *origsuite) +{ + assert(suites->count < MAX_TEST_CASES); + suites->list[suites->count] = origsuite; + suites->count++; +} + +void CuSuiteListRun(CuSuiteList* testSuite) +{ + int i; + for (i = 0 ; i < testSuite->count ; ++i) + { + CuSuite* testCase = testSuite->list[i]; + CuSuiteRun(testCase); + } +} + +static const char *genspaces(int i) +{ + char *str = malloc((i + 1) * sizeof(char)); + memset(str, ' ', i); + str[i] = '\0'; + return str; +} + +void CuSuiteListRunWithSummary(CuSuiteList* testSuite) +{ + int i; + + printf("%s:\n", testSuite->name); + for (i = 0 ; i < testSuite->count ; ++i) + { + CuSuite* testCase = testSuite->list[i]; + CuString *str = CuStringNew(); + + printf(" %s:%s", testCase->name, + genspaces(21 - strlen(testCase->name))); + fflush(stdout); + CuSuiteRun(testCase); + CuSuiteSummary(testCase, str); + printf(" %s", str->buffer); + + } + printf("\n"); +} + +void CuSuiteListSummary(CuSuiteList* testSuite, CuString* summary) +{ + int i; + CuStringAppendFormat(summary, "%s:\n", testSuite->name); + for (i = 0 ; i < testSuite->count ; ++i) + { + CuSuite* testCase = testSuite->list[i]; + CuString *str = CuStringNew(); + CuSuiteSummary(testCase, str); + CuStringAppend(summary, " "); + CuStringAppend(summary, str->buffer); + } + CuStringAppend(summary, "\n"); +} + +int CuSuiteListDetails(CuSuiteList* testSuite, CuString* details) +{ + int i; + int failCount = 0; + int notImplCount = 0; + int count = 0; + + for (i = 0 ; i < testSuite->count ; ++i) + { + failCount += testSuite->list[i]->failCount; + notImplCount += testSuite->list[i]->notimplCount; + count += testSuite->list[i]->count; + } + CuStringAppendFormat(details, "%d %s run: %d passed, %d failed, " + "%d not implemented.\n", + count, + count == 1 ? "test" : "tests", + count - failCount - notImplCount, + failCount, notImplCount); + + if (failCount != 0 && verbose) + { + for (i = 0 ; i < testSuite->count ; ++i) + { + CuString *str = CuStringNew(); + CuSuite* testCase = testSuite->list[i]; + if (testCase->failCount) + { + CuSuiteDetails(testCase, str); + CuStringAppend(details, str->buffer); + } + } + } + if (notImplCount != 0 && verbose) + { + for (i = 0 ; i < testSuite->count ; ++i) + { + CuString *str = CuStringNew(); + CuSuite* testCase = testSuite->list[i]; + if (testCase->notimplCount) + { + CuSuiteDetails(testCase, str); + CuStringAppend(details, str->buffer); + } + } + } + return failCount; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/CuTest.h b/rubbos/app/httpd-2.0.64/srclib/apr/test/CuTest.h new file mode 100644 index 00000000..e607d3ac --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/CuTest.h @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2002-2006 Asim Jalis + * + * This library is released under the zlib/libpng license as described at + * + * http://www.opensource.org/licenses/zlib-license.html + * + * Here is the statement of the license: + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the authors be held liable for any damages arising from + * the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software in a + * product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source distribution. + */ +/* + * This file has been modified from the original distribution. + */ + +#ifndef CU_TEST_H +#define CU_TEST_H + +#include <setjmp.h> +#include <stdarg.h> + +/* CuString */ + +char* CuStrAlloc(int size); +char* CuStrCopy(const char* old); + +#define CU_ALLOC(TYPE) ((TYPE*) malloc(sizeof(TYPE))) + +#define HUGE_STRING_LEN 8192 +#define STRING_MAX 256 +#define STRING_INC 256 + +typedef struct +{ + int length; + int size; + char* buffer; +} CuString; + +void CuStringInit(CuString* str); +CuString* CuStringNew(void); +void CuStringRead(CuString* str, char* path); +void CuStringAppend(CuString* str, const char* text); +void CuStringAppendChar(CuString* str, char ch); +void CuStringAppendFormat(CuString* str, const char* format, ...); +void CuStringResize(CuString* str, int newSize); + +/* CuTest */ + +typedef struct CuTest CuTest; + +typedef void (*TestFunction)(CuTest *); + +struct CuTest +{ + char* name; + TestFunction function; + int notimpl; + int failed; + int ran; + char* message; + jmp_buf *jumpBuf; +}; + +void CuInit(int argc, char *argv[]); +void CuTestInit(CuTest* t, char* name, TestFunction function); +CuTest* CuTestNew(char* name, TestFunction function); +void CuFail(CuTest* tc, const char* message); +void CuNotImpl(CuTest* tc, const char* message); +void CuAssert(CuTest* tc, const char* message, int condition); +void CuAssertTrue(CuTest* tc, int condition); +void CuAssertStrEquals(CuTest* tc, const char* expected, const char* actual); +void CuAssertStrNEquals(CuTest* tc, const char* expected, const char* actual, + int n); +void CuAssertIntEquals(CuTest* tc, int expected, int actual); +void CuAssertPtrEquals(CuTest* tc, const void* expected, const void* actual); +void CuAssertPtrNotNull(CuTest* tc, const void* pointer); + +void CuTestRun(CuTest* tc); + +/* CuSuite */ + +#define MAX_TEST_CASES 1024 + +#define SUITE_ADD_TEST(SUITE,TEST) CuSuiteAdd(SUITE, CuTestNew(#TEST, TEST)) + +typedef struct +{ + char *name; + int count; + CuTest* list[MAX_TEST_CASES]; + int failCount; + int notimplCount; + +} CuSuite; + + +void CuSuiteInit(CuSuite* testSuite, char* name); +CuSuite* CuSuiteNew(char* name); +void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase); +void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2); +void CuSuiteRun(CuSuite* testSuite); +void CuSuiteSummary(CuSuite* testSuite, CuString* summary); +void CuSuiteOverView(CuSuite* testSuite, CuString* details); +void CuSuiteDetails(CuSuite* testSuite, CuString* details); + +typedef struct +{ + char *name; + int count; + CuSuite* list[MAX_TEST_CASES]; +} CuSuiteList; + + +CuSuiteList* CuSuiteListNew(char* name); +void CuSuiteListAdd(CuSuiteList* testSuite, CuSuite *testCase); +void CuSuiteListRun(CuSuiteList* testSuite); +void CuSuiteListRunWithSummary(CuSuiteList* testSuite); +void CuSuiteListSummary(CuSuiteList* testSuite, CuString* summary); +/* Print details of test suite results; returns total number of + * tests which failed. */ +int CuSuiteListDetails(CuSuiteList* testSuite, CuString* details); +#endif /* CU_TEST_H */ + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/MakeWin32Make.awk b/rubbos/app/httpd-2.0.64/srclib/apr/test/MakeWin32Make.awk new file mode 100644 index 00000000..c5529f8f --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/MakeWin32Make.awk @@ -0,0 +1,53 @@ +{ + + if (match($0, /\@INCLUDE_RULES\@/ ) ) { + print "ALL: \$(TARGETS)"; + print ""; + print "CL = cl.exe"; + print "LINK = link.exe /nologo /debug /machine:I386 /subsystem:console /incremental:no "; + print ""; + print "CFLAGS = /nologo /c /MDd /W3 /Gm /GX /Zi /Od /D _DEBUG /D WIN32 /D APR_DECLARE_STATIC /FD "; + print ""; + print ".c.obj::"; + $0 = "\t\$(CL) -c \$< \$(CFLAGS) \$(INCLUDES)"; + } + if ( match( $0, /^ALL_LIBS=/ ) ) { + $0 = ""; + } + if ( match( $0, /^LOCAL_LIBS=/ ) ) { + print "LOCAL_LIBS= ../LibD/apr.lib "; + print "ALL_LIBS= kernel32\.lib user32\.lib advapi32\.lib Rpcrt4\.lib ws2_32\.lib wsock32\.lib ole32\.lib "; + $0 = "" + } + if ( match( $0, /\@CFLAGS\@/ ) ) { + $0 = ""; + } + gsub( /\$\([^\)]* [^\)]*\)/, "", $0 ); + gsub( /\$\{LD_FLAGS\}/, "", $0 ); + gsub( /\.\.\/libapr\.la/, "../LibD/apr.lib", $0 ); + gsub( /\@RM\@/, "del", $0 ); + if (gsub( /\$\(RM\) -f/, "del" ) ) { + gsub( /\*\.a/, "*.lib *.exp *.idb *.ilk *.pdb", $0 ); + gsub( /Makefile/, "Makefile *.ncb *.opt", $0 ); + } + gsub( /\@CC\@/, "cl", $0); + gsub( /\@RANLIB\@/, "", $0); + gsub( /-I\$\(INCDIR\)/, "/I \"$(INCDIR)\"", $0); + + gsub( /\.\.\/libapr\.a/, "../LibD/apr.lib", $0 ); + if ( gsub( /\@EXEEXT\@/, ".exe", $0 ) ) { + gsub( /\$\(CC\) \$\(CFLAGS\)/, "\$\(LINK\) /subsystem:console", $0 ); + gsub( /-o (\S+)/, "/out:\"$1\"", $0 ); + gsub( /--export-dynamic /, "", $0 ); + gsub( /-fPIC /, "", $0 ); + } + if ( gsub( /-shared/, "/subsystem:windows /dll", $0 ) ) { + gsub( /-o (\S+)/ "/out:\"$1\"", $0 ); + } + gsub( /\$\(NONPORTABLE\)/, "", $0 ); + gsub( /\.a /, ".lib ", $0 ); + gsub( /\.o /, ".obj ", $0 ); + gsub( /\.lo /, ".obj ", $0 ); + + print $0; +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/Makefile b/rubbos/app/httpd-2.0.64/srclib/apr/test/Makefile new file mode 100644 index 00000000..bb66cf89 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/Makefile @@ -0,0 +1,123 @@ +srcdir = . + + +# PROGRAMS includes all test programs built on this platform. +# STDTEST_PORTABLE +# test programs invoked via standard user interface, run on all platforms +# STDTEST_NONPORTABLE +# test programs invoked via standard user interface, not portable +# OTHER_PROGRAMS +# programs such as sendfile, that have to be invoked in a special sequence +# or with special parameters + +STDTEST_PORTABLE = \ + testflock \ + testsock \ + testlockperf \ + testatomic \ + testmutexscope \ + testall + +STDTEST_NONPORTABLE = \ + testshm \ + testglobalmutex + +OTHER_PROGRAMS = client sendfile \ + server + +PROGRAMS = $(STDTEST_PORTABLE) $(STDTEST_NONPORTABLE) $(OTHER_PROGRAMS) + +TARGETS = $(PROGRAMS) + +# bring in rules.mk for standard functionality +include /bottlenecks/rubbos/app/httpd-2.0.64/srclib/apr/build/apr_rules.mk + +LOCAL_LIBS=../libapr-${APR_MAJOR_VERSION}.la + +CLEAN_TARGETS = testfile.tmp mod_test.slo proc_child occhild \ +readchild + +INCDIR=../include +INCLUDES=-I$(INCDIR) + +check: $(STDTEST_PORTABLE) $(STDTEST_NONPORTABLE) + for prog in $(STDTEST_PORTABLE) $(STDTEST_NONPORTABLE); do \ + ./$$prog; \ + if test $$? = 255; then \ + echo "$$prog failed"; \ + break; \ + fi; \ + done + +testflock: testflock.lo $(LOCAL_LIBS) + $(LINK) testflock.lo $(LOCAL_LIBS) $(ALL_LIBS) + +occhild: occhild.lo $(LOCAL_LIBS) + $(LINK) occhild.lo $(LOCAL_LIBS) $(ALL_LIBS) + +readchild: readchild.lo $(LOCAL_LIBS) + $(LINK) readchild.lo $(LOCAL_LIBS) $(ALL_LIBS) + +proc_child: 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: $(srcdir)/mod_test.c + $(LIBTOOL) --mode=compile $(COMPILE) -prefer-pic -c $(srcdir)/mod_test.c && touch $@ + +mod_test.la: mod_test.slo $(LOCAL_LIBS) + $(LIBTOOL) --mode=link $(COMPILE) -rpath `pwd` -avoid-version -module mod_test.lo $(LT_LDFLAGS) $(ALL_LDFLAGS) -o $@ + +libmod_test.la: mod_test.slo $(LOCAL_LIBS) + $(LIBTOOL) --mode=link $(COMPILE) -rpath `pwd` -avoid-version mod_test.lo $(LT_LDFLAGS) $(ALL_LDFLAGS) -o $@ + +testlockperf: testlockperf.lo $(LOCAL_LIBS) + $(LINK) testlockperf.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testsock: testsock.lo client server sendfile $(LOCAL_LIBS) + $(LINK) testsock.lo $(LOCAL_LIBS) $(ALL_LIBS) + +client: client.lo $(LOCAL_LIBS) + $(LINK) client.lo $(LOCAL_LIBS) $(ALL_LIBS) + +server: server.lo $(LOCAL_LIBS) + $(LINK) server.lo $(LOCAL_LIBS) $(ALL_LIBS) + +sendfile: sendfile.lo $(LOCAL_LIBS) + $(LINK) sendfile.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testshm: testshm.lo $(LOCAL_LIBS) testshmproducer testshmconsumer + $(LINK) testshm.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testshmproducer: testshmproducer.lo $(LOCAL_LIBS) + $(LINK) testshmproducer.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testshmconsumer: testshmconsumer.lo $(LOCAL_LIBS) + $(LINK) testshmconsumer.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testprocmutex: testprocmutex.lo $(LOCAL_LIBS) + $(LINK) testprocmutex.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testglobalmutex: testglobalmutex.lo $(LOCAL_LIBS) + $(LINK) testglobalmutex.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testatomic: testatomic.lo $(LOCAL_LIBS) + $(LINK) testatomic.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testmutexscope: testmutexscope.lo $(LOCAL_LIBS) + $(LINK) testmutexscope.lo $(LOCAL_LIBS) $(ALL_LIBS) + +TESTS = 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 testproc.lo \ + testpoll.lo testlock.lo testsockopt.lo testpipe.lo testthread.lo \ + testhash.lo testargs.lo testnames.lo testuser.lo testpath.lo \ + testenv.lo testprocmutex.lo + +testall: $(TESTS) mod_test.la libmod_test.la occhild \ + readchild CuTest.lo proc_child $(LOCAL_LIBS) + $(LINK) $(TESTS) CuTest.lo $(LOCAL_LIBS) $(ALL_LIBS) + + +# DO NOT REMOVE diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/Makefile.in b/rubbos/app/httpd-2.0.64/srclib/apr/test/Makefile.in new file mode 100644 index 00000000..1f7d047e --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/Makefile.in @@ -0,0 +1,123 @@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +# PROGRAMS includes all test programs built on this platform. +# STDTEST_PORTABLE +# test programs invoked via standard user interface, run on all platforms +# STDTEST_NONPORTABLE +# test programs invoked via standard user interface, not portable +# OTHER_PROGRAMS +# programs such as sendfile, that have to be invoked in a special sequence +# or with special parameters + +STDTEST_PORTABLE = \ + testflock@EXEEXT@ \ + testsock@EXEEXT@ \ + testlockperf@EXEEXT@ \ + testatomic@EXEEXT@ \ + testmutexscope@EXEEXT@ \ + testall@EXEEXT@ + +STDTEST_NONPORTABLE = \ + testshm@EXEEXT@ \ + testglobalmutex@EXEEXT@ + +OTHER_PROGRAMS = client@EXEEXT@ sendfile@EXEEXT@ \ + server@EXEEXT@ + +PROGRAMS = $(STDTEST_PORTABLE) $(STDTEST_NONPORTABLE) $(OTHER_PROGRAMS) + +TARGETS = $(PROGRAMS) + +# bring in rules.mk for standard functionality +@INCLUDE_RULES@ + +LOCAL_LIBS=../lib@APR_LIBNAME@.la + +CLEAN_TARGETS = testfile.tmp mod_test.slo proc_child@EXEEXT@ occhild@EXEEXT@ \ +readchild@EXEEXT@ + +INCDIR=../include +INCLUDES=-I$(INCDIR) + +check: $(STDTEST_PORTABLE) $(STDTEST_NONPORTABLE) + for prog in $(STDTEST_PORTABLE) $(STDTEST_NONPORTABLE); do \ + ./$$prog; \ + if test $$? = 255; then \ + echo "$$prog failed"; \ + break; \ + fi; \ + done + +testflock@EXEEXT@: testflock.lo $(LOCAL_LIBS) + $(LINK) testflock.lo $(LOCAL_LIBS) $(ALL_LIBS) + +occhild@EXEEXT@: occhild.lo $(LOCAL_LIBS) + $(LINK) occhild.lo $(LOCAL_LIBS) $(ALL_LIBS) + +readchild@EXEEXT@: readchild.lo $(LOCAL_LIBS) + $(LINK) readchild.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: $(srcdir)/mod_test.c + $(LIBTOOL) --mode=compile $(COMPILE) -prefer-pic -c $(srcdir)/mod_test.c && touch $@ + +mod_test.la: mod_test.slo $(LOCAL_LIBS) + $(LIBTOOL) --mode=link $(COMPILE) -rpath `pwd` -avoid-version -module mod_test.lo $(LT_LDFLAGS) $(ALL_LDFLAGS) -o $@ + +libmod_test.la: mod_test.slo $(LOCAL_LIBS) + $(LIBTOOL) --mode=link $(COMPILE) -rpath `pwd` -avoid-version mod_test.lo $(LT_LDFLAGS) $(ALL_LDFLAGS) -o $@ + +testlockperf@EXEEXT@: testlockperf.lo $(LOCAL_LIBS) + $(LINK) testlockperf.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testsock@EXEEXT@: testsock.lo client@EXEEXT@ server@EXEEXT@ sendfile@EXEEXT@ $(LOCAL_LIBS) + $(LINK) testsock.lo $(LOCAL_LIBS) $(ALL_LIBS) + +client@EXEEXT@: client.lo $(LOCAL_LIBS) + $(LINK) client.lo $(LOCAL_LIBS) $(ALL_LIBS) + +server@EXEEXT@: server.lo $(LOCAL_LIBS) + $(LINK) server.lo $(LOCAL_LIBS) $(ALL_LIBS) + +sendfile@EXEEXT@: sendfile.lo $(LOCAL_LIBS) + $(LINK) sendfile.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testshm@EXEEXT@: testshm.lo $(LOCAL_LIBS) testshmproducer@EXEEXT@ testshmconsumer@EXEEXT@ + $(LINK) testshm.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testshmproducer@EXEEXT@: testshmproducer.lo $(LOCAL_LIBS) + $(LINK) testshmproducer.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testshmconsumer@EXEEXT@: testshmconsumer.lo $(LOCAL_LIBS) + $(LINK) testshmconsumer.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testprocmutex@EXEEXT@: testprocmutex.lo $(LOCAL_LIBS) + $(LINK) testprocmutex.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testglobalmutex@EXEEXT@: testglobalmutex.lo $(LOCAL_LIBS) + $(LINK) testglobalmutex.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testatomic@EXEEXT@: testatomic.lo $(LOCAL_LIBS) + $(LINK) testatomic.lo $(LOCAL_LIBS) $(ALL_LIBS) + +testmutexscope@EXEEXT@: testmutexscope.lo $(LOCAL_LIBS) + $(LINK) testmutexscope.lo $(LOCAL_LIBS) $(ALL_LIBS) + +TESTS = 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 testproc.lo \ + testpoll.lo testlock.lo testsockopt.lo testpipe.lo testthread.lo \ + testhash.lo testargs.lo testnames.lo testuser.lo testpath.lo \ + testenv.lo testprocmutex.lo + +testall: $(TESTS) mod_test.la libmod_test.la occhild@EXEEXT@ \ + readchild@EXEEXT@ CuTest.lo proc_child@EXEEXT@ $(LOCAL_LIBS) + $(LINK) $(TESTS) CuTest.lo $(LOCAL_LIBS) $(ALL_LIBS) + + +# DO NOT REMOVE diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/Makefile.win b/rubbos/app/httpd-2.0.64/srclib/apr/test/Makefile.win new file mode 100644 index 00000000..bdedc4d4 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/Makefile.win @@ -0,0 +1,113 @@ + +LINK=link /nologo + +NONPORTABLE = \ + testshm.exe \ + testglobalmutex.exe + +PROGRAMS = \ + client.exe \ + sendfile.exe \ + server.exe \ + proc_child.exe \ + occhild.exe \ + readchild.exe \ + testflock.exe \ + testsock.exe \ + testlockperf.exe \ + testshmproducer.exe \ + testshmconsumer.exe \ + testatomic.exe \ + testmutexscope.exe \ + testall.exe \ + mod_test.so + + +TARGETS = $(PROGRAMS) + +LOCAL_LIBS=..\LibD\apr.lib +ALL_LIBS=kernel32.lib advapi32.lib ws2_32.lib mswsock.lib ole32.lib shell32.lib rpcrt4.lib + +CLEAN_TARGETS = mod_test.lib mod_test.exp + +INCDIR=../include +INCLUDES=/I "$(INCDIR)" + +all: $(TARGETS) + +clean: + -del $(CLEAN_TARGETS) $(PROGRAMS) *.obj *.pdb *.ilk 2>NUL + +.c.obj: + cl /nologo /c /MDd /W3 /EHsc /Zi /Od /DWIN32 /D_DEBUG /D_WINDOWS /DAPR_DECLARE_STATIC $(INCLUDES) $< + +testflock.exe: testflock.obj $(LOCAL_LIBS) + $(LINK) testflock.obj $(LOCAL_LIBS) $(ALL_LIBS) + +occhild.exe: occhild.obj $(LOCAL_LIBS) + $(LINK) occhild.obj $(LOCAL_LIBS) $(ALL_LIBS) + +readchild.exe: readchild.obj $(LOCAL_LIBS) + $(LINK) readchild.obj $(LOCAL_LIBS) $(ALL_LIBS) + +proc_child.exe: proc_child.obj $(LOCAL_LIBS) + $(LINK) /debug /subsystem:console \ + proc_child.obj $(LOCAL_LIBS) $(ALL_LIBS) + +# FIXME: This is BS ... we should deal with namespace decoration within the +# apr_dso_sym() function or within the test (take y'r pick) since many platforms +# have decoration and decoration issues. +mod_test.so: mod_test.obj + $(LINK) mod_test.obj /dll /out:mod_test.so $(LOCAL_LIBS) $(ALL_LIBS) \ + /export:print_hello /export:count_reps + +testlockperf.exe: testlockperf.obj $(LOCAL_LIBS) + $(LINK) testlockperf.obj $(LOCAL_LIBS) $(ALL_LIBS) + +testsock.exe: testsock.obj client.exe server.exe sendfile.exe $(LOCAL_LIBS) + $(LINK) testsock.obj $(LOCAL_LIBS) $(ALL_LIBS) + +client.exe: client.obj $(LOCAL_LIBS) + $(LINK) client.obj $(LOCAL_LIBS) $(ALL_LIBS) + +server.exe: server.obj $(LOCAL_LIBS) + $(LINK) server.obj $(LOCAL_LIBS) $(ALL_LIBS) + +sendfile.exe: sendfile.obj $(LOCAL_LIBS) + $(LINK) sendfile.obj $(LOCAL_LIBS) $(ALL_LIBS) + +testshm.exe: testshm.obj $(LOCAL_LIBS) testshmproducer.exe testshmconsumer.exe + $(LINK) testshm.obj $(LOCAL_LIBS) $(ALL_LIBS) + +testshmproducer.exe: testshmproducer.obj $(LOCAL_LIBS) + $(LINK) testshmproducer.obj $(LOCAL_LIBS) $(ALL_LIBS) + +testshmconsumer.exe: testshmconsumer.obj $(LOCAL_LIBS) + $(LINK) testshmconsumer.obj $(LOCAL_LIBS) $(ALL_LIBS) + +testprocmutex.exe: testprocmutex.obj $(LOCAL_LIBS) + $(LINK) testprocmutex.obj $(LOCAL_LIBS) $(ALL_LIBS) + +testglobalmutex.exe: testglobalmutex.obj $(LOCAL_LIBS) + $(LINK) testglobalmutex.obj $(LOCAL_LIBS) $(ALL_LIBS) + +testatomic.exe: testatomic.obj $(LOCAL_LIBS) + $(LINK) testatomic.obj $(LOCAL_LIBS) $(ALL_LIBS) + +testmutexscope.exe: testmutexscope.obj $(LOCAL_LIBS) + $(LINK) testmutexscope.obj $(LOCAL_LIBS) $(ALL_LIBS) + +TESTS = testall.obj testtime.obj teststr.obj testvsn.obj testipsub.obj \ + testmmap.obj testud.obj testtable.obj testsleep.obj testpools.obj \ + testfmt.obj testfile.obj testdir.obj testfileinfo.obj testrand.obj \ + testdso.obj testoc.obj testdup.obj testsockets.obj testproc.obj \ + testpoll.obj testlock.obj testsockopt.obj testpipe.obj testthread.obj \ + testhash.obj testargs.obj testnames.obj testuser.obj testpath.obj \ + testenv.obj testprocmutex.obj + +testall.exe: $(TESTS) CuTest.obj $(LOCAL_LIBS) + $(LINK) /debug /subsystem:console $(TESTS) CuTest.obj \ + $(LOCAL_LIBS) $(ALL_LIBS) + + +# DO NOT REMOVE diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/NWGNUaprtest b/rubbos/app/httpd-2.0.64/srclib/apr/test/NWGNUaprtest new file mode 100644 index 00000000..76d1ca4c --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/NWGNUaprtest @@ -0,0 +1,287 @@ +# +# Make sure all needed macro's are defined +# + +# +# Get the 'head' of the build environment if necessary. This includes default +# targets and paths to tools +# + +ifndef EnvironmentDefined +include $(APR_WORK)\build\NWGNUhead.inc +endif + +# +# These directories will be at the beginning of the include list, followed by +# INCDIRS +# +XINCDIRS += \ + $(APR_WORK)/include \ + $(APR_WORK)/include/arch/NetWare \ + $(EOLIST) + +# +# These flags will come after CFLAGS +# +XCFLAGS += \ + $(EOLIST) + +# +# These defines will come after DEFINES +# +XDEFINES += \ + $(EOLIST) + +# +# These flags will be added to the link.opt file +# +XLFLAGS += \ + $(EOLIST) + +# +# These values will be appended to the correct variables based on the value of +# RELEASE +# +ifeq "$(RELEASE)" "debug" +XINCDIRS += \ + $(EOLIST) + +XCFLAGS += \ + $(EOLIST) + +XDEFINES += \ + $(EOLIST) + +XLFLAGS += \ + $(EOLIST) +endif + +ifeq "$(RELEASE)" "noopt" +XINCDIRS += \ + $(EOLIST) + +XCFLAGS += \ + $(EOLIST) + +XDEFINES += \ + $(EOLIST) + +XLFLAGS += \ + $(EOLIST) +endif + +ifeq "$(RELEASE)" "release" +XINCDIRS += \ + $(EOLIST) + +XCFLAGS += \ + $(EOLIST) + +XDEFINES += \ + $(EOLIST) + +XLFLAGS += \ + $(EOLIST) +endif + +# +# These are used by the link target if an NLM is being generated +# This is used by the link 'name' directive to name the nlm. If left blank +# TARGET_nlm (see below) will be used. +# +NLM_NAME = aprtest +# +# This is used by the link '-desc ' directive. +# If left blank, NLM_NAME will be used. +# +NLM_DESCRIPTION = NLM is to test the apr layer + +# +# This is used by the '-threadname' directive. If left blank, +# NLM_NAME Thread will be used. +# +NLM_THREAD_NAME = $(NLM_NAME) Thread + +# +# This is used by the '-screenname' directive. If left blank, +# 'Apache for NetWare' Thread will be used. +# +NLM_SCREEN_NAME = $(NLM_NAME) + +# +# If this is specified, it will override VERSION value in +# $(APR_WORK)\build\NWGNUenvironment.inc +# +NLM_VERSION = + +# +# If this is specified, it will override the default of 64K +# +NLM_STACK_SIZE = 524288 + +# +# If this is specified it will be used by the link '-entry' directive +# +NLM_ENTRY_SYM = _LibCPrelude + +# +# If this is specified it will be used by the link '-exit' directive +# +NLM_EXIT_SYM = _LibCPostlude + +# +# If this is specified it will be used by the link '-check' directive +# +NLM_CHECK_SYM = + +# +# If this is specified it will be used by the link '-flags' directive +# +NLM_FLAGS = AUTOUNLOAD, PSEUDOPREEMPTION + +# +# If this is specified it will be linked in with the XDCData option in the def +# file instead of the default of $(APR)/misc/netware/apache.xdc. XDCData can +# be disabled by setting APACHE_UNIPROC in the environment +# +XDCDATA = + +# +# Declare all target files (you must add your files here) +# + +# +# If there is an NLM target, put it here +# +TARGET_nlm = \ + $(OBJDIR)/aprtest.nlm \ + $(EOLIST) + +# +# If there is an LIB target, put it here +# +TARGET_lib = \ + $(EOLIST) + +# +# These are the OBJ files needed to create the NLM target above. +# Paths must all use the '/' character +# +FILES_nlm_objs = \ + $(OBJDIR)/CuTest.o \ + $(OBJDIR)/testall.o \ + $(OBJDIR)/testargs.o \ + $(OBJDIR)/testdir.o \ + $(OBJDIR)/testdup.o \ + $(OBJDIR)/testdso.o \ + $(OBJDIR)/testenv.o \ + $(OBJDIR)/testfileinfo.o \ + $(OBJDIR)/testfile.o \ + $(OBJDIR)/testfmt.o \ + $(OBJDIR)/testhash.o \ + $(OBJDIR)/testipsub.o \ + $(OBJDIR)/testlock.o \ + $(OBJDIR)/testmmap.o \ + $(OBJDIR)/testnames.o \ + $(OBJDIR)/testoc.o \ + $(OBJDIR)/testpath.o \ + $(OBJDIR)/testpoll.o \ + $(OBJDIR)/testpools.o \ + $(OBJDIR)/testproc.o \ + $(OBJDIR)/testprocmutex.o \ + $(OBJDIR)/testrand.o \ + $(OBJDIR)/testsleep.o \ + $(OBJDIR)/testsockets.o \ + $(OBJDIR)/testsockopt.o \ + $(OBJDIR)/teststr.o \ + $(OBJDIR)/testthread.o \ + $(OBJDIR)/testtime.o \ + $(OBJDIR)/testtable.o \ + $(OBJDIR)/testud.o \ + $(OBJDIR)/testuser.o \ + $(OBJDIR)/testvsn.o \ + $(OBJDIR)/nw_misc.o \ + $(OBJDIR)/testpipe.o \ + $(EOLIST) + +# Pending tests + +# +# These are the LIB files needed to create the NLM target above. +# These will be added as a library command in the link.opt file. +# +FILES_nlm_libs = \ + libcpre.o \ + $(EOLIST) + +# +# These are the modules that the above NLM target depends on to load. +# These will be added as a module command in the link.opt file. +# +FILES_nlm_modules = \ + Libc \ + APRLIB \ + $(EOLIST) + +# +# If the nlm has a msg file, put it's path here +# +FILE_nlm_msg = + +# +# If the nlm has a hlp file put it's path here +# +FILE_nlm_hlp = + +# +# If this is specified, it will override the default copyright. +# +FILE_nlm_copyright = + +# +# Any additional imports go here +# +FILES_nlm_Ximports = \ + @libc.imp \ + @$(APR)/aprlib.imp \ + $(EOLIST) + +# +# Any symbols exported to here +# +FILES_nlm_exports = \ + $(EOLIST) + +# +# These are the OBJ files needed to create the LIB target above. +# Paths must all use the '/' character +# +FILES_lib_objs = \ + $(EOLIST) + +# +# implement targets and dependancies (leave this section alone) +# + +libs :: $(OBJDIR) $(TARGET_lib) + +nlms :: libs $(TARGET_nlm) + +# +# Updated this target to create necessary directories and copy files to the +# correct place. (See $(APR_WORK)\build\NWGNUhead.inc for examples) +# +install :: nlms FORCE + +# +# Any specialized rules here +# + + +# +# Include the 'tail' makefile that has targets that depend on variables defined +# in this makefile +# + +include $(APR_WORK)\build\NWGNUtail.inc + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/NWGNUmakefile b/rubbos/app/httpd-2.0.64/srclib/apr/test/NWGNUmakefile new file mode 100644 index 00000000..c63714a5 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/NWGNUmakefile @@ -0,0 +1,260 @@ +# +# Declare the sub-directories to be built here +# + +SUBDIRS = \ + $(EOLIST) + +# +# Get the 'head' of the build environment. This includes default targets and +# paths to tools +# + +include $(APR_WORK)\build\NWGNUhead.inc + +# +# build this level's files + +# +# Make sure all needed macro's are defined +# + + +# +# These directories will be at the beginning of the include list, followed by +# INCDIRS +# +XINCDIRS += \ + $(APR_WORK)/include \ + $(APR_WORK)/include/arch/NetWare \ + $(EOLIST) + +# +# These flags will come after CFLAGS +# +XCFLAGS += \ + $(EOLIST) + +# +# These defines will come after DEFINES +# +XDEFINES += \ + $(EOLIST) + +# +# These flags will be added to the link.opt file +# +XLFLAGS += \ + $(EOLIST) + +# +# These values will be appended to the correct variables based on the value of +# RELEASE +# +ifeq "$(RELEASE)" "debug" +XINCDIRS += \ + $(EOLIST) + +XCFLAGS += \ + $(EOLIST) + +XDEFINES += \ + $(EOLIST) + +XLFLAGS += \ + $(EOLIST) + +endif + +ifeq "$(RELEASE)" "noopt" +XINCDIRS += \ + $(EOLIST) + +XCFLAGS += \ + $(EOLIST) + +XDEFINES += \ + $(EOLIST) + +XLFLAGS += \ + $(EOLIST) +endif + +ifeq "$(RELEASE)" "release" +XINCDIRS += \ + $(EOLIST) + +XCFLAGS += \ + $(EOLIST) + +XDEFINES += \ + $(EOLIST) + +XLFLAGS += \ + $(EOLIST) +endif + +# +# These are used by the link target if an NLM is being generated +# This is used by the link 'name' directive to name the nlm. If left blank +# TARGET_nlm (see below) will be used. +# +NLM_NAME = + +# +# This is used by the link '-desc ' directive. +# If left blank, NLM_NAME will be used. +# +NLM_DESCRIPTION = NLM is to test the apr layer + +# +# This is used by the '-threadname' directive. If left blank, +# NLM_NAME Thread will be used. +# +NLM_THREAD_NAME = + +# +# This is used by the '-screenname' directive. If left blank, +# 'Apache for NetWare' Thread will be used. +# +NLM_SCREEN_NAME = + +# +# If this is specified, it will override VERSION value in +# $(APR_WORK)\build\NWGNUenvironment.inc +# +NLM_VERSION = + +# +# If this is specified, it will override the default of 64K +# +NLM_STACK_SIZE = + +# +# If this is specified it will be used by the link '-entry' directive +# +NLM_ENTRY_SYM = + +# +# If this is specified it will be used by the link '-exit' directive +# +NLM_EXIT_SYM = + +# +# If this is specified it will be used by the link '-check' directive +# +NLM_CHECK_SYM = + +# +# If this is specified it will be used by the link '-flags' directive +# +NLM_FLAGS = + +# +# If this is specified it will be linked in with the XDCData option in the def +# file instead of the default of $(APR)/misc/netware/apache.xdc. XDCData can +# be disabled by setting APACHE_UNIPROC in the environment +# +XDCDATA = + +# +# Declare all target files (you must add your files here) +# + +# +# If there is an NLM target, put it here +# +TARGET_nlm = \ + $(OBJDIR)/aprtest.nlm \ + $(OBJDIR)/mod_test.nlm \ + $(OBJDIR)/proc_child.nlm \ + $(OBJDIR)/testatmc.nlm \ + $(EOLIST) +# +# If there is an LIB target, put it here +# +TARGET_lib = \ + $(EOLIST) + +# +# These are the OBJ files needed to create the NLM target above. +# Paths must all use the '/' character +# +FILES_nlm_objs = \ + $(EOLIST) + +# +# These are the LIB files needed to create the NLM target above. +# These will be added as a library command in the link.opt file. +# +FILES_nlm_libs = \ + $(EOLIST) + +# +# These are the modules that the above NLM target depends on to load. +# These will be added as a module command in the link.opt file. +# +FILES_nlm_modules = \ + aprlib \ + $(EOLIST) + +# +# If the nlm has a msg file, put it's path here +# +FILE_nlm_msg = + +# +# If the nlm has a hlp file put it's path here +# +FILE_nlm_hlp = + +# +# If this is specified, it will override the default copyright. +# +FILE_nlm_copyright = + +# +# Any additional imports go here +# +FILES_nlm_Ximports = \ + $(EOLIST) + +# +# Any symbols exported to here +# +FILES_nlm_exports = \ + $(EOLIST) + +# +# These are the OBJ files needed to create the LIB target above. +# Paths must all use the '/' character +# +FILES_lib_objs = \ + $(EOLIST) + +# +# implement targets and dependancies (leave this section alone) +# + +libs :: $(OBJDIR) $(TARGET_lib) + +nlms :: libs $(TARGET_nlm) + +# +# Updated this target to create necessary directories and copy files to the +# correct place. (See $(APR_WORK)\build\NWGNUhead.inc for examples) +# +install :: nlms FORCE + copy $(OBJDIR)\*.nlm $(INSTALL)\Apache2 + +# +# Any specialized rules here +# + +# +# Include the 'tail' makefile that has targets that depend on variables defined +# in this makefile +# + +include $(APR_WORK)\build\NWGNUtail.inc + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/NWGNUmod_test b/rubbos/app/httpd-2.0.64/srclib/apr/test/NWGNUmod_test new file mode 100644 index 00000000..a454ef0c --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/NWGNUmod_test @@ -0,0 +1,254 @@ +# +# Make sure all needed macro's are defined +# + +# +# Get the 'head' of the build environment if necessary. This includes default +# targets and paths to tools +# + +ifndef EnvironmentDefined +include $(APR_WORK)\build\NWGNUhead.inc +endif + +# +# These directories will be at the beginning of the include list, followed by +# INCDIRS +# +XINCDIRS += \ + $(APR_WORK)/include \ + $(APR_WORK)/include/arch/NetWare \ + $(EOLIST) + +# +# These flags will come after CFLAGS +# +XCFLAGS += \ + $(EOLIST) + +# +# These defines will come after DEFINES +# +XDEFINES += \ + $(EOLIST) + +# +# These flags will be added to the link.opt file +# +XLFLAGS += \ + $(EOLIST) + +# +# These values will be appended to the correct variables based on the value of +# RELEASE +# +ifeq "$(RELEASE)" "debug" +XINCDIRS += \ + $(EOLIST) + +XCFLAGS += \ + $(EOLIST) + +XDEFINES += \ + $(EOLIST) + +XLFLAGS += \ + $(EOLIST) +endif + +ifeq "$(RELEASE)" "noopt" +XINCDIRS += \ + $(EOLIST) + +XCFLAGS += \ + $(EOLIST) + +XDEFINES += \ + $(EOLIST) + +XLFLAGS += \ + $(EOLIST) +endif + +ifeq "$(RELEASE)" "release" +XINCDIRS += \ + $(EOLIST) + +XCFLAGS += \ + $(EOLIST) + +XDEFINES += \ + $(EOLIST) + +XLFLAGS += \ + $(EOLIST) +endif + +# +# These are used by the link target if an NLM is being generated +# This is used by the link 'name' directive to name the nlm. If left blank +# TARGET_nlm (see below) will be used. +# +NLM_NAME = mod_test + +# +# This is used by the link '-desc ' directive. +# If left blank, NLM_NAME will be used. +# +NLM_DESCRIPTION = DSO NLM to test the apr DSO loading layer + +# +# This is used by the '-threadname' directive. If left blank, +# NLM_NAME Thread will be used. +# +NLM_THREAD_NAME = $(NLM_NAME) Thread + +# +# This is used by the '-screenname' directive. If left blank, +# 'Apache for NetWare' Thread will be used. +# +NLM_SCREEN_NAME = DEFAULT + +# +# If this is specified, it will override VERSION value in +# $(APR_WORK)\build\NWGNUenvironment.inc +# +NLM_VERSION = + +# +# If this is specified, it will override the default of 64K +# +NLM_STACK_SIZE = + +# +# If this is specified it will be used by the link '-entry' directive +# +NLM_ENTRY_SYM = _LibCPrelude + +# +# If this is specified it will be used by the link '-exit' directive +# +NLM_EXIT_SYM = _LibCPostlude + +# +# If this is specified it will be used by the link '-check' directive +# +NLM_CHECK_SYM = + +# +# If this is specified it will be used by the link '-flags' directive +# +NLM_FLAGS = AUTOUNLOAD, PSEUDOPREEMPTION + +# +# If this is specified it will be linked in with the XDCData option in the def +# file instead of the default of $(APR)/misc/netware/apache.xdc. XDCData can +# be disabled by setting APACHE_UNIPROC in the environment +# +XDCDATA = + +# +# Declare all target files (you must add your files here) +# + +# +# If there is an NLM target, put it here +# +TARGET_nlm = \ + $(OBJDIR)/mod_test.nlm \ + $(EOLIST) + +# +# If there is an LIB target, put it here +# +TARGET_lib = \ + $(EOLIST) + +# +# These are the OBJ files needed to create the NLM target above. +# Paths must all use the '/' character +# +FILES_nlm_objs = \ + $(OBJDIR)/mod_test.o \ + $(EOLIST) + +# +# These are the LIB files needed to create the NLM target above. +# These will be added as a library command in the link.opt file. +# +FILES_nlm_libs = \ + libcpre.o \ + $(EOLIST) + +# +# These are the modules that the above NLM target depends on to load. +# These will be added as a module command in the link.opt file. +# +FILES_nlm_modules = \ + aprlib \ + Libc \ + $(EOLIST) + +# +# If the nlm has a msg file, put it's path here +# +FILE_nlm_msg = + +# +# If the nlm has a hlp file put it's path here +# +FILE_nlm_hlp = + +# +# If this is specified, it will override the default copyright. +# +FILE_nlm_copyright = + +# +# Any additional imports go here +# +FILES_nlm_Ximports = \ + @$(APR)/aprlib.imp \ + @libc.imp \ + $(EOLIST) + +# +# Any symbols exported to here +# +FILES_nlm_exports = \ + print_hello \ + count_reps \ + $(EOLIST) + +# +# These are the OBJ files needed to create the LIB target above. +# Paths must all use the '/' character +# +FILES_lib_objs = \ + $(EOLIST) + +# +# implement targets and dependancies (leave this section alone) +# + +libs :: $(OBJDIR) $(TARGET_lib) + +nlms :: libs $(TARGET_nlm) + +# +# Updated this target to create necessary directories and copy files to the +# correct place. (See $(APR_WORK)\build\NWGNUhead.inc for examples) +# +install :: nlms FORCE + +# +# Any specialized rules here +# + +# +# Include the 'tail' makefile that has targets that depend on variables defined +# in this makefile +# + +include $(APR_WORK)\build\NWGNUtail.inc + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/NWGNUproc_child b/rubbos/app/httpd-2.0.64/srclib/apr/test/NWGNUproc_child new file mode 100644 index 00000000..090bbddf --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/NWGNUproc_child @@ -0,0 +1,252 @@ +# +# Make sure all needed macro's are defined +# + +# +# Get the 'head' of the build environment if necessary. This includes default +# targets and paths to tools +# + +ifndef EnvironmentDefined +include $(APR_WORK)\build\NWGNUhead.inc +endif + +# +# These directories will be at the beginning of the include list, followed by +# INCDIRS +# +XINCDIRS += \ + $(APR_WORK)/include \ + $(APR_WORK)/include/arch/NetWare \ + $(EOLIST) + +# +# These flags will come after CFLAGS +# +XCFLAGS += \ + $(EOLIST) + +# +# These defines will come after DEFINES +# +XDEFINES += \ + $(EOLIST) + +# +# These flags will be added to the link.opt file +# +XLFLAGS += \ + $(EOLIST) + +# +# These values will be appended to the correct variables based on the value of +# RELEASE +# +ifeq "$(RELEASE)" "debug" +XINCDIRS += \ + $(EOLIST) + +XCFLAGS += \ + $(EOLIST) + +XDEFINES += \ + $(EOLIST) + +XLFLAGS += \ + $(EOLIST) +endif + +ifeq "$(RELEASE)" "noopt" +XINCDIRS += \ + $(EOLIST) + +XCFLAGS += \ + $(EOLIST) + +XDEFINES += \ + $(EOLIST) + +XLFLAGS += \ + $(EOLIST) +endif + +ifeq "$(RELEASE)" "release" +XINCDIRS += \ + $(EOLIST) + +XCFLAGS += \ + $(EOLIST) + +XDEFINES += \ + $(EOLIST) + +XLFLAGS += \ + $(EOLIST) +endif + +# +# These are used by the link target if an NLM is being generated +# This is used by the link 'name' directive to name the nlm. If left blank +# TARGET_nlm (see below) will be used. +# +NLM_NAME = proc_child + +# +# This is used by the link '-desc ' directive. +# If left blank, NLM_NAME will be used. +# +NLM_DESCRIPTION = child NLM to test the proc layer + +# +# This is used by the '-threadname' directive. If left blank, +# NLM_NAME Thread will be used. +# +NLM_THREAD_NAME = $(NLM_NAME) Thread + +# +# This is used by the '-screenname' directive. If left blank, +# 'Apache for NetWare' Thread will be used. +# +NLM_SCREEN_NAME = DEFAULT + +# +# If this is specified, it will override VERSION value in +# $(APR_WORK)\build\NWGNUenvironment.inc +# +NLM_VERSION = + +# +# If this is specified, it will override the default of 64K +# +NLM_STACK_SIZE = + +# +# If this is specified it will be used by the link '-entry' directive +# +NLM_ENTRY_SYM = _LibCPrelude + +# +# If this is specified it will be used by the link '-exit' directive +# +NLM_EXIT_SYM = _LibCPostlude + +# +# If this is specified it will be used by the link '-check' directive +# +NLM_CHECK_SYM = + +# +# If this is specified it will be used by the link '-flags' directive +# +NLM_FLAGS = AUTOUNLOAD, PSEUDOPREEMPTION, MULTIPLE + +# +# If this is specified it will be linked in with the XDCData option in the def +# file instead of the default of $(APR)/misc/netware/apache.xdc. XDCData can +# be disabled by setting APACHE_UNIPROC in the environment +# +XDCDATA = + +# +# Declare all target files (you must add your files here) +# + +# +# If there is an NLM target, put it here +# +TARGET_nlm = \ + $(OBJDIR)/proc_child.nlm \ + $(EOLIST) + +# +# If there is an LIB target, put it here +# +TARGET_lib = \ + $(EOLIST) + +# +# These are the OBJ files needed to create the NLM target above. +# Paths must all use the '/' character +# +FILES_nlm_objs = \ + $(OBJDIR)/proc_child.o \ + $(EOLIST) + +# +# These are the LIB files needed to create the NLM target above. +# These will be added as a library command in the link.opt file. +# +FILES_nlm_libs = \ + libcpre.o \ + $(EOLIST) + +# +# These are the modules that the above NLM target depends on to load. +# These will be added as a module command in the link.opt file. +# +FILES_nlm_modules = \ + aprlib \ + Libc \ + $(EOLIST) + +# +# If the nlm has a msg file, put it's path here +# +FILE_nlm_msg = + +# +# If the nlm has a hlp file put it's path here +# +FILE_nlm_hlp = + +# +# If this is specified, it will override the default copyright. +# +FILE_nlm_copyright = + +# +# Any additional imports go here +# +FILES_nlm_Ximports = \ + @$(APR)/aprlib.imp \ + @libc.imp \ + $(EOLIST) + +# +# Any symbols exported to here +# +FILES_nlm_exports = \ + $(EOLIST) + +# +# These are the OBJ files needed to create the LIB target above. +# Paths must all use the '/' character +# +FILES_lib_objs = \ + $(EOLIST) + +# +# implement targets and dependancies (leave this section alone) +# + +libs :: $(OBJDIR) $(TARGET_lib) + +nlms :: libs $(TARGET_nlm) + +# +# Updated this target to create necessary directories and copy files to the +# correct place. (See $(APR_WORK)\build\NWGNUhead.inc for examples) +# +install :: nlms FORCE + +# +# Any specialized rules here +# + +# +# Include the 'tail' makefile that has targets that depend on variables defined +# in this makefile +# + +include $(APR_WORK)\build\NWGNUtail.inc + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/NWGNUtestatmc b/rubbos/app/httpd-2.0.64/srclib/apr/test/NWGNUtestatmc new file mode 100644 index 00000000..e24bf36a --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/NWGNUtestatmc @@ -0,0 +1,255 @@ +# +# Make sure all needed macro's are defined +# + +# +# Get the 'head' of the build environment if necessary. This includes default +# targets and paths to tools +# + +ifndef EnvironmentDefined +include $(APR_WORK)\build\NWGNUhead.inc +endif + +# +# These directories will be at the beginning of the include list, followed by +# INCDIRS +# +XINCDIRS += \ + $(APR_WORK)/include \ + $(APR_WORK)/include/arch/NetWare \ + $(EOLIST) + +# +# These flags will come after CFLAGS +# +XCFLAGS += \ + $(EOLIST) + +# +# These defines will come after DEFINES +# +XDEFINES += \ + $(EOLIST) + +# +# These flags will be added to the link.opt file +# +XLFLAGS += \ + $(EOLIST) + +# +# These values will be appended to the correct variables based on the value of +# RELEASE +# +ifeq "$(RELEASE)" "debug" +XINCDIRS += \ + $(EOLIST) + +XCFLAGS += \ + $(EOLIST) + +XDEFINES += \ + $(EOLIST) + +XLFLAGS += \ + $(EOLIST) +endif + +ifeq "$(RELEASE)" "noopt" +XINCDIRS += \ + $(EOLIST) + +XCFLAGS += \ + $(EOLIST) + +XDEFINES += \ + $(EOLIST) + +XLFLAGS += \ + $(EOLIST) +endif + +ifeq "$(RELEASE)" "release" +XINCDIRS += \ + $(EOLIST) + +XCFLAGS += \ + $(EOLIST) + +XDEFINES += \ + $(EOLIST) + +XLFLAGS += \ + $(EOLIST) +endif + +# +# These are used by the link target if an NLM is being generated +# This is used by the link 'name' directive to name the nlm. If left blank +# TARGET_nlm (see below) will be used. +# +NLM_NAME = testatmc +# +# This is used by the link '-desc ' directive. +# If left blank, NLM_NAME will be used. +# +NLM_DESCRIPTION = NLM is to test the atomic functions + +# +# This is used by the '-threadname' directive. If left blank, +# NLM_NAME Thread will be used. +# +NLM_THREAD_NAME = $(NLM_NAME) Thread + +# +# This is used by the '-screenname' directive. If left blank, +# 'Apache for NetWare' Thread will be used. +# +NLM_SCREEN_NAME = $(NLM_NAME) + +# +# If this is specified, it will override VERSION value in +# $(APR_WORK)\build\NWGNUenvironment.inc +# +NLM_VERSION = + +# +# If this is specified, it will override the default of 64K +# +NLM_STACK_SIZE = + +# +# If this is specified it will be used by the link '-entry' directive +# +NLM_ENTRY_SYM = _LibCPrelude + +# +# If this is specified it will be used by the link '-exit' directive +# +NLM_EXIT_SYM = _LibCPostlude + +# +# If this is specified it will be used by the link '-check' directive +# +NLM_CHECK_SYM = + +# +# If this is specified it will be used by the link '-flags' directive +# +NLM_FLAGS = AUTOUNLOAD, PSEUDOPREEMPTION + +# +# If this is specified it will be linked in with the XDCData option in the def +# file instead of the default of $(APR)/misc/netware/apache.xdc. XDCData can +# be disabled by setting APACHE_UNIPROC in the environment +# +XDCDATA = + +# +# Declare all target files (you must add your files here) +# + +# +# If there is an NLM target, put it here +# +TARGET_nlm = \ + $(OBJDIR)/testatmc.nlm \ + $(EOLIST) + +# +# If there is an LIB target, put it here +# +TARGET_lib = \ + $(EOLIST) + +# +# These are the OBJ files needed to create the NLM target above. +# Paths must all use the '/' character +# +FILES_nlm_objs = \ + $(OBJDIR)/testatomic.o \ + $(OBJDIR)/nw_misc.o \ + $(EOLIST) + +# Pending tests + +# +# These are the LIB files needed to create the NLM target above. +# These will be added as a library command in the link.opt file. +# +FILES_nlm_libs = \ + libcpre.o \ + $(EOLIST) + +# +# These are the modules that the above NLM target depends on to load. +# These will be added as a module command in the link.opt file. +# +FILES_nlm_modules = \ + Libc \ + APRLIB \ + $(EOLIST) + +# +# If the nlm has a msg file, put it's path here +# +FILE_nlm_msg = + +# +# If the nlm has a hlp file put it's path here +# +FILE_nlm_hlp = + +# +# If this is specified, it will override the default copyright. +# +FILE_nlm_copyright = + +# +# Any additional imports go here +# +FILES_nlm_Ximports = \ + @libc.imp \ + @$(APR)/aprlib.imp \ + $(EOLIST) + +# +# Any symbols exported to here +# +FILES_nlm_exports = \ + $(EOLIST) + +# +# These are the OBJ files needed to create the LIB target above. +# Paths must all use the '/' character +# +FILES_lib_objs = \ + $(EOLIST) + +# +# implement targets and dependancies (leave this section alone) +# + +libs :: $(OBJDIR) $(TARGET_lib) + +nlms :: libs $(TARGET_nlm) + +# +# Updated this target to create necessary directories and copy files to the +# correct place. (See $(APR_WORK)\build\NWGNUhead.inc for examples) +# +install :: nlms FORCE + +# +# Any specialized rules here +# + + +# +# Include the 'tail' makefile that has targets that depend on variables defined +# in this makefile +# + +include $(APR_WORK)\build\NWGNUtail.inc + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/README b/rubbos/app/httpd-2.0.64/srclib/apr/test/README new file mode 100644 index 00000000..42ecdd47 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/README @@ -0,0 +1,248 @@ +Writing APR tests + +All APR tests should be executable in 2 ways, as an individual program, or +as a part of the full test suite. The full test suite is controlled with +the testall program. At the beginning of the testall.c file, there is an +array of functions called tests. The testall program loops through this +array calling each function. Each function returns a CuSuite variable, which +is then added to the SuiteList. Once all Suites have been added, the SuiteList +is executed, and the output is printed to the screen. All functions in the +array should follow the same basic format: + +The Full Suite +-------------- + +/* The driver function. This must return a CuSuite variable, which will + * then be used to actually run the tests. Essentially, all Suites are a + * collection of tests. The driver will take each Suite, and put it in a + * SuiteList, which is a collection of Suites. + */ +CuSuite *testtime(void) +{ + /* The actual suite, this must be created for each test program. Please + * give it a useful name, that will inform the user of the feature being + * tested. + */ + CuSuite *suite = CuSuiteNew("Test Time"); + + /* Each function must be added to the suite. Each function represents + * a single test. It is possible to test multiple features in a single + * function, although no tests currently do that. + */ + SUITE_ADD_TEST(suite, test_now); + SUITE_ADD_TEST(suite, test_gmtstr); + SUITE_ADD_TEST(suite, test_localstr); + SUITE_ADD_TEST(suite, test_exp_get_gmt); + SUITE_ADD_TEST(suite, test_exp_get_lt); + SUITE_ADD_TEST(suite, test_imp_gmt); + SUITE_ADD_TEST(suite, test_rfcstr); + SUITE_ADD_TEST(suite, test_ctime); + SUITE_ADD_TEST(suite, test_strftime); + SUITE_ADD_TEST(suite, test_strftimesmall); + SUITE_ADD_TEST(suite, test_exp_tz); + SUITE_ADD_TEST(suite, test_strftimeoffset); + + /* You must return the suite so that the driver knows which suites to + * run. + */ + return suite; +} + +Building the full driver +------------------------ + +All you need to do to build the full driver is run: + + make testall + +To run it, run: + + ./testall + +Caveats +------- + +Currently, some tests are known to fail in certain circumstances: + + * 'testpoll' opens 64 sockets concurrently; ensure that resource +limits are high enough to allow this (using ulimit or limit); for +instance, Solaris <=2.7 and HP-UX 11.00 both set the limit to <=64 by +default + + * 'testipsub' will tickle the Solaris 8 getaddrinfo() IPv6 +bug, causing the test to hang. Configure with --disable-ipv6 if using +an unpatched Solaris 8 installation. + + * The 'testdso' tests will not work if configured with +--disable-shared since the loadable modules cannot be built. + +Running individual tests +--------------------------------- + +It is not possible to build individual tests, however it is possible to +run individual tests. When running the test suite, specify the name of the +tests that you want to run on the command line. For example: + + ./testall teststr testrand + +Will run the Strings and Random generator tests. + +Reading the test suite output +----------------------------- + +Once you run the test suite, you will get output like: + +All APR Tests: + Test Strings: .... + Test Time: ............ + +16 tests run: 16 passed, 0 failed, 0 not implemented. + +There are a couple of things to look at with this. First, if you look at the +first function in this document, you should notice that the string passed to +the CuSuiteNew function is in the output. That is why the string should +explain the feature you are testing. + +Second, this test passed completely. This is obvious in two ways. First, and +most obvious, the summary line tells you that 16 tests were run and 16 tests +passed. However, the results can also be found in the lines above. Every +'.' in the output represents a passed test. + +If a test fails, the output will look like: + +All APR Tests: + Test Strings: .... + Test Time: ..F......... + +16 tests run: 15 passed, 1 failed, 0 not implemented. + +This is not very useful, because you don't know which test failed. However, +once you know that a test failed, you can run the suite again, with the +-v option. If you do this, you will get something like: + +All APR Tests: + Test Strings: .... + Test Time: ..F......... + +16 tests run: 15 passed, 1 failed, 0 not implemented. +Failed tests: +1) test_localstr: assert failed + +In this case, we know the test_localstr function failed, and there is an +Assert in this that failed (I modified the test to fail for this document). +Now, you can look at what that test does, and why it would have failed. + +There is one other possible output for the test suite (run with -v): + +All APR Tests: + Test Strings: .... + Test Time: ..N......... + +16 tests run: 15 passed, 0 failed, 1 not implemented. + +Not Implemented tests: + +Not Implemented tests: +1) test_localstr: apr_time_exp_lt not implemented on this platform + +The 'N' means that a function has returned APR_ENOTIMPL. This should be +treated as an error, and the function should be implemented as soon as +possible. + +Adding New test Suites to the full driver +------------------------------------------- + +To add a new Suite to the full driver, you must make a couple of modifications. + +1) Edit test_apr.h, and add the prototype for the function. +2) Edit testall.c, and add the function and name to the tests array. +3) Edit Makefile.in, and add the .lo file to the testall target. + +Once those four things are done, your tests will automatically be added +to the suite. + +Writing tests +------------- + +There are a couple of rules for writing good tests for the test suite. + +1) All tests can determine for themselves if it passed or not. This means +that there is no reason for the person running the test suite to interpret +the results of the tests. +2) Never use printf to add to the output of the test suite. The suite +library should be able to print all of the information required to debug +a problem. +3) Functions should be tested with both positive and negative tests. This +means that you should test things that should both succeed and fail. +4) Just checking the return code does _NOT_ make a useful test. You must +check to determine that the test actually did what you expected it to do. + +An example test +--------------- + +Finally, we will look at a quick test: + +/* All tests are passed a CuTest variable. This is how the suite determines + * if the test succeeded or failed. + */ +static void test_localstr(CuTest *tc) +{ + apr_status_t rv; + apr_time_exp_t xt; + time_t os_now; + + rv = apr_time_exp_lt(&xt, now); + os_now = now / APR_USEC_PER_SEC; + + /* If the function can return APR_ENOTIMPL, then you should check for it. + * This allows platform implementors to know if they have to implement + * the function. + */ + if (rv == APR_ENOTIMPL) { + CuNotImpl(tc, "apr_time_exp_lt"); + } + + /* It often helps to ensure that the return code was APR_SUCESS. If it + * wasn't, then we know the test failed. + */ + CuAssertTrue(tc, rv == APR_SUCCESS); + + /* Now that we know APR thinks it worked properly, we need to check the + * output to ensure that we got what we expected. + */ + CuAssertStrEquals(tc, "2002-08-14 12:05:36.186711 -25200 [257 Sat] DST", + print_time(p, &xt)); +} + +Notice, the same test can fail for any of a number of reasons. The first +test to fail ends the test. + +CuTest +------ + +CuTest is an open source test suite written by Asim Jalis. It has been +released under the zlib/libpng license. That license can be found in the +CuTest.c and CuTest.h files. + +The version of CuTest that is included in the APR test suite has been modified +from the original distribution in the following ways: + +1) The original distribution does not have a -v flag, the details are always +printed. +2) The NotImplemented result does not exist. +3) SuiteLists do not exist. In the original distribution, you can add suites +to suites, but it just adds the tests in the first suite to the list of tests +in the original suite. The output wasn't as detailed as I wanted, so I created +SuiteLists. + +The first two modifications have been sent to the original author of CuTest, +but they have not been integrated into the base distribution. The SuiteList +changes will be sent to the original author soon. + +The modified version of CuTest is not currently in any CVS or Subversion +server. In time, it will be hosted at rkbloom.net. + +There are currently no docs for how to write tests, but the teststr and +testtime programs should give an idea of how it is done. In time, a document +should be written to define how tests are written. + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/aprtest.def b/rubbos/app/httpd-2.0.64/srclib/apr/test/aprtest.def new file mode 100644 index 00000000..bfea210d --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/aprtest.def @@ -0,0 +1,3 @@ +MODULE LIBC.NLM +MODULE APRLIB.NLM + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/aprtest.dsp b/rubbos/app/httpd-2.0.64/srclib/apr/test/aprtest.dsp new file mode 100644 index 00000000..e31b898d --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/aprtest.dsp @@ -0,0 +1,199 @@ +# Microsoft Developer Studio Project File - Name="aprtest" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) External Target" 0x0106 + +CFG=aprtest - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "aprtest.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "aprtest.mak" CFG="aprtest - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "aprtest - Win32 Release" (based on "Win32 (x86) External Target") +!MESSAGE "aprtest - Win32 Debug" (based on "Win32 (x86) External Target") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" + +!IF "$(CFG)" == "aprtest - Win32 Release" + +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Cmd_Line "NMAKE /f Makefile" +# PROP BASE Rebuild_Opt "/a" +# PROP BASE Target_File "aprtest.exe" +# PROP BASE Bsc_Name "aprtest.bsc" +# PROP BASE Target_Dir "" +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Cmd_Line "NMAKE /f aprtest.win" +# PROP Rebuild_Opt "/a" +# PROP Bsc_Name "" +# PROP Target_Dir "" + +!ELSEIF "$(CFG)" == "aprtest - Win32 Debug" + +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Cmd_Line "NMAKE /f aprtest.mak" +# PROP BASE Rebuild_Opt "/a" +# PROP BASE Target_File "aprtest.exe" +# PROP BASE Bsc_Name "aprtest.bsc" +# PROP BASE Target_Dir "" +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Cmd_Line "NMAKE /f aprtest.win" +# PROP Rebuild_Opt "/a" +# PROP Bsc_Name "" +# PROP Target_Dir "" + +!ENDIF + +# Begin Target + +# Name "aprtest - Win32 Release" +# Name "aprtest - Win32 Debug" + +!IF "$(CFG)" == "aprtest - Win32 Release" + +!ELSEIF "$(CFG)" == "aprtest - Win32 Debug" + +!ENDIF + +# Begin Group "Sources" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\abc.c +# End Source File +# Begin Source File + +SOURCE=.\client.c +# End Source File +# Begin Source File + +SOURCE=.\mod_test.c +# End Source File +# Begin Source File + +SOURCE=.\occhild.c +# End Source File +# Begin Source File + +SOURCE=.\sendfile.c +# End Source File +# Begin Source File + +SOURCE=.\server.c +# End Source File +# Begin Source File + +SOURCE=.\testargs.c +# End Source File +# Begin Source File + +SOURCE=.\testcontext.c +# End Source File +# Begin Source File + +SOURCE=.\testdso.c +# End Source File +# Begin Source File + +SOURCE=.\testfile.c +# End Source File +# Begin Source File + +SOURCE=.\testflock.c +# End Source File +# Begin Source File + +SOURCE=.\testlock.c +# End Source File +# Begin Source File + +SOURCE=.\testmmap.c +# End Source File +# Begin Source File + +SOURCE=.\testnames.c +# End Source File +# Begin Source File + +SOURCE=.\testoc.c +# End Source File +# Begin Source File + +SOURCE=.\testpath.c +# End Source File +# Begin Source File + +SOURCE=.\testpipe.c +# End Source File +# Begin Source File + +SOURCE=.\testproc.c +# End Source File +# Begin Source File + +SOURCE=.\testshm.c +# End Source File +# Begin Source File + +SOURCE=.\testsock.c +# End Source File +# Begin Source File + +SOURCE=.\testthread.c +# End Source File +# Begin Source File + +SOURCE=.\testtime.c +# End Source File +# Begin Source File + +SOURCE=.\testucs.c +# End Source File +# Begin Source File + +SOURCE=.\testuser.c +# End Source File +# Begin Source File + +SOURCE=.\testuuid.c +# End Source File +# End Group +# Begin Source File + +SOURCE=.\aprtest.win +# End Source File +# Begin Source File + +SOURCE=.\Makefile +# End Source File +# Begin Source File + +SOURCE=.\Makefile.in +# End Source File +# Begin Source File + +SOURCE=.\MakeWin32Make.awk +# End Source File +# End Target +# End Project diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/aprtest.h b/rubbos/app/httpd-2.0.64/srclib/apr/test/aprtest.h new file mode 100644 index 00000000..9da542b3 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/aprtest.h @@ -0,0 +1,52 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_strings.h" + +#ifndef APR_TEST_PREFIX +#define APR_TEST_PREFIX "" +#endif + +#define APR_TEST_BEGIN(rv, desc, op) \ + fprintf(stdout, "%s%.*s ", APR_TEST_PREFIX desc, \ + strlen(desc) < 37 ? (int)(40 - strlen(desc)) : 3, \ + "........................................"); \ + APR_TEST_MORE(rv, op) + +#define APR_TEST_MORE(rv, op) \ + if ((rv = (op)) != APR_SUCCESS) { \ + char msgbuf[256]; \ + fprintf (stdout, "Failed\n"); \ + fprintf (stderr, "Error (%d): %s\n%s", rv, #op, \ + apr_strerror(rv, msgbuf, sizeof(msgbuf))); \ + exit(-1); } + +#define APR_TEST_END(rv, op) \ + APR_TEST_MORE(rv, op) \ + fprintf(stdout, "OK\n"); + +#define APR_TEST_SUCCESS(rv, desc, op) \ + APR_TEST_BEGIN(rv, desc, op) \ + fprintf(stdout, "OK\n"); + +#define APR_TEST_INITIALIZE(rv, pool) \ + APR_TEST_SUCCESS(rv, "Initializing", apr_initialize()); \ + atexit(apr_terminate); \ + APR_TEST_SUCCESS(rv, "Creating context", \ + apr_pool_create(&pool, NULL)); + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/aprtest.win b/rubbos/app/httpd-2.0.64/srclib/apr/test/aprtest.win new file mode 100644 index 00000000..85ad5b4d --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/aprtest.win @@ -0,0 +1,18 @@ +# Note: +# +# You may need to modify the configuration of Build - Options - Directories +# for the Executable path to include the perl interpreter within DevStudio. +# E.g. add c:\program files\perl\bin to the list of directories + +!IF "$(TARGET)" == "" +TARGET=ALL +!ENDIF + +$(TARGET): Makefile + $(MAKE) /nologo /f Makefile $(TARGET) + +Makefile: Makefile.in MakeWin32Make.awk + awk -f MakeWin32Make.awk <Makefile.in >Makefile + +clean: + del Makefile *.obj *.exe *.idb *.pdb diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/client.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/client.c new file mode 100644 index 00000000..bab7fe59 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/client.c @@ -0,0 +1,153 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdlib.h> +#include "apr_network_io.h" +#include "apr_errno.h" +#include "apr_general.h" +#include <errno.h> + +#define STRLEN 15 + +int main(int argc, char *argv[]) +{ + apr_pool_t *context; + apr_socket_t *sock; + apr_size_t length; + apr_status_t stat; + char datasend[STRLEN] = "Send data test"; + char datarecv[STRLEN]; + char msgbuf[80]; + char *local_ipaddr, *remote_ipaddr; + char *dest = "127.0.0.1"; + apr_port_t local_port, remote_port; + apr_interval_time_t timeout = apr_time_from_sec(2); + apr_sockaddr_t *local_sa, *remote_sa; + + setbuf(stdout, NULL); + if (argc > 1) { + dest = argv[1]; + } + + if (argc > 2) { + timeout = atoi(argv[2]); + } + + fprintf(stdout, "Initializing........."); + if (apr_initialize() != APR_SUCCESS) { + fprintf(stderr, "Something went wrong\n"); + exit(-1); + } + fprintf(stdout, "OK\n"); + atexit(apr_terminate); + + fprintf(stdout, "Creating context......."); + if (apr_pool_create(&context, NULL) != APR_SUCCESS) { + fprintf(stderr, "Something went wrong\n"); + exit(-1); + } + fprintf(stdout, "OK\n"); + + fprintf(stdout,"\tClient: Making socket address..............."); + if ((stat = apr_sockaddr_info_get(&remote_sa, dest, APR_UNSPEC, 8021, 0, context)) + != APR_SUCCESS) { + fprintf(stdout, "Failed!\n"); + fprintf(stdout, "Address resolution failed for %s: %s\n", + dest, apr_strerror(stat, msgbuf, sizeof(msgbuf))); + exit(-1); + } + fprintf(stdout,"OK\n"); + + fprintf(stdout, "\tClient: Creating new socket......."); + if (apr_socket_create(&sock, remote_sa->family, SOCK_STREAM, + context) != APR_SUCCESS) { + fprintf(stderr, "Couldn't create socket\n"); + exit(-1); + } + fprintf(stdout, "OK\n"); + + fprintf(stdout, "\tClient: Setting socket timeout......."); + stat = apr_socket_timeout_set(sock, timeout); + if (stat) { + fprintf(stderr, "Problem setting timeout: %d\n", stat); + exit(-1); + } + fprintf(stdout, "OK\n"); + + fprintf(stdout, "\tClient: Connecting to socket......."); + + stat = apr_socket_connect(sock, remote_sa); + + if (stat != APR_SUCCESS) { + apr_socket_close(sock); + fprintf(stderr, "Could not connect: %s (%d)\n", + apr_strerror(stat, msgbuf, sizeof(msgbuf)), stat); + fflush(stderr); + exit(-1); + } + fprintf(stdout, "OK\n"); + + apr_socket_addr_get(&remote_sa, APR_REMOTE, sock); + apr_sockaddr_ip_get(&remote_ipaddr, remote_sa); + apr_sockaddr_port_get(&remote_port, remote_sa); + apr_socket_addr_get(&local_sa, APR_LOCAL, sock); + apr_sockaddr_ip_get(&local_ipaddr, local_sa); + apr_sockaddr_port_get(&local_port, local_sa); + fprintf(stdout, "\tClient socket: %s:%u -> %s:%u\n", local_ipaddr, local_port, remote_ipaddr, remote_port); + + fprintf(stdout, "\tClient: Trying to send data over socket......."); + length = STRLEN; + if ((stat = apr_socket_send(sock, datasend, &length) != APR_SUCCESS)) { + apr_socket_close(sock); + fprintf(stderr, "Problem sending data: %s (%d)\n", + apr_strerror(stat, msgbuf, sizeof(msgbuf)), stat); + exit(-1); + } + fprintf(stdout, "OK\n"); + + length = STRLEN; + fprintf(stdout, "\tClient: Trying to receive data over socket......."); + + if ((stat = apr_socket_recv(sock, datarecv, &length)) != APR_SUCCESS) { + apr_socket_close(sock); + fprintf(stderr, "Problem receiving data: %s (%d)\n", + apr_strerror(stat, msgbuf, sizeof(msgbuf)), stat); + exit(-1); + } + if (strcmp(datarecv, "Recv data test")) { + apr_socket_close(sock); + fprintf(stderr, "I did not receive the correct data %s\n", datarecv); + exit(-1); + } + fprintf(stdout, "OK\n"); + + fprintf(stdout, "\tClient: Shutting down socket......."); + if (apr_socket_shutdown(sock, APR_SHUTDOWN_WRITE) != APR_SUCCESS) { + apr_socket_close(sock); + fprintf(stderr, "Could not shutdown socket\n"); + exit(-1); + } + fprintf(stdout, "OK\n"); + + fprintf(stdout, "\tClient: Closing down socket......."); + if (apr_socket_close(sock) != APR_SUCCESS) { + fprintf(stderr, "Could not shutdown socket\n"); + exit(-1); + } + fprintf(stdout, "OK\n"); + + return 1; +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/data/file_datafile.txt b/rubbos/app/httpd-2.0.64/srclib/apr/test/data/file_datafile.txt new file mode 100644 index 00000000..1651a329 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/data/file_datafile.txt @@ -0,0 +1 @@ +This is the file data file.
\ No newline at end of file diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/data/mmap_datafile.txt b/rubbos/app/httpd-2.0.64/srclib/apr/test/data/mmap_datafile.txt new file mode 100644 index 00000000..50f47a60 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/data/mmap_datafile.txt @@ -0,0 +1 @@ +This is the MMAP data file. diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/internal/Makefile b/rubbos/app/httpd-2.0.64/srclib/apr/test/internal/Makefile new file mode 100644 index 00000000..5a790860 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/internal/Makefile @@ -0,0 +1,37 @@ +srcdir = . + + +NONPORTABLE = \ + testregex + +PROGRAMS = \ + +TARGETS = $(PROGRAMS) $(NONPORTABLE) + +# bring in rules.mk for standard functionality +include /bottlenecks/rubbos/app/httpd-2.0.64/srclib/apr/build/apr_rules.mk + +LOCAL_LIBS=../../libapr-${APR_MAJOR_VERSION}.la + +CLEAN_TARGETS = testregex + +INCDIR=../../include +INCLUDES=-I$(INCDIR) + +CFLAGS=$(MY_CFLAGS) + +all: $(PROGRAMS) $(NONPORTABLE) + +check: $(PROGRAMS) $(NONPORTABLE) + for prog in $(PROGRAMS) $(NONPORTABLE); do \ + ./$$prog; \ + if test $$i = 255; then \ + echo "$$prog failed"; \ + break; \ + fi \ + done + +testregex: testregex.lo $(LOCAL_LIBS) + $(LINK) testregex.lo $(LOCAL_LIBS) $(ALL_LIBS) + +# DO NOT REMOVE diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/internal/Makefile.in b/rubbos/app/httpd-2.0.64/srclib/apr/test/internal/Makefile.in new file mode 100644 index 00000000..b1f6c6a6 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/internal/Makefile.in @@ -0,0 +1,37 @@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +NONPORTABLE = \ + testregex@EXEEXT@ + +PROGRAMS = \ + +TARGETS = $(PROGRAMS) $(NONPORTABLE) + +# bring in rules.mk for standard functionality +@INCLUDE_RULES@ + +LOCAL_LIBS=../../lib@APR_LIBNAME@.la + +CLEAN_TARGETS = testregex@EXEEXT@ + +INCDIR=../../include +INCLUDES=-I$(INCDIR) + +CFLAGS=$(MY_CFLAGS) + +all: $(PROGRAMS) $(NONPORTABLE) + +check: $(PROGRAMS) $(NONPORTABLE) + for prog in $(PROGRAMS) $(NONPORTABLE); do \ + ./$$prog; \ + if test $$i = 255; then \ + echo "$$prog failed"; \ + break; \ + fi \ + done + +testregex@EXEEXT@: testregex.lo $(LOCAL_LIBS) + $(LINK) testregex.lo $(LOCAL_LIBS) $(ALL_LIBS) + +# DO NOT REMOVE diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/internal/testregex.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/internal/testregex.c new file mode 100644 index 00000000..20dcfdeb --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/internal/testregex.c @@ -0,0 +1,91 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "apr_strings.h" +#include "apr_pools.h" +#include "apr_general.h" +#include "apr_hash.h" +#include "apr_lib.h" +#include "apr_time.h" +#include <regex.h> +#include <stdio.h> +#include <stdlib.h> + +int main( int argc, char** argv) { + apr_pool_t *context; + regex_t regex; + int rc; + int i; + int iters; + apr_time_t now; + apr_time_t end; + apr_hash_t *h; + + + if (argc !=4 ) { + fprintf(stderr, "Usage %s match string #iterations\n",argv[0]); + return -1; + } + iters = atoi( argv[3]); + + apr_initialize() ; + atexit(apr_terminate); + if (apr_pool_create(&context, NULL) != APR_SUCCESS) { + fprintf(stderr, "Something went wrong\n"); + exit(-1); + } + rc = regcomp( ®ex, argv[1], REG_EXTENDED|REG_NOSUB); + + + if (rc) { + char errbuf[2000]; + regerror(rc, ®ex,errbuf,2000); + fprintf(stderr,"Couldn't compile regex ;(\n%s\n ",errbuf); + return -1; + } + if ( regexec( ®ex, argv[2], 0, NULL,0) == 0 ) { + fprintf(stderr,"Match\n"); + } + else { + fprintf(stderr,"No Match\n"); + } + now = apr_time_now(); + for (i=0;i<iters;i++) { + regexec( ®ex, argv[2], 0, NULL,0) ; + } + end=apr_time_now(); + puts(apr_psprintf( context, "Time to run %d regex's %8lld\n",iters,end-now)); + h = apr_hash_make( context); + for (i=0;i<70;i++) { + apr_hash_set(h,apr_psprintf(context, "%dkey",i),APR_HASH_KEY_STRING,"1"); + } + now = apr_time_now(); + for (i=0;i<iters;i++) { + apr_hash_get( h, argv[2], APR_HASH_KEY_STRING); + } + end=apr_time_now(); + puts(apr_psprintf( context, "Time to run %d hash (no find)'s %8lld\n",iters,end-now)); + apr_hash_set(h, argv[2],APR_HASH_KEY_STRING,"1"); + now = apr_time_now(); + for (i=0;i<iters;i++) { + apr_hash_get( h, argv[2], APR_HASH_KEY_STRING); + } + end=apr_time_now(); + puts(apr_psprintf( context, "Time to run %d hash (find)'s %8lld\n",iters,end-now)); + + return 0; +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/internal/testucs.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/internal/testucs.c new file mode 100644 index 00000000..ca735d23 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/internal/testucs.c @@ -0,0 +1,176 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr.h" +#include "arch/win32/apr_arch_utf8.h" +#include <wchar.h> +#include <string.h> + +struct testval { + unsigned char n[8]; + wchar_t w[4]; + int nl; + int wl; +}; + +void displaynw(struct testval *f, struct testval *l) +{ + char x[80], *t = x; + int i; + for (i = 0; i < f->nl; ++i) + t += sprintf(t, "%02X ", f->n[i]); + *(t++) = '-'; + for (i = 0; i < l->nl; ++i) + t += sprintf(t, " %02X", l->n[i]); + *(t++) = ' '; + *(t++) = '='; + *(t++) = ' '; + for (i = 0; i < f->wl; ++i) + t += sprintf(t, "%04X ", f->w[i]); + *(t++) = '-'; + for (i = 0; i < l->wl; ++i) + t += sprintf(t, " %04X", l->w[i]); + puts(x); +} + +/* + * Test every possible byte value. + * If the test passes or fails at this byte value we are done. + * Otherwise iterate test_nrange again, appending another byte. + */ +void test_nrange(struct testval *p) +{ + struct testval f, l, s; + apr_status_t rc; + int success = 0; + + memcpy (&s, p, sizeof(s)); + ++s.nl; + + do { + apr_size_t nl = s.nl, wl = sizeof(s.w) / 2; + rc = apr_conv_utf8_to_ucs2(s.n, &nl, s.w, &wl); + s.wl = (sizeof(s.w) / 2) - wl; + if (!nl && rc == APR_SUCCESS) { + if (!success) { + memcpy(&f, &s, sizeof(s)); + success = -1; + } + else { + if (s.wl != l.wl + || memcmp(s.w, l.w, (s.wl - 1) * 2) != 0 + || s.w[s.wl - 1] != l.w[l.wl - 1] + 1) { + displaynw(&f, &l); + memcpy(&f, &s, sizeof(s)); + } + } + memcpy(&l, &s, sizeof(s)); + } + else { + if (success) { + displaynw(&f, &l); + success = 0; + } + if (rc == APR_INCOMPLETE) { + test_nrange(&s); + } + } + } while (++s.n[s.nl - 1]); + + if (success) { + displaynw(&f, &l); + success = 0; + } +} + +/* + * Test every possible word value. + * Once we are finished, retest every possible word value. + * if the test fails on the following null word, iterate test_nrange + * again, appending another word. + * This assures the output order of the two tests are in sync. + */ +void test_wrange(struct testval *p) +{ + struct testval f, l, s; + apr_status_t rc; + int success = 0; + + memcpy (&s, p, sizeof(s)); + ++s.wl; + + do { + apr_size_t nl = sizeof(s.n), wl = s.wl; + rc = apr_conv_ucs2_to_utf8(s.w, &wl, s.n, &nl); + s.nl = sizeof(s.n) - nl; + if (!wl && rc == APR_SUCCESS) { + if (!success) { + memcpy(&f, &s, sizeof(s)); + success = -1; + } + else { + if (s.nl != l.nl + || memcmp(s.n, l.n, s.nl - 1) != 0 + || s.n[s.nl - 1] != l.n[l.nl - 1] + 1) { + displaynw(&f, &l); + memcpy(&f, &s, sizeof(s)); + } + } + memcpy(&l, &s, sizeof(s)); + } + else { + if (success) { + displaynw(&f, &l); + success = 0; + } + } + } while (++s.w[s.wl - 1]); + + if (success) { + displaynw(&f, &l); + success = 0; + } + + do { + int wl = s.wl, nl = sizeof(s.n); + rc = apr_conv_ucs2_to_utf8(s.w, &wl, s.n, &nl); + s.nl = sizeof(s.n) - s.nl; + if (rc == APR_INCOMPLETE) { + test_wrange(&s); + } + } while (++s.w[s.wl - 1]); +} + +/* + * Syntax: testucs [w|n] + * + * If arg is not recognized, run both tests. + */ +int main(int argc, char **argv) +{ + struct testval s; + memset (&s, 0, sizeof(s)); + + if (argc < 2 || apr_tolower(*argv[1]) != 'w') { + printf ("\n\nTesting Narrow Char Ranges\n"); + test_nrange(&s); + } + if (argc < 2 || apr_tolower(*argv[1]) != 'n') { + printf ("\n\nTesting Wide Char Ranges\n"); + test_wrange(&s); + } + return 0; +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/mod_test.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/mod_test.c new file mode 100644 index 00000000..2178e940 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/mod_test.c @@ -0,0 +1,32 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_strings.h" + +void print_hello(char str[256]); +int count_reps(int reps); + +void print_hello(char str[256]) +{ + apr_cpystrn(str, "Hello - I'm a DSO!\n", strlen("Hello - I'm a DSO!\n") + 1); +} + +int count_reps(int reps) +{ + int i = 0; + for (i = 0;i < reps; i++); + return i; +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/nw_misc.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/nw_misc.c new file mode 100644 index 00000000..2f670935 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/nw_misc.c @@ -0,0 +1,15 @@ +#include <netware.h> +#include <screen.h> +#include "test_apr.h" + +void _NonAppStop( void ) +{ + if (getenv("_IN_NETWARE_BASH_") == NULL) + pressanykey(); +} + +static void test_not_impl(CuTest *tc) +{ + CuNotImpl(tc, "Test not implemented on this platform yet"); +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/occhild.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/occhild.c new file mode 100644 index 00000000..a96885d8 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/occhild.c @@ -0,0 +1,26 @@ +#include "apr.h" +#include "apr_file_io.h" +#include "apr.h" + +#if APR_HAVE_STDLIB_H +#include <stdlib.h> +#endif + +int main(void) +{ + char buf[256]; + apr_file_t *err; + apr_pool_t *p; + + apr_initialize(); + atexit(apr_terminate); + + apr_pool_create(&p, NULL); + apr_file_open_stdin(&err, p); + + while (1) { + apr_size_t length = 256; + apr_file_read(err, buf, &length); + } + exit(0); /* just to keep the compiler happy */ +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/proc_child.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/proc_child.c new file mode 100644 index 00000000..405bb7f5 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/proc_child.c @@ -0,0 +1,21 @@ +#include "apr.h" +#include <stdio.h> +#if APR_HAVE_UNISTD_H +#include <unistd.h> +#endif +#if APR_HAVE_IO_H +#include <io.h> +#endif +#include <stdlib.h> + +int main(void) +{ + char buf[256]; + apr_ssize_t bytes; + + bytes = read(STDIN_FILENO, buf, 256); + if (bytes > 0) + write(STDOUT_FILENO, buf, bytes); + + return 0; /* just to keep the compiler happy */ +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/readchild.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/readchild.c new file mode 100644 index 00000000..f8443cce --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/readchild.c @@ -0,0 +1,46 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdlib.h> + +#include "apr_file_io.h" + +int main(int argc, char *argv[]) +{ + apr_file_t *in, *out; + apr_size_t nbytes, total_bytes; + apr_pool_t *p; + char buf[128]; + apr_status_t rv; + + apr_initialize(); + atexit(apr_terminate); + apr_pool_create(&p, NULL); + + apr_file_open_stdin(&in, p); + apr_file_open_stdout(&out, p); + + total_bytes = 0; + nbytes = sizeof(buf); + while ((rv = apr_file_read(in, buf, &nbytes)) == APR_SUCCESS) { + total_bytes += nbytes; + nbytes = sizeof(buf); + } + + apr_file_printf(out, "%" APR_SIZE_T_FMT " bytes were read\n", + total_bytes); + return 0; +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/sendfile.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/sendfile.c new file mode 100644 index 00000000..b14765fd --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/sendfile.c @@ -0,0 +1,749 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <assert.h> +#include <errno.h> +#include <signal.h> +#include <stdlib.h> +#include <string.h> +#include "apr_network_io.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_poll.h" + +#if !APR_HAS_SENDFILE +int main(void) +{ + fprintf(stderr, + "This program won't work on this platform because there is no " + "support for sendfile().\n"); + return 0; +} +#else /* !APR_HAS_SENDFILE */ + +#define FILE_LENGTH 200000 + +#define FILE_DATA_CHAR '0' + +#define HDR1 "1234567890ABCD\n" +#define HDR2 "EFGH\n" +#define HDR3_LEN 80000 +#define HDR3_CHAR '^' +#define TRL1 "IJKLMNOPQRSTUVWXYZ\n" +#define TRL2 "!@#$%&*()\n" +#define TRL3_LEN 90000 +#define TRL3_CHAR '@' + +#define TESTSF_PORT 8021 + +#define TESTFILE "testsf.dat" + +typedef enum {BLK, NONBLK, TIMEOUT} client_socket_mode_t; + +static void apr_setup(apr_pool_t **p, apr_socket_t **sock, int *family) +{ + char buf[120]; + apr_status_t rv; + + rv = apr_initialize(); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_initialize()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + atexit(apr_terminate); + + rv = apr_pool_create(p, NULL); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_pool_create()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + *sock = NULL; + rv = apr_socket_create(sock, *family, SOCK_STREAM, *p); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_create()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + if (*family == APR_UNSPEC) { + apr_sockaddr_t *localsa; + + rv = apr_socket_addr_get(&localsa, APR_LOCAL, *sock); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_addr_get()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + *family = localsa->family; + } +} + +static void create_testfile(apr_pool_t *p, const char *fname) +{ + apr_file_t *f = NULL; + apr_status_t rv; + char buf[120]; + int i; + apr_finfo_t finfo; + + printf("Creating a test file...\n"); + rv = apr_file_open(&f, fname, + APR_CREATE | APR_WRITE | APR_TRUNCATE | APR_BUFFERED, + APR_UREAD | APR_UWRITE, p); + if (rv) { + fprintf(stderr, "apr_file_open()->%d/%s\n", + rv, apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + buf[0] = FILE_DATA_CHAR; + buf[1] = '\0'; + for (i = 0; i < FILE_LENGTH; i++) { + /* exercise apr_file_putc() and apr_file_puts() on buffered files */ + if ((i % 2) == 0) { + rv = apr_file_putc(buf[0], f); + if (rv) { + fprintf(stderr, "apr_file_putc()->%d/%s\n", + rv, apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + } + else { + rv = apr_file_puts(buf, f); + if (rv) { + fprintf(stderr, "apr_file_puts()->%d/%s\n", + rv, apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + } + } + + rv = apr_file_close(f); + if (rv) { + fprintf(stderr, "apr_file_close()->%d/%s\n", + rv, apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + rv = apr_stat(&finfo, fname, APR_FINFO_NORM, p); + if (rv != APR_SUCCESS && rv != APR_INCOMPLETE) { + fprintf(stderr, "apr_stat()->%d/%s\n", + rv, apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + if (finfo.size != FILE_LENGTH) { + fprintf(stderr, + "test file %s should be %ld-bytes long\n" + "instead it is %ld-bytes long\n", + fname, + (long int)FILE_LENGTH, + (long int)finfo.size); + exit(1); + } +} + +static int client(client_socket_mode_t socket_mode, char *host) +{ + apr_status_t rv, tmprv; + apr_socket_t *sock; + apr_pool_t *p; + char buf[120]; + apr_file_t *f = NULL; + apr_size_t len; + apr_size_t expected_len; + apr_off_t current_file_offset; + apr_hdtr_t hdtr; + struct iovec headers[3]; + struct iovec trailers[3]; + apr_size_t bytes_read; + apr_pollfd_t *pfd; + apr_int32_t nsocks; + int i; + int family; + apr_sockaddr_t *destsa; + + family = APR_INET; + apr_setup(&p, &sock, &family); + create_testfile(p, TESTFILE); + + rv = apr_file_open(&f, TESTFILE, APR_READ, 0, p); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_file_open()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + if (!host) { + host = "127.0.0.1"; + } + rv = apr_sockaddr_info_get(&destsa, host, family, TESTSF_PORT, 0, p); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_sockaddr_info_get()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + rv = apr_socket_connect(sock, destsa); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_connect()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + switch(socket_mode) { + case BLK: + /* leave it blocking */ + break; + case NONBLK: + /* set it non-blocking */ + rv = apr_socket_opt_set(sock, APR_SO_NONBLOCK, 1); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_opt_set(APR_SO_NONBLOCK)->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + break; + case TIMEOUT: + /* set a timeout */ + rv = apr_socket_timeout_set(sock, 100 * APR_USEC_PER_SEC); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_opt_set(APR_SO_NONBLOCK)->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + break; + default: + assert(1 != 1); + } + + printf("Sending the file...\n"); + + hdtr.headers = headers; + hdtr.numheaders = 3; + hdtr.headers[0].iov_base = HDR1; + hdtr.headers[0].iov_len = strlen(hdtr.headers[0].iov_base); + hdtr.headers[1].iov_base = HDR2; + hdtr.headers[1].iov_len = strlen(hdtr.headers[1].iov_base); + hdtr.headers[2].iov_base = malloc(HDR3_LEN); + assert(hdtr.headers[2].iov_base); + memset(hdtr.headers[2].iov_base, HDR3_CHAR, HDR3_LEN); + hdtr.headers[2].iov_len = HDR3_LEN; + + hdtr.trailers = trailers; + hdtr.numtrailers = 3; + hdtr.trailers[0].iov_base = TRL1; + hdtr.trailers[0].iov_len = strlen(hdtr.trailers[0].iov_base); + hdtr.trailers[1].iov_base = TRL2; + hdtr.trailers[1].iov_len = strlen(hdtr.trailers[1].iov_base); + hdtr.trailers[2].iov_base = malloc(TRL3_LEN); + memset(hdtr.trailers[2].iov_base, TRL3_CHAR, TRL3_LEN); + assert(hdtr.trailers[2].iov_base); + hdtr.trailers[2].iov_len = TRL3_LEN; + + expected_len = + strlen(HDR1) + strlen(HDR2) + HDR3_LEN + + strlen(TRL1) + strlen(TRL2) + TRL3_LEN + + FILE_LENGTH; + + if (socket_mode == BLK) { + current_file_offset = 0; + len = FILE_LENGTH; + rv = apr_socket_sendfile(sock, f, &hdtr, ¤t_file_offset, &len, 0); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_sendfile()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + printf("apr_socket_sendfile() updated offset with %ld\n", + (long int)current_file_offset); + + printf("apr_socket_sendfile() updated len with %ld\n", + (long int)len); + + printf("bytes really sent: %" APR_SIZE_T_FMT "\n", + expected_len); + + if (len != expected_len) { + fprintf(stderr, "apr_socket_sendfile() didn't report the correct " + "number of bytes sent!\n"); + exit(1); + } + } + else { + /* non-blocking... wooooooo */ + apr_size_t total_bytes_sent; + + pfd = NULL; + rv = apr_poll_setup(&pfd, 1, p); + assert(!rv); + rv = apr_poll_socket_add(pfd, sock, APR_POLLOUT); + assert(!rv); + + total_bytes_sent = 0; + current_file_offset = 0; + len = FILE_LENGTH; + do { + apr_size_t tmplen; + + tmplen = len; /* bytes remaining to send from the file */ + printf("Calling apr_socket_sendfile()...\n"); + printf("Headers (%d):\n", hdtr.numheaders); + for (i = 0; i < hdtr.numheaders; i++) { + printf("\t%ld bytes (%c)\n", + (long)hdtr.headers[i].iov_len, + *(char *)hdtr.headers[i].iov_base); + } + printf("File: %ld bytes from offset %ld\n", + (long)tmplen, (long)current_file_offset); + printf("Trailers (%d):\n", hdtr.numtrailers); + for (i = 0; i < hdtr.numtrailers; i++) { + printf("\t%ld bytes\n", + (long)hdtr.trailers[i].iov_len); + } + + rv = apr_socket_sendfile(sock, f, &hdtr, ¤t_file_offset, &tmplen, 0); + printf("apr_socket_sendfile()->%d, sent %ld bytes\n", rv, (long)tmplen); + if (rv) { + if (APR_STATUS_IS_EAGAIN(rv)) { + assert(tmplen == 0); + nsocks = 1; + tmprv = apr_poll(pfd, 1, &nsocks, -1); + assert(!tmprv); + assert(nsocks == 1); + /* continue; */ + } + } + + total_bytes_sent += tmplen; + + /* Adjust hdtr to compensate for partially-written + * data. + */ + + /* First, skip over any header data which might have + * been written. + */ + while (tmplen && hdtr.numheaders) { + if (tmplen >= hdtr.headers[0].iov_len) { + tmplen -= hdtr.headers[0].iov_len; + --hdtr.numheaders; + ++hdtr.headers; + } + else { + hdtr.headers[0].iov_len -= tmplen; + hdtr.headers[0].iov_base = + (char*) hdtr.headers[0].iov_base + tmplen; + tmplen = 0; + } + } + + /* Now, skip over any file data which might have been + * written. + */ + + if (tmplen <= len) { + current_file_offset += tmplen; + len -= tmplen; + tmplen = 0; + } + else { + tmplen -= len; + len = 0; + current_file_offset = 0; + } + + /* Last, skip over any trailer data which might have + * been written. + */ + + while (tmplen && hdtr.numtrailers) { + if (tmplen >= hdtr.trailers[0].iov_len) { + tmplen -= hdtr.trailers[0].iov_len; + --hdtr.numtrailers; + ++hdtr.trailers; + } + else { + hdtr.trailers[0].iov_len -= tmplen; + hdtr.trailers[0].iov_base = + (char *)hdtr.trailers[0].iov_base + tmplen; + tmplen = 0; + } + } + + } while (total_bytes_sent < expected_len && + (rv == APR_SUCCESS || + (APR_STATUS_IS_EAGAIN(rv) && socket_mode != TIMEOUT))); + if (total_bytes_sent != expected_len) { + fprintf(stderr, + "client problem: sent %ld of %ld bytes\n", + (long)total_bytes_sent, (long)expected_len); + exit(1); + } + + if (rv) { + fprintf(stderr, + "client problem: rv %d\n", + rv); + exit(1); + } + } + + current_file_offset = 0; + rv = apr_file_seek(f, APR_CUR, ¤t_file_offset); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_file_seek()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + printf("After apr_socket_sendfile(), the kernel file pointer is " + "at offset %ld.\n", + (long int)current_file_offset); + + rv = apr_socket_shutdown(sock, APR_SHUTDOWN_WRITE); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_shutdown()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + /* in case this is the non-blocking test, set socket timeout; + * we're just waiting for EOF */ + + rv = apr_socket_timeout_set(sock, apr_time_from_sec(3)); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_timeout_set()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + bytes_read = 1; + rv = apr_socket_recv(sock, buf, &bytes_read); + if (rv != APR_EOF) { + fprintf(stderr, "apr_socket_recv()->%d/%s (expected APR_EOF)\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + if (bytes_read != 0) { + fprintf(stderr, "We expected to get 0 bytes read with APR_EOF\n" + "but instead we read %ld bytes.\n", + (long int)bytes_read); + exit(1); + } + + printf("client: apr_socket_sendfile() worked as expected!\n"); + + rv = apr_file_remove(TESTFILE, p); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_file_remove()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + return 0; +} + +static int server(void) +{ + apr_status_t rv; + apr_socket_t *sock; + apr_pool_t *p; + char buf[120]; + int i; + apr_socket_t *newsock = NULL; + apr_size_t bytes_read; + apr_sockaddr_t *localsa; + int family; + + family = APR_UNSPEC; + apr_setup(&p, &sock, &family); + + rv = apr_socket_opt_set(sock, APR_SO_REUSEADDR, 1); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_opt_set()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + rv = apr_sockaddr_info_get(&localsa, NULL, family, TESTSF_PORT, 0, p); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_sockaddr_info_get()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + rv = apr_socket_bind(sock, localsa); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_bind()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + rv = apr_socket_listen(sock, 5); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_listen()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + printf("Waiting for a client to connect...\n"); + + rv = apr_socket_accept(&newsock, sock, p); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_accept()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + + printf("Processing a client...\n"); + + assert(sizeof buf > strlen(HDR1)); + bytes_read = strlen(HDR1); + rv = apr_socket_recv(newsock, buf, &bytes_read); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_recv()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + if (bytes_read != strlen(HDR1)) { + fprintf(stderr, "wrong data read (1)\n"); + exit(1); + } + if (memcmp(buf, HDR1, strlen(HDR1))) { + fprintf(stderr, "wrong data read (2)\n"); + fprintf(stderr, "received: `%.*s'\nexpected: `%s'\n", + (int)bytes_read, buf, HDR1); + exit(1); + } + + assert(sizeof buf > strlen(HDR2)); + bytes_read = strlen(HDR2); + rv = apr_socket_recv(newsock, buf, &bytes_read); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_recv()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + if (bytes_read != strlen(HDR2)) { + fprintf(stderr, "wrong data read (3)\n"); + exit(1); + } + if (memcmp(buf, HDR2, strlen(HDR2))) { + fprintf(stderr, "wrong data read (4)\n"); + fprintf(stderr, "received: `%.*s'\nexpected: `%s'\n", + (int)bytes_read, buf, HDR2); + exit(1); + } + + for (i = 0; i < HDR3_LEN; i++) { + bytes_read = 1; + rv = apr_socket_recv(newsock, buf, &bytes_read); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_recv()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + if (bytes_read != 1) { + fprintf(stderr, "apr_socket_recv()->%ld bytes instead of 1\n", + (long int)bytes_read); + exit(1); + } + if (buf[0] != HDR3_CHAR) { + fprintf(stderr, + "problem with data read (byte %d of hdr 3):\n", + i); + fprintf(stderr, "read `%c' (0x%x) from client; expected " + "`%c'\n", + buf[0], buf[0], HDR3_CHAR); + exit(1); + } + } + + for (i = 0; i < FILE_LENGTH; i++) { + bytes_read = 1; + rv = apr_socket_recv(newsock, buf, &bytes_read); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_recv()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + if (bytes_read != 1) { + fprintf(stderr, "apr_socket_recv()->%ld bytes instead of 1\n", + (long int)bytes_read); + exit(1); + } + if (buf[0] != FILE_DATA_CHAR) { + fprintf(stderr, + "problem with data read (byte %d of file):\n", + i); + fprintf(stderr, "read `%c' (0x%x) from client; expected " + "`%c'\n", + buf[0], buf[0], FILE_DATA_CHAR); + exit(1); + } + } + + assert(sizeof buf > strlen(TRL1)); + bytes_read = strlen(TRL1); + rv = apr_socket_recv(newsock, buf, &bytes_read); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_recv()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + if (bytes_read != strlen(TRL1)) { + fprintf(stderr, "wrong data read (5)\n"); + exit(1); + } + if (memcmp(buf, TRL1, strlen(TRL1))) { + fprintf(stderr, "wrong data read (6)\n"); + fprintf(stderr, "received: `%.*s'\nexpected: `%s'\n", + (int)bytes_read, buf, TRL1); + exit(1); + } + + assert(sizeof buf > strlen(TRL2)); + bytes_read = strlen(TRL2); + rv = apr_socket_recv(newsock, buf, &bytes_read); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_recv()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + if (bytes_read != strlen(TRL2)) { + fprintf(stderr, "wrong data read (7)\n"); + exit(1); + } + if (memcmp(buf, TRL2, strlen(TRL2))) { + fprintf(stderr, "wrong data read (8)\n"); + fprintf(stderr, "received: `%.*s'\nexpected: `%s'\n", + (int)bytes_read, buf, TRL2); + exit(1); + } + + for (i = 0; i < TRL3_LEN; i++) { + bytes_read = 1; + rv = apr_socket_recv(newsock, buf, &bytes_read); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_socket_recv()->%d/%s\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + if (bytes_read != 1) { + fprintf(stderr, "apr_socket_recv()->%ld bytes instead of 1\n", + (long int)bytes_read); + exit(1); + } + if (buf[0] != TRL3_CHAR) { + fprintf(stderr, + "problem with data read (byte %d of trl 3):\n", + i); + fprintf(stderr, "read `%c' (0x%x) from client; expected " + "`%c'\n", + buf[0], buf[0], TRL3_CHAR); + exit(1); + } + } + + bytes_read = 1; + rv = apr_socket_recv(newsock, buf, &bytes_read); + if (rv != APR_EOF) { + fprintf(stderr, "apr_socket_recv()->%d/%s (expected APR_EOF)\n", + rv, + apr_strerror(rv, buf, sizeof buf)); + exit(1); + } + if (bytes_read != 0) { + fprintf(stderr, "We expected to get 0 bytes read with APR_EOF\n" + "but instead we read %ld bytes (%c).\n", + (long int)bytes_read, buf[0]); + exit(1); + } + + printf("server: apr_socket_sendfile() worked as expected!\n"); + + return 0; +} + +int main(int argc, char *argv[]) +{ +#ifdef SIGPIPE + signal(SIGPIPE, SIG_IGN); +#endif + + /* Gee whiz this is goofy logic but I wanna drive sendfile right now, + * not dork around with the command line! + */ + if (argc >= 3 && !strcmp(argv[1], "client")) { + char *host = 0; + if (argv[3]) { + host = argv[3]; + } + if (!strcmp(argv[2], "blocking")) { + return client(BLK, host); + } + else if (!strcmp(argv[2], "timeout")) { + return client(TIMEOUT, host); + } + else if (!strcmp(argv[2], "nonblocking")) { + return client(NONBLK, host); + } + } + else if (argc == 2 && !strcmp(argv[1], "server")) { + return server(); + } + + fprintf(stderr, + "Usage: %s client {blocking|nonblocking|timeout}\n" + " %s server\n", + argv[0], argv[0]); + return -1; +} + +#endif /* !APR_HAS_SENDFILE */ diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/server.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/server.c new file mode 100644 index 00000000..03c10270 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/server.c @@ -0,0 +1,167 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define APR_TEST_PREFIX "server: " + +#include "aprtest.h" +#include <stdlib.h> +#include "apr_network_io.h" +#include "apr_getopt.h" +#include "apr_poll.h" + +#define STRLEN 15 + +int main(int argc, const char * const argv[]) +{ + apr_pool_t *context; + apr_status_t rv; + apr_socket_t *sock; + apr_socket_t *sock2; + apr_size_t length; + apr_int32_t pollres; + apr_pollfd_t *sdset; + char datasend[STRLEN]; + char datarecv[STRLEN] = "Recv data test"; + const char *bind_to_ipaddr = NULL; + char *local_ipaddr, *remote_ipaddr; + apr_port_t local_port, remote_port; + apr_sockaddr_t *localsa = NULL, *remotesa; + apr_status_t stat; + int family = APR_UNSPEC; + int protocol; + apr_getopt_t *opt; + const char *optarg; + char optchar; + + APR_TEST_INITIALIZE(rv, context); + + APR_TEST_SUCCESS(rv, "Preparing getopt", + apr_getopt_init(&opt, context, argc, argv)) + + while ((stat = apr_getopt(opt, "i:", &optchar, &optarg)) == APR_SUCCESS) { + switch(optchar) { + case 'i': + bind_to_ipaddr = optarg; + break; + } + } + if (stat != APR_EOF) { + fprintf(stderr, + "usage: %s [-i local-interface-address]\n", + argv[0]); + exit(-1); + } + + if (bind_to_ipaddr) { + /* First, parse/resolve ipaddr so we know what address family of + * socket we need. We'll use the returned sockaddr later when + * we bind. + */ + APR_TEST_SUCCESS(rv, "Preparing sockaddr", + apr_sockaddr_info_get(&localsa, bind_to_ipaddr, APR_UNSPEC, 8021, 0, context)) + family = localsa->family; + } + + APR_TEST_SUCCESS(rv, "Creating new socket", + apr_socket_create_ex(&sock, family, SOCK_STREAM, APR_PROTO_TCP, context)) + + APR_TEST_SUCCESS(rv, "Setting option APR_SO_NONBLOCK", + apr_socket_opt_set(sock, APR_SO_NONBLOCK, 1)) + + APR_TEST_SUCCESS(rv, "Setting option APR_SO_REUSEADDR", + apr_socket_opt_set(sock, APR_SO_REUSEADDR, 1)) + + if (!localsa) { + apr_socket_addr_get(&localsa, APR_LOCAL, sock); + apr_sockaddr_port_set(localsa, 8021); + } + + APR_TEST_SUCCESS(rv, "Binding socket to port", + apr_socket_bind(sock, localsa)) + + APR_TEST_SUCCESS(rv, "Listening to socket", + apr_socket_listen(sock, 5)) + + APR_TEST_BEGIN(rv, "Setting up for polling", + apr_poll_setup(&sdset, 1, context)) + APR_TEST_END(rv, + apr_poll_socket_add(sdset, sock, APR_POLLIN)) + + pollres = 1; + APR_TEST_BEGIN(rv, "Polling for socket", + apr_poll(sdset, 1, &pollres, -1)) + + if (pollres == 0) { + fprintf(stdout, "Failed\n"); + apr_socket_close(sock); + fprintf(stderr, "Error: Unrecognized poll result, " + "expected 1, received %d\n", pollres); + exit(-1); + } + fprintf(stdout, "OK\n"); + + APR_TEST_SUCCESS(rv, "Accepting a connection", + apr_socket_accept(&sock2, sock, context)) + + apr_socket_protocol_get(sock2, &protocol); + if (protocol != APR_PROTO_TCP) { + fprintf(stderr, "Error: protocol not conveyed from listening socket " + "to connected socket!\n"); + exit(1); + } + apr_socket_addr_get(&remotesa, APR_REMOTE, sock2); + apr_sockaddr_ip_get(&remote_ipaddr, remotesa); + apr_sockaddr_port_get(&remote_port, remotesa); + apr_socket_addr_get(&localsa, APR_LOCAL, sock2); + apr_sockaddr_ip_get(&local_ipaddr, localsa); + apr_sockaddr_port_get(&local_port, localsa); + fprintf(stdout, "Server socket: %s:%u -> %s:%u\n", local_ipaddr, + local_port, remote_ipaddr, remote_port); + + APR_TEST_SUCCESS(rv, "Setting timeout on client socket", + apr_socket_timeout_set(sock2, apr_time_from_sec(3))); + + length = STRLEN; + APR_TEST_BEGIN(rv, "Receiving data from socket", + apr_socket_recv(sock2, datasend, &length)) + + if (strcmp(datasend, "Send data test")) { + fprintf(stdout, "Failed\n"); + apr_socket_close(sock); + apr_socket_close(sock2); + fprintf(stderr, "Error: Unrecognized response;\n" + "Expected: \"Send data test\"\n" + "Received: \"%s\"\n", datarecv); + exit(-1); + } + fprintf(stdout, "OK\n"); + + length = STRLEN; + APR_TEST_SUCCESS(rv, "Sending data over socket", + apr_socket_send(sock2, datarecv, &length)) + + APR_TEST_SUCCESS(rv, "Shutting down accepted socket", + apr_socket_shutdown(sock2, APR_SHUTDOWN_READ)) + + APR_TEST_SUCCESS(rv, "Closing duplicate socket", + apr_socket_close(sock2)) + + APR_TEST_SUCCESS(rv, "Closing original socket", + apr_socket_close(sock)) + + return 0; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/test_apr.h b/rubbos/app/httpd-2.0.64/srclib/apr/test/test_apr.h new file mode 100644 index 00000000..7bb8dab7 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/test_apr.h @@ -0,0 +1,68 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef APR_TEST_INCLUDES +#define APR_TEST_INCLUDES + +#include "CuTest.h" +#include "apr_pools.h" + +/* Some simple functions to make the test apps easier to write and + * a bit more consistent... + */ + +extern apr_pool_t *p; + +CuSuite *getsuite(void); + +CuSuite *teststr(void); +CuSuite *testtime(void); +CuSuite *testvsn(void); +CuSuite *testipsub(void); +CuSuite *testmmap(void); +CuSuite *testud(void); +CuSuite *testtable(void); +CuSuite *testhash(void); +CuSuite *testsleep(void); +CuSuite *testpool(void); +CuSuite *testfmt(void); +CuSuite *testfile(void); +CuSuite *testdir(void); +CuSuite *testfileinfo(void); +CuSuite *testrand(void); +CuSuite *testdso(void); +CuSuite *testoc(void); +CuSuite *testdup(void); +CuSuite *testsockets(void); +CuSuite *testproc(void); +CuSuite *testprocmutex(void); +CuSuite *testpoll(void); +CuSuite *testlock(void); +CuSuite *testsockopt(void); +CuSuite *testpipe(void); +CuSuite *testthread(void); +CuSuite *testgetopt(void); +CuSuite *testnames(void); +CuSuite *testuser(void); +CuSuite *testpath(void); +CuSuite *testenv(void); + +/* Assert that RV is an APR_SUCCESS value; else fail giving strerror + * for RV and CONTEXT message. */ +void apr_assert_success(CuTest* tc, const char *context, apr_status_t rv); + + +#endif /* APR_TEST_INCLUDES */ diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testall.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testall.c new file mode 100644 index 00000000..c7e8fe9c --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testall.c @@ -0,0 +1,167 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdio.h> +#include <stdlib.h> + +#include "test_apr.h" + +/* Top-level pool which can be used by tests. */ +apr_pool_t *p; + +void apr_assert_success(CuTest* tc, const char* context, apr_status_t rv) +{ + if (rv == APR_ENOTIMPL) { + CuNotImpl(tc, context); + } + + if (rv != APR_SUCCESS) { + char buf[STRING_MAX], ebuf[128]; + sprintf(buf, "%s (%d): %s\n", context, rv, + apr_strerror(rv, ebuf, sizeof ebuf)); + CuFail(tc, buf); + } +} + +static const struct testlist { + const char *testname; + CuSuite *(*func)(void); +} tests[] = { + {"teststr", teststr}, + {"testtime", testtime}, + {"testvsn", testvsn}, + {"testipsub", testipsub}, + {"testmmap", testmmap}, + {"testud", testud}, + {"testtable", testtable}, + {"testhash", testhash}, + {"testsleep", testsleep}, + {"testpool", testpool}, + {"testfmt", testfmt}, + {"testfile", testfile}, + {"testfileinfo", testfileinfo}, + {"testpipe", testpipe}, + {"testdup", testdup}, + {"testdir", testdir}, + {"testrand", testrand}, + {"testdso", testdso}, + {"testoc", testoc}, + {"testsockets", testsockets}, + {"testsockopt", testsockopt}, + {"testproc", testproc}, + {"testprocmutex", testprocmutex}, + {"testpoll", testpoll}, + {"testlock", testlock}, + {"testthread", testthread}, + {"testargs", testgetopt}, + {"testnames", testnames}, + {"testuser", testuser}, + {"testpath", testpath}, + {"testenv", testenv}, + {"LastTest", NULL} +}; + +int main(int argc, char *argv[]) +{ + CuSuiteList *alltests = NULL; + CuString *output = CuStringNew(); + int i; + int exclude = 0; + int list_provided = 0; + + apr_initialize(); + atexit(apr_terminate); + + CuInit(argc, argv); + + apr_pool_create(&p, NULL); + + /* see if we're in exclude mode, see if list of testcases provided */ + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-v")) { + continue; + } + if (!strcmp(argv[i], "-x")) { + exclude = 1; + continue; + } + if (!strcmp(argv[i], "-l")) { + for (i = 0; tests[i].func != NULL; i++) { + printf("%s\n", tests[i].testname); + } + exit(0); + } + if (argv[i][0] == '-') { + fprintf(stderr, "invalid option: `%s'\n", argv[i]); + exit(1); + } + list_provided = 1; + } + + if (!list_provided) { + /* add everything */ + alltests = CuSuiteListNew("All APR Tests"); + for (i = 0; tests[i].func != NULL; i++) { + CuSuiteListAdd(alltests, tests[i].func()); + } + } + else if (exclude) { + /* add everything but the tests listed */ + alltests = CuSuiteListNew("Partial APR Tests"); + for (i = 0; tests[i].func != NULL; i++) { + int this_test_excluded = 0; + int j; + + for (j = 1; j < argc && !this_test_excluded; j++) { + if (!strcmp(argv[j], tests[i].testname)) { + this_test_excluded = 1; + } + } + if (!this_test_excluded) { + CuSuiteListAdd(alltests, tests[i].func()); + } + } + } + else { + /* add only the tests listed */ + alltests = CuSuiteListNew("Partial APR Tests"); + for (i = 1; i < argc; i++) { + int j; + int found = 0; + + if (argv[i][0] == '-') { + continue; + } + for (j = 0; tests[j].func != NULL; j++) { + if (!strcmp(argv[i], tests[j].testname)) { + CuSuiteListAdd(alltests, tests[j].func()); + found = 1; + } + } + if (!found) { + fprintf(stderr, "invalid test name: `%s'\n", argv[i]); + exit(1); + } + } + } + + CuSuiteListRunWithSummary(alltests); + i = CuSuiteListDetails(alltests, output); + printf("%s\n", output->buffer); + + return i > 0 ? 1 : 0; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testall.dsp b/rubbos/app/httpd-2.0.64/srclib/apr/test/testall.dsp new file mode 100644 index 00000000..12f031cb --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testall.dsp @@ -0,0 +1,253 @@ +# Microsoft Developer Studio Project File - Name="testall" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) External Target" 0x0106 + +CFG=testall - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "testall.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "testall.mak" CFG="testall - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "testall - Win32 Release" (based on "Win32 (x86) External Target") +!MESSAGE "testall - Win32 Debug" (based on "Win32 (x86) External Target") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" + +!IF "$(CFG)" == "testall - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "" +# PROP BASE Intermediate_Dir "" +# PROP BASE Cmd_Line "NMAKE /f Makefile.win all" +# PROP BASE Rebuild_Opt "/a" +# PROP BASE Target_File "testall.exe" +# PROP BASE Bsc_Name "testall.bsc" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "" +# PROP Intermediate_Dir "" +# PROP Cmd_Line "NMAKE /f Makefile.win all" +# PROP Rebuild_Opt "/a" +# PROP Target_File "testall.exe" +# PROP Bsc_Name "" +# PROP Target_Dir "" + +!ELSEIF "$(CFG)" == "testall - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "" +# PROP BASE Intermediate_Dir "" +# PROP BASE Cmd_Line "NMAKE /f Makefile.win all" +# PROP BASE Rebuild_Opt "/a" +# PROP BASE Target_File "testall.exe" +# PROP BASE Bsc_Name "testall.bsc" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "" +# PROP Intermediate_Dir "" +# PROP Cmd_Line "NMAKE /f Makefile.win all" +# PROP Rebuild_Opt "/a" +# PROP Target_File "testall.exe" +# PROP Bsc_Name "" +# PROP Target_Dir "" + +!ENDIF + +# Begin Target + +# Name "testall - Win32 Release" +# Name "testall - Win32 Debug" + +!IF "$(CFG)" == "testall - Win32 Release" + +!ELSEIF "$(CFG)" == "testall - Win32 Debug" + +!ENDIF + +# Begin Source File + +SOURCE=.\Makefile.win +# End Source File +# Begin Source File + +SOURCE=.\testall.c +# End Source File +# Begin Source File + +SOURCE=.\testapp.c +# End Source File +# Begin Source File + +SOURCE=.\testargs.c +# End Source File +# Begin Source File + +SOURCE=.\testatomic.c +# End Source File +# Begin Source File + +SOURCE=.\testdir.c +# End Source File +# Begin Source File + +SOURCE=.\testdso.c +# End Source File +# Begin Source File + +SOURCE=.\testdup.c +# End Source File +# Begin Source File + +SOURCE=.\testfile.c +# End Source File +# Begin Source File + +SOURCE=.\testfileinfo.c +# End Source File +# Begin Source File + +SOURCE=.\testflock.c +# End Source File +# Begin Source File + +SOURCE=.\testfmt.c +# End Source File +# Begin Source File + +SOURCE=.\testglobalmutex.c +# End Source File +# Begin Source File + +SOURCE=.\testhash.c +# End Source File +# Begin Source File + +SOURCE=.\testipsub.c +# End Source File +# Begin Source File + +SOURCE=.\testlock.c +# End Source File +# Begin Source File + +SOURCE=.\testlockperf.c +# End Source File +# Begin Source File + +SOURCE=.\testmmap.c +# End Source File +# Begin Source File + +SOURCE=.\testmutexscope.c +# End Source File +# Begin Source File + +SOURCE=.\testnames.c +# End Source File +# Begin Source File + +SOURCE=.\testoc.c +# End Source File +# Begin Source File + +SOURCE=.\testpath.c +# End Source File +# Begin Source File + +SOURCE=.\testpipe.c +# End Source File +# Begin Source File + +SOURCE=.\testpoll.c +# End Source File +# Begin Source File + +SOURCE=.\testpools.c +# End Source File +# Begin Source File + +SOURCE=.\testproc.c +# End Source File +# Begin Source File + +SOURCE=.\testprocmutex.c +# End Source File +# Begin Source File + +SOURCE=.\testrand.c +# End Source File +# Begin Source File + +SOURCE=.\testshm.c +# End Source File +# Begin Source File + +SOURCE=.\testshmconsumer.c +# End Source File +# Begin Source File + +SOURCE=.\testshmproducer.c +# End Source File +# Begin Source File + +SOURCE=.\testsleep.c +# End Source File +# Begin Source File + +SOURCE=.\testsock.c +# End Source File +# Begin Source File + +SOURCE=.\testsockets.c +# End Source File +# Begin Source File + +SOURCE=.\testsockopt.c +# End Source File +# Begin Source File + +SOURCE=.\teststr.c +# End Source File +# Begin Source File + +SOURCE=.\testtable.c +# End Source File +# Begin Source File + +SOURCE=.\testthread.c +# End Source File +# Begin Source File + +SOURCE=.\testtime.c +# End Source File +# Begin Source File + +SOURCE=.\testud.c +# End Source File +# Begin Source File + +SOURCE=.\testuser.c +# End Source File +# Begin Source File + +SOURCE=.\testvsn.c +# End Source File +# End Target +# End Project diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testall.dsw b/rubbos/app/httpd-2.0.64/srclib/apr/test/testall.dsw new file mode 100644 index 00000000..f4be05d9 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testall.dsw @@ -0,0 +1,122 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "apr"="..\apr.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "apr_app"="..\build\apr_app.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name apr + End Project Dependency +}}} + +############################################################################### + +Project: "testall"=".\testall.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name apr + End Project Dependency +}}} + +############################################################################### + +Project: "libapr"="..\libapr.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "libapr_app"="..\build\libapr_app.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name libapr + End Project Dependency +}}} + +############################################################################### + +Project: "testapp"=".\testapp.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name apr + End Project Dependency + Begin Project Dependency + Project_Dep_Name apr_app + End Project Dependency +}}} + +############################################################################### + +Project: "testappnt"=".\testappnt.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name apr + End Project Dependency + Begin Project Dependency + Project_Dep_Name apr_app + End Project Dependency +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testapp.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testapp.c new file mode 100644 index 00000000..9e5bec3c --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testapp.c @@ -0,0 +1,10 @@ +#include <apr.h> +#include <apr_general.h> + +int main(int argc, const char * const * argv, const char * const *env) +{ + apr_app_initialize(&argc, &argv, &env); + + + apr_terminate(); +}
\ No newline at end of file diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testapp.dsp b/rubbos/app/httpd-2.0.64/srclib/apr/test/testapp.dsp new file mode 100644 index 00000000..93c4aa28 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testapp.dsp @@ -0,0 +1,90 @@ +# Microsoft Developer Studio Project File - Name="testapp" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=testapp - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "testapp.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "testapp.mak" CFG="testapp - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "testapp - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "testapp - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "testapp - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "APR_DECLARE_STATIC" /D "APU_DECLARE_STATIC" /FD /c +# ADD CPP /nologo /MD /W3 /O2 /I "../include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "APR_DECLARE_STATIC" /D "APU_DECLARE_STATIC" /Fd"./testapp" /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib advapi32.lib wsock32.lib ws2_32.lib /nologo /subsystem:console +# ADD LINK32 kernel32.lib advapi32.lib wsock32.lib ws2_32.lib /nologo /subsystem:console + +!ELSEIF "$(CFG)" == "testapp - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "." +# PROP BASE Intermediate_Dir "." +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "." +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /EHsc /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "APR_DECLARE_STATIC" /D "APU_DECLARE_STATIC" /FD /c +# ADD CPP /nologo /MDd /W3 /EHsc /Zi /Od /I "../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "APR_DECLARE_STATIC" /D "APU_DECLARE_STATIC" /Fd"./testapp" /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib advapi32.lib wsock32.lib ws2_32.lib /nologo /subsystem:console /incremental:no /debug +# ADD LINK32 kernel32.lib advapi32.lib wsock32.lib ws2_32.lib /nologo /subsystem:console /incremental:no /debug + +!ENDIF + +# Begin Target + +# Name "testapp - Win32 Release" +# Name "testapp - Win32 Debug" +# Begin Source File + +SOURCE=.\testapp.c +# End Source File +# End Target +# End Project diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testappnt.dsp b/rubbos/app/httpd-2.0.64/srclib/apr/test/testappnt.dsp new file mode 100644 index 00000000..f5cd4339 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testappnt.dsp @@ -0,0 +1,101 @@ +# Microsoft Developer Studio Project File - Name="testappnt" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=testappnt - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "testappnt.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "testappnt.mak" CFG="testappnt - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "testappnt - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "testappnt - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "testappnt - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "WINNT" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "APR_DECLARE_STATIC" /D "APU_DECLARE_STATIC" /FD /c +# ADD CPP /nologo /MD /W3 /O2 /I "../include" /D "NDEBUG" /D "WIN32" /D "WINNT" /D "_CONSOLE" /D "APR_DECLARE_STATIC" /D "APU_DECLARE_STATIC" /Fd"./testappnt" /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib advapi32.lib wsock32.lib ws2_32.lib /nologo /subsystem:console +# ADD LINK32 kernel32.lib advapi32.lib wsock32.lib ws2_32.lib /nologo /entry:"wmainCRTStartup" /subsystem:console + +!ELSEIF "$(CFG)" == "testappnt - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "." +# PROP BASE Intermediate_Dir "." +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "." +# PROP Intermediate_Dir "." +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MDd /W3 /EHsc /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "APR_DECLARE_STATIC" /D "APU_DECLARE_STATIC" /FD /c +# ADD CPP /nologo /MDd /W3 /EHsc /Zi /Od /I "../include" /D "_DEBUG" /D "WIN32" /D "WINNT" /D "_CONSOLE" /D "APR_DECLARE_STATIC" /D "APU_DECLARE_STATIC" /Fd"./testappnt" /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib advapi32.lib wsock32.lib ws2_32.lib /nologo /subsystem:console /incremental:no /debug +# ADD LINK32 kernel32.lib advapi32.lib wsock32.lib ws2_32.lib /nologo /entry:"wmainCRTStartup" /subsystem:console /incremental:no /debug + +!ENDIF + +# Begin Target + +# Name "testappnt - Win32 Release" +# Name "testappnt - Win32 Debug" +# Begin Source File + +SOURCE=.\testapp.c + +!IF "$(CFG)" == "testappnt - Win32 Release" + +# ADD CPP /Fo"testappnt" + +!ELSEIF "$(CFG)" == "testappnt - Win32 Debug" + +# ADD CPP /Fo"testappnt" + +!ENDIF + +# End Source File +# End Target +# End Project diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testargs.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testargs.c new file mode 100644 index 00000000..73cd766a --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testargs.c @@ -0,0 +1,236 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_getopt.h" +#include "apr_strings.h" +#include "test_apr.h" + +static void format_arg(char *str, char option, const char *arg) +{ + if (arg) { + apr_snprintf(str, 8196, "%soption: %c with %s\n", str, option, arg); + } + else { + apr_snprintf(str, 8196, "%soption: %c\n", str, option); + } +} + +static void unknown_arg(void *str, const char *err, ...) +{ + va_list va; + + va_start(va, err); + apr_vsnprintf(str, 8196, err, va); + va_end(va); +} + +static void no_options_found(CuTest *tc) +{ + int largc = 5; + const char * const largv[] = {"testprog", "-a", "-b", "-c", "-d"}; + apr_getopt_t *opt; + apr_status_t rv; + char data; + const char *optarg; + char str[8196]; + + str[0] = '\0'; + rv = apr_getopt_init(&opt, p, largc, largv); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + while (apr_getopt(opt, "abcd", &data, &optarg) == APR_SUCCESS) { + switch (data) { + case 'a': + case 'b': + case 'c': + case 'd': + default: + format_arg(str, data, optarg); + } + } + CuAssertStrEquals(tc, "option: a\n" + "option: b\n" + "option: c\n" + "option: d\n", str); +} + +static void no_options(CuTest *tc) +{ + int largc = 5; + const char * const largv[] = {"testprog", "-a", "-b", "-c", "-d"}; + apr_getopt_t *opt; + apr_status_t rv; + char data; + const char *optarg; + char str[8196]; + + str[0] = '\0'; + rv = apr_getopt_init(&opt, p, largc, largv); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + opt->errfn = unknown_arg; + opt->errarg = str; + + while (apr_getopt(opt, "efgh", &data, &optarg) == APR_SUCCESS) { + switch (data) { + case 'a': + case 'b': + case 'c': + case 'd': + format_arg(str, data, optarg); + break; + default: + break; + } + } + CuAssertStrEquals(tc, "testprog: illegal option -- a\n", str); +} + +static void required_option(CuTest *tc) +{ + int largc = 3; + const char * const largv[] = {"testprog", "-a", "foo"}; + apr_getopt_t *opt; + apr_status_t rv; + char data; + const char *optarg; + char str[8196]; + + str[0] = '\0'; + rv = apr_getopt_init(&opt, p, largc, largv); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + opt->errfn = unknown_arg; + opt->errarg = str; + + while (apr_getopt(opt, "a:", &data, &optarg) == APR_SUCCESS) { + switch (data) { + case 'a': + format_arg(str, data, optarg); + break; + default: + break; + } + } + CuAssertStrEquals(tc, "option: a with foo\n", str); +} + +static void required_option_notgiven(CuTest *tc) +{ + int largc = 2; + const char * const largv[] = {"testprog", "-a"}; + apr_getopt_t *opt; + apr_status_t rv; + char data; + const char *optarg; + char str[8196]; + + str[0] = '\0'; + rv = apr_getopt_init(&opt, p, largc, largv); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + opt->errfn = unknown_arg; + opt->errarg = str; + + while (apr_getopt(opt, "a:", &data, &optarg) == APR_SUCCESS) { + switch (data) { + case 'a': + format_arg(str, data, optarg); + break; + default: + break; + } + } + CuAssertStrEquals(tc, "testprog: option requires an argument -- a\n", str); +} + +static void optional_option(CuTest *tc) +{ + int largc = 3; + const char * const largv[] = {"testprog", "-a", "foo"}; + apr_getopt_t *opt; + apr_status_t rv; + char data; + const char *optarg; + char str[8196]; + + str[0] = '\0'; + rv = apr_getopt_init(&opt, p, largc, largv); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + opt->errfn = unknown_arg; + opt->errarg = str; + + while (apr_getopt(opt, "a::", &data, &optarg) == APR_SUCCESS) { + switch (data) { + case 'a': + format_arg(str, data, optarg); + break; + default: + break; + } + } + CuAssertStrEquals(tc, "option: a with foo\n", str); +} + +static void optional_option_notgiven(CuTest *tc) +{ + int largc = 2; + const char * const largv[] = {"testprog", "-a"}; + apr_getopt_t *opt; + apr_status_t rv; + char data; + const char *optarg; + char str[8196]; + + str[0] = '\0'; + rv = apr_getopt_init(&opt, p, largc, largv); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + opt->errfn = unknown_arg; + opt->errarg = str; + + while (apr_getopt(opt, "a::", &data, &optarg) == APR_SUCCESS) { + switch (data) { + case 'a': + format_arg(str, data, optarg); + break; + default: + break; + } + } +#if 0 +/* Our version of getopt doesn't allow for optional arguments. */ + CuAssertStrEquals(tc, "option: a\n", str); +#endif + CuAssertStrEquals(tc, "testprog: option requires an argument -- a\n", str); +} + +CuSuite *testgetopt(void) +{ + CuSuite *suite = CuSuiteNew("Getopt"); + + SUITE_ADD_TEST(suite, no_options); + SUITE_ADD_TEST(suite, no_options_found); + SUITE_ADD_TEST(suite, required_option); + SUITE_ADD_TEST(suite, required_option_notgiven); + SUITE_ADD_TEST(suite, optional_option); + SUITE_ADD_TEST(suite, optional_option_notgiven); + + return suite; +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testatomic.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testatomic.c new file mode 100644 index 00000000..d226bd1b --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testatomic.c @@ -0,0 +1,344 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdio.h> +#include <stdlib.h> +#include "apr_thread_proc.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_atomic.h" +#include "errno.h" +#include "apr_time.h" +#if APR_HAVE_UNISTD_H +#include <unistd.h> +#endif + +#if !(defined WIN32) && !(defined NETWARE) +#include <pthread.h> +#endif + +apr_pool_t *context; +apr_atomic_t y; /* atomic locks */ + +static apr_status_t check_basic_atomics(volatile apr_atomic_t*p) +{ + apr_atomic_t oldval; + apr_uint32_t casval = 0; + float object1, object2; +#if !(defined NETWARE) + volatile void *casptr; +#else + void *casptr; +#endif + void *oldptr; + + apr_atomic_set(&y, 2); + printf("%-60s", "testing apr_atomic_dec"); + if (apr_atomic_dec(&y) == 0) { + fprintf(stderr, "Failed\noldval =%d should not be zero\n", + apr_atomic_read(&y)); + return APR_EGENERAL; + } + if (apr_atomic_dec(&y) != 0) { + fprintf(stderr, "Failed\noldval =%d should be zero\n", + apr_atomic_read(&y)); + return APR_EGENERAL; + } + printf("OK\n"); + + printf("%-60s", "testing CAS"); + oldval = apr_atomic_cas(&casval, 12, 0); + if (oldval != 0) { + fprintf(stderr, "Failed\noldval =%d should be zero\n", oldval); + return APR_EGENERAL; + } + printf("OK\n"); + printf("%-60s", "testing CAS - match non-null"); + oldval = apr_atomic_cas(&casval, 23, 12); + if (oldval != 12) { + fprintf(stderr, "Failed\noldval =%d should be 12 y=%d\n", + oldval, casval); + return APR_EGENERAL; + } + printf("OK\n"); + printf("%-60s", "testing CAS - no match"); + oldval = apr_atomic_cas(&casval, 23, 12); + if (oldval != 23) { + fprintf(stderr, "Failed\noldval =%d should be 23 y=%d\n", + oldval, casval); + return APR_EGENERAL; + } + printf("OK\n"); + + printf("%-60s", "testing CAS for pointers"); + casptr = NULL; + oldptr = apr_atomic_casptr(&casptr, &object1, 0); + if (oldptr != 0) { + fprintf(stderr, "Failed\noldval =%p should be zero\n", oldptr); + return APR_EGENERAL; + } + printf("OK\n"); + printf("%-60s", "testing CAS for pointers - match non-null"); + oldptr = apr_atomic_casptr(&casptr, &object2, &object1); + if (oldptr != &object1) { + fprintf(stderr, "Failed\noldval =%p should be %p\n", oldptr, &object1); + return APR_EGENERAL; + } + printf("OK\n"); + printf("%-60s", "testing CAS for pointers - no match"); + oldptr = apr_atomic_casptr(&casptr, &object2, &object1); + if (oldptr != &object2) { + fprintf(stderr, "Failed\noldval =%p should be %p\n", oldptr, &object2); + return APR_EGENERAL; + } + printf("OK\n"); + + printf("%-60s", "testing add"); + apr_atomic_set(&y, 23); + apr_atomic_add(&y, 4); + if (apr_atomic_read(&y) != 27) { + fprintf(stderr, + "Failed\nAtomic Add doesn't add up ;( expected 27 got %d\n", + oldval); + return APR_EGENERAL; + } + + printf("OK\n"); + printf("%-60s", "testing add/inc"); + apr_atomic_set(&y, 0); + apr_atomic_add(&y, 20); + apr_atomic_inc(&y); + if (apr_atomic_read(&y) != 21) { + fprintf(stderr, "Failed.\natomics do not add up\n"); + return APR_EGENERAL; + } + fprintf(stdout, "OK\n"); + + return APR_SUCCESS; +} + +#if !APR_HAS_THREADS +int main(void) +{ + apr_status_t rv; + + apr_initialize(); + + fprintf(stderr, + "This program won't work fully on this platform because there is no " + "support for threads.\n"); + if (apr_pool_create(&context, NULL) != APR_SUCCESS) { + fflush(stdout); + fprintf(stderr, "Failed.\nCould not initialize\n"); + exit(-1); + } + rv = apr_atomic_init(context); + if (rv != APR_SUCCESS) { + fprintf(stderr, "Failed.\nCould not initialize atomics\n"); + exit(-1); + } + rv = check_basic_atomics(&y); + if (rv != APR_SUCCESS) { + fprintf(stderr, "Failed.\n"); + exit(-1); + } + return 0; +} +#else /* !APR_HAS_THREADS */ + +void * APR_THREAD_FUNC thread_func_mutex(apr_thread_t *thd, void *data); +void * APR_THREAD_FUNC thread_func_atomic(apr_thread_t *thd, void *data); +void * APR_THREAD_FUNC thread_func_none(apr_thread_t *thd, void *data); + +apr_thread_mutex_t *thread_lock; +volatile long x = 0; /* mutex locks */ +volatile long z = 0; /* no locks */ +int value = 0; +apr_status_t exit_ret_val = 123; /* just some made up number to check on later */ + +#define NUM_THREADS 50 +#define NUM_ITERATIONS 20000 +void * APR_THREAD_FUNC thread_func_mutex(apr_thread_t *thd, void *data) +{ + int i; + + for (i = 0; i < NUM_ITERATIONS; i++) { + apr_thread_mutex_lock(thread_lock); + x++; + apr_thread_mutex_unlock(thread_lock); + } + apr_thread_exit(thd, exit_ret_val); + return NULL; +} + +void * APR_THREAD_FUNC thread_func_atomic(apr_thread_t *thd, void *data) +{ + int i; + + for (i = 0; i < NUM_ITERATIONS ; i++) { + apr_atomic_inc(&y); + apr_atomic_add(&y, 2); + apr_atomic_dec(&y); + apr_atomic_dec(&y); + } + apr_thread_exit(thd, exit_ret_val); + return NULL; +} + +void * APR_THREAD_FUNC thread_func_none(apr_thread_t *thd, void *data) +{ + int i; + + for (i = 0; i < NUM_ITERATIONS ; i++) { + z++; + } + apr_thread_exit(thd, exit_ret_val); + return NULL; +} + +int main(int argc, char**argv) +{ + apr_thread_t *t1[NUM_THREADS]; + apr_thread_t *t2[NUM_THREADS]; + apr_status_t r1[NUM_THREADS]; + apr_status_t r2[NUM_THREADS]; + apr_status_t s1[NUM_THREADS]; + apr_status_t s2[NUM_THREADS]; + apr_status_t rv; + int i; + int mutex; + + apr_initialize(); + + if (argc == 2 && argv[1][0] == 'm') { + mutex = 1; + } + else { + mutex = 0; + } + + printf("APR Atomic Test\n===============\n\n"); +#if !(defined WIN32) && !(defined NETWARE) && !(defined __MVS__) && !(defined DARWIN) + pthread_setconcurrency(8); +#endif + printf("%-60s", "Initializing the context"); + if (apr_pool_create(&context, NULL) != APR_SUCCESS) { + fflush(stdout); + fprintf(stderr, "Failed.\nCould not initialize\n"); + exit(-1); + } + printf("OK\n"); + + if (mutex == 1) { + printf("%-60s", "Initializing the lock"); + rv = apr_thread_mutex_create(&thread_lock, APR_THREAD_MUTEX_DEFAULT, + context); + if (rv != APR_SUCCESS) { + fflush(stdout); + fprintf(stderr, "Failed\nCould not create lock\n"); + exit(-1); + } + printf("OK\n"); + } + printf("%-60s", "Initializing the atomics"); + rv = apr_atomic_init(context); + if (rv != APR_SUCCESS) { + fprintf(stderr, "Failed.\n"); + exit(-1); + } + printf("OK\n"); + + rv = check_basic_atomics(&y); + if (rv != APR_SUCCESS) { + fprintf(stderr, "Failed.\n"); + exit(-1); + } + apr_atomic_set(&y, 0); + + printf("%-60s", "Starting all the threads"); + for (i = 0; i < NUM_THREADS; i++) { + r1[i] = apr_thread_create(&t1[i], NULL, + (mutex == 1 ? thread_func_mutex : thread_func_atomic), + NULL, context); + r2[i] = apr_thread_create(&t2[i], NULL, thread_func_none, NULL, + context); + if (r1[i] != APR_SUCCESS || r2[i] != APR_SUCCESS ) { + fflush(stdout); + fprintf(stderr, "Failed\nError starting thread in group %d\n",i); + exit(-1); + } + } + printf("OK\n"); + + printf("%-60s\n", "Waiting for threads to exit"); + printf("%-60s", "(Note that this may take a while to complete.)"); + fflush(stdout); + + for (i = 0; i < NUM_THREADS; i++) { + apr_thread_join(&s1[i], t1[i]); + apr_thread_join(&s2[i], t2[i]); + if (s1[i] != exit_ret_val || s2[i] != exit_ret_val) { + fprintf(stderr, + "Invalid return value\n" + "Got %d/%d, but expected %d for all \n", + s1[i], s2[i], exit_ret_val); + } + } + printf("OK\n"); + + if (mutex == 1) { + printf("%-60s", "Checking if mutex locks worked"); + if (x != NUM_THREADS * NUM_ITERATIONS) { + fflush(stdout); + fprintf(stderr, + "No!\nThe locks didn't work?? x = %ld instead of %ld\n", + x, + (long)NUM_THREADS * NUM_ITERATIONS); + } + else { + printf("OK\n"); + } + } + else { + printf("%-60s", "Checking if atomic worked"); + if (apr_atomic_read(&y) != NUM_THREADS * NUM_ITERATIONS) { + fflush(stdout); + fprintf(stderr, + "No!\nThe atomics didn't work?? y = %ld instead of %ld\n", + (long)apr_atomic_read(&y), + (long)NUM_THREADS * NUM_ITERATIONS); + } + else { + printf("OK\n"); + } + } + printf("%-60s", "Checking if nolock worked"); + if (z != NUM_THREADS * NUM_ITERATIONS) { + fflush(stdout); + fprintf(stderr, + "no surprise\n" + "The no-locks didn't work. z = %ld instead of %ld\n", + z, + (long)NUM_THREADS * NUM_ITERATIONS); + } + else { + printf("OK\n"); + } + + return 0; +} + +#endif /* !APR_HAS_THREADS */ diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testdir.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testdir.c new file mode 100644 index 00000000..98506463 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testdir.c @@ -0,0 +1,275 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "apr_file_io.h" +#include "apr_file_info.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_lib.h" +#include "test_apr.h" + +static void test_mkdir(CuTest *tc) +{ + apr_status_t rv; + apr_finfo_t finfo; + + rv = apr_dir_make("data/testdir", APR_UREAD | APR_UWRITE | APR_UEXECUTE, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_stat(&finfo, "data/testdir", APR_FINFO_TYPE, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, APR_DIR, finfo.filetype); +} + +static void test_mkdir_recurs(CuTest *tc) +{ + apr_status_t rv; + apr_finfo_t finfo; + + rv = apr_dir_make_recursive("data/one/two/three", + APR_UREAD | APR_UWRITE | APR_UEXECUTE, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_stat(&finfo, "data/one", APR_FINFO_TYPE, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, APR_DIR, finfo.filetype); + + rv = apr_stat(&finfo, "data/one/two", APR_FINFO_TYPE, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, APR_DIR, finfo.filetype); + + rv = apr_stat(&finfo, "data/one/two/three", APR_FINFO_TYPE, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, APR_DIR, finfo.filetype); +} + +static void test_remove(CuTest *tc) +{ + apr_status_t rv; + apr_finfo_t finfo; + + rv = apr_dir_remove("data/testdir", p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_stat(&finfo, "data/testdir", APR_FINFO_TYPE, p); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_ENOENT(rv)); +} + +static void test_removeall_fail(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_dir_remove("data/one", p); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_ENOTEMPTY(rv)); +} + +static void test_removeall(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_dir_remove("data/one/two/three", p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_dir_remove("data/one/two", p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_dir_remove("data/one", p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); +} + +static void test_remove_notthere(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_dir_remove("data/notthere", p); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_ENOENT(rv)); +} + +static void test_mkdir_twice(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_dir_make("data/testdir", APR_UREAD | APR_UWRITE | APR_UEXECUTE, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_dir_make("data/testdir", APR_UREAD | APR_UWRITE | APR_UEXECUTE, p); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_EEXIST(rv)); + + rv = apr_dir_remove("data/testdir", p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); +} + +static void test_opendir(CuTest *tc) +{ + apr_status_t rv; + apr_dir_t *dir; + + rv = apr_dir_open(&dir, "data", p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + apr_dir_close(dir); +} + +static void test_opendir_notthere(CuTest *tc) +{ + apr_status_t rv; + apr_dir_t *dir; + + rv = apr_dir_open(&dir, "notthere", p); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_ENOENT(rv)); +} + +static void test_closedir(CuTest *tc) +{ + apr_status_t rv; + apr_dir_t *dir; + + rv = apr_dir_open(&dir, "data", p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_dir_close(dir); + CuAssertIntEquals(tc, APR_SUCCESS, rv); +} + +static void test_rewind(CuTest *tc) +{ + apr_dir_t *dir; + apr_finfo_t first, second; + + apr_assert_success(tc, "apr_dir_open failed", apr_dir_open(&dir, "data", p)); + + apr_assert_success(tc, "apr_dir_read failed", + apr_dir_read(&first, APR_FINFO_DIRENT, dir)); + + apr_assert_success(tc, "apr_dir_rewind failed", apr_dir_rewind(dir)); + + apr_assert_success(tc, "second apr_dir_read failed", + apr_dir_read(&second, APR_FINFO_DIRENT, dir)); + + apr_assert_success(tc, "apr_dir_close failed", apr_dir_close(dir)); + + CuAssertStrEquals(tc, first.name, second.name); +} + +/* Test for a (fixed) bug in apr_dir_read(). This bug only happened + in threadless cases. */ +static void test_uncleared_errno(CuTest *tc) +{ + apr_file_t *thefile = NULL; + apr_finfo_t finfo; + apr_int32_t finfo_flags = APR_FINFO_TYPE | APR_FINFO_NAME; + apr_dir_t *this_dir; + apr_status_t rv; + + rv = apr_dir_make("dir1", APR_OS_DEFAULT, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_dir_make("dir2", APR_OS_DEFAULT, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_file_open(&thefile, "dir1/file1", + APR_READ | APR_WRITE | APR_CREATE, APR_OS_DEFAULT, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_file_close(thefile); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + /* Try to remove dir1. This should fail because it's not empty. + However, on a platform with threads disabled (such as FreeBSD), + `errno' will be set as a result. */ + rv = apr_dir_remove("dir1", p); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_ENOTEMPTY(rv)); + + /* Read `.' and `..' out of dir2. */ + rv = apr_dir_open(&this_dir, "dir2", p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_dir_read(&finfo, finfo_flags, this_dir); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_dir_read(&finfo, finfo_flags, this_dir); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + /* Now, when we attempt to do a third read of empty dir2, and the + underlying system readdir() returns NULL, the old value of + errno shouldn't cause a false alarm. We should get an ENOENT + back from apr_dir_read, and *not* the old errno. */ + rv = apr_dir_read(&finfo, finfo_flags, this_dir); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_ENOENT(rv)); + + rv = apr_dir_close(this_dir); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + /* Cleanup */ + rv = apr_file_remove("dir1/file1", p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_dir_remove("dir1", p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_dir_remove("dir2", p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + +} + +static void test_rmkdir_nocwd(CuTest *tc) +{ + char *cwd, *path; + apr_status_t rv; + + apr_assert_success(tc, "make temp dir", + apr_dir_make("dir3", APR_OS_DEFAULT, p)); + + apr_assert_success(tc, "obtain cwd", apr_filepath_get(&cwd, 0, p)); + + apr_assert_success(tc, "determine path to temp dir", + apr_filepath_merge(&path, cwd, "dir3", 0, p)); + + apr_assert_success(tc, "change to temp dir", apr_filepath_set(path, p)); + + rv = apr_dir_remove(path, p); + /* Some platforms cannot remove a directory which is in use. */ + if (rv == APR_SUCCESS) { + CuAssert(tc, "fail to create dir", + apr_dir_make_recursive("foobar", APR_OS_DEFAULT, + p) != APR_SUCCESS); + } + + apr_assert_success(tc, "restore cwd", apr_filepath_set(cwd, p)); + + if (rv) { + apr_dir_remove(path, p); + CuNotImpl(tc, "cannot remove in-use directory"); + } +} + +CuSuite *testdir(void) +{ + CuSuite *suite = CuSuiteNew("Directory"); + + SUITE_ADD_TEST(suite, test_mkdir); + SUITE_ADD_TEST(suite, test_mkdir_recurs); + SUITE_ADD_TEST(suite, test_remove); + SUITE_ADD_TEST(suite, test_removeall_fail); + SUITE_ADD_TEST(suite, test_removeall); + SUITE_ADD_TEST(suite, test_remove_notthere); + SUITE_ADD_TEST(suite, test_mkdir_twice); + SUITE_ADD_TEST(suite, test_rmkdir_nocwd); + + SUITE_ADD_TEST(suite, test_rewind); + + SUITE_ADD_TEST(suite, test_opendir); + SUITE_ADD_TEST(suite, test_opendir_notthere); + SUITE_ADD_TEST(suite, test_closedir); + SUITE_ADD_TEST(suite, test_uncleared_errno); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testdso.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testdso.c new file mode 100644 index 00000000..f30beb14 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testdso.c @@ -0,0 +1,247 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "test_apr.h" +#include "apr_general.h" +#include "apr_pools.h" +#include "apr_errno.h" +#include "apr_dso.h" +#include "apr_strings.h" +#include "apr_file_info.h" +#include "apr.h" +#if APR_HAVE_UNISTD_H +#include <unistd.h> +#endif + +#ifdef NETWARE +# define MOD_NAME "mod_test.nlm" +#elif defined(BEOS) || defined(WIN32) +# define MOD_NAME "mod_test.so" +#elif defined(DARWIN) +# define MOD_NAME ".libs/mod_test.so" +# define LIB_NAME ".libs/libmod_test.dylib" +#elif defined(__hpux__) || defined(__hpux) +# define MOD_NAME ".libs/mod_test.sl" +# define LIB_NAME ".libs/libmod_test.sl" +#elif defined(_AIX) || defined(__bsdi__) +# define MOD_NAME ".libs/libmod_test.so" +# define LIB_NAME ".libs/libmod_test.so" +#else /* Every other Unix */ +# define MOD_NAME ".libs/mod_test.so" +# define LIB_NAME ".libs/libmod_test.so" +#endif + +static char *modname; + +static void test_load_module(CuTest *tc) +{ + apr_dso_handle_t *h = NULL; + apr_status_t status; + char errstr[256]; + + status = apr_dso_load(&h, modname, p); + CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); + CuAssertPtrNotNull(tc, h); + + apr_dso_unload(h); +} + +static void test_dso_sym(CuTest *tc) +{ + apr_dso_handle_t *h = NULL; + apr_dso_handle_sym_t func1 = NULL; + apr_status_t status; + void (*function)(char str[256]); + char teststr[256]; + char errstr[256]; + + status = apr_dso_load(&h, modname, p); + CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); + CuAssertPtrNotNull(tc, h); + + status = apr_dso_sym(&func1, h, "print_hello"); + CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); + CuAssertPtrNotNull(tc, func1); + + function = (void (*)(char *))func1; + (*function)(teststr); + CuAssertStrEquals(tc, "Hello - I'm a DSO!\n", teststr); + + apr_dso_unload(h); +} + +static void test_dso_sym_return_value(CuTest *tc) +{ + apr_dso_handle_t *h = NULL; + apr_dso_handle_sym_t func1 = NULL; + apr_status_t status; + int (*function)(int); + char errstr[256]; + + status = apr_dso_load(&h, modname, p); + CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); + CuAssertPtrNotNull(tc, h); + + status = apr_dso_sym(&func1, h, "count_reps"); + CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); + CuAssertPtrNotNull(tc, func1); + + function = (int (*)(int))func1; + status = (*function)(5); + CuAssertIntEquals(tc, 5, status); + + apr_dso_unload(h); +} + +static void test_unload_module(CuTest *tc) +{ + apr_dso_handle_t *h = NULL; + apr_status_t status; + char errstr[256]; + apr_dso_handle_sym_t func1 = NULL; + + status = apr_dso_load(&h, modname, p); + CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); + CuAssertPtrNotNull(tc, h); + + status = apr_dso_unload(h); + CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); + + status = apr_dso_sym(&func1, h, "print_hello"); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_ESYMNOTFOUND(status)); +} + + +#ifdef LIB_NAME +static char *libname; + +static void test_load_library(CuTest *tc) +{ + apr_dso_handle_t *h = NULL; + apr_status_t status; + char errstr[256]; + + status = apr_dso_load(&h, libname, p); + CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); + CuAssertPtrNotNull(tc, h); + + apr_dso_unload(h); +} + +static void test_dso_sym_library(CuTest *tc) +{ + apr_dso_handle_t *h = NULL; + apr_dso_handle_sym_t func1 = NULL; + apr_status_t status; + void (*function)(char str[256]); + char teststr[256]; + char errstr[256]; + + status = apr_dso_load(&h, libname, p); + CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); + CuAssertPtrNotNull(tc, h); + + status = apr_dso_sym(&func1, h, "print_hello"); + CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); + CuAssertPtrNotNull(tc, func1); + + function = (void (*)(char *))func1; + (*function)(teststr); + CuAssertStrEquals(tc, "Hello - I'm a DSO!\n", teststr); + + apr_dso_unload(h); +} + +static void test_dso_sym_return_value_library(CuTest *tc) +{ + apr_dso_handle_t *h = NULL; + apr_dso_handle_sym_t func1 = NULL; + apr_status_t status; + int (*function)(int); + char errstr[256]; + + status = apr_dso_load(&h, libname, p); + CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); + CuAssertPtrNotNull(tc, h); + + status = apr_dso_sym(&func1, h, "count_reps"); + CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); + CuAssertPtrNotNull(tc, func1); + + function = (int (*)(int))func1; + status = (*function)(5); + CuAssertIntEquals(tc, 5, status); + + apr_dso_unload(h); +} + +static void test_unload_library(CuTest *tc) +{ + apr_dso_handle_t *h = NULL; + apr_status_t status; + char errstr[256]; + apr_dso_handle_sym_t func1 = NULL; + + status = apr_dso_load(&h, libname, p); + CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); + CuAssertPtrNotNull(tc, h); + + status = apr_dso_unload(h); + CuAssert(tc, apr_dso_error(h, errstr, 256), APR_SUCCESS == status); + + status = apr_dso_sym(&func1, h, "print_hello"); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_ESYMNOTFOUND(status)); +} + +#endif /* def(LIB_NAME) */ + +static void test_load_notthere(CuTest *tc) +{ + apr_dso_handle_t *h = NULL; + apr_status_t status; + + status = apr_dso_load(&h, "No_File.so", p); + + CuAssertIntEquals(tc, 1, APR_STATUS_IS_EDSOOPEN(status)); + CuAssertPtrNotNull(tc, h); +} + +CuSuite *testdso(void) +{ + CuSuite *suite = CuSuiteNew("DSO"); + + apr_filepath_merge(&modname, NULL, MOD_NAME, 0, p); + + SUITE_ADD_TEST(suite, test_load_module); + SUITE_ADD_TEST(suite, test_dso_sym); + SUITE_ADD_TEST(suite, test_dso_sym_return_value); + SUITE_ADD_TEST(suite, test_unload_module); + +#ifdef LIB_NAME + apr_filepath_merge(&libname, NULL, LIB_NAME, 0, p); + + SUITE_ADD_TEST(suite, test_load_library); + SUITE_ADD_TEST(suite, test_dso_sym_library); + SUITE_ADD_TEST(suite, test_dso_sym_return_value_library); + SUITE_ADD_TEST(suite, test_unload_library); +#endif + + SUITE_ADD_TEST(suite, test_load_notthere); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testdup.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testdup.c new file mode 100644 index 00000000..74f64aee --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testdup.c @@ -0,0 +1,194 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "apr_general.h" +#include "apr_pools.h" +#include "apr_errno.h" +#include "apr_file_io.h" +#include "test_apr.h" + +#define TEST "Testing\n" +#define TEST2 "Testing again\n" +#define FILEPATH "data/" + +static void test_file_dup(CuTest *tc) +{ + apr_file_t *file1 = NULL; + apr_file_t *file3 = NULL; + apr_status_t rv; + apr_finfo_t finfo; + + /* First, create a new file, empty... */ + rv = apr_file_open(&file1, FILEPATH "testdup.file", + APR_READ | APR_WRITE | APR_CREATE | + APR_DELONCLOSE, APR_OS_DEFAULT, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, file1); + + rv = apr_file_dup(&file3, file1, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, file3); + + rv = apr_file_close(file1); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + /* cleanup after ourselves */ + rv = apr_file_close(file3); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_stat(&finfo, FILEPATH "testdup.file", APR_FINFO_NORM, p); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_ENOENT(rv)); +} + +static void test_file_readwrite(CuTest *tc) +{ + apr_file_t *file1 = NULL; + apr_file_t *file3 = NULL; + apr_status_t rv; + apr_finfo_t finfo; + apr_size_t txtlen = sizeof(TEST); + char buff[50]; + apr_off_t fpos; + + /* First, create a new file, empty... */ + rv = apr_file_open(&file1, FILEPATH "testdup.readwrite.file", + APR_READ | APR_WRITE | APR_CREATE | + APR_DELONCLOSE, APR_OS_DEFAULT, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, file1); + + rv = apr_file_dup(&file3, file1, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, file3); + + rv = apr_file_write(file3, TEST, &txtlen); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, sizeof(TEST), txtlen); + + fpos = 0; + rv = apr_file_seek(file1, APR_SET, &fpos); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssert(tc, "File position mismatch, expected 0", fpos == 0); + + txtlen = 50; + rv = apr_file_read(file1, buff, &txtlen); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, TEST, buff); + + /* cleanup after ourselves */ + rv = apr_file_close(file1); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_close(file3); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_stat(&finfo, FILEPATH "testdup.readwrite.file", APR_FINFO_NORM, p); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_ENOENT(rv)); +} + +static void test_dup2(CuTest *tc) +{ + apr_file_t *testfile = NULL; + apr_file_t *errfile = NULL; + apr_file_t *saveerr = NULL; + apr_status_t rv; + + rv = apr_file_open(&testfile, FILEPATH "testdup2.file", + APR_READ | APR_WRITE | APR_CREATE | + APR_DELONCLOSE, APR_OS_DEFAULT, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, testfile); + + rv = apr_file_open_stderr(&errfile, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + /* Set aside the real errfile */ + rv = apr_file_dup(&saveerr, errfile, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, saveerr); + + rv = apr_file_dup2(errfile, testfile, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, errfile); + + apr_file_close(testfile); + + rv = apr_file_dup2(errfile, saveerr, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, errfile); +} + +static void test_dup2_readwrite(CuTest *tc) +{ + apr_file_t *errfile = NULL; + apr_file_t *testfile = NULL; + apr_file_t *saveerr = NULL; + apr_status_t rv; + apr_size_t txtlen = sizeof(TEST); + char buff[50]; + apr_off_t fpos; + + rv = apr_file_open(&testfile, FILEPATH "testdup2.readwrite.file", + APR_READ | APR_WRITE | APR_CREATE | + APR_DELONCLOSE, APR_OS_DEFAULT, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, testfile); + + rv = apr_file_open_stderr(&errfile, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + /* Set aside the real errfile */ + rv = apr_file_dup(&saveerr, errfile, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, saveerr); + + rv = apr_file_dup2(errfile, testfile, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, errfile); + + txtlen = sizeof(TEST2); + rv = apr_file_write(errfile, TEST2, &txtlen); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, sizeof(TEST2), txtlen); + + fpos = 0; + rv = apr_file_seek(testfile, APR_SET, &fpos); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssert(tc, "File position mismatch, expected 0", fpos == 0); + + txtlen = 50; + rv = apr_file_read(testfile, buff, &txtlen); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, TEST2, buff); + + apr_file_close(testfile); + + rv = apr_file_dup2(errfile, saveerr, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, errfile); +} + +CuSuite *testdup(void) +{ + CuSuite *suite = CuSuiteNew("File duplication"); + + SUITE_ADD_TEST(suite, test_file_dup); + SUITE_ADD_TEST(suite, test_file_readwrite); + SUITE_ADD_TEST(suite, test_dup2); + SUITE_ADD_TEST(suite, test_dup2_readwrite); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testenv.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testenv.c new file mode 100644 index 00000000..6bc97a11 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testenv.c @@ -0,0 +1,144 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_env.h" +#include "apr_errno.h" +#include "test_apr.h" + +#define TEST_ENVVAR_NAME "apr_test_envvar" +#define TEST_ENVVAR2_NAME "apr_test_envvar2" +#define TEST_ENVVAR_VALUE "Just a value that we'll check" + +static int have_env_set; +static int have_env_get; +static int have_env_del; + +static void test_setenv(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_env_set(TEST_ENVVAR_NAME, TEST_ENVVAR_VALUE, p); + have_env_set = (rv != APR_ENOTIMPL); + if (!have_env_set) { + CuNotImpl(tc, "apr_env_set"); + return; + } + apr_assert_success(tc, "set environment variable", rv); +} + +static void test_getenv(CuTest *tc) +{ + char *value; + apr_status_t rv; + + if (!have_env_set) { + CuNotImpl(tc, "apr_env_set (skip test for apr_env_get)"); + return; + } + + rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); + have_env_get = (rv != APR_ENOTIMPL); + if (!have_env_get) { + CuNotImpl(tc, "apr_env_get"); + return; + } + apr_assert_success(tc, "get environment variable", rv); + CuAssertStrEquals(tc, TEST_ENVVAR_VALUE, value); +} + +static void test_delenv(CuTest *tc) +{ + char *value; + apr_status_t rv; + + if (!have_env_set) { + CuNotImpl(tc, "apr_env_set (skip test for apr_env_delete)"); + return; + } + + rv = apr_env_delete(TEST_ENVVAR_NAME, p); + have_env_del = (rv != APR_ENOTIMPL); + if (!have_env_del) { + CuNotImpl(tc, "apr_env_delete"); + return; + } + apr_assert_success(tc, "delete environment variable", rv); + + if (!have_env_get) { + CuNotImpl(tc, "apr_env_get (skip sanity check for apr_env_delete)"); + return; + } + rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); + CuAssertIntEquals(tc, APR_ENOENT, rv); +} + +/** http://issues.apache.org/bugzilla/show_bug.cgi?id=40764 */ +static void test_emptyenv(CuTest *tc) +{ + char *value; + apr_status_t rv; + + if (!(have_env_set && have_env_get)) { + CuNotImpl(tc, "apr_env_set (skip test_emptyenv)"); + return; + } + /** Set empty string and test that rv != ENOENT) */ + rv = apr_env_set(TEST_ENVVAR_NAME, "", p); + apr_assert_success(tc, "set environment variable", rv); + rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); + apr_assert_success(tc, "get environment variable", rv); + CuAssertStrEquals(tc, "", value); + + if (!have_env_del) { + CuNotImpl(tc, "apr_env_del (skip recycle test_emptyenv)"); + return; + } + /** Delete and retest */ + rv = apr_env_delete(TEST_ENVVAR_NAME, p); + apr_assert_success(tc, "delete environment variable", rv); + rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); + CuAssertIntEquals(tc, APR_ENOENT, rv); + + /** Set second variable + test*/ + rv = apr_env_set(TEST_ENVVAR2_NAME, TEST_ENVVAR_VALUE, p); + apr_assert_success(tc, "set second environment variable", rv); + rv = apr_env_get(&value, TEST_ENVVAR2_NAME, p); + apr_assert_success(tc, "get second environment variable", rv); + CuAssertStrEquals(tc, TEST_ENVVAR_VALUE, value); + + /** Finally, test ENOENT (first variable) followed by second != ENOENT) */ + rv = apr_env_get(&value, TEST_ENVVAR_NAME, p); + CuAssertIntEquals(tc, APR_ENOENT, rv); + rv = apr_env_get(&value, TEST_ENVVAR2_NAME, p); + apr_assert_success(tc, "verify second environment variable", rv); + CuAssertStrEquals(tc, TEST_ENVVAR_VALUE, value); + + /** Cleanup */ + apr_env_delete(TEST_ENVVAR2_NAME, p); +} + +CuSuite *testenv(void) +{ + CuSuite *suite = CuSuiteNew("Environment"); + + SUITE_ADD_TEST(suite, test_setenv); + SUITE_ADD_TEST(suite, test_getenv); + SUITE_ADD_TEST(suite, test_delenv); + SUITE_ADD_TEST(suite, test_emptyenv); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testfile.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testfile.c new file mode 100644 index 00000000..4e842f97 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testfile.c @@ -0,0 +1,782 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_file_io.h" +#include "apr_file_info.h" +#include "apr_network_io.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_poll.h" +#include "apr_lib.h" +#include "test_apr.h" + +#define DIRNAME "data" +#define FILENAME DIRNAME "/file_datafile.txt" +#define TESTSTR "This is the file data file." + +#define TESTREAD_BLKSIZE 1024 +#define APR_BUFFERSIZE 4096 /* This should match APR's buffer size. */ + + + +static void test_open_noreadwrite(CuTest *tc) +{ + apr_status_t rv; + apr_file_t *thefile = NULL; + + rv = apr_file_open(&thefile, FILENAME, + APR_CREATE | APR_EXCL, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + CuAssertTrue(tc, rv != APR_SUCCESS); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_EACCES(rv)); + CuAssertPtrEquals(tc, NULL, thefile); +} + +static void test_open_excl(CuTest *tc) +{ + apr_status_t rv; + apr_file_t *thefile = NULL; + + rv = apr_file_open(&thefile, FILENAME, + APR_CREATE | APR_EXCL | APR_WRITE, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + CuAssertTrue(tc, rv != APR_SUCCESS); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_EEXIST(rv)); + CuAssertPtrEquals(tc, NULL, thefile); +} + +static void test_open_read(CuTest *tc) +{ + apr_status_t rv; + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_READ, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, filetest); + apr_file_close(filetest); +} + +static void test_read(CuTest *tc) +{ + apr_status_t rv; + apr_size_t nbytes = 256; + char *str = apr_pcalloc(p, nbytes + 1); + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_READ, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + + apr_assert_success(tc, "Opening test file " FILENAME, rv); + rv = apr_file_read(filetest, str, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, strlen(TESTSTR), nbytes); + CuAssertStrEquals(tc, TESTSTR, str); + + apr_file_close(filetest); +} + +static void test_filename(CuTest *tc) +{ + const char *str; + apr_status_t rv; + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_READ, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + apr_assert_success(tc, "Opening test file " FILENAME, rv); + + rv = apr_file_name_get(&str, filetest); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, FILENAME, str); + + apr_file_close(filetest); +} + +static void test_fileclose(CuTest *tc) +{ + char str; + apr_status_t rv; + apr_size_t one = 1; + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_READ, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + apr_assert_success(tc, "Opening test file " FILENAME, rv); + + rv = apr_file_close(filetest); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + /* We just closed the file, so this should fail */ + rv = apr_file_read(filetest, &str, &one); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_EBADF(rv)); +} + +static void test_file_remove(CuTest *tc) +{ + apr_status_t rv; + apr_file_t *filetest = NULL; + + rv = apr_file_remove(FILENAME, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_open(&filetest, FILENAME, APR_READ, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_ENOENT(rv)); +} + +static void test_open_write(CuTest *tc) +{ + apr_status_t rv; + apr_file_t *filetest = NULL; + + filetest = NULL; + rv = apr_file_open(&filetest, FILENAME, + APR_WRITE, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_ENOENT(rv)); + CuAssertPtrEquals(tc, NULL, filetest); +} + +static void test_open_writecreate(CuTest *tc) +{ + apr_status_t rv; + apr_file_t *filetest = NULL; + + filetest = NULL; + rv = apr_file_open(&filetest, FILENAME, + APR_WRITE | APR_CREATE, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + apr_file_close(filetest); +} + +static void test_write(CuTest *tc) +{ + apr_status_t rv; + apr_size_t bytes = strlen(TESTSTR); + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_WRITE | APR_CREATE, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_write(filetest, TESTSTR, &bytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + apr_file_close(filetest); +} + +static void test_open_readwrite(CuTest *tc) +{ + apr_status_t rv; + apr_file_t *filetest = NULL; + + filetest = NULL; + rv = apr_file_open(&filetest, FILENAME, + APR_READ | APR_WRITE, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, filetest); + + apr_file_close(filetest); +} + +static void test_seek(CuTest *tc) +{ + apr_status_t rv; + apr_off_t offset = 5; + apr_size_t nbytes = 256; + char *str = apr_pcalloc(p, nbytes + 1); + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_READ, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + apr_assert_success(tc, "Open test file " FILENAME, rv); + + rv = apr_file_read(filetest, str, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, strlen(TESTSTR), nbytes); + CuAssertStrEquals(tc, TESTSTR, str); + + memset(str, 0, nbytes + 1); + + rv = apr_file_seek(filetest, SEEK_SET, &offset); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_read(filetest, str, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, strlen(TESTSTR) - 5, nbytes); + CuAssertStrEquals(tc, TESTSTR + 5, str); + + apr_file_close(filetest); + + /* Test for regression of sign error bug with SEEK_END and + buffered files. */ + rv = apr_file_open(&filetest, FILENAME, + APR_READ | APR_BUFFERED, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + apr_assert_success(tc, "Open test file " FILENAME, rv); + + offset = -5; + rv = apr_file_seek(filetest, SEEK_END, &offset); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, strlen(TESTSTR) - 5, offset); + + memset(str, 0, nbytes + 1); + nbytes = 256; + rv = apr_file_read(filetest, str, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, 5, nbytes); + CuAssertStrEquals(tc, TESTSTR + strlen(TESTSTR) - 5, str); + + apr_file_close(filetest); +} + +static void test_userdata_set(CuTest *tc) +{ + apr_status_t rv; + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_WRITE, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_data_set(filetest, "This is a test", + "test", apr_pool_cleanup_null); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + apr_file_close(filetest); +} + +static void test_userdata_get(CuTest *tc) +{ + apr_status_t rv; + char *teststr; + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_WRITE, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_data_set(filetest, "This is a test", + "test", apr_pool_cleanup_null); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_data_get((void **)&teststr, "test", filetest); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, "This is a test", teststr); + + apr_file_close(filetest); +} + +static void test_userdata_getnokey(CuTest *tc) +{ + apr_status_t rv; + char *teststr; + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_WRITE, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_data_get((void **)&teststr, "nokey", filetest); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrEquals(tc, NULL, teststr); + apr_file_close(filetest); +} + +static void test_getc(CuTest *tc) +{ + apr_file_t *f = NULL; + apr_status_t rv; + char ch; + + rv = apr_file_open(&f, FILENAME, APR_READ, 0, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + apr_file_getc(&ch, f); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, (int)TESTSTR[0], (int)ch); + apr_file_close(f); +} + +static void test_ungetc(CuTest *tc) +{ + apr_file_t *f = NULL; + apr_status_t rv; + char ch; + + rv = apr_file_open(&f, FILENAME, APR_READ, 0, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + apr_file_getc(&ch, f); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, (int)TESTSTR[0], (int)ch); + + apr_file_ungetc('X', f); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + apr_file_getc(&ch, f); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, 'X', (int)ch); + + apr_file_close(f); +} + +static void test_gets(CuTest *tc) +{ + apr_file_t *f = NULL; + apr_status_t rv; + char *str = apr_palloc(p, 256); + + rv = apr_file_open(&f, FILENAME, APR_READ, 0, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_gets(str, 256, f); + /* Only one line in the test file, so APR will encounter EOF on the first + * call to gets, but we should get APR_SUCCESS on this call and + * APR_EOF on the next. + */ + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, TESTSTR, str); + rv = apr_file_gets(str, 256, f); + CuAssertIntEquals(tc, APR_EOF, rv); + CuAssertStrEquals(tc, "", str); + apr_file_close(f); +} + +static void test_bigread(CuTest *tc) +{ + apr_file_t *f = NULL; + apr_status_t rv; + char buf[APR_BUFFERSIZE * 2]; + apr_size_t nbytes; + + /* Create a test file with known content. + */ + rv = apr_file_open(&f, "data/created_file", + APR_CREATE | APR_WRITE | APR_TRUNCATE, + APR_UREAD | APR_UWRITE, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + nbytes = APR_BUFFERSIZE; + memset(buf, 0xFE, nbytes); + + rv = apr_file_write(f, buf, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, APR_BUFFERSIZE, nbytes); + + rv = apr_file_close(f); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + f = NULL; + rv = apr_file_open(&f, "data/created_file", APR_READ, 0, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + nbytes = sizeof buf; + rv = apr_file_read(f, buf, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, APR_BUFFERSIZE, nbytes); + + rv = apr_file_close(f); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_remove("data/created_file", p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); +} + +/* Test that the contents of file FNAME are equal to data EXPECT of + * length EXPECTLEN. */ +static void file_contents_equal(CuTest *tc, + const char *fname, + const void *expect, + apr_size_t expectlen) +{ + void *actual = apr_palloc(p, expectlen); + apr_file_t *f; + apr_status_t rv; + int rc; + + rv = apr_file_open(&f, fname, APR_READ|APR_BUFFERED, 0, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_read_full(f, actual, expectlen, NULL); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rc = memcmp(expect, actual, expectlen); + CuAssertIntEquals(tc, 0, rc); + + rv = apr_file_close(f); + CuAssertIntEquals(tc, APR_SUCCESS, rv); +} + +#define LINE1 "this is a line of text\n" +#define LINE2 "this is a second line of text\n" + +static void test_writev_buffered(CuTest *tc) +{ + apr_status_t rv; + apr_file_t *f; + apr_size_t nbytes; + struct iovec vec[2]; + const char *fname = "data/testwritev_buffered.dat"; + + rv = apr_file_open(&f, fname, + APR_WRITE | APR_CREATE | APR_TRUNCATE | + APR_BUFFERED, APR_OS_DEFAULT, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + nbytes = strlen(TESTSTR); + rv = apr_file_write(f, TESTSTR, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + vec[0].iov_base = LINE1; + vec[0].iov_len = strlen(LINE1); + vec[1].iov_base = LINE2; + vec[1].iov_len = strlen(LINE2); + + rv = apr_file_writev(f, vec, 2, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_close(f); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + file_contents_equal(tc, fname, TESTSTR LINE1 LINE2, + strlen(TESTSTR) + strlen(LINE1) + strlen(LINE2)); +} + +static void test_writev_buffered_seek(CuTest *tc) +{ + apr_file_t *f; + apr_status_t rv; + apr_off_t off = 0; + struct iovec vec[3]; + apr_size_t nbytes = strlen(TESTSTR); + char *str = apr_pcalloc(p, nbytes+1); + const char *fname = "data/testwritev_buffered.dat"; + + rv = apr_file_open(&f, fname, + APR_WRITE | APR_READ | APR_BUFFERED, + APR_OS_DEFAULT, p); + + rv = apr_file_read(f, str, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, TESTSTR, str); + + rv = apr_file_seek(f, APR_SET, &off); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + vec[0].iov_base = LINE1; + vec[0].iov_len = strlen(LINE1); + vec[1].iov_base = LINE2; + vec[1].iov_len = strlen(LINE2); + vec[2].iov_base = TESTSTR; + vec[2].iov_len = strlen(TESTSTR); + + rv = apr_file_writev(f, vec, 3, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_close(f); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + file_contents_equal(tc, fname, LINE1 LINE2 TESTSTR, + strlen(LINE1) + strlen(LINE2) + strlen(TESTSTR)); + + rv = apr_file_remove(fname, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); +} + +/* This is a horrible name for this function. We are testing APR, not how + * Apache uses APR. And, this function tests _way_ too much stuff. + */ +static void test_mod_neg(CuTest *tc) +{ + apr_status_t rv; + apr_file_t *f; + const char *s; + int i; + apr_size_t nbytes; + char buf[8192]; + apr_off_t cur; + const char *fname = "data/modneg.dat"; + + rv = apr_file_open(&f, fname, + APR_CREATE | APR_WRITE, APR_UREAD | APR_UWRITE, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + s = "body56789\n"; + nbytes = strlen(s); + rv = apr_file_write(f, s, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, strlen(s), nbytes); + + for (i = 0; i < 7980; i++) { + s = "0"; + nbytes = strlen(s); + rv = apr_file_write(f, s, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, strlen(s), nbytes); + } + + s = "end456789\n"; + nbytes = strlen(s); + rv = apr_file_write(f, s, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, strlen(s), nbytes); + + for (i = 0; i < 10000; i++) { + s = "1"; + nbytes = strlen(s); + rv = apr_file_write(f, s, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, strlen(s), nbytes); + } + + rv = apr_file_close(f); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_open(&f, fname, APR_READ, 0, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_gets(buf, 11, f); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, "body56789\n", buf); + + cur = 0; + rv = apr_file_seek(f, APR_CUR, &cur); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssert(tc, "File Pointer Mismatch, expected 10", cur == 10); + + nbytes = sizeof(buf); + rv = apr_file_read(f, buf, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, nbytes, sizeof(buf)); + + cur = -((apr_off_t)nbytes - 7980); + rv = apr_file_seek(f, APR_CUR, &cur); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssert(tc, "File Pointer Mismatch, expected 7990", cur == 7990); + + rv = apr_file_gets(buf, 11, f); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, "end456789\n", buf); + + rv = apr_file_close(f); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_remove(fname, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); +} + +static void test_truncate(CuTest *tc) +{ + apr_status_t rv; + apr_file_t *f; + const char *fname = "data/testtruncate.dat"; + const char *s; + apr_size_t nbytes; + apr_finfo_t finfo; + + apr_file_remove(fname, p); + + rv = apr_file_open(&f, fname, + APR_CREATE | APR_WRITE, APR_UREAD | APR_UWRITE, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + s = "some data"; + nbytes = strlen(s); + rv = apr_file_write(f, s, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, strlen(s), nbytes); + + rv = apr_file_close(f); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_open(&f, fname, + APR_TRUNCATE | APR_WRITE, APR_UREAD | APR_UWRITE, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_close(f); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssert(tc, "File size mismatch, expected 0 (empty)", finfo.size == 0); + + rv = apr_file_remove(fname, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); +} + +static void test_fail_write_flush(CuTest *tc) +{ + apr_file_t *f; + const char *fname = "data/testflush.dat"; + apr_status_t rv; + char buf[APR_BUFFERSIZE]; + int n; + + apr_file_remove(fname, p); + + apr_assert_success(tc, "open test file", + apr_file_open(&f, fname, + APR_CREATE|APR_READ|APR_BUFFERED, + APR_UREAD|APR_UWRITE, p)); + + memset(buf, 'A', sizeof buf); + + /* Try three writes. One of these should fail when it exceeds the + * internal buffer and actually tries to write to the file, which + * was opened read-only and hence should be unwritable. */ + for (n = 0, rv = APR_SUCCESS; n < 4 && rv == APR_SUCCESS; n++) { + apr_size_t bytes = sizeof buf; + rv = apr_file_write(f, buf, &bytes); + } + + CuAssert(tc, "failed to write to read-only buffered fd", + rv != APR_SUCCESS); + + apr_file_close(f); + apr_file_remove(fname, p); +} + +static void test_fail_read_flush(CuTest *tc) +{ + apr_file_t *f; + const char *fname = "data/testflush.dat"; + apr_status_t rv; + char buf[2]; + + apr_file_remove(fname, p); + + apr_assert_success(tc, "open test file", + apr_file_open(&f, fname, + APR_CREATE|APR_READ|APR_BUFFERED, + APR_UREAD|APR_UWRITE, p)); + + /* this write should be buffered. */ + apr_assert_success(tc, "buffered write should succeed", + apr_file_puts("hello", f)); + + /* Now, trying a read should fail since the write must be flushed, + * and should fail with something other than EOF since the file is + * opened read-only. */ + rv = apr_file_read_full(f, buf, 2, NULL); + + CuAssert(tc, "read should flush buffered write and fail", + rv != APR_SUCCESS && rv != APR_EOF); + + /* Likewise for gets */ + rv = apr_file_gets(buf, 2, f); + + CuAssert(tc, "gets should flush buffered write and fail", + rv != APR_SUCCESS && rv != APR_EOF); + + apr_file_close(f); + apr_file_remove(fname, p); +} + +static void test_xthread(CuTest *tc) +{ + apr_file_t *f; + const char *fname = "data/testxthread.dat"; + apr_status_t rv; + apr_int32_t flags = APR_CREATE|APR_READ|APR_WRITE|APR_APPEND|APR_XTHREAD; + char buf[128] = { 0 }; + + /* Test for bug 38438, opening file with append + xthread and seeking to + the end of the file resulted in writes going to the beginning not the + end. */ + + apr_file_remove(fname, p); + + rv = apr_file_open(&f, fname, flags, APR_UREAD|APR_UWRITE, p); + CuAssert(tc, "open test file", rv == APR_SUCCESS); + + rv = apr_file_puts("hello", f); + CuAssert(tc, "write should succeed", rv == APR_SUCCESS); + + apr_file_close(f); + + rv = apr_file_open(&f, fname, flags, APR_UREAD|APR_UWRITE, p); + CuAssert(tc, "open test file", rv == APR_SUCCESS); + + /* Seek to the end. */ + { + apr_off_t offset = 0; + + rv = apr_file_seek(f, APR_END, &offset); + } + + rv = apr_file_puts("world", f); + CuAssert(tc, "more writes should succeed", rv == APR_SUCCESS); + + /* Back to the beginning. */ + { + apr_off_t offset = 0; + + rv = apr_file_seek(f, APR_SET, &offset); + } + + apr_file_read_full(f, buf, sizeof(buf), NULL); + + CuAssertStrEquals(tc, "helloworld", buf); + + apr_file_close(f); +} + +CuSuite *testfile(void) +{ + CuSuite *suite = CuSuiteNew("File I/O"); + + SUITE_ADD_TEST(suite, test_open_noreadwrite); + SUITE_ADD_TEST(suite, test_open_excl); + SUITE_ADD_TEST(suite, test_open_read); + SUITE_ADD_TEST(suite, test_open_readwrite); + SUITE_ADD_TEST(suite, test_read); + SUITE_ADD_TEST(suite, test_seek); + SUITE_ADD_TEST(suite, test_filename); + SUITE_ADD_TEST(suite, test_fileclose); + SUITE_ADD_TEST(suite, test_file_remove); + SUITE_ADD_TEST(suite, test_open_write); + SUITE_ADD_TEST(suite, test_open_writecreate); + SUITE_ADD_TEST(suite, test_write); + SUITE_ADD_TEST(suite, test_userdata_set); + SUITE_ADD_TEST(suite, test_userdata_get); + SUITE_ADD_TEST(suite, test_userdata_getnokey); + SUITE_ADD_TEST(suite, test_getc); + SUITE_ADD_TEST(suite, test_ungetc); + SUITE_ADD_TEST(suite, test_gets); + SUITE_ADD_TEST(suite, test_bigread); + SUITE_ADD_TEST(suite, test_writev_buffered); + SUITE_ADD_TEST(suite, test_writev_buffered_seek); + SUITE_ADD_TEST(suite, test_mod_neg); + SUITE_ADD_TEST(suite, test_truncate); + SUITE_ADD_TEST(suite, test_fail_write_flush); + SUITE_ADD_TEST(suite, test_fail_read_flush); + SUITE_ADD_TEST(suite, test_xthread); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testfileinfo.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testfileinfo.c new file mode 100644 index 00000000..00ad9631 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testfileinfo.c @@ -0,0 +1,263 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_file_io.h" +#include "apr_file_info.h" +#include "apr_strings.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_poll.h" +#include "apr_lib.h" +#include "test_apr.h" + +#define FILENAME "data/file_datafile.txt" +#define NEWFILENAME "data/new_datafile.txt" +#define NEWFILEDATA "This is new text in a new file." + +static const struct view_fileinfo +{ + apr_int32_t bits; + char *description; +} vfi[] = { + {APR_FINFO_MTIME, "MTIME"}, + {APR_FINFO_CTIME, "CTIME"}, + {APR_FINFO_ATIME, "ATIME"}, + {APR_FINFO_SIZE, "SIZE"}, + {APR_FINFO_DEV, "DEV"}, + {APR_FINFO_INODE, "INODE"}, + {APR_FINFO_NLINK, "NLINK"}, + {APR_FINFO_TYPE, "TYPE"}, + {APR_FINFO_USER, "USER"}, + {APR_FINFO_GROUP, "GROUP"}, + {APR_FINFO_UPROT, "UPROT"}, + {APR_FINFO_GPROT, "GPROT"}, + {APR_FINFO_WPROT, "WPROT"}, + {0, NULL} +}; + +static void finfo_equal(CuTest *tc, apr_finfo_t f1, apr_finfo_t f2) +{ + /* Minimum supported flags across all platforms (APR_FINFO_MIN) */ + CuAssert(tc, "apr_stat and apr_getfileinfo must return APR_FINFO_TYPE", + (f1.valid & f2.valid & APR_FINFO_TYPE)); + CuAssert(tc, "apr_stat and apr_getfileinfo differ in filetype", + f1.filetype == f2.filetype); + CuAssert(tc, "apr_stat and apr_getfileinfo must return APR_FINFO_SIZE", + (f1.valid & f2.valid & APR_FINFO_SIZE)); + CuAssert(tc, "apr_stat and apr_getfileinfo differ in size", + f1.size == f2.size); + CuAssert(tc, "apr_stat and apr_getfileinfo must return APR_FINFO_ATIME", + (f1.valid & f2.valid & APR_FINFO_ATIME)); + CuAssert(tc, "apr_stat and apr_getfileinfo differ in atime", + f1.atime == f2.atime); + CuAssert(tc, "apr_stat and apr_getfileinfo must return APR_FINFO_MTIME", + (f1.valid & f2.valid & APR_FINFO_MTIME)); + CuAssert(tc, "apr_stat and apr_getfileinfo differ in mtime", + f1.mtime == f2.mtime); + CuAssert(tc, "apr_stat and apr_getfileinfo must return APR_FINFO_CTIME", + (f1.valid & f2.valid & APR_FINFO_CTIME)); + CuAssert(tc, "apr_stat and apr_getfileinfo differ in ctime", + f1.ctime == f2.ctime); + + if (f1.valid & f2.valid & APR_FINFO_NAME) + CuAssert(tc, "apr_stat and apr_getfileinfo differ in name", + !strcmp(f1.name, f2.name)); + if (f1.fname && f2.fname) + CuAssert(tc, "apr_stat and apr_getfileinfo differ in fname", + !strcmp(f1.fname, f2.fname)); + + /* Additional supported flags not supported on all platforms */ + if (f1.valid & f2.valid & APR_FINFO_USER) + CuAssert(tc, "apr_stat and apr_getfileinfo differ in user", + !apr_uid_compare(f1.user, f2.user)); + if (f1.valid & f2.valid & APR_FINFO_GROUP) + CuAssert(tc, "apr_stat and apr_getfileinfo differ in group", + !apr_gid_compare(f1.group, f2.group)); + if (f1.valid & f2.valid & APR_FINFO_INODE) + CuAssert(tc, "apr_stat and apr_getfileinfo differ in inode", + f1.inode == f2.inode); + if (f1.valid & f2.valid & APR_FINFO_DEV) + CuAssert(tc, "apr_stat and apr_getfileinfo differ in device", + f1.device == f2.device); + if (f1.valid & f2.valid & APR_FINFO_NLINK) + CuAssert(tc, "apr_stat and apr_getfileinfo differ in nlink", + f1.nlink == f2.nlink); + if (f1.valid & f2.valid & APR_FINFO_CSIZE) + CuAssert(tc, "apr_stat and apr_getfileinfo differ in csize", + f1.csize == f2.csize); + if (f1.valid & f2.valid & APR_FINFO_PROT) + CuAssert(tc, "apr_stat and apr_getfileinfo differ in protection", + f1.protection == f2.protection); +} + +static void test_info_get(CuTest *tc) +{ + apr_file_t *thefile; + apr_finfo_t finfo; + apr_status_t rv; + + rv = apr_file_open(&thefile, FILENAME, APR_READ, APR_OS_DEFAULT, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_info_get(&finfo, APR_FINFO_NORM, thefile); + if (rv == APR_INCOMPLETE) { + char *str; + int i; + str = apr_pstrdup(p, "APR_INCOMPLETE: Missing "); + for (i = 0; vfi[i].bits; ++i) { + if (vfi[i].bits & ~finfo.valid) { + str = apr_pstrcat(p, str, vfi[i].description, " ", NULL); + } + } + CuFail(tc, str); + } + CuAssertIntEquals(tc, APR_SUCCESS, rv); + apr_file_close(thefile); +} + +static void test_stat(CuTest *tc) +{ + apr_finfo_t finfo; + apr_status_t rv; + + rv = apr_stat(&finfo, FILENAME, APR_FINFO_NORM, p); + if (rv == APR_INCOMPLETE) { + char *str; + int i; + str = apr_pstrdup(p, "APR_INCOMPLETE: Missing "); + for (i = 0; vfi[i].bits; ++i) { + if (vfi[i].bits & ~finfo.valid) { + str = apr_pstrcat(p, str, vfi[i].description, " ", NULL); + } + } + CuFail(tc, str); + } + CuAssertIntEquals(tc, APR_SUCCESS, rv); +} + +static void test_stat_eq_finfo(CuTest *tc) +{ + apr_file_t *thefile; + apr_finfo_t finfo; + apr_finfo_t stat_finfo; + apr_status_t rv; + + rv = apr_file_open(&thefile, FILENAME, APR_READ, APR_OS_DEFAULT, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_file_info_get(&finfo, APR_FINFO_NORM, thefile); + + /* Opening the file may have toggled the atime member (time last + * accessed), so fetch our apr_stat() after getting the fileinfo + * of the open file... + */ + rv = apr_stat(&stat_finfo, FILENAME, APR_FINFO_NORM, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + apr_file_close(thefile); + + finfo_equal(tc, stat_finfo, finfo); +} + +static void test_buffered_write_size(CuTest *tc) +{ + const apr_size_t data_len = strlen(NEWFILEDATA); + apr_file_t *thefile; + apr_finfo_t finfo; + apr_status_t rv; + apr_size_t bytes; + + rv = apr_file_open(&thefile, NEWFILENAME, + APR_READ | APR_WRITE | APR_CREATE | APR_TRUNCATE + | APR_BUFFERED | APR_DELONCLOSE, + APR_OS_DEFAULT, p); + apr_assert_success(tc, "open file", rv); + + /* A funny thing happened to me the other day: I wrote something + * into a buffered file, then asked for its size using + * apr_file_info_get; and guess what? The size was 0! That's not a + * nice way to behave. + */ + bytes = data_len; + rv = apr_file_write(thefile, NEWFILEDATA, &bytes); + apr_assert_success(tc, "write file contents", rv); + CuAssertTrue(tc, data_len == bytes); + + rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, thefile); + apr_assert_success(tc, "get file size", rv); + CuAssertTrue(tc, bytes == (apr_size_t) finfo.size); + apr_file_close(thefile); +} + +static void test_mtime_set(CuTest *tc) +{ + apr_file_t *thefile; + apr_finfo_t finfo; + apr_time_t epoch = 0; + apr_status_t rv; + + /* This test sort of depends on the system clock being at least + * marginally ccorrect; We'll be setting the modification time to + * the epoch. + */ + rv = apr_file_open(&thefile, NEWFILENAME, + APR_READ | APR_WRITE | APR_CREATE | APR_TRUNCATE + | APR_BUFFERED | APR_DELONCLOSE, + APR_OS_DEFAULT, p); + apr_assert_success(tc, "open file", rv); + + /* Check that the current mtime is not the epoch */ + rv = apr_stat(&finfo, NEWFILENAME, APR_FINFO_MTIME, p); + if (rv == APR_INCOMPLETE) { + char *str; + int i; + str = apr_pstrdup(p, "APR_INCOMPLETE: Missing "); + for (i = 0; vfi[i].bits; ++i) { + if (vfi[i].bits & ~finfo.valid) { + str = apr_pstrcat(p, str, vfi[i].description, " ", NULL); + } + } + CuFail(tc, str); + } + apr_assert_success(tc, "get initial mtime", rv); + CuAssertTrue(tc, finfo.mtime != epoch); + + /* Reset the mtime to the epoch and verify the result. + * Note: we blindly assume that if the first apr_stat succeeded, + * the second one will, too. + */ + rv = apr_file_mtime_set(NEWFILENAME, epoch, p); + apr_assert_success(tc, "set mtime", rv); + + rv = apr_stat(&finfo, NEWFILENAME, APR_FINFO_MTIME, p); + apr_assert_success(tc, "get modified mtime", rv); + CuAssertTrue(tc, finfo.mtime == epoch); + + apr_file_close(thefile); +} + +CuSuite *testfileinfo(void) +{ + CuSuite *suite = CuSuiteNew("File Info"); + + SUITE_ADD_TEST(suite, test_info_get); + SUITE_ADD_TEST(suite, test_stat); + SUITE_ADD_TEST(suite, test_stat_eq_finfo); + SUITE_ADD_TEST(suite, test_buffered_write_size); + SUITE_ADD_TEST(suite, test_mtime_set); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testflock.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testflock.c new file mode 100644 index 00000000..86f25ba2 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testflock.c @@ -0,0 +1,156 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * USAGE + * + * Start one process, no args, and place it into the background. Start a + * second process with the "-r" switch to attempt a read on the file + * created by the first process. + * + * $ ./testflock & + * ...messages... + * $ ./testflock -r + * ...messages... + * + * The first process will sleep for 30 seconds while holding a lock. The + * second process will attempt to grab it (non-blocking) and fail. It + * will then grab it with a blocking scheme. When the first process' 30 + * seconds are up, it will exit (thus releasing its lock). The second + * process will acquire the lock, then exit. + */ + +#include "apr_pools.h" +#include "apr_file_io.h" +#include "apr_time.h" +#include "apr_general.h" +#include "apr_getopt.h" +#include "apr_strings.h" + +#include <stdlib.h> +#include <stdio.h> + +const char *testfile = "testfile.tmp"; + +static apr_pool_t *pool = NULL; + +static void errmsg(const char *msg) +{ + if (pool != NULL) + apr_pool_destroy(pool); + fprintf(stderr, msg); + exit(1); +} + +static void errmsg2(const char *msg, apr_status_t rv) +{ + char *newmsg; + char errstr[120]; + + apr_strerror(rv, errstr, sizeof errstr); + newmsg = apr_psprintf(pool, "%s: %s (%d)\n", + msg, errstr, rv); + errmsg(newmsg); + exit(1); +} + +static void do_read(void) +{ + apr_file_t *file; + apr_status_t status; + + if (apr_file_open(&file, testfile, APR_WRITE, + APR_OS_DEFAULT, pool) != APR_SUCCESS) + errmsg("Could not open test file.\n"); + printf("Test file opened.\n"); + + status = apr_file_lock(file, APR_FLOCK_EXCLUSIVE | APR_FLOCK_NONBLOCK); + if (!APR_STATUS_IS_EAGAIN(status)) { + char msg[200]; + errmsg(apr_psprintf(pool, "Expected APR_EAGAIN. Got %d: %s.\n", + status, apr_strerror(status, msg, sizeof(msg)))); + } + printf("First attempt: we were properly locked out.\nWaiting for lock..."); + fflush(stdout); + + if (apr_file_lock(file, APR_FLOCK_EXCLUSIVE) != APR_SUCCESS) + errmsg("Could not establish lock on test file."); + printf(" got it.\n"); + + (void) apr_file_close(file); + printf("Exiting.\n"); +} + +static void do_write(void) +{ + apr_file_t *file; + apr_status_t rv; + + if (apr_file_open(&file, testfile, APR_WRITE|APR_CREATE, APR_OS_DEFAULT, + pool) != APR_SUCCESS) + errmsg("Could not create file.\n"); + printf("Test file created.\n"); + + if ((rv = apr_file_lock(file, APR_FLOCK_EXCLUSIVE)) != APR_SUCCESS) + errmsg2("Could not lock the file", rv); + printf("Lock created.\nSleeping..."); + fflush(stdout); + + apr_sleep(apr_time_from_sec(30)); + + (void) apr_file_close(file); + printf(" done.\nExiting.\n"); +} + +int main(int argc, const char * const *argv) +{ + int reader = 0; + apr_status_t status; + char optchar; + const char *optarg; + apr_getopt_t *opt; + + if (apr_initialize() != APR_SUCCESS) + errmsg("Could not initialize APR.\n"); + atexit(apr_terminate); + + if (apr_pool_create(&pool, NULL) != APR_SUCCESS) + errmsg("Could not create global pool.\n"); + + if (apr_getopt_init(&opt, pool, argc, argv) != APR_SUCCESS) + errmsg("Could not parse options.\n"); + + while ((status = apr_getopt(opt, "rf:", &optchar, &optarg)) == APR_SUCCESS) { + if (optchar == 'r') + ++reader; + else if (optchar == 'f') + testfile = optarg; + } + if (status != APR_SUCCESS && status != APR_EOF) { + char msgbuf[80]; + + fprintf(stderr, "error: %s\n", + apr_strerror(status, msgbuf, sizeof msgbuf)); + exit(1); + } + + if (reader) + do_read(); + else + do_write(); + + return 0; +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testfmt.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testfmt.c new file mode 100644 index 00000000..eff39e0d --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testfmt.c @@ -0,0 +1,113 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test_apr.h" +#include "apr.h" +#include "apr_portable.h" +#include "apr_strings.h" + +static void ssize_t_fmt(CuTest *tc) +{ + char buf[100]; + apr_ssize_t var = 0; + + sprintf(buf, "%" APR_SSIZE_T_FMT, var); + CuAssertStrEquals(tc, "0", buf); + apr_snprintf(buf, sizeof(buf), "%" APR_SSIZE_T_FMT, var); + CuAssertStrEquals(tc, "0", buf); +} + +static void size_t_fmt(CuTest *tc) +{ + char buf[100]; + apr_size_t var = 0; + + sprintf(buf, "%" APR_SIZE_T_FMT, var); + CuAssertStrEquals(tc, "0", buf); + apr_snprintf(buf, sizeof(buf), "%" APR_SIZE_T_FMT, var); + CuAssertStrEquals(tc, "0", buf); +} + +static void off_t_fmt(CuTest *tc) +{ + char buf[100]; + apr_off_t var = 0; + + sprintf(buf, "%" APR_OFF_T_FMT, var); + CuAssertStrEquals(tc, "0", buf); + apr_snprintf(buf, sizeof(buf), "%" APR_OFF_T_FMT, var); + CuAssertStrEquals(tc, "0", buf); +} + +static void pid_t_fmt(CuTest *tc) +{ + char buf[100]; + pid_t var = 0; + + sprintf(buf, "%" APR_PID_T_FMT, var); + CuAssertStrEquals(tc, "0", buf); + apr_snprintf(buf, sizeof(buf), "%" APR_PID_T_FMT, var); + CuAssertStrEquals(tc, "0", buf); +} + +static void int64_t_fmt(CuTest *tc) +{ + char buf[100]; + apr_int64_t var = 0; + + sprintf(buf, "%" APR_INT64_T_FMT, var); + CuAssertStrEquals(tc, "0", buf); + apr_snprintf(buf, sizeof(buf), "%" APR_INT64_T_FMT, var); + CuAssertStrEquals(tc, "0", buf); +} + +static void uint64_t_fmt(CuTest *tc) +{ + char buf[100]; + apr_uint64_t var = 14000000; + + sprintf(buf, "%" APR_UINT64_T_FMT, var); + CuAssertStrEquals(tc, "14000000", buf); + apr_snprintf(buf, sizeof(buf), "%" APR_UINT64_T_FMT, var); + CuAssertStrEquals(tc, "14000000", buf); +} + +static void uint64_t_hex_fmt(CuTest *tc) +{ + char buf[100]; + apr_uint64_t var = 14000000; + + sprintf(buf, "%" APR_UINT64_T_HEX_FMT, var); + CuAssertStrEquals(tc, "d59f80", buf); + apr_snprintf(buf, sizeof(buf), "%" APR_UINT64_T_HEX_FMT, var); + CuAssertStrEquals(tc, "d59f80", buf); +} + +CuSuite *testfmt(void) +{ + CuSuite *suite = CuSuiteNew("Formats"); + + SUITE_ADD_TEST(suite, ssize_t_fmt); + SUITE_ADD_TEST(suite, size_t_fmt); + SUITE_ADD_TEST(suite, off_t_fmt); + SUITE_ADD_TEST(suite, pid_t_fmt); + SUITE_ADD_TEST(suite, int64_t_fmt); + SUITE_ADD_TEST(suite, uint64_t_fmt); + SUITE_ADD_TEST(suite, uint64_t_hex_fmt); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testglobalmutex.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testglobalmutex.c new file mode 100644 index 00000000..7ac3b518 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testglobalmutex.c @@ -0,0 +1,158 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_shm.h" +#include "apr_thread_proc.h" +#include "apr_file_io.h" +#include "apr_global_mutex.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_getopt.h" +#include "errno.h" +#include <stdio.h> +#include <stdlib.h> +#include "test_apr.h" + + +#define MAX_ITER 4000 +#define MAX_COUNTER (MAX_ITER * 4) + +apr_global_mutex_t *global_lock; +apr_pool_t *pool; +volatile int *x; + +static int make_child(apr_proc_t **proc, apr_pool_t *p) +{ + int i = 0; + *proc = apr_pcalloc(p, sizeof(**proc)); + + /* slight delay to allow things to settle */ + apr_sleep (1); + + if (apr_proc_fork(*proc, p) == APR_INCHILD) { + apr_initialize(); + + apr_global_mutex_child_init(&global_lock, NULL, p); + + while (1) { + apr_global_mutex_lock(global_lock); + if (i == MAX_ITER) { + apr_global_mutex_unlock(global_lock); + exit(1); + } + i++; + (*x)++; + apr_global_mutex_unlock(global_lock); + } + exit(1); + } + return APR_SUCCESS; +} + +static apr_status_t test_exclusive(const char *lockname) +{ + apr_proc_t *p1, *p2, *p3, *p4; + apr_status_t s1, s2, s3, s4; + + printf("Exclusive lock test\n"); + printf("%-60s", " Initializing the lock"); + s1 = apr_global_mutex_create(&global_lock, lockname, APR_LOCK_DEFAULT, pool); + + if (s1 != APR_SUCCESS) { + printf("Failed!\n"); + return s1; + } + printf("OK\n"); + + printf("%-60s", " Starting all of the processes"); + fflush(stdout); + s1 = make_child(&p1, pool); + s2 = make_child(&p2, pool); + s3 = make_child(&p3, pool); + s4 = make_child(&p4, pool); + if (s1 != APR_SUCCESS || s2 != APR_SUCCESS || + s3 != APR_SUCCESS || s4 != APR_SUCCESS) { + printf("Failed!\n"); + return s1; + } + printf("OK\n"); + + printf("%-60s", " Waiting for processes to exit"); + s1 = apr_proc_wait(p1, NULL, NULL, APR_WAIT); + s2 = apr_proc_wait(p2, NULL, NULL, APR_WAIT); + s3 = apr_proc_wait(p3, NULL, NULL, APR_WAIT); + s4 = apr_proc_wait(p4, NULL, NULL, APR_WAIT); + printf("OK\n"); + + if ((*x) != MAX_COUNTER) { + fprintf(stderr, "Locks don't appear to work! x = %d instead of %d\n", + (*x), MAX_COUNTER); + } + else { + printf("Test passed\n"); + } + return APR_SUCCESS; +} + +int main(int argc, const char * const *argv) +{ + apr_status_t rv; + char errmsg[200]; + const char *lockname = NULL; + const char *shmname = "shm.file"; + apr_getopt_t *opt; + char optchar; + const char *optarg; + apr_shm_t *shm; + + printf("APR Proc Mutex Test\n==============\n\n"); + + apr_initialize(); + atexit(apr_terminate); + + if (apr_pool_create(&pool, NULL) != APR_SUCCESS) + exit(-1); + + if ((rv = apr_getopt_init(&opt, pool, argc, argv)) != APR_SUCCESS) { + fprintf(stderr, "Could not set up to parse options: [%d] %s\n", + rv, apr_strerror(rv, errmsg, sizeof errmsg)); + exit(-1); + } + + while ((rv = apr_getopt(opt, "f:", &optchar, &optarg)) == APR_SUCCESS) { + if (optchar == 'f') { + lockname = optarg; + } + } + + if (rv != APR_SUCCESS && rv != APR_EOF) { + fprintf(stderr, "Could not parse options: [%d] %s\n", + rv, apr_strerror(rv, errmsg, sizeof errmsg)); + exit(-1); + } + + apr_shm_create(&shm, sizeof(int), shmname, pool); + x = apr_shm_baseaddr_get(shm); + + if ((rv = test_exclusive(lockname)) != APR_SUCCESS) { + fprintf(stderr,"Exclusive Lock test failed : [%d] %s\n", + rv, apr_strerror(rv, (char*)errmsg, 200)); + exit(-2); + } + + return 0; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testhash.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testhash.c new file mode 100644 index 00000000..6962236e --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testhash.c @@ -0,0 +1,403 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test_apr.h" +#include "apr.h" +#include "apr_strings.h" +#include "apr_general.h" +#include "apr_pools.h" +#include "apr_hash.h" + +static void dump_hash(apr_pool_t *p, apr_hash_t *h, char *str) +{ + apr_hash_index_t *hi; + char *val, *key; + apr_ssize_t len; + int i = 0; + + str[0] = '\0'; + + for (hi = apr_hash_first(p, h); hi; hi = apr_hash_next(hi)) { + apr_hash_this(hi,(void*) &key, &len, (void*) &val); + apr_snprintf(str, 8196, "%sKey %s (%" APR_SSIZE_T_FMT ") Value %s\n", + str, key, len, val); + i++; + } + apr_snprintf(str, 8196, "%s#entries %d\n", str, i); +} + +static void sum_hash(apr_pool_t *p, apr_hash_t *h, int *pcount, int *keySum, int *valSum) +{ + apr_hash_index_t *hi; + void *val, *key; + int count = 0; + + *keySum = 0; + *valSum = 0; + *pcount = 0; + for (hi = apr_hash_first(p, h); hi; hi = apr_hash_next(hi)) { + apr_hash_this(hi, (void*)&key, NULL, &val); + *valSum += *(int *)val; + *keySum += *(int *)key; + count++; + } + *pcount=count; +} + +static void hash_make(CuTest *tc) +{ + apr_hash_t *h = NULL; + + h = apr_hash_make(p); + CuAssertPtrNotNull(tc, h); +} + +static void hash_set(CuTest *tc) +{ + apr_hash_t *h = NULL; + char *result = NULL; + + h = apr_hash_make(p); + CuAssertPtrNotNull(tc, h); + + apr_hash_set(h, "key", APR_HASH_KEY_STRING, "value"); + result = apr_hash_get(h, "key", APR_HASH_KEY_STRING); + CuAssertStrEquals(tc, "value", result); +} + +static void hash_reset(CuTest *tc) +{ + apr_hash_t *h = NULL; + char *result = NULL; + + h = apr_hash_make(p); + CuAssertPtrNotNull(tc, h); + + apr_hash_set(h, "key", APR_HASH_KEY_STRING, "value"); + result = apr_hash_get(h, "key", APR_HASH_KEY_STRING); + CuAssertStrEquals(tc, "value", result); + + apr_hash_set(h, "key", APR_HASH_KEY_STRING, "new"); + result = apr_hash_get(h, "key", APR_HASH_KEY_STRING); + CuAssertStrEquals(tc, "new", result); +} + +static void same_value(CuTest *tc) +{ + apr_hash_t *h = NULL; + char *result = NULL; + + h = apr_hash_make(p); + CuAssertPtrNotNull(tc, h); + + apr_hash_set(h, "same1", APR_HASH_KEY_STRING, "same"); + result = apr_hash_get(h, "same1", APR_HASH_KEY_STRING); + CuAssertStrEquals(tc, "same", result); + + apr_hash_set(h, "same2", APR_HASH_KEY_STRING, "same"); + result = apr_hash_get(h, "same2", APR_HASH_KEY_STRING); + CuAssertStrEquals(tc, "same", result); +} + +static void key_space(CuTest *tc) +{ + apr_hash_t *h = NULL; + char *result = NULL; + + h = apr_hash_make(p); + CuAssertPtrNotNull(tc, h); + + apr_hash_set(h, "key with space", APR_HASH_KEY_STRING, "value"); + result = apr_hash_get(h, "key with space", APR_HASH_KEY_STRING); + CuAssertStrEquals(tc, "value", result); +} + +/* This is kind of a hack, but I am just keeping an existing test. This is + * really testing apr_hash_first, apr_hash_next, and apr_hash_this which + * should be tested in three separate tests, but this will do for now. + */ +static void hash_traverse(CuTest *tc) +{ + apr_hash_t *h; + char str[8196]; + + h = apr_hash_make(p); + CuAssertPtrNotNull(tc, h); + + apr_hash_set(h, "OVERWRITE", APR_HASH_KEY_STRING, "should not see this"); + apr_hash_set(h, "FOO3", APR_HASH_KEY_STRING, "bar3"); + apr_hash_set(h, "FOO3", APR_HASH_KEY_STRING, "bar3"); + apr_hash_set(h, "FOO1", APR_HASH_KEY_STRING, "bar1"); + apr_hash_set(h, "FOO2", APR_HASH_KEY_STRING, "bar2"); + apr_hash_set(h, "FOO4", APR_HASH_KEY_STRING, "bar4"); + apr_hash_set(h, "SAME1", APR_HASH_KEY_STRING, "same"); + apr_hash_set(h, "SAME2", APR_HASH_KEY_STRING, "same"); + apr_hash_set(h, "OVERWRITE", APR_HASH_KEY_STRING, "Overwrite key"); + + dump_hash(p, h, str); + CuAssertStrEquals(tc, "Key FOO1 (4) Value bar1\n" + "Key FOO2 (4) Value bar2\n" + "Key OVERWRITE (9) Value Overwrite key\n" + "Key FOO3 (4) Value bar3\n" + "Key SAME1 (5) Value same\n" + "Key FOO4 (4) Value bar4\n" + "Key SAME2 (5) Value same\n" + "#entries 7\n", str); +} + +/* This is kind of a hack, but I am just keeping an existing test. This is + * really testing apr_hash_first, apr_hash_next, and apr_hash_this which + * should be tested in three separate tests, but this will do for now. + */ +static void summation_test(CuTest *tc) +{ + apr_hash_t *h; + int sumKeys, sumVal, trySumKey, trySumVal; + int i, j, *val, *key; + + h =apr_hash_make(p); + CuAssertPtrNotNull(tc, h); + + sumKeys = 0; + sumVal = 0; + trySumKey = 0; + trySumVal = 0; + + for (i = 0; i < 100; i++) { + j = i * 10 + 1; + sumKeys += j; + sumVal += i; + key = apr_palloc(p, sizeof(int)); + *key = j; + val = apr_palloc(p, sizeof(int)); + *val = i; + apr_hash_set(h, key, sizeof(int), val); + } + + sum_hash(p, h, &i, &trySumKey, &trySumVal); + CuAssertIntEquals(tc, 100, i); + CuAssertIntEquals(tc, sumVal, trySumVal); + CuAssertIntEquals(tc, sumKeys, trySumKey); +} + +static void delete_key(CuTest *tc) +{ + apr_hash_t *h = NULL; + char *result = NULL; + + h = apr_hash_make(p); + CuAssertPtrNotNull(tc, h); + + apr_hash_set(h, "key", APR_HASH_KEY_STRING, "value"); + apr_hash_set(h, "key2", APR_HASH_KEY_STRING, "value2"); + + result = apr_hash_get(h, "key", APR_HASH_KEY_STRING); + CuAssertStrEquals(tc, "value", result); + + result = apr_hash_get(h, "key2", APR_HASH_KEY_STRING); + CuAssertStrEquals(tc, "value2", result); + + apr_hash_set(h, "key", APR_HASH_KEY_STRING, NULL); + + result = apr_hash_get(h, "key", APR_HASH_KEY_STRING); + CuAssertPtrEquals(tc, NULL, result); + + result = apr_hash_get(h, "key2", APR_HASH_KEY_STRING); + CuAssertStrEquals(tc, "value2", result); +} + +static void hash_count_0(CuTest *tc) +{ + apr_hash_t *h = NULL; + int count; + + h = apr_hash_make(p); + CuAssertPtrNotNull(tc, h); + + count = apr_hash_count(h); + CuAssertIntEquals(tc, 0, count); +} + +static void hash_count_1(CuTest *tc) +{ + apr_hash_t *h = NULL; + int count; + + h = apr_hash_make(p); + CuAssertPtrNotNull(tc, h); + + apr_hash_set(h, "key", APR_HASH_KEY_STRING, "value"); + + count = apr_hash_count(h); + CuAssertIntEquals(tc, 1, count); +} + +static void hash_count_5(CuTest *tc) +{ + apr_hash_t *h = NULL; + int count; + + h = apr_hash_make(p); + CuAssertPtrNotNull(tc, h); + + apr_hash_set(h, "key1", APR_HASH_KEY_STRING, "value1"); + apr_hash_set(h, "key2", APR_HASH_KEY_STRING, "value2"); + apr_hash_set(h, "key3", APR_HASH_KEY_STRING, "value3"); + apr_hash_set(h, "key4", APR_HASH_KEY_STRING, "value4"); + apr_hash_set(h, "key5", APR_HASH_KEY_STRING, "value5"); + + count = apr_hash_count(h); + CuAssertIntEquals(tc, 5, count); +} + +static void overlay_empty(CuTest *tc) +{ + apr_hash_t *base = NULL; + apr_hash_t *overlay = NULL; + apr_hash_t *result = NULL; + int count; + char str[8196]; + + base = apr_hash_make(p); + overlay = apr_hash_make(p); + CuAssertPtrNotNull(tc, base); + CuAssertPtrNotNull(tc, overlay); + + apr_hash_set(base, "key1", APR_HASH_KEY_STRING, "value1"); + apr_hash_set(base, "key2", APR_HASH_KEY_STRING, "value2"); + apr_hash_set(base, "key3", APR_HASH_KEY_STRING, "value3"); + apr_hash_set(base, "key4", APR_HASH_KEY_STRING, "value4"); + apr_hash_set(base, "key5", APR_HASH_KEY_STRING, "value5"); + + result = apr_hash_overlay(p, overlay, base); + + count = apr_hash_count(result); + CuAssertIntEquals(tc, 5, count); + + dump_hash(p, result, str); + CuAssertStrEquals(tc, "Key key1 (4) Value value1\n" + "Key key2 (4) Value value2\n" + "Key key3 (4) Value value3\n" + "Key key4 (4) Value value4\n" + "Key key5 (4) Value value5\n" + "#entries 5\n", str); +} + +static void overlay_2unique(CuTest *tc) +{ + apr_hash_t *base = NULL; + apr_hash_t *overlay = NULL; + apr_hash_t *result = NULL; + int count; + char str[8196]; + + base = apr_hash_make(p); + overlay = apr_hash_make(p); + CuAssertPtrNotNull(tc, base); + CuAssertPtrNotNull(tc, overlay); + + apr_hash_set(base, "base1", APR_HASH_KEY_STRING, "value1"); + apr_hash_set(base, "base2", APR_HASH_KEY_STRING, "value2"); + apr_hash_set(base, "base3", APR_HASH_KEY_STRING, "value3"); + apr_hash_set(base, "base4", APR_HASH_KEY_STRING, "value4"); + apr_hash_set(base, "base5", APR_HASH_KEY_STRING, "value5"); + + apr_hash_set(overlay, "overlay1", APR_HASH_KEY_STRING, "value1"); + apr_hash_set(overlay, "overlay2", APR_HASH_KEY_STRING, "value2"); + apr_hash_set(overlay, "overlay3", APR_HASH_KEY_STRING, "value3"); + apr_hash_set(overlay, "overlay4", APR_HASH_KEY_STRING, "value4"); + apr_hash_set(overlay, "overlay5", APR_HASH_KEY_STRING, "value5"); + + result = apr_hash_overlay(p, overlay, base); + + count = apr_hash_count(result); + CuAssertIntEquals(tc, 10, count); + + dump_hash(p, result, str); + /* I don't know why these are out of order, but they are. I would probably + * consider this a bug, but others should comment. + */ + CuAssertStrEquals(tc, "Key base5 (5) Value value5\n" + "Key overlay1 (8) Value value1\n" + "Key overlay2 (8) Value value2\n" + "Key overlay3 (8) Value value3\n" + "Key overlay4 (8) Value value4\n" + "Key overlay5 (8) Value value5\n" + "Key base1 (5) Value value1\n" + "Key base2 (5) Value value2\n" + "Key base3 (5) Value value3\n" + "Key base4 (5) Value value4\n" + "#entries 10\n", str); +} + +static void overlay_same(CuTest *tc) +{ + apr_hash_t *base = NULL; + apr_hash_t *result = NULL; + int count; + char str[8196]; + + base = apr_hash_make(p); + CuAssertPtrNotNull(tc, base); + + apr_hash_set(base, "base1", APR_HASH_KEY_STRING, "value1"); + apr_hash_set(base, "base2", APR_HASH_KEY_STRING, "value2"); + apr_hash_set(base, "base3", APR_HASH_KEY_STRING, "value3"); + apr_hash_set(base, "base4", APR_HASH_KEY_STRING, "value4"); + apr_hash_set(base, "base5", APR_HASH_KEY_STRING, "value5"); + + result = apr_hash_overlay(p, base, base); + + count = apr_hash_count(result); + CuAssertIntEquals(tc, 5, count); + + dump_hash(p, result, str); + /* I don't know why these are out of order, but they are. I would probably + * consider this a bug, but others should comment. + */ + CuAssertStrEquals(tc, "Key base5 (5) Value value5\n" + "Key base1 (5) Value value1\n" + "Key base2 (5) Value value2\n" + "Key base3 (5) Value value3\n" + "Key base4 (5) Value value4\n" + "#entries 5\n", str); +} + +CuSuite *testhash(void) +{ + CuSuite *suite = CuSuiteNew("Hash"); + + SUITE_ADD_TEST(suite, hash_make); + SUITE_ADD_TEST(suite, hash_set); + SUITE_ADD_TEST(suite, hash_reset); + SUITE_ADD_TEST(suite, same_value); + SUITE_ADD_TEST(suite, key_space); + SUITE_ADD_TEST(suite, delete_key); + + SUITE_ADD_TEST(suite, hash_count_0); + SUITE_ADD_TEST(suite, hash_count_1); + SUITE_ADD_TEST(suite, hash_count_5); + + SUITE_ADD_TEST(suite, hash_traverse); + SUITE_ADD_TEST(suite, summation_test); + + SUITE_ADD_TEST(suite, overlay_empty); + SUITE_ADD_TEST(suite, overlay_2unique); + SUITE_ADD_TEST(suite, overlay_same); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testipsub.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testipsub.c new file mode 100644 index 00000000..8238fffd --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testipsub.c @@ -0,0 +1,173 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test_apr.h" +#include "apr_general.h" +#include "apr_network_io.h" +#include "apr_errno.h" + +static void test_bad_input(CuTest *tc) +{ + struct { + const char *ipstr; + const char *mask; + apr_status_t expected_rv; + } testcases[] = + { + /* so we have a few good inputs in here; sue me */ + {"my.host.name", NULL, APR_EINVAL} + ,{"127.0.0.256", NULL, APR_EBADIP} + ,{"127.0.0.1", NULL, APR_SUCCESS} + ,{"127.0.0.1", "32", APR_SUCCESS} + ,{"127.0.0.1", "1", APR_SUCCESS} + ,{"127.0.0.1", "15", APR_SUCCESS} + ,{"127.0.0.1", "-1", APR_EBADMASK} + ,{"127.0.0.1", "0", APR_EBADMASK} + ,{"127.0.0.1", "33", APR_EBADMASK} + ,{"127.0.0.1", "255.0.0.0", APR_SUCCESS} + ,{"127.0.0.1", "255.0", APR_EBADMASK} + ,{"127.0.0.1", "255.255.256.0", APR_EBADMASK} + ,{"127.0.0.1", "abc", APR_EBADMASK} + ,{"127", NULL, APR_SUCCESS} + ,{"127.0.0.1.2", NULL, APR_EBADIP} + ,{"127.0.0.1.2", "8", APR_EBADIP} + ,{"127", "255.0.0.0", APR_EBADIP} /* either EBADIP or EBADMASK seems fine */ +#if APR_HAVE_IPV6 + ,{"::1", NULL, APR_SUCCESS} + ,{"::1", "20", APR_SUCCESS} + ,{"::ffff:9.67.113.15", NULL, APR_EBADIP} /* yes, this is goodness */ + ,{"fe80::", "16", APR_SUCCESS} + ,{"fe80::", "255.0.0.0", APR_EBADMASK} + ,{"fe80::1", "0", APR_EBADMASK} + ,{"fe80::1", "-1", APR_EBADMASK} + ,{"fe80::1", "1", APR_SUCCESS} + ,{"fe80::1", "33", APR_SUCCESS} + ,{"fe80::1", "128", APR_SUCCESS} + ,{"fe80::1", "129", APR_EBADMASK} +#else + /* do some IPv6 stuff and verify that it fails with APR_EBADIP */ + ,{"::ffff:9.67.113.15", NULL, APR_EBADIP} +#endif + }; + int i; + apr_ipsubnet_t *ipsub; + apr_status_t rv; + + for (i = 0; i < (sizeof testcases / sizeof testcases[0]); i++) { + rv = apr_ipsubnet_create(&ipsub, testcases[i].ipstr, testcases[i].mask, p); + CuAssertIntEquals(tc, rv, testcases[i].expected_rv); + } +} + +static void test_singleton_subnets(CuTest *tc) +{ + const char *v4addrs[] = { + "127.0.0.1", "129.42.18.99", "63.161.155.20", "207.46.230.229", "64.208.42.36", + "198.144.203.195", "192.18.97.241", "198.137.240.91", "62.156.179.119", + "204.177.92.181" + }; + apr_ipsubnet_t *ipsub; + apr_sockaddr_t *sa; + apr_status_t rv; + int i, j, rc; + + for (i = 0; i < sizeof v4addrs / sizeof v4addrs[0]; i++) { + rv = apr_ipsubnet_create(&ipsub, v4addrs[i], NULL, p); + CuAssertTrue(tc, rv == APR_SUCCESS); + for (j = 0; j < sizeof v4addrs / sizeof v4addrs[0]; j++) { + rv = apr_sockaddr_info_get(&sa, v4addrs[j], APR_INET, 0, 0, p); + CuAssertTrue(tc, rv == APR_SUCCESS); + rc = apr_ipsubnet_test(ipsub, sa); + if (!strcmp(v4addrs[i], v4addrs[j])) { + CuAssertTrue(tc, rc != 0); + } + else { + CuAssertTrue(tc, rc == 0); + } + } + } + + /* same for v6? */ +} + +static void test_interesting_subnets(CuTest *tc) +{ + struct { + const char *ipstr, *mask; + int family; + char *in_subnet, *not_in_subnet; + } testcases[] = + { + {"9.67", NULL, APR_INET, "9.67.113.15", "10.1.2.3"} + ,{"9.67.0.0", "16", APR_INET, "9.67.113.15", "10.1.2.3"} + ,{"9.67.0.0", "255.255.0.0", APR_INET, "9.67.113.15", "10.1.2.3"} + ,{"9.67.113.99", "16", APR_INET, "9.67.113.15", "10.1.2.3"} + ,{"9.67.113.99", "255.255.255.0", APR_INET, "9.67.113.15", "10.1.2.3"} +#if APR_HAVE_IPV6 + ,{"fe80::", "8", APR_INET6, "fe80::1", "ff01::1"} + ,{"ff01::", "8", APR_INET6, "ff01::1", "fe80::1"} + ,{"3FFE:8160::", "28", APR_INET6, "3ffE:816e:abcd:1234::1", "3ffe:8170::1"} + ,{"127.0.0.1", NULL, APR_INET6, "::ffff:127.0.0.1", "fe80::1"} + ,{"127.0.0.1", "8", APR_INET6, "::ffff:127.0.0.1", "fe80::1"} +#endif + }; + apr_ipsubnet_t *ipsub; + apr_sockaddr_t *sa; + apr_status_t rv; + int i, rc; + + for (i = 0; i < sizeof testcases / sizeof testcases[0]; i++) { + rv = apr_ipsubnet_create(&ipsub, testcases[i].ipstr, testcases[i].mask, p); + CuAssertTrue(tc, rv == APR_SUCCESS); + rv = apr_sockaddr_info_get(&sa, testcases[i].in_subnet, testcases[i].family, 0, 0, p); + CuAssertTrue(tc, rv == APR_SUCCESS); + rc = apr_ipsubnet_test(ipsub, sa); + CuAssertTrue(tc, rc != 0); + rv = apr_sockaddr_info_get(&sa, testcases[i].not_in_subnet, testcases[i].family, 0, 0, p); + CuAssertTrue(tc, rv == APR_SUCCESS); + rc = apr_ipsubnet_test(ipsub, sa); + CuAssertTrue(tc, rc == 0); + } +} + +static void test_badmask_str(CuTest *tc) +{ + char buf[128]; + + CuAssertStrEquals(tc, apr_strerror(APR_EBADMASK, buf, sizeof buf), + "The specified network mask is invalid."); +} + +static void test_badip_str(CuTest *tc) +{ + char buf[128]; + + CuAssertStrEquals(tc, apr_strerror(APR_EBADIP, buf, sizeof buf), + "The specified IP address is invalid."); +} + +CuSuite *testipsub(void) +{ + CuSuite *suite = CuSuiteNew("IP subnets"); + + SUITE_ADD_TEST(suite, test_bad_input); + SUITE_ADD_TEST(suite, test_singleton_subnets); + SUITE_ADD_TEST(suite, test_interesting_subnets); + SUITE_ADD_TEST(suite, test_badmask_str); + SUITE_ADD_TEST(suite, test_badip_str); + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testlock.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testlock.c new file mode 100644 index 00000000..134426c4 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testlock.c @@ -0,0 +1,322 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_thread_proc.h" +#include "apr_file_io.h" +#include "apr_thread_mutex.h" +#include "apr_thread_rwlock.h" +#include "apr_thread_cond.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_getopt.h" +#include "test_apr.h" + +#if APR_HAS_THREADS + +#define MAX_ITER 40000 +#define MAX_COUNTER 100000 +#define MAX_RETRY 5 + +static void *APR_THREAD_FUNC thread_rwlock_func(apr_thread_t *thd, void *data); +static void *APR_THREAD_FUNC thread_mutex_function(apr_thread_t *thd, void *data); +static void *APR_THREAD_FUNC thread_cond_producer(apr_thread_t *thd, void *data); +static void *APR_THREAD_FUNC thread_cond_consumer(apr_thread_t *thd, void *data); + +static apr_thread_mutex_t *thread_mutex; +static apr_thread_rwlock_t *rwlock; +static int i = 0, x = 0; + +static int buff[MAX_COUNTER]; + +struct { + apr_thread_mutex_t *mutex; + int nput; + int nval; +} put; + +struct { + apr_thread_mutex_t *mutex; + apr_thread_cond_t *cond; + int nready; +} nready; + +static apr_thread_mutex_t *timeout_mutex; +static apr_thread_cond_t *timeout_cond; + +static void *APR_THREAD_FUNC thread_rwlock_func(apr_thread_t *thd, void *data) +{ + int exitLoop = 1; + + while (1) + { + apr_thread_rwlock_rdlock(rwlock); + if (i == MAX_ITER) + exitLoop = 0; + apr_thread_rwlock_unlock(rwlock); + + if (!exitLoop) + break; + + apr_thread_rwlock_wrlock(rwlock); + if (i != MAX_ITER) + { + i++; + x++; + } + apr_thread_rwlock_unlock(rwlock); + } + return NULL; +} + +static void *APR_THREAD_FUNC thread_mutex_function(apr_thread_t *thd, void *data) +{ + int exitLoop = 1; + + /* slight delay to allow things to settle */ + apr_sleep (1); + + while (1) + { + apr_thread_mutex_lock(thread_mutex); + if (i == MAX_ITER) + exitLoop = 0; + else + { + i++; + x++; + } + apr_thread_mutex_unlock(thread_mutex); + + if (!exitLoop) + break; + } + return NULL; +} + +static void *APR_THREAD_FUNC thread_cond_producer(apr_thread_t *thd, void *data) +{ + for (;;) { + apr_thread_mutex_lock(put.mutex); + if (put.nput >= MAX_COUNTER) { + apr_thread_mutex_unlock(put.mutex); + return NULL; + } + buff[put.nput] = put.nval; + put.nput++; + put.nval++; + apr_thread_mutex_unlock(put.mutex); + + apr_thread_mutex_lock(nready.mutex); + if (nready.nready == 0) + apr_thread_cond_signal(nready.cond); + nready.nready++; + apr_thread_mutex_unlock(nready.mutex); + + *((int *) data) += 1; + } + + return NULL; +} + +static void *APR_THREAD_FUNC thread_cond_consumer(apr_thread_t *thd, void *data) +{ + int i; + + for (i = 0; i < MAX_COUNTER; i++) { + apr_thread_mutex_lock(nready.mutex); + while (nready.nready == 0) + apr_thread_cond_wait(nready.cond, nready.mutex); + nready.nready--; + apr_thread_mutex_unlock(nready.mutex); + + if (buff[i] != i) + printf("buff[%d] = %d\n", i, buff[i]); + } + + return NULL; +} + +static void test_thread_mutex(CuTest *tc) +{ + apr_thread_t *t1, *t2, *t3, *t4; + apr_status_t s1, s2, s3, s4; + + s1 = apr_thread_mutex_create(&thread_mutex, APR_THREAD_MUTEX_DEFAULT, p); + CuAssertIntEquals(tc, APR_SUCCESS, s1); + CuAssertPtrNotNull(tc, thread_mutex); + + i = 0; + x = 0; + + s1 = apr_thread_create(&t1, NULL, thread_mutex_function, NULL, p); + CuAssertIntEquals(tc, APR_SUCCESS, s1); + s2 = apr_thread_create(&t2, NULL, thread_mutex_function, NULL, p); + CuAssertIntEquals(tc, APR_SUCCESS, s2); + s3 = apr_thread_create(&t3, NULL, thread_mutex_function, NULL, p); + CuAssertIntEquals(tc, APR_SUCCESS, s3); + s4 = apr_thread_create(&t4, NULL, thread_mutex_function, NULL, p); + CuAssertIntEquals(tc, APR_SUCCESS, s4); + + apr_thread_join(&s1, t1); + apr_thread_join(&s2, t2); + apr_thread_join(&s3, t3); + apr_thread_join(&s4, t4); + + CuAssertIntEquals(tc, MAX_ITER, x); +} + +static void test_thread_rwlock(CuTest *tc) +{ + apr_thread_t *t1, *t2, *t3, *t4; + apr_status_t s1, s2, s3, s4; + + s1 = apr_thread_rwlock_create(&rwlock, p); + apr_assert_success(tc, "rwlock_create", s1); + CuAssertPtrNotNull(tc, rwlock); + + i = 0; + x = 0; + + s1 = apr_thread_create(&t1, NULL, thread_rwlock_func, NULL, p); + apr_assert_success(tc, "create thread 1", s1); + s2 = apr_thread_create(&t2, NULL, thread_rwlock_func, NULL, p); + apr_assert_success(tc, "create thread 2", s2); + s3 = apr_thread_create(&t3, NULL, thread_rwlock_func, NULL, p); + apr_assert_success(tc, "create thread 3", s3); + s4 = apr_thread_create(&t4, NULL, thread_rwlock_func, NULL, p); + apr_assert_success(tc, "create thread 4", s4); + + apr_thread_join(&s1, t1); + apr_thread_join(&s2, t2); + apr_thread_join(&s3, t3); + apr_thread_join(&s4, t4); + + CuAssertIntEquals(tc, MAX_ITER, x); + + apr_thread_rwlock_destroy(rwlock); +} + +static void test_cond(CuTest *tc) +{ + apr_thread_t *p1, *p2, *p3, *p4, *c1; + apr_status_t s0, s1, s2, s3, s4; + int count1, count2, count3, count4; + int sum; + + s1 = apr_thread_mutex_create(&put.mutex, APR_THREAD_MUTEX_DEFAULT, p); + CuAssertIntEquals(tc, APR_SUCCESS, s1); + CuAssertPtrNotNull(tc, put.mutex); + + s1 = apr_thread_mutex_create(&nready.mutex, APR_THREAD_MUTEX_DEFAULT, p); + CuAssertIntEquals(tc, APR_SUCCESS, s1); + CuAssertPtrNotNull(tc, nready.mutex); + + s1 = apr_thread_cond_create(&nready.cond, p); + CuAssertIntEquals(tc, APR_SUCCESS, s1); + CuAssertPtrNotNull(tc, nready.cond); + + count1 = count2 = count3 = count4 = 0; + put.nput = put.nval = 0; + nready.nready = 0; + i = 0; + x = 0; + + s0 = apr_thread_create(&p1, NULL, thread_cond_producer, &count1, p); + CuAssertIntEquals(tc, APR_SUCCESS, s0); + s1 = apr_thread_create(&p2, NULL, thread_cond_producer, &count2, p); + CuAssertIntEquals(tc, APR_SUCCESS, s1); + s2 = apr_thread_create(&p3, NULL, thread_cond_producer, &count3, p); + CuAssertIntEquals(tc, APR_SUCCESS, s2); + s3 = apr_thread_create(&p4, NULL, thread_cond_producer, &count4, p); + CuAssertIntEquals(tc, APR_SUCCESS, s3); + s4 = apr_thread_create(&c1, NULL, thread_cond_consumer, NULL, p); + CuAssertIntEquals(tc, APR_SUCCESS, s4); + + apr_thread_join(&s0, p1); + apr_thread_join(&s1, p2); + apr_thread_join(&s2, p3); + apr_thread_join(&s3, p4); + apr_thread_join(&s4, c1); + + sum = count1 + count2 + count3 + count4; + /* + printf("count1 = %d count2 = %d count3 = %d count4 = %d\n", + count1, count2, count3, count4); + */ + CuAssertIntEquals(tc, MAX_COUNTER, sum); +} + +static void test_timeoutcond(CuTest *tc) +{ + apr_status_t s; + apr_interval_time_t timeout; + apr_time_t begin, end; + int i; + + s = apr_thread_mutex_create(&timeout_mutex, APR_THREAD_MUTEX_DEFAULT, p); + CuAssertIntEquals(tc, APR_SUCCESS, s); + CuAssertPtrNotNull(tc, timeout_mutex); + + s = apr_thread_cond_create(&timeout_cond, p); + CuAssertIntEquals(tc, APR_SUCCESS, s); + CuAssertPtrNotNull(tc, timeout_cond); + + timeout = apr_time_from_sec(5); + + for (i = 0; i < MAX_RETRY; i++) { + apr_thread_mutex_lock(timeout_mutex); + + begin = apr_time_now(); + s = apr_thread_cond_timedwait(timeout_cond, timeout_mutex, timeout); + end = apr_time_now(); + apr_thread_mutex_unlock(timeout_mutex); + + if (s != APR_SUCCESS && !APR_STATUS_IS_TIMEUP(s)) { + continue; + } + CuAssertIntEquals(tc, 1, APR_STATUS_IS_TIMEUP(s)); + CuAssert(tc, "Timer returned too late", end - begin - timeout < 100000); + break; + } + CuAssert(tc, "Too many retries", i < MAX_RETRY); +} + +#endif /* !APR_HAS_THREADS */ + +#if !APR_HAS_THREADS +static void threads_not_impl(CuTest *tc) +{ + CuNotImpl(tc, "Threads not implemented on this platform"); +} +#endif + + +CuSuite *testlock(void) +{ + CuSuite *suite = CuSuiteNew("Thread Locks"); + +#if !APR_HAS_THREADS + SUITE_ADD_TEST(suite, threads_not_impl); +#else + SUITE_ADD_TEST(suite, test_thread_mutex); + SUITE_ADD_TEST(suite, test_thread_rwlock); + SUITE_ADD_TEST(suite, test_cond); + SUITE_ADD_TEST(suite, test_timeoutcond); +#endif + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testlockperf.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testlockperf.c new file mode 100644 index 00000000..ba785775 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testlockperf.c @@ -0,0 +1,282 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_thread_proc.h" +#include "apr_thread_mutex.h" +#include "apr_thread_rwlock.h" +#include "apr_file_io.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_getopt.h" +#include "errno.h" +#include <stdio.h> +#include <stdlib.h> +#include "test_apr.h" + +#if !APR_HAS_THREADS +int main(void) +{ + printf("This program won't work on this platform because there is no " + "support for threads.\n"); + return 0; +} +#else /* !APR_HAS_THREADS */ + +#define MAX_COUNTER 1000000 +#define MAX_THREADS 6 + +static long mutex_counter; + +static apr_thread_mutex_t *thread_lock; +void * APR_THREAD_FUNC thread_mutex_func(apr_thread_t *thd, void *data); +apr_status_t test_thread_mutex(int num_threads); /* apr_thread_mutex_t */ + +static apr_thread_rwlock_t *thread_rwlock; +void * APR_THREAD_FUNC thread_rwlock_func(apr_thread_t *thd, void *data); +apr_status_t test_thread_rwlock(int num_threads); /* apr_thread_rwlock_t */ + +int test_thread_mutex_nested(int num_threads); + +apr_pool_t *pool; +int i = 0, x = 0; + +void * APR_THREAD_FUNC thread_mutex_func(apr_thread_t *thd, void *data) +{ + int i; + + for (i = 0; i < MAX_COUNTER; i++) { + apr_thread_mutex_lock(thread_lock); + mutex_counter++; + apr_thread_mutex_unlock(thread_lock); + } + return NULL; +} + +void * APR_THREAD_FUNC thread_rwlock_func(apr_thread_t *thd, void *data) +{ + int i; + + for (i = 0; i < MAX_COUNTER; i++) { + apr_thread_rwlock_wrlock(thread_rwlock); + mutex_counter++; + apr_thread_rwlock_unlock(thread_rwlock); + } + return NULL; +} + +int test_thread_mutex(int num_threads) +{ + apr_thread_t *t[MAX_THREADS]; + apr_status_t s[MAX_THREADS]; + apr_time_t time_start, time_stop; + int i; + + mutex_counter = 0; + + printf("apr_thread_mutex_t Tests\n"); + printf("%-60s", " Initializing the apr_thread_mutex_t (UNNESTED)"); + s[0] = apr_thread_mutex_create(&thread_lock, APR_THREAD_MUTEX_UNNESTED, pool); + if (s[0] != APR_SUCCESS) { + printf("Failed!\n"); + return s[0]; + } + printf("OK\n"); + + apr_thread_mutex_lock(thread_lock); + /* set_concurrency(4)? -aaron */ + printf(" Starting %d threads ", num_threads); + for (i = 0; i < num_threads; ++i) { + s[i] = apr_thread_create(&t[i], NULL, thread_mutex_func, NULL, pool); + if (s[i] != APR_SUCCESS) { + printf("Failed!\n"); + return s[i]; + } + } + printf("OK\n"); + + time_start = apr_time_now(); + apr_thread_mutex_unlock(thread_lock); + + /* printf("%-60s", " Waiting for threads to exit"); */ + for (i = 0; i < num_threads; ++i) { + apr_thread_join(&s[i], t[i]); + } + /* printf("OK\n"); */ + + time_stop = apr_time_now(); + printf("microseconds: %" APR_INT64_T_FMT " usec\n", + (time_stop - time_start)); + if (mutex_counter != MAX_COUNTER * num_threads) + printf("error: counter = %ld\n", mutex_counter); + + return APR_SUCCESS; +} + +int test_thread_mutex_nested(int num_threads) +{ + apr_thread_t *t[MAX_THREADS]; + apr_status_t s[MAX_THREADS]; + apr_time_t time_start, time_stop; + int i; + + mutex_counter = 0; + + printf("apr_thread_mutex_t Tests\n"); + printf("%-60s", " Initializing the apr_thread_mutex_t (NESTED)"); + s[0] = apr_thread_mutex_create(&thread_lock, APR_THREAD_MUTEX_NESTED, pool); + if (s[0] != APR_SUCCESS) { + printf("Failed!\n"); + return s[0]; + } + printf("OK\n"); + + apr_thread_mutex_lock(thread_lock); + /* set_concurrency(4)? -aaron */ + printf(" Starting %d threads ", num_threads); + for (i = 0; i < num_threads; ++i) { + s[i] = apr_thread_create(&t[i], NULL, thread_mutex_func, NULL, pool); + if (s[i] != APR_SUCCESS) { + printf("Failed!\n"); + return s[i]; + } + } + printf("OK\n"); + + time_start = apr_time_now(); + apr_thread_mutex_unlock(thread_lock); + + /* printf("%-60s", " Waiting for threads to exit"); */ + for (i = 0; i < num_threads; ++i) { + apr_thread_join(&s[i], t[i]); + } + /* printf("OK\n"); */ + + time_stop = apr_time_now(); + printf("microseconds: %" APR_INT64_T_FMT " usec\n", + (time_stop - time_start)); + if (mutex_counter != MAX_COUNTER * num_threads) + printf("error: counter = %ld\n", mutex_counter); + + return APR_SUCCESS; +} + +int test_thread_rwlock(int num_threads) +{ + apr_thread_t *t[MAX_THREADS]; + apr_status_t s[MAX_THREADS]; + apr_time_t time_start, time_stop; + int i; + + mutex_counter = 0; + + printf("apr_thread_rwlock_t Tests\n"); + printf("%-60s", " Initializing the apr_thread_rwlock_t"); + s[0] = apr_thread_rwlock_create(&thread_rwlock, pool); + if (s[0] != APR_SUCCESS) { + printf("Failed!\n"); + return s[0]; + } + printf("OK\n"); + + apr_thread_rwlock_wrlock(thread_rwlock); + /* set_concurrency(4)? -aaron */ + printf(" Starting %d threads ", num_threads); + for (i = 0; i < num_threads; ++i) { + s[i] = apr_thread_create(&t[i], NULL, thread_rwlock_func, NULL, pool); + if (s[i] != APR_SUCCESS) { + printf("Failed!\n"); + return s[i]; + } + } + printf("OK\n"); + + time_start = apr_time_now(); + apr_thread_rwlock_unlock(thread_rwlock); + + /* printf("%-60s", " Waiting for threads to exit"); */ + for (i = 0; i < num_threads; ++i) { + apr_thread_join(&s[i], t[i]); + } + /* printf("OK\n"); */ + + time_stop = apr_time_now(); + printf("microseconds: %" APR_INT64_T_FMT " usec\n", + (time_stop - time_start)); + if (mutex_counter != MAX_COUNTER * num_threads) + printf("error: counter = %ld\n", mutex_counter); + + return APR_SUCCESS; +} + +int main(int argc, const char * const *argv) +{ + apr_status_t rv; + char errmsg[200]; + const char *lockname = "multi.lock"; + apr_getopt_t *opt; + char optchar; + const char *optarg; + + printf("APR Lock Performance Test\n==============\n\n"); + + apr_initialize(); + atexit(apr_terminate); + + if (apr_pool_create(&pool, NULL) != APR_SUCCESS) + exit(-1); + + if ((rv = apr_getopt_init(&opt, pool, argc, argv)) != APR_SUCCESS) { + fprintf(stderr, "Could not set up to parse options: [%d] %s\n", + rv, apr_strerror(rv, errmsg, sizeof errmsg)); + exit(-1); + } + + while ((rv = apr_getopt(opt, "f:", &optchar, &optarg)) == APR_SUCCESS) { + if (optchar == 'f') { + lockname = optarg; + } + } + + if (rv != APR_SUCCESS && rv != APR_EOF) { + fprintf(stderr, "Could not parse options: [%d] %s\n", + rv, apr_strerror(rv, errmsg, sizeof errmsg)); + exit(-1); + } + + for (i = 1; i <= MAX_THREADS; ++i) { + if ((rv = test_thread_mutex(i)) != APR_SUCCESS) { + fprintf(stderr,"thread_mutex test failed : [%d] %s\n", + rv, apr_strerror(rv, (char*)errmsg, 200)); + exit(-3); + } + + if ((rv = test_thread_mutex_nested(i)) != APR_SUCCESS) { + fprintf(stderr,"thread_mutex (NESTED) test failed : [%d] %s\n", + rv, apr_strerror(rv, (char*)errmsg, 200)); + exit(-4); + } + + if ((rv = test_thread_rwlock(i)) != APR_SUCCESS) { + fprintf(stderr,"thread_rwlock test failed : [%d] %s\n", + rv, apr_strerror(rv, (char*)errmsg, 200)); + exit(-6); + } + } + + return 0; +} + +#endif /* !APR_HAS_THREADS */ diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testmmap.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testmmap.c new file mode 100644 index 00000000..012d8d0e --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testmmap.c @@ -0,0 +1,154 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test_apr.h" +#include "apr_mmap.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_lib.h" +#include "apr_file_io.h" +#include "apr_strings.h" + +/* hmmm, what is a truly portable define for the max path + * length on a platform? + */ +#define PATH_LEN 255 +#define TEST_STRING "This is the MMAP data file."APR_EOL_STR + +#if !APR_HAS_MMAP +static void not_implemented(CuTest *tc) +{ + CuNotImpl(tc, "User functions"); +} + +#else + +static apr_mmap_t *themmap = NULL; +static apr_file_t *thefile = NULL; +static char *file1; +static apr_finfo_t finfo; +static int fsize; + +static void create_filename(CuTest *tc) +{ + char *oldfileptr; + + apr_filepath_get(&file1, 0, p); +#ifndef NETWARE +#ifdef WIN32 + CuAssertTrue(tc, file1[1] == ':'); +#else + CuAssertTrue(tc, file1[0] == '/'); +#endif +#endif + CuAssertTrue(tc, file1[strlen(file1) - 1] != '/'); + + oldfileptr = file1; + file1 = apr_pstrcat(p, file1,"/data/mmap_datafile.txt" ,NULL); + CuAssertTrue(tc, oldfileptr != file1); +} + +static void test_file_close(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_file_close(thefile); + CuAssertIntEquals(tc, rv, APR_SUCCESS); +} + +static void test_file_open(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_file_open(&thefile, file1, APR_READ, APR_UREAD | APR_GREAD, p); + CuAssertIntEquals(tc, rv, APR_SUCCESS); + CuAssertPtrNotNull(tc, thefile); +} + +static void test_get_filesize(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_file_info_get(&finfo, APR_FINFO_NORM, thefile); + CuAssertIntEquals(tc, rv, APR_SUCCESS); + CuAssert(tc, "File size mismatch", fsize == finfo.size); +} + +static void test_mmap_create(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_mmap_create(&themmap, thefile, 0, (apr_size_t)finfo.size, + APR_MMAP_READ, p); + CuAssertPtrNotNull(tc, themmap); + CuAssertIntEquals(tc, rv, APR_SUCCESS); +} + +static void test_mmap_contents(CuTest *tc) +{ + + CuAssertPtrNotNull(tc, themmap); + CuAssertPtrNotNull(tc, themmap->mm); + CuAssertIntEquals(tc, fsize, themmap->size); + + /* Must use nEquals since the string is not guaranteed to be NULL terminated */ + CuAssertStrNEquals(tc, themmap->mm, TEST_STRING, fsize); +} + +static void test_mmap_delete(CuTest *tc) +{ + apr_status_t rv; + + CuAssertPtrNotNull(tc, themmap); + rv = apr_mmap_delete(themmap); + CuAssertIntEquals(tc, rv, APR_SUCCESS); +} + +static void test_mmap_offset(CuTest *tc) +{ + apr_status_t rv; + void *addr; + + CuAssertPtrNotNull(tc, themmap); + rv = apr_mmap_offset(&addr, themmap, 5); + + /* Must use nEquals since the string is not guaranteed to be NULL terminated */ + CuAssertStrNEquals(tc, addr, TEST_STRING + 5, fsize-5); +} +#endif + +CuSuite *testmmap(void) +{ + CuSuite *suite = CuSuiteNew("MMAP"); + +#if APR_HAS_MMAP + fsize = strlen(TEST_STRING); + + SUITE_ADD_TEST(suite, create_filename); + SUITE_ADD_TEST(suite, test_file_open); + SUITE_ADD_TEST(suite, test_get_filesize); + SUITE_ADD_TEST(suite, test_mmap_create); + SUITE_ADD_TEST(suite, test_mmap_contents); + SUITE_ADD_TEST(suite, test_mmap_offset); + SUITE_ADD_TEST(suite, test_mmap_delete); + SUITE_ADD_TEST(suite, test_file_close); +#else + SUITE_ADD_TEST(suite, not_implemented); +#endif + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testmutexscope.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testmutexscope.c new file mode 100644 index 00000000..0ea08cc6 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testmutexscope.c @@ -0,0 +1,218 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <assert.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> + +#include "apr.h" +#include "apr_general.h" +#include "apr_proc_mutex.h" +#include "apr_global_mutex.h" +#include "apr_thread_proc.h" + +#if !APR_HAS_THREADS +int main(void) +{ + printf("This test requires APR thread support.\n"); + return 0; +} + +#else /* APR_HAS_THREADS */ + +static apr_thread_mutex_t *thread_mutex; +static apr_proc_mutex_t *proc_mutex; +static apr_global_mutex_t *global_mutex; +static apr_pool_t *p; +static volatile int counter; +typedef enum {TEST_GLOBAL, TEST_PROC} test_mode_e; + +static void lock_init(apr_lockmech_e mech, test_mode_e test_mode) +{ + if (test_mode == TEST_PROC) { + assert(apr_proc_mutex_create(&proc_mutex, + NULL, + mech, + p) == APR_SUCCESS); + } + else { + assert(apr_global_mutex_create(&global_mutex, + NULL, + mech, + p) == APR_SUCCESS); + } +} + +static void lock_destroy(test_mode_e test_mode) +{ + if (test_mode == TEST_PROC) { + assert(apr_proc_mutex_destroy(proc_mutex) == APR_SUCCESS); + } + else { + assert(apr_global_mutex_destroy(global_mutex) == APR_SUCCESS); + } +} + +static void lock_grab(test_mode_e test_mode) +{ + if (test_mode == TEST_PROC) { + assert(apr_proc_mutex_lock(proc_mutex) == APR_SUCCESS); + } + else { + assert(apr_global_mutex_lock(global_mutex) == APR_SUCCESS); + } +} + +static void lock_release(test_mode_e test_mode) +{ + if (test_mode == TEST_PROC) { + assert(apr_proc_mutex_unlock(proc_mutex) == APR_SUCCESS); + } + else { + assert(apr_global_mutex_unlock(global_mutex) == APR_SUCCESS); + } +} + +static void * APR_THREAD_FUNC eachThread(apr_thread_t *id, void *p) +{ + test_mode_e test_mode = (test_mode_e)p; + + lock_grab(test_mode); + ++counter; + assert(apr_thread_mutex_lock(thread_mutex) == APR_SUCCESS); + assert(apr_thread_mutex_unlock(thread_mutex) == APR_SUCCESS); + lock_release(test_mode); + return NULL; +} + +static void test_mech_mode(apr_lockmech_e mech, const char *mech_name, + test_mode_e test_mode) +{ + apr_thread_t *threads[20]; + int numThreads = 5; + int i; + apr_status_t rv; + + printf("Trying %s mutexes with mechanism `%s'...\n", + test_mode == TEST_GLOBAL ? "global" : "proc", mech_name); + + assert(numThreads <= sizeof(threads) / sizeof(threads[0])); + + assert(apr_pool_create(&p, NULL) == APR_SUCCESS); + + assert(apr_thread_mutex_create(&thread_mutex, 0, p) == APR_SUCCESS); + assert(apr_thread_mutex_lock(thread_mutex) == APR_SUCCESS); + + lock_init(mech, test_mode); + + counter = 0; + + i = 0; + while (i < numThreads) + { + rv = apr_thread_create(&threads[i], + NULL, + eachThread, + (void *)test_mode, + p); + if (rv != APR_SUCCESS) { + fprintf(stderr, "apr_thread_create->%d\n", rv); + exit(1); + } + ++i; + } + + apr_sleep(apr_time_from_sec(5)); + + if (test_mode == TEST_PROC) { + printf(" Mutex mechanism `%s' is %sglobal in scope on this platform.\n", + mech_name, counter == 1 ? "" : "not "); + } + else { + if (counter != 1) { + fprintf(stderr, "\n!!!apr_global_mutex operations are broken on this " + "platform for mutex mechanism `%s'!\n" + "They don't block out threads within the same process.\n", + mech_name); + fprintf(stderr, "counter value: %d\n", counter); + exit(1); + } + else { + printf(" no problems encountered...\n"); + } + } + + assert(apr_thread_mutex_unlock(thread_mutex) == APR_SUCCESS); + + i = 0; + while (i < numThreads) + { + apr_status_t ignored; + + rv = apr_thread_join(&ignored, + threads[i]); + assert(rv == APR_SUCCESS); + ++i; + } + + lock_destroy(test_mode); + apr_thread_mutex_destroy(thread_mutex); + apr_pool_destroy(p); +} + +static void test_mech(apr_lockmech_e mech, const char *mech_name) +{ + test_mech_mode(mech, mech_name, TEST_PROC); + test_mech_mode(mech, mech_name, TEST_GLOBAL); +} + +int main(void) +{ + struct { + apr_lockmech_e mech; + const char *mech_name; + } lockmechs[] = { + {APR_LOCK_DEFAULT, "default"} +#if APR_HAS_FLOCK_SERIALIZE + ,{APR_LOCK_FLOCK, "flock"} +#endif +#if APR_HAS_SYSVSEM_SERIALIZE + ,{APR_LOCK_SYSVSEM, "sysvsem"} +#endif +#if APR_HAS_POSIXSEM_SERIALIZE + ,{APR_LOCK_POSIXSEM, "posix"} +#endif +#if APR_HAS_FCNTL_SERIALIZE + ,{APR_LOCK_FCNTL, "fcntl"} +#endif +#if APR_HAS_PROC_PTHREAD_SERIALIZE + ,{APR_LOCK_PROC_PTHREAD, "proc_pthread"} +#endif + }; + int i; + + assert(apr_initialize() == APR_SUCCESS); + + for (i = 0; i < sizeof(lockmechs) / sizeof(lockmechs[0]); i++) { + test_mech(lockmechs[i].mech, lockmechs[i].mech_name); + } + + apr_terminate(); + return 0; +} + +#endif /* APR_HAS_THREADS */ diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testnames.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testnames.c new file mode 100644 index 00000000..8df4b083 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testnames.c @@ -0,0 +1,273 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test_apr.h" +#include "apr_file_io.h" +#include "apr_file_info.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_pools.h" +#include "apr_lib.h" + +#if WIN32 +#define ABS_ROOT "C:/" +#elif defined(NETWARE) +#define ABS_ROOT "SYS:/" +#else +#define ABS_ROOT "/" +#endif + +static void merge_aboveroot(CuTest *tc) +{ + apr_status_t rv; + char *dstpath = NULL; + char errmsg[256]; + + rv = apr_filepath_merge(&dstpath, ABS_ROOT"foo", ABS_ROOT"bar", APR_FILEPATH_NOTABOVEROOT, + p); + apr_strerror(rv, errmsg, sizeof(errmsg)); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_EABOVEROOT(rv)); + CuAssertPtrEquals(tc, NULL, dstpath); + CuAssertStrEquals(tc, "The given path was above the root path", errmsg); +} + +static void merge_belowroot(CuTest *tc) +{ + apr_status_t rv; + char *dstpath = NULL; + + rv = apr_filepath_merge(&dstpath, ABS_ROOT"foo", ABS_ROOT"foo/bar", + APR_FILEPATH_NOTABOVEROOT, p); + CuAssertPtrNotNull(tc, dstpath); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, ABS_ROOT"foo/bar", dstpath); +} + +static void merge_noflag(CuTest *tc) +{ + apr_status_t rv; + char *dstpath = NULL; + + rv = apr_filepath_merge(&dstpath, ABS_ROOT"foo", ABS_ROOT"foo/bar", 0, p); + CuAssertPtrNotNull(tc, dstpath); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, ABS_ROOT"foo/bar", dstpath); +} + +static void merge_dotdot(CuTest *tc) +{ + apr_status_t rv; + char *dstpath = NULL; + + rv = apr_filepath_merge(&dstpath, ABS_ROOT"foo/bar", "../baz", 0, p); + CuAssertPtrNotNull(tc, dstpath); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, ABS_ROOT"foo/baz", dstpath); + + rv = apr_filepath_merge(&dstpath, "", "../test", 0, p); + CuAssertIntEquals(tc, 0, APR_SUCCESS); + CuAssertStrEquals(tc, "../test", dstpath); + + /* Very dangerous assumptions here about what the cwd is. However, let's assume + * that the testall is invoked from within apr/test/ so the following test should + * return ../test unless a previously fixed bug remains or the developer changes + * the case of the test directory: + */ + rv = apr_filepath_merge(&dstpath, "", "../test", APR_FILEPATH_TRUENAME, p); + CuAssertIntEquals(tc, 0, APR_SUCCESS); + CuAssertStrEquals(tc, "../test", dstpath); +} + +static void merge_dotdot_dotdot_dotdot(CuTest *tc) +{ + apr_status_t rv; + char *dstpath = NULL; + + rv = apr_filepath_merge(&dstpath, "", + "../../..", APR_FILEPATH_TRUENAME, p); + CuAssertPtrNotNull(tc, dstpath); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, "../../..", dstpath); + + rv = apr_filepath_merge(&dstpath, "", + "../../../", APR_FILEPATH_TRUENAME, p); + CuAssertPtrNotNull(tc, dstpath); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, "../../../", dstpath); +} + +static void merge_secure(CuTest *tc) +{ + apr_status_t rv; + char *dstpath = NULL; + + rv = apr_filepath_merge(&dstpath, ABS_ROOT"foo/bar", "../bar/baz", 0, p); + CuAssertPtrNotNull(tc, dstpath); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, ABS_ROOT"foo/bar/baz", dstpath); +} + +static void merge_notrel(CuTest *tc) +{ + apr_status_t rv; + char *dstpath = NULL; + + rv = apr_filepath_merge(&dstpath, ABS_ROOT"foo/bar", "../baz", + APR_FILEPATH_NOTRELATIVE, p); + CuAssertPtrNotNull(tc, dstpath); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, ABS_ROOT"foo/baz", dstpath); +} + +static void merge_notrelfail(CuTest *tc) +{ + apr_status_t rv; + char *dstpath = NULL; + char errmsg[256]; + + rv = apr_filepath_merge(&dstpath, "foo/bar", "../baz", + APR_FILEPATH_NOTRELATIVE, p); + apr_strerror(rv, errmsg, sizeof(errmsg)); + + CuAssertPtrEquals(tc, NULL, dstpath); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_ERELATIVE(rv)); + CuAssertStrEquals(tc, "The given path is relative", errmsg); +} + +static void merge_notabsfail(CuTest *tc) +{ + apr_status_t rv; + char *dstpath = NULL; + char errmsg[256]; + + rv = apr_filepath_merge(&dstpath, ABS_ROOT"foo/bar", "../baz", + APR_FILEPATH_NOTABSOLUTE, p); + apr_strerror(rv, errmsg, sizeof(errmsg)); + + CuAssertPtrEquals(tc, NULL, dstpath); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_EABSOLUTE(rv)); + CuAssertStrEquals(tc, "The given path is absolute", errmsg); +} + +static void merge_notabs(CuTest *tc) +{ + apr_status_t rv; + char *dstpath = NULL; + + rv = apr_filepath_merge(&dstpath, "foo/bar", "../baz", + APR_FILEPATH_NOTABSOLUTE, p); + + CuAssertPtrNotNull(tc, dstpath); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, "foo/baz", dstpath); +} + +static void root_absolute(CuTest *tc) +{ + apr_status_t rv; + const char *root = NULL; + const char *path = ABS_ROOT"foo/bar"; + + rv = apr_filepath_root(&root, &path, 0, p); + + CuAssertPtrNotNull(tc, root); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, ABS_ROOT, root); +} + +static void root_relative(CuTest *tc) +{ + apr_status_t rv; + const char *root = NULL; + const char *path = "foo/bar"; + char errmsg[256]; + + rv = apr_filepath_root(&root, &path, 0, p); + apr_strerror(rv, errmsg, sizeof(errmsg)); + + CuAssertPtrEquals(tc, NULL, root); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_ERELATIVE(rv)); + CuAssertStrEquals(tc, "The given path is relative", errmsg); +} + + +static void root_from_cwd_and_back(CuTest *tc) +{ + apr_status_t rv; + const char *root = NULL; + const char *path = "//"; + char *origpath; + char *testpath; + + CuAssertIntEquals(tc, APR_SUCCESS, apr_filepath_get(&origpath, 0, p)); + path = origpath; + rv = apr_filepath_root(&root, &path, APR_FILEPATH_TRUENAME, p); + +#if defined(WIN32) || defined(OS2) + CuAssertIntEquals(tc, origpath[0], root[0]); + CuAssertIntEquals(tc, ':', root[1]); + CuAssertIntEquals(tc, '/', root[2]); + CuAssertIntEquals(tc, 0, root[3]); + CuAssertStrEquals(tc, origpath + 3, path); +#elif defined(NETWARE) + CuAssertIntEquals(tc, origpath[0], root[0]); + { + char *pt = strchr(root, ':'); + CuAssertPtrNotNull(tc, pt); + CuAssertIntEquals(tc, ':', pt[0]); + CuAssertIntEquals(tc, '/', pt[1]); + CuAssertIntEquals(tc, 0, pt[2]); + pt = strchr(origpath, ':'); + CuAssertPtrNotNull(tc, pt); + CuAssertStrEquals(tc, (pt+2), path); + } +#else + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, "/", root); + CuAssertStrEquals(tc, origpath + 1, path); +#endif + + rv = apr_filepath_merge(&testpath, root, path, + APR_FILEPATH_TRUENAME + | APR_FILEPATH_NOTABOVEROOT + | APR_FILEPATH_NOTRELATIVE, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, origpath, testpath); +} + + +CuSuite *testnames(void) +{ + CuSuite *suite = CuSuiteNew("Path names"); + + SUITE_ADD_TEST(suite, merge_aboveroot); + SUITE_ADD_TEST(suite, merge_belowroot); + SUITE_ADD_TEST(suite, merge_noflag); + SUITE_ADD_TEST(suite, merge_dotdot); + SUITE_ADD_TEST(suite, merge_secure); + SUITE_ADD_TEST(suite, merge_notrel); + SUITE_ADD_TEST(suite, merge_notrelfail); + SUITE_ADD_TEST(suite, merge_notabs); + SUITE_ADD_TEST(suite, merge_notabsfail); + SUITE_ADD_TEST(suite, merge_dotdot_dotdot_dotdot); + + SUITE_ADD_TEST(suite, root_absolute); + SUITE_ADD_TEST(suite, root_relative); + SUITE_ADD_TEST(suite, root_from_cwd_and_back); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testoc.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testoc.c new file mode 100644 index 00000000..bebf4822 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testoc.c @@ -0,0 +1,126 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#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" + +#if APR_HAS_OTHER_CHILD + +/* XXX I'm sure there has to be a better way to do this ... */ +#ifdef WIN32 +#define EXTENSION ".exe" +#elif NETWARE +#define EXTENSION ".nlm" +#else +#define EXTENSION +#endif + +static char reasonstr[256]; + +static void ocmaint(int reason, void *data, int status) +{ + switch (reason) { + case APR_OC_REASON_DEATH: + apr_cpystrn(reasonstr, "APR_OC_REASON_DEATH", + strlen("APR_OC_REASON_DEATH") + 1); + break; + case APR_OC_REASON_LOST: + apr_cpystrn(reasonstr, "APR_OC_REASON_LOST", + strlen("APR_OC_REASON_LOST") + 1); + break; + case APR_OC_REASON_UNWRITABLE: + apr_cpystrn(reasonstr, "APR_OC_REASON_UNWRITEABLE", + strlen("APR_OC_REASON_UNWRITEABLE") + 1); + break; + case APR_OC_REASON_RESTART: + apr_cpystrn(reasonstr, "APR_OC_REASON_RESTART", + strlen("APR_OC_REASON_RESTART") + 1); + break; + } +} + +#ifndef SIGKILL +#define SIGKILL 1 +#endif + +/* It would be great if we could stress this stuff more, and make the test + * more granular. + */ +static void test_child_kill(CuTest *tc) +{ + apr_file_t *std = NULL; + apr_proc_t newproc; + apr_procattr_t *procattr = NULL; + const char *args[3]; + apr_status_t rv; + + args[0] = apr_pstrdup(p, "occhild" EXTENSION); + args[1] = apr_pstrdup(p, "-X"); + args[2] = NULL; + + rv = apr_procattr_create(&procattr, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + 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" EXTENSION, 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, p); + + apr_sleep(apr_time_from_sec(1)); + rv = apr_proc_kill(&newproc, SIGKILL); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + /* allow time for things to settle... */ + apr_sleep(apr_time_from_sec(3)); + + apr_proc_other_child_check(); + CuAssertStrEquals(tc, "APR_OC_REASON_DEATH", reasonstr); +} +#else + +static void oc_not_impl(CuTest *tc) +{ + CuNotImpl(tc, "Other child logic not implemented on this platform"); +} +#endif + +CuSuite *testoc(void) +{ + CuSuite *suite = CuSuiteNew("Other Child"); + +#if !APR_HAS_OTHER_CHILD + SUITE_ADD_TEST(suite, oc_not_impl); +#else + + SUITE_ADD_TEST(suite, test_child_kill); + +#endif + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testpath.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testpath.c new file mode 100644 index 00000000..e41e26ac --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testpath.c @@ -0,0 +1,138 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test_apr.h" +#include "apr_file_info.h" +#include "apr_errno.h" +#include "apr_pools.h" +#include "apr_tables.h" + +#if defined(WIN32) || defined(NETWARE) || defined(OS2) +#define PSEP ";" +#define DSEP "\\" +#else +#define PSEP ":" +#define DSEP "/" +#endif + +#define PX "" +#define P1 "first path" +#define P2 "second" DSEP "path" +#define P3 "th ird" DSEP "path" +#define P4 "fourth" DSEP "pa th" +#define P5 "fifthpath" + +static const char *parts_in[] = { P1, P2, P3, PX, P4, P5 }; +static const char *path_in = P1 PSEP P2 PSEP P3 PSEP PX PSEP P4 PSEP P5; +static const int parts_in_count = sizeof(parts_in)/sizeof(*parts_in); + +static const char *parts_out[] = { P1, P2, P3, P4, P5 }; +static const char *path_out = P1 PSEP P2 PSEP P3 PSEP P4 PSEP P5; +static const int parts_out_count = sizeof(parts_out)/sizeof(*parts_out); + +static void list_split_multi(CuTest *tc) +{ + int i; + apr_status_t rv; + apr_array_header_t *pathelts; + + pathelts = NULL; + rv = apr_filepath_list_split(&pathelts, path_in, p); + CuAssertPtrNotNull(tc, pathelts); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, parts_out_count, pathelts->nelts); + for (i = 0; i < pathelts->nelts; ++i) + CuAssertStrEquals(tc, parts_out[i], ((char**)pathelts->elts)[i]); +} + +static void list_split_single(CuTest *tc) +{ + int i; + apr_status_t rv; + apr_array_header_t *pathelts; + + for (i = 0; i < parts_in_count; ++i) + { + pathelts = NULL; + rv = apr_filepath_list_split(&pathelts, parts_in[i], p); + CuAssertPtrNotNull(tc, pathelts); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + if (parts_in[i][0] == '\0') + CuAssertIntEquals(tc, 0, pathelts->nelts); + else + { + CuAssertIntEquals(tc, 1, pathelts->nelts); + CuAssertStrEquals(tc, parts_in[i], *(char**)pathelts->elts); + } + } +} + +static void list_merge_multi(CuTest *tc) +{ + int i; + char *liststr; + apr_status_t rv; + apr_array_header_t *pathelts; + + pathelts = apr_array_make(p, parts_in_count, sizeof(const char*)); + for (i = 0; i < parts_in_count; ++i) + *(const char**)apr_array_push(pathelts) = parts_in[i]; + + liststr = NULL; + rv = apr_filepath_list_merge(&liststr, pathelts, p); + CuAssertPtrNotNull(tc, liststr); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, liststr, path_out); +} + +static void list_merge_single(CuTest *tc) +{ + int i; + char *liststr; + apr_status_t rv; + apr_array_header_t *pathelts; + + pathelts = apr_array_make(p, 1, sizeof(const char*)); + apr_array_push(pathelts); + for (i = 0; i < parts_in_count; ++i) + { + *(const char**)pathelts->elts = parts_in[i]; + liststr = NULL; + rv = apr_filepath_list_merge(&liststr, pathelts, p); + if (parts_in[i][0] == '\0') + CuAssertPtrEquals(tc, NULL, liststr); + else + { + CuAssertPtrNotNull(tc, liststr); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, liststr, parts_in[i]); + } + } +} + + +CuSuite *testpath(void) +{ + CuSuite *suite = CuSuiteNew("Path lists"); + + SUITE_ADD_TEST(suite, list_split_multi); + SUITE_ADD_TEST(suite, list_split_single); + SUITE_ADD_TEST(suite, list_merge_multi); + SUITE_ADD_TEST(suite, list_merge_single); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testpipe.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testpipe.c new file mode 100644 index 00000000..79adf56b --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testpipe.c @@ -0,0 +1,204 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdlib.h> + +#include "test_apr.h" +#include "apr_file_io.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_lib.h" +#include "apr_thread_proc.h" +#include "apr_strings.h" + +static apr_file_t *readp = NULL; +static apr_file_t *writep = NULL; + +static void create_pipe(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_file_pipe_create(&readp, &writep, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, readp); + CuAssertPtrNotNull(tc, writep); +} + +static void close_pipe(CuTest *tc) +{ + apr_status_t rv; + apr_size_t nbytes = 256; + char buf[256]; + + rv = apr_file_close(readp); + rv = apr_file_close(writep); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_read(readp, buf, &nbytes); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_EBADF(rv)); +} + +static void set_timeout(CuTest *tc) +{ + apr_status_t rv; + apr_file_t *readp = NULL; + apr_file_t *writep = NULL; + apr_interval_time_t timeout; + + rv = apr_file_pipe_create(&readp, &writep, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, readp); + CuAssertPtrNotNull(tc, writep); + + rv = apr_file_pipe_timeout_get(readp, &timeout); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssert(tc, "Timeout mismatch, expected -1", timeout == -1); + + rv = apr_file_pipe_timeout_set(readp, apr_time_from_sec(1)); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_pipe_timeout_get(readp, &timeout); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssert(tc, "Timeout mismatch, expected 1 second", + timeout == apr_time_from_sec(1)); +} + +static void read_write(CuTest *tc) +{ + apr_status_t rv; + char *buf; + apr_size_t nbytes; + + nbytes = strlen("this is a test"); + buf = (char *)apr_palloc(p, nbytes + 1); + + rv = apr_file_pipe_create(&readp, &writep, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, readp); + CuAssertPtrNotNull(tc, writep); + + rv = apr_file_pipe_timeout_set(readp, apr_time_from_sec(1)); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_read(readp, buf, &nbytes); + if (!rv) { + CuAssertIntEquals(tc, 1, APR_STATUS_IS_TIMEUP(rv)); + CuAssertIntEquals(tc, 0, nbytes); + } +} + +static void read_write_notimeout(CuTest *tc) +{ + apr_status_t rv; + char *buf = "this is a test"; + char *input; + apr_size_t nbytes; + + nbytes = strlen("this is a test"); + + rv = apr_file_pipe_create(&readp, &writep, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, readp); + CuAssertPtrNotNull(tc, writep); + + rv = apr_file_write(writep, buf, &nbytes); + CuAssertIntEquals(tc, strlen("this is a test"), nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + nbytes = 256; + input = apr_pcalloc(p, nbytes + 1); + rv = apr_file_read(readp, input, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, strlen("this is a test"), nbytes); + CuAssertStrEquals(tc, "this is a test", input); +} + +/* XXX FIXME */ +#ifdef WIN32 +#define EXTENSION ".exe" +#elif NETWARE +#define EXTENSION ".nlm" +#else +#define EXTENSION +#endif + +static void test_pipe_writefull(CuTest *tc) +{ + int iterations = 1000; + int i; + int bytes_per_iteration = 8000; + char *buf = (char *)malloc(bytes_per_iteration); + char responsebuf[128]; + apr_size_t nbytes; + int bytes_processed; + apr_proc_t proc = {0}; + apr_procattr_t *procattr; + const char *args[2]; + apr_status_t rv; + + rv = apr_procattr_create(&procattr, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_procattr_io_set(procattr, APR_CHILD_BLOCK, APR_CHILD_BLOCK, + APR_CHILD_BLOCK); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_procattr_error_check_set(procattr, 1); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + args[0] = "readchild" EXTENSION; + args[1] = NULL; + rv = apr_proc_create(&proc, "./readchild" EXTENSION, args, NULL, procattr, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_pipe_timeout_set(proc.in, apr_time_from_sec(10)); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_pipe_timeout_set(proc.out, apr_time_from_sec(10)); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + i = iterations; + do { + rv = apr_file_write_full(proc.in, buf, bytes_per_iteration, NULL); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + } while (--i); + + free(buf); + + rv = apr_file_close(proc.in); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + nbytes = sizeof(responsebuf); + rv = apr_file_read(proc.out, responsebuf, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + bytes_processed = (int)apr_strtoi64(responsebuf, NULL, 10); + CuAssertIntEquals(tc, iterations * bytes_per_iteration, bytes_processed); +} + +CuSuite *testpipe(void) +{ + CuSuite *suite = CuSuiteNew("Pipes"); + + SUITE_ADD_TEST(suite, create_pipe); + SUITE_ADD_TEST(suite, close_pipe); + SUITE_ADD_TEST(suite, set_timeout); + SUITE_ADD_TEST(suite, read_write); + SUITE_ADD_TEST(suite, read_write_notimeout); + SUITE_ADD_TEST(suite, test_pipe_writefull); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testpoll.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testpoll.c new file mode 100644 index 00000000..4e2fac8f --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testpoll.c @@ -0,0 +1,526 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test_apr.h" +#include "apr_strings.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_lib.h" +#include "apr_network_io.h" +#include "apr_poll.h" + +#define SMALL_NUM_SOCKETS 3 +/* We can't use 64 here, because some platforms *ahem* Solaris *ahem* have + * a default limit of 64 open file descriptors per process. If we use + * 64, the test will fail even though the code is correct. + */ +#define LARGE_NUM_SOCKETS 50 + +static apr_socket_t *s[LARGE_NUM_SOCKETS]; +static apr_sockaddr_t *sa[LARGE_NUM_SOCKETS]; +static apr_pollfd_t *pollarray; +static apr_pollfd_t *pollarray_large; +static apr_pollset_t *pollset; + +static void make_socket(apr_socket_t **sock, apr_sockaddr_t **sa, + apr_port_t port, apr_pool_t *p, CuTest *tc) +{ + apr_status_t rv; + + rv = apr_sockaddr_info_get(sa, "127.0.0.1", APR_UNSPEC, port, 0, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_socket_create(sock, (*sa)->family, SOCK_DGRAM, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv =apr_socket_bind((*sock), (*sa)); + CuAssertIntEquals(tc, APR_SUCCESS, rv); +} + +static void check_sockets(const apr_pollfd_t *pollarray, + apr_socket_t **sockarray, int which, int pollin, + CuTest *tc) +{ + apr_status_t rv; + apr_int16_t event; + char *str; + + rv = apr_poll_revents_get(&event, sockarray[which], + (apr_pollfd_t *)pollarray); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + if (pollin) { + str = apr_psprintf(p, "Socket %d not signalled when it should be", + which); + CuAssert(tc, str, event & APR_POLLIN); + } else { + str = apr_psprintf(p, "Socket %d signalled when it should not be", + which); + CuAssert(tc, str, !(event & APR_POLLIN)); + } +} + +static void send_msg(apr_socket_t **sockarray, apr_sockaddr_t **sas, int which, + CuTest *tc) +{ + apr_size_t len = 5; + apr_status_t rv; + + CuAssertPtrNotNull(tc, sockarray[which]); + + rv = apr_socket_sendto(sockarray[which], sas[which], 0, "hello", &len); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, strlen("hello"), len); +} + +static void recv_msg(apr_socket_t **sockarray, int which, apr_pool_t *p, + CuTest *tc) +{ + apr_size_t buflen = 5; + char *buffer = apr_pcalloc(p, sizeof(char) * (buflen + 1)); + apr_sockaddr_t *recsa; + apr_status_t rv; + + CuAssertPtrNotNull(tc, sockarray[which]); + + apr_sockaddr_info_get(&recsa, "127.0.0.1", APR_UNSPEC, 7770, 0, p); + + rv = apr_socket_recvfrom(recsa, sockarray[which], 0, buffer, &buflen); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, strlen("hello"), buflen); + CuAssertStrEquals(tc, "hello", buffer); +} + + +static void create_all_sockets(CuTest *tc) +{ + int i; + + for (i = 0; i < LARGE_NUM_SOCKETS; i++){ + make_socket(&s[i], &sa[i], 7777 + i, p, tc); + } +} + +static void setup_small_poll(CuTest *tc) +{ + apr_status_t rv; + int i; + + rv = apr_poll_setup(&pollarray, SMALL_NUM_SOCKETS, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + for (i = 0; i < SMALL_NUM_SOCKETS;i++){ + CuAssertIntEquals(tc, 0, pollarray[i].reqevents); + CuAssertIntEquals(tc, 0, pollarray[i].rtnevents); + + rv = apr_poll_socket_add(pollarray, s[i], APR_POLLIN); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrEquals(tc, s[i], pollarray[i].desc.s); + } +} + +static void setup_large_poll(CuTest *tc) +{ + apr_status_t rv; + int i; + + rv = apr_poll_setup(&pollarray_large, LARGE_NUM_SOCKETS, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + for (i = 0; i < LARGE_NUM_SOCKETS;i++){ + CuAssertIntEquals(tc, 0, pollarray_large[i].reqevents); + CuAssertIntEquals(tc, 0, pollarray_large[i].rtnevents); + + rv = apr_poll_socket_add(pollarray_large, s[i], APR_POLLIN); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrEquals(tc, s[i], pollarray_large[i].desc.s); + } +} + +static void nomessage(CuTest *tc) +{ + apr_status_t rv; + int srv = SMALL_NUM_SOCKETS; + + rv = apr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_TIMEUP(rv)); + check_sockets(pollarray, s, 0, 0, tc); + check_sockets(pollarray, s, 1, 0, tc); + check_sockets(pollarray, s, 2, 0, tc); +} + +static void send_2(CuTest *tc) +{ + apr_status_t rv; + int srv = SMALL_NUM_SOCKETS; + + send_msg(s, sa, 2, tc); + + rv = apr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + check_sockets(pollarray, s, 0, 0, tc); + check_sockets(pollarray, s, 1, 0, tc); + check_sockets(pollarray, s, 2, 1, tc); +} + +static void recv_2_send_1(CuTest *tc) +{ + apr_status_t rv; + int srv = SMALL_NUM_SOCKETS; + + recv_msg(s, 2, p, tc); + send_msg(s, sa, 1, tc); + + rv = apr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + check_sockets(pollarray, s, 0, 0, tc); + check_sockets(pollarray, s, 1, 1, tc); + check_sockets(pollarray, s, 2, 0, tc); +} + +static void send_2_signaled_1(CuTest *tc) +{ + apr_status_t rv; + int srv = SMALL_NUM_SOCKETS; + + send_msg(s, sa, 2, tc); + + rv = apr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + check_sockets(pollarray, s, 0, 0, tc); + check_sockets(pollarray, s, 1, 1, tc); + check_sockets(pollarray, s, 2, 1, tc); +} + +static void recv_1_send_0(CuTest *tc) +{ + apr_status_t rv; + int srv = SMALL_NUM_SOCKETS; + + recv_msg(s, 1, p, tc); + send_msg(s, sa, 0, tc); + + rv = apr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + check_sockets(pollarray, s, 0, 1, tc); + check_sockets(pollarray, s, 1, 0, tc); + check_sockets(pollarray, s, 2, 1, tc); +} + +static void clear_all_signalled(CuTest *tc) +{ + apr_status_t rv; + int srv = SMALL_NUM_SOCKETS; + + recv_msg(s, 0, p, tc); + recv_msg(s, 2, p, tc); + + rv = apr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_TIMEUP(rv)); + check_sockets(pollarray, s, 0, 0, tc); + check_sockets(pollarray, s, 1, 0, tc); + check_sockets(pollarray, s, 2, 0, tc); +} + +static void send_large_pollarray(CuTest *tc) +{ + apr_status_t rv; + int lrv = LARGE_NUM_SOCKETS; + int i; + + send_msg(s, sa, LARGE_NUM_SOCKETS - 1, tc); + + rv = apr_poll(pollarray_large, LARGE_NUM_SOCKETS, &lrv, + 2 * APR_USEC_PER_SEC); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + for (i = 0; i < LARGE_NUM_SOCKETS; i++) { + if (i == (LARGE_NUM_SOCKETS - 1)) { + check_sockets(pollarray_large, s, i, 1, tc); + } + else { + check_sockets(pollarray_large, s, i, 0, tc); + } + } +} + +static void recv_large_pollarray(CuTest *tc) +{ + apr_status_t rv; + int lrv = LARGE_NUM_SOCKETS; + int i; + + recv_msg(s, LARGE_NUM_SOCKETS - 1, p, tc); + + rv = apr_poll(pollarray_large, LARGE_NUM_SOCKETS, &lrv, + 2 * APR_USEC_PER_SEC); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_TIMEUP(rv)); + + for (i = 0; i < LARGE_NUM_SOCKETS; i++) { + check_sockets(pollarray_large, s, i, 0, tc); + } +} + +static void setup_pollset(CuTest *tc) +{ + apr_status_t rv; + rv = apr_pollset_create(&pollset, LARGE_NUM_SOCKETS, p, 0); + CuAssertIntEquals(tc, APR_SUCCESS, rv); +} + +static void add_sockets_pollset(CuTest *tc) +{ + apr_status_t rv; + int i; + + for (i = 0; i < LARGE_NUM_SOCKETS;i++){ + apr_pollfd_t socket_pollfd; + + CuAssertPtrNotNull(tc, s[i]); + + socket_pollfd.desc_type = APR_POLL_SOCKET; + socket_pollfd.reqevents = APR_POLLIN; + socket_pollfd.desc.s = s[i]; + socket_pollfd.client_data = s[i]; + rv = apr_pollset_add(pollset, &socket_pollfd); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + } +} + +static void nomessage_pollset(CuTest *tc) +{ + apr_status_t rv; + int lrv; + const apr_pollfd_t *descs = NULL; + + rv = apr_pollset_poll(pollset, 0, &lrv, &descs); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_TIMEUP(rv)); + CuAssertIntEquals(tc, 0, lrv); + CuAssertPtrEquals(tc, NULL, descs); +} + +static void send0_pollset(CuTest *tc) +{ + apr_status_t rv; + const apr_pollfd_t *descs = NULL; + int num; + + send_msg(s, sa, 0, tc); + rv = apr_pollset_poll(pollset, 0, &num, &descs); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, 1, num); + CuAssertPtrNotNull(tc, descs); + + CuAssertPtrEquals(tc, s[0], descs[0].desc.s); + CuAssertPtrEquals(tc, s[0], descs[0].client_data); +} + +static void recv0_pollset(CuTest *tc) +{ + apr_status_t rv; + int lrv; + const apr_pollfd_t *descs = NULL; + + recv_msg(s, 0, p, tc); + rv = apr_pollset_poll(pollset, 0, &lrv, &descs); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_TIMEUP(rv)); + CuAssertIntEquals(tc, 0, lrv); + CuAssertPtrEquals(tc, NULL, descs); +} + +static void send_middle_pollset(CuTest *tc) +{ + apr_status_t rv; + const apr_pollfd_t *descs = NULL; + int num; + + send_msg(s, sa, 2, tc); + send_msg(s, sa, 5, tc); + rv = apr_pollset_poll(pollset, 0, &num, &descs); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, 2, num); + CuAssertPtrNotNull(tc, descs); + + CuAssert(tc, "Incorrect socket in result set", + ((descs[0].desc.s == s[2]) && (descs[1].desc.s == s[5])) || + ((descs[0].desc.s == s[5]) && (descs[1].desc.s == s[2]))); +} + +static void clear_middle_pollset(CuTest *tc) +{ + apr_status_t rv; + int lrv; + const apr_pollfd_t *descs = NULL; + + recv_msg(s, 2, p, tc); + recv_msg(s, 5, p, tc); + + rv = apr_pollset_poll(pollset, 0, &lrv, &descs); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_TIMEUP(rv)); + CuAssertIntEquals(tc, 0, lrv); + CuAssertPtrEquals(tc, NULL, descs); +} + +static void send_last_pollset(CuTest *tc) +{ + apr_status_t rv; + const apr_pollfd_t *descs = NULL; + int num; + + send_msg(s, sa, LARGE_NUM_SOCKETS - 1, tc); + rv = apr_pollset_poll(pollset, 0, &num, &descs); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, 1, num); + CuAssertPtrNotNull(tc, descs); + + CuAssertPtrEquals(tc, s[LARGE_NUM_SOCKETS - 1], descs[0].desc.s); + CuAssertPtrEquals(tc, s[LARGE_NUM_SOCKETS - 1], descs[0].client_data); +} + +static void clear_last_pollset(CuTest *tc) +{ + apr_status_t rv; + int lrv; + const apr_pollfd_t *descs = NULL; + + recv_msg(s, LARGE_NUM_SOCKETS - 1, p, tc); + + rv = apr_pollset_poll(pollset, 0, &lrv, &descs); + CuAssertIntEquals(tc, 1, APR_STATUS_IS_TIMEUP(rv)); + CuAssertIntEquals(tc, 0, lrv); + CuAssertPtrEquals(tc, NULL, descs); +} + +static void close_all_sockets(CuTest *tc) +{ + apr_status_t rv; + int i; + + for (i = 0; i < LARGE_NUM_SOCKETS; i++){ + rv = apr_socket_close(s[i]); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + } +} + +static void pollset_remove(CuTest *tc) +{ + apr_status_t rv; + apr_pollset_t *pollset; + const apr_pollfd_t *hot_files; + apr_pollfd_t pfd; + apr_int32_t num; + + rv = apr_pollset_create(&pollset, 5, p, 0); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + pfd.p = p; + pfd.desc_type = APR_POLL_SOCKET; + pfd.reqevents = APR_POLLOUT; + + pfd.desc.s = s[0]; + pfd.client_data = (void *)1; + rv = apr_pollset_add(pollset, &pfd); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + pfd.desc.s = s[1]; + pfd.client_data = (void *)2; + rv = apr_pollset_add(pollset, &pfd); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + pfd.desc.s = s[2]; + pfd.client_data = (void *)3; + rv = apr_pollset_add(pollset, &pfd); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + pfd.desc.s = s[1]; + pfd.client_data = (void *)4; + rv = apr_pollset_add(pollset, &pfd); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + pfd.desc.s = s[3]; + pfd.client_data = (void *)5; + rv = apr_pollset_add(pollset, &pfd); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_pollset_poll(pollset, 1000, &num, &hot_files); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, 5, num); + + /* now remove the pollset elements referring to desc s[1] */ + pfd.desc.s = s[1]; + pfd.client_data = (void *)999; /* not used on this call */ + rv = apr_pollset_remove(pollset, &pfd); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + /* this time only three should match */ + rv = apr_pollset_poll(pollset, 1000, &num, &hot_files); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, 3, num); + CuAssertPtrEquals(tc, (void *)1, hot_files[0].client_data); + CuAssertPtrEquals(tc, s[0], hot_files[0].desc.s); + CuAssertPtrEquals(tc, (void *)3, hot_files[1].client_data); + CuAssertPtrEquals(tc, s[2], hot_files[1].desc.s); + CuAssertPtrEquals(tc, (void *)5, hot_files[2].client_data); + CuAssertPtrEquals(tc, s[3], hot_files[2].desc.s); + + /* now remove the pollset elements referring to desc s[2] */ + pfd.desc.s = s[2]; + pfd.client_data = (void *)999; /* not used on this call */ + rv = apr_pollset_remove(pollset, &pfd); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + /* this time only two should match */ + rv = apr_pollset_poll(pollset, 1000, &num, &hot_files); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, 2, num); + CuAssertPtrEquals(tc, (void *)1, hot_files[0].client_data); + CuAssertPtrEquals(tc, s[0], hot_files[0].desc.s); + CuAssertPtrEquals(tc, (void *)5, hot_files[1].client_data); + CuAssertPtrEquals(tc, s[3], hot_files[1].desc.s); +} + +CuSuite *testpoll(void) +{ + CuSuite *suite = CuSuiteNew("Poll"); + + SUITE_ADD_TEST(suite, create_all_sockets); + SUITE_ADD_TEST(suite, setup_small_poll); + SUITE_ADD_TEST(suite, setup_large_poll); + SUITE_ADD_TEST(suite, nomessage); + SUITE_ADD_TEST(suite, send_2); + SUITE_ADD_TEST(suite, recv_2_send_1); + SUITE_ADD_TEST(suite, send_2_signaled_1); + SUITE_ADD_TEST(suite, recv_1_send_0); + SUITE_ADD_TEST(suite, clear_all_signalled); + SUITE_ADD_TEST(suite, send_large_pollarray); + SUITE_ADD_TEST(suite, recv_large_pollarray); + + SUITE_ADD_TEST(suite, setup_pollset); + SUITE_ADD_TEST(suite, add_sockets_pollset); + SUITE_ADD_TEST(suite, nomessage_pollset); + SUITE_ADD_TEST(suite, send0_pollset); + SUITE_ADD_TEST(suite, recv0_pollset); + SUITE_ADD_TEST(suite, send_middle_pollset); + SUITE_ADD_TEST(suite, clear_middle_pollset); + SUITE_ADD_TEST(suite, send_last_pollset); + SUITE_ADD_TEST(suite, clear_last_pollset); + + SUITE_ADD_TEST(suite, pollset_remove); + + SUITE_ADD_TEST(suite, close_all_sockets); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testpools.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testpools.c new file mode 100644 index 00000000..efabf0d0 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testpools.c @@ -0,0 +1,108 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "apr_general.h" +#include "apr_pools.h" +#include "apr_errno.h" +#include "apr_file_io.h" +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#if APR_HAVE_UNISTD_H +#include <unistd.h> +#endif +#include "test_apr.h" + +#define ALLOC_BYTES 1024 + +static apr_pool_t *pmain = NULL; +static apr_pool_t *pchild = NULL; + +static void alloc_bytes(CuTest *tc) +{ + int i; + char *alloc; + + alloc = apr_palloc(pmain, ALLOC_BYTES); + CuAssertPtrNotNull(tc, alloc); + + for (i=0;i<ALLOC_BYTES;i++) { + char *ptr = alloc + i; + *ptr = 0xa; + } + /* This is just added to get the positive. If this test fails, the + * suite will seg fault. + */ + CuAssertTrue(tc, 1); +} + +static void calloc_bytes(CuTest *tc) +{ + int i; + char *alloc; + + alloc = apr_pcalloc(pmain, ALLOC_BYTES); + CuAssertPtrNotNull(tc, alloc); + + for (i=0;i<ALLOC_BYTES;i++) { + char *ptr = alloc + i; + CuAssertTrue(tc, *ptr == '\0'); + } +} + +static void parent_pool(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_pool_create(&pmain, NULL); + CuAssertIntEquals(tc, rv, APR_SUCCESS); + CuAssertPtrNotNull(tc, pmain); +} + +static void child_pool(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_pool_create(&pchild, pmain); + CuAssertIntEquals(tc, rv, APR_SUCCESS); + CuAssertPtrNotNull(tc, pchild); +} + +static void test_ancestor(CuTest *tc) +{ + CuAssertIntEquals(tc, 1, apr_pool_is_ancestor(pmain, pchild)); +} + +static void test_notancestor(CuTest *tc) +{ + CuAssertIntEquals(tc, 0, apr_pool_is_ancestor(pchild, pmain)); +} + +CuSuite *testpool(void) +{ + CuSuite *suite = CuSuiteNew("Pools"); + + SUITE_ADD_TEST(suite, parent_pool); + SUITE_ADD_TEST(suite, child_pool); + SUITE_ADD_TEST(suite, test_ancestor); + SUITE_ADD_TEST(suite, test_notancestor); + SUITE_ADD_TEST(suite, alloc_bytes); + SUITE_ADD_TEST(suite, calloc_bytes); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testproc.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testproc.c new file mode 100644 index 00000000..85f28801 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testproc.c @@ -0,0 +1,178 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_thread_proc.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_lib.h" +#include "apr_strings.h" +#include "test_apr.h" + +/* XXX I'm sure there has to be a better way to do this ... */ +#ifdef WIN32 +#define EXTENSION ".exe" +#elif NETWARE +#define EXTENSION ".nlm" +#else +#define EXTENSION +#endif + +#define TESTSTR "This is a test" + +static apr_proc_t newproc; + +static void test_create_proc(CuTest *tc) +{ + const char *args[2]; + apr_procattr_t *attr; + apr_file_t *testfile = NULL; + apr_status_t rv; + apr_size_t length; + char *buf; + + 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); + + rv = apr_procattr_cmdtype_set(attr, APR_PROGRAM); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + args[0] = "proc_child" EXTENSION; + args[1] = NULL; + + rv = apr_proc_create(&newproc, "../proc_child" EXTENSION, args, NULL, + attr, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + testfile = newproc.in; + + length = strlen(TESTSTR); + rv = apr_file_write(testfile, TESTSTR, &length); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, strlen(TESTSTR), length); + + testfile = newproc.out; + length = 256; + 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; + + 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; + 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; + rv = apr_file_seek(testfile, APR_SET, &offset); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssert(tc, "File position mismatch, expected 0", offset == 0); + + 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); + + rv = apr_proc_wait(&newproc, NULL, NULL, APR_WAIT); + CuAssertIntEquals(tc, APR_CHILD_DONE, rv); + + offset = 0; + rv = apr_file_seek(testout, APR_SET, &offset); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + length = 256; + buf = apr_pcalloc(p, length); + rv = apr_file_read(testout, buf, &length); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, TESTSTR, buf); + + + apr_file_close(testfile); + apr_file_close(testout); + apr_file_close(testerr); + + 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"); + + SUITE_ADD_TEST(suite, test_create_proc); + SUITE_ADD_TEST(suite, test_proc_wait); + SUITE_ADD_TEST(suite, test_file_redir); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testprocmutex.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testprocmutex.c new file mode 100644 index 00000000..ef3a89ff --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testprocmutex.c @@ -0,0 +1,147 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_shm.h" +#include "apr_thread_proc.h" +#include "apr_file_io.h" +#include "apr_proc_mutex.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_getopt.h" +#include "errno.h" +#include <stdio.h> +#include <stdlib.h> +#include "test_apr.h" + +#if APR_HAS_FORK + +#define MAX_ITER 200 +#define CHILDREN 6 +#define MAX_COUNTER (MAX_ITER * CHILDREN) + +static apr_proc_mutex_t *proc_lock; +static volatile int *x; + +/* a slower more racy way to implement (*x)++ */ +static int increment(int n) +{ + apr_sleep(1); + return n+1; +} + +static void make_child(CuTest *tc, apr_proc_t **proc, apr_pool_t *p) +{ + apr_status_t rv; + + *proc = apr_pcalloc(p, sizeof(**proc)); + + /* slight delay to allow things to settle */ + apr_sleep (1); + + rv = apr_proc_fork(*proc, p); + if (rv == APR_INCHILD) { + int i = 0; + /* The parent process has setup all processes to call apr_terminate + * at exit. But, that means that all processes must also call + * apr_initialize at startup. You cannot have an unequal number + * of apr_terminate and apr_initialize calls. If you do, bad things + * will happen. In this case, the bad thing is that if the mutex + * is a semaphore, it will be destroyed before all of the processes + * die. That means that the test will most likely fail. + */ + apr_initialize(); + + if (apr_proc_mutex_child_init(&proc_lock, NULL, p)) + exit(1); + + do { + if (apr_proc_mutex_lock(proc_lock)) + exit(1); + i++; + *x = increment(*x); + if (apr_proc_mutex_unlock(proc_lock)) + exit(1); + } while (i < MAX_ITER); + exit(0); + } + + CuAssert(tc, "fork failed", rv == APR_INPARENT); +} + +/* Wait for a child process and check it terminated with success. */ +static void await_child(CuTest *tc, apr_proc_t *proc) +{ + int code; + apr_exit_why_e why; + apr_status_t rv; + + rv = apr_proc_wait(proc, &code, &why, APR_WAIT); + CuAssert(tc, "child did not terminate with success", + rv == APR_CHILD_DONE && why == APR_PROC_EXIT && code == 0); +} + +static void test_exclusive(CuTest *tc, const char *lockname) +{ + apr_proc_t *child[CHILDREN]; + apr_status_t rv; + int n; + + rv = apr_proc_mutex_create(&proc_lock, lockname, APR_LOCK_DEFAULT, p); + apr_assert_success(tc, "create the mutex", rv); + + for (n = 0; n < CHILDREN; n++) + make_child(tc, &child[n], p); + + for (n = 0; n < CHILDREN; n++) + await_child(tc, child[n]); + + CuAssert(tc, "Locks don't appear to work", *x == MAX_COUNTER); +} +#endif + +static void proc_mutex(CuTest *tc) +{ +#if APR_HAS_FORK + apr_status_t rv; + const char *shmname = "tpm.shm"; + apr_shm_t *shm; + + /* Use anonymous shm if available. */ + rv = apr_shm_create(&shm, sizeof(int), NULL, p); + if (rv == APR_ENOTIMPL) { + apr_file_remove(shmname, p); + rv = apr_shm_create(&shm, sizeof(int), shmname, p); + } + + apr_assert_success(tc, "create shm segment", rv); + + x = apr_shm_baseaddr_get(shm); + test_exclusive(tc, NULL); +#else + CuNotImpl(tc, "APR lacks fork() support"); +#endif +} + + +CuSuite *testprocmutex(void) +{ + CuSuite *suite = CuSuiteNew("Cross-Process Mutexes"); + + SUITE_ADD_TEST(suite, proc_mutex); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testrand.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testrand.c new file mode 100644 index 00000000..03090ca9 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testrand.c @@ -0,0 +1,46 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_general.h" +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include "test_apr.h" + +static void rand_exists(CuTest *tc) +{ +#if !APR_HAS_RANDOM + CuNotImpl(tc, "apr_generate_random_bytes"); +#else + unsigned char c[42]; + + /* There must be a better way to test random-ness, but I don't know + * what it is right now. + */ + apr_assert_success(tc, "apr_generate_random_bytes failed", + apr_generate_random_bytes(c, sizeof c)); +#endif +} + +CuSuite *testrand(void) +{ + CuSuite *suite = CuSuiteNew("Random"); + + SUITE_ADD_TEST(suite, rand_exists); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testshm.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testshm.c new file mode 100644 index 00000000..01357d5b --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testshm.c @@ -0,0 +1,293 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_shm.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_lib.h" +#include "apr_strings.h" +#include "apr_time.h" +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#if APR_HAVE_UNISTD_H +#include <unistd.h> +#endif + +#if APR_HAS_SHARED_MEMORY + +typedef struct mbox { + char msg[1024]; + int msgavail; +} mbox; +mbox *boxes; + +#define N_BOXES 10 +#define N_MESSAGES 100 +#define SHARED_SIZE (apr_size_t)(N_BOXES * sizeof(mbox)) +#define SHARED_FILENAME "/tmp/apr.testshm.shm" + +static void msgwait(int sleep_sec, int first_box, int last_box) +{ + int i; + apr_time_t start = apr_time_now(); + apr_interval_time_t sleep_duration = apr_time_from_sec(sleep_sec); + while (apr_time_now() - start < sleep_duration) { + for (i = first_box; i < last_box; i++) { + if (boxes[i].msgavail) { + fprintf(stdout, "received a message in box %d, message was: %s\n", + i, boxes[i].msg); + boxes[i].msgavail = 0; /* reset back to 0 */ + } + } + apr_sleep(apr_time_make(0, 10000)); /* 10ms */ + } + fprintf(stdout, "done waiting on mailboxes...\n"); +} + +static void msgput(int boxnum, char *msg) +{ + fprintf(stdout, "Sending message to box %d\n", boxnum); + apr_cpystrn(boxes[boxnum].msg, msg, strlen(msg)); + boxes[boxnum].msgavail = 1; +} + +static apr_status_t test_anon(apr_pool_t *parpool) +{ + apr_status_t rv; + apr_pool_t *pool; + apr_shm_t *shm; + apr_size_t retsize; + pid_t pid; + int cnt, i, exit_int; + + rv = apr_pool_create(&pool, parpool); + if (rv != APR_SUCCESS) { + fprintf(stderr, "Error creating child pool\n"); + return rv; + } + + printf("Creating anonymous shared memory block (%" + APR_SIZE_T_FMT " bytes)........", SHARED_SIZE); + rv = apr_shm_create(&shm, SHARED_SIZE, NULL, pool); + if (rv != APR_SUCCESS) { + fprintf(stderr, "Error allocating shared memory block\n"); + return rv; + } + fprintf(stdout, "OK\n"); + + printf("Checking size...%" APR_SIZE_T_FMT " bytes...", + retsize = apr_shm_size_get(shm)); + if (retsize != SHARED_SIZE) { + fprintf(stderr, "Error allocating shared memory block\n"); + return rv; + } + fprintf(stdout, "OK\n"); + + printf("Allocating shared mbox memory for %d boxes ..............", + N_BOXES); + boxes = apr_shm_baseaddr_get(shm); + if (boxes == NULL) { + fprintf(stderr, "Error creating message boxes.\n"); + return rv; + } + fprintf(stdout, "OK\n"); + + printf("Shared Process Test (child/parent)\n"); + pid = fork(); + if (pid == 0) { /* child */ + msgwait(5, 0, N_BOXES); + exit(0); + } + else if (pid > 0) { /* parent */ + i = N_BOXES; + cnt = N_MESSAGES; + while (--cnt > 0) { + if ((i-=3) < 0) { + i += N_BOXES; /* start over at the top */ + } + msgput(i, "Sending a message\n"); + apr_sleep(apr_time_make(0, 10000)); + } + } + else { + printf("Error creating a child process\n"); + return errno; + } + /* wait for the child */ + printf("Waiting for child to exit.\n"); + if (waitpid(pid, &exit_int, 0) < 0) { + return errno; + } + + printf("Destroying shared memory segment..."); + rv = apr_shm_destroy(shm); + if (rv != APR_SUCCESS) { + printf("FAILED\n"); + return rv; + } + printf("OK\n"); + + apr_pool_destroy(pool); + + return APR_SUCCESS; +} + +static apr_status_t test_named(apr_pool_t *parpool) +{ + apr_status_t rv; + apr_pool_t *pool; + apr_shm_t *shm; + apr_size_t retsize; + pid_t pidproducer, pidconsumer; + int exit_int; + + rv = apr_pool_create(&pool, parpool); + if (rv != APR_SUCCESS) { + fprintf(stderr, "Error creating child pool\n"); + return rv; + } + + printf("Creating named shared memory block (%" + APR_SIZE_T_FMT " bytes)........", SHARED_SIZE); + rv = apr_shm_create(&shm, SHARED_SIZE, SHARED_FILENAME, pool); + if (rv != APR_SUCCESS) { + fprintf(stderr, "Error allocating shared memory block\n"); + return rv; + } + fprintf(stdout, "OK\n"); + + printf("Checking size...%" APR_SIZE_T_FMT " bytes...", + retsize = apr_shm_size_get(shm)); + if (retsize != SHARED_SIZE) { + fprintf(stderr, "Error allocating shared memory block\n"); + return rv; + } + fprintf(stdout, "OK\n"); + + printf("Allocating shared mbox memory for %d boxes ..............", + N_BOXES); + boxes = apr_shm_baseaddr_get(shm); + if (boxes == NULL) { + fprintf(stderr, "Error creating message boxes.\n"); + return rv; + } + fprintf(stdout, "OK\n"); + + printf("fork()ing and exec()ing children:\n"); + pidproducer = fork(); + if (pidproducer == 0) { /* child */ + /* FIXME: exec a producer */ + printf("starting consumer.....\n"); + if (execlp("testshmconsumer", "testshmconsumer", (char*)0) < 0) { + return errno; + } + } + else if (pidproducer > 0) { /* parent */ + /* fork another child */ + pidconsumer = fork(); + if (pidconsumer == 0) { /* child */ + /* FIXME: exec a producer */ + printf("starting producer.....\n"); + if (execlp("testshmproducer", "testshmproducer", (char*)0) < 0) { + return errno; + } + } + else if (pidconsumer < 0) { /* parent */ + printf("Error creating a child process\n"); + return errno; + } + } + else { + printf("Error creating a child process\n"); + return errno; + } + /* wait for the child */ + printf("Waiting for producer to exit.\n"); + if (waitpid(pidconsumer, &exit_int, 0) < 0) { + return errno; + } + if (!WIFEXITED(exit_int)) { + printf("Producer was unsuccessful.\n"); + return APR_EGENERAL; + } + printf("Waiting for consumer to exit.\n"); + if (waitpid(pidproducer, &exit_int, 0) < 0) { + return errno; + } + if (!WIFEXITED(exit_int)) { + printf("Consumer was unsuccessful.\n"); + return APR_EGENERAL; + } + + printf("Destroying shared memory segment..."); + rv = apr_shm_destroy(shm); + if (rv != APR_SUCCESS) { + printf("FAILED\n"); + return rv; + } + printf("OK\n"); + + apr_pool_destroy(pool); + + return APR_SUCCESS; +} + +int main(void) +{ + apr_status_t rv; + apr_pool_t *pool; + char errmsg[200]; + + apr_initialize(); + + printf("APR Shared Memory Test\n"); + printf("======================\n\n"); + + printf("Initializing the pool............................"); + if (apr_pool_create(&pool, NULL) != APR_SUCCESS) { + printf("could not initialize pool\n"); + exit(-1); + } + printf("OK\n"); + + rv = test_anon(pool); + if (rv != APR_SUCCESS) { + if (rv == APR_ENOTIMPL) { + printf("Anonymous shared memory unavailable on this platform.\n"); + } + else { + printf("Anonymous shared memory test FAILED: [%d] %s\n", + rv, apr_strerror(rv, errmsg, sizeof(errmsg))); + exit(-2); + } + } + printf("Anonymous shared memory test passed!\n"); + + if ((rv = test_named(pool)) != APR_SUCCESS) { + printf("Name-based shared memory test FAILED: [%d] %s \n", + rv, apr_strerror(rv, errmsg, sizeof(errmsg))); + exit(-3); + } + printf("Named shared memory test passed!\n"); + + return 0; +} + +#else /* APR_HAS_SHARED_MEMORY */ +#error shmem is not supported on this platform +#endif /* APR_HAS_SHARED_MEMORY */ + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testshmconsumer.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testshmconsumer.c new file mode 100644 index 00000000..4064cd7d --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testshmconsumer.c @@ -0,0 +1,116 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_shm.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_lib.h" +#include "apr_strings.h" +#include "apr_time.h" +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#if APR_HAVE_UNISTD_H +#include <unistd.h> +#endif + +#if APR_HAS_SHARED_MEMORY + +typedef struct mbox { + char msg[1024]; + int msgavail; +} mbox; +mbox *boxes; + +#define N_BOXES 10 +#define SHARED_SIZE (apr_size_t)(N_BOXES * sizeof(mbox)) +#define SHARED_FILENAME "/tmp/apr.testshm.shm" + +static void msgwait(int sleep_sec, int first_box, int last_box) +{ + int i; + apr_time_t start = apr_time_now(); + apr_interval_time_t sleep_duration = apr_time_from_sec(sleep_sec); + while (apr_time_now() - start < sleep_duration) { + for (i = first_box; i < last_box; i++) { + if (boxes[i].msgavail) { + fprintf(stdout, "Consumer: received a message in box %d, message was: %s\n", + i, boxes[i].msg); + boxes[i].msgavail = 0; /* reset back to 0 */ + } + } + apr_sleep(apr_time_from_sec(1)); + } + fprintf(stdout, "Consumer: done waiting on mailboxes...\n"); +} + +int main(void) +{ + apr_status_t rv; + apr_pool_t *pool; + apr_shm_t *shm; + char errmsg[200]; + + apr_initialize(); + + printf("APR Shared Memory Test: CONSUMER\n"); + + printf("Initializing the pool............................"); + if (apr_pool_create(&pool, NULL) != APR_SUCCESS) { + printf("could not initialize pool\n"); + exit(-1); + } + printf("OK\n"); + + printf("Consumer attaching to name-based shared memory...."); + rv = apr_shm_attach(&shm, SHARED_FILENAME, pool); + if (rv != APR_SUCCESS) { + printf("Consumer unable to attach to name-based shared memory " + "segment: [%d] %s \n", rv, + apr_strerror(rv, errmsg, sizeof(errmsg))); + exit(-2); + } + printf("OK\n"); + + boxes = apr_shm_baseaddr_get(shm); + + /* consume messages on all of the boxes */ + msgwait(30, 0, N_BOXES); /* wait for 30 seconds for messages */ + + printf("Consumer detaching from name-based shared memory...."); + rv = apr_shm_detach(shm); + if (rv != APR_SUCCESS) { + printf("Consumer unable to detach from name-based shared memory " + "segment: [%d] %s \n", rv, + apr_strerror(rv, errmsg, sizeof(errmsg))); + exit(-3); + } + printf("OK\n"); + + return 0; +} + +#else /* APR_HAS_SHARED_MEMORY */ + +int main(void) +{ + printf("APR SHMEM test not run!\n"); + printf("shmem is not supported on this platform\n"); + return -1; +} + +#endif /* APR_HAS_SHARED_MEMORY */ + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testshmproducer.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testshmproducer.c new file mode 100644 index 00000000..3589a439 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testshmproducer.c @@ -0,0 +1,109 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_shm.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_lib.h" +#include "apr_strings.h" +#include "apr_time.h" +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#if APR_HAVE_UNISTD_H +#include <unistd.h> +#endif + +#if APR_HAS_SHARED_MEMORY + +typedef struct mbox { + char msg[1024]; + int msgavail; +} mbox; +mbox *boxes; + +#define N_BOXES 10 +#define SHARED_SIZE (apr_size_t)(N_BOXES * sizeof(mbox)) +#define SHARED_FILENAME "/tmp/apr.testshm.shm" + +static void msgput(int boxnum, char *msg) +{ + fprintf(stdout, "Producer: Sending message to box %d\n", boxnum); + apr_cpystrn(boxes[boxnum].msg, msg, strlen(msg)); + boxes[boxnum].msgavail = 1; +} + +int main(void) +{ + apr_status_t rv; + apr_pool_t *pool; + apr_shm_t *shm; + int i; + char errmsg[200]; + + apr_initialize(); + + printf("APR Shared Memory Test: PRODUCER\n"); + + printf("Initializing the pool............................"); + if (apr_pool_create(&pool, NULL) != APR_SUCCESS) { + printf("could not initialize pool\n"); + exit(-1); + } + printf("OK\n"); + + printf("Producer attaching to name-based shared memory...."); + rv = apr_shm_attach(&shm, SHARED_FILENAME, pool); + if (rv != APR_SUCCESS) { + printf("Producer unable to attach to name-based shared memory " + "segment: [%d] %s \n", rv, + apr_strerror(rv, errmsg, sizeof(errmsg))); + exit(-2); + } + printf("OK\n"); + + boxes = apr_shm_baseaddr_get(shm); + + /* produce messages on all of the boxes, in descending order */ + for (i = N_BOXES - 1; i > 0; i--) { + msgput(i, "Sending a message\n"); + apr_sleep(apr_time_from_sec(1)); + } + + printf("Producer detaching from name-based shared memory...."); + rv = apr_shm_detach(shm); + if (rv != APR_SUCCESS) { + printf("Producer unable to detach from name-based shared memory " + "segment: [%d] %s \n", rv, + apr_strerror(rv, errmsg, sizeof(errmsg))); + exit(-3); + } + printf("OK\n"); + + return 0; +} + +#else /* APR_HAS_SHARED_MEMORY */ + +int main(void) +{ + printf("APR SHMEM test not run!\n"); + printf("shmem is not supported on this platform\n"); + return -1; +} + +#endif /* APR_HAS_SHARED_MEMORY */ + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testsleep.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testsleep.c new file mode 100644 index 00000000..8b2451f9 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testsleep.c @@ -0,0 +1,54 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "time.h" +#include "apr_thread_proc.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_lib.h" +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include "test_apr.h" + +#define SLEEP_INTERVAL 5 + +static void sleep_one(CuTest *tc) +{ + time_t pretime = time(NULL); + time_t posttime; + time_t timediff; + + apr_sleep(apr_time_from_sec(SLEEP_INTERVAL)); + posttime = time(NULL); + + /* normalize the timediff. We should have slept for SLEEP_INTERVAL, so + * we should just subtract that out. + */ + timediff = posttime - pretime - SLEEP_INTERVAL; + CuAssertTrue(tc, timediff >= 0); + CuAssertTrue(tc, timediff <= 1); +} + +CuSuite *testsleep(void) +{ + CuSuite *suite = CuSuiteNew("Sleep"); + + SUITE_ADD_TEST(suite, sleep_one); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testsock.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testsock.c new file mode 100644 index 00000000..79477b8a --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testsock.c @@ -0,0 +1,175 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <signal.h> +#include "apr_thread_proc.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_lib.h" +#include "apr_strings.h" + +#define STRLEN 15 + +static int run_basic_test(apr_pool_t *context) +{ + apr_procattr_t *attr1 = NULL; + apr_procattr_t *attr2 = NULL; + apr_proc_t proc1; + apr_proc_t proc2; + apr_status_t s1; + apr_status_t s2; + const char *args[2]; + + fprintf(stdout, "Creating children to run network tests.......\n"); + s1 = apr_procattr_create(&attr1, context); + s2 = apr_procattr_create(&attr2, context); + + if (s1 != APR_SUCCESS || s2 != APR_SUCCESS) { + fprintf(stderr, "Problem creating proc attrs\n"); + exit(-1); + } + + args[0] = apr_pstrdup(context, "server"); + args[1] = NULL; + s1 = apr_proc_create(&proc1, "./server", args, NULL, attr1, context); + + /* Sleep for 5 seconds to ensure the server is setup before we begin */ + apr_sleep(5000000); + args[0] = apr_pstrdup(context, "client"); + s2 = apr_proc_create(&proc2, "./client", args, NULL, attr2, context); + + if (s1 != APR_SUCCESS || s2 != APR_SUCCESS) { + fprintf(stderr, "Problem spawning new process\n"); + exit(-1); + } + + while ((s1 = apr_proc_wait(&proc1, NULL, NULL, APR_NOWAIT)) == APR_CHILD_NOTDONE && + (s2 = apr_proc_wait(&proc2, NULL, NULL, APR_NOWAIT)) == APR_CHILD_NOTDONE) { + continue; + } + + if (s1 == APR_SUCCESS) { + apr_proc_kill(&proc2, SIGTERM); + while (apr_proc_wait(&proc2, NULL, NULL, APR_WAIT) == APR_CHILD_NOTDONE); + } + else { + apr_proc_kill(&proc1, SIGTERM); + while (apr_proc_wait(&proc1, NULL, NULL, APR_WAIT) == APR_CHILD_NOTDONE); + } + fprintf(stdout, "Network test completed.\n"); + + return 1; +} + +static int run_sendfile(apr_pool_t *context, int number) +{ + apr_procattr_t *attr1 = NULL; + apr_procattr_t *attr2 = NULL; + apr_proc_t proc1; + apr_proc_t proc2; + apr_status_t s1; + apr_status_t s2; + const char *args[4]; + + fprintf(stdout, "Creating children to run network tests.......\n"); + s1 = apr_procattr_create(&attr1, context); + s2 = apr_procattr_create(&attr2, context); + + if (s1 != APR_SUCCESS || s2 != APR_SUCCESS) { + fprintf(stderr, "Problem creating proc attrs\n"); + exit(-1); + } + + args[0] = apr_pstrdup(context, "sendfile"); + args[1] = apr_pstrdup(context, "server"); + args[2] = NULL; + s1 = apr_proc_create(&proc1, "./sendfile", args, NULL, attr1, context); + + /* Sleep for 5 seconds to ensure the server is setup before we begin */ + apr_sleep(5000000); + args[1] = apr_pstrdup(context, "client"); + switch (number) { + case 0: { + args[2] = apr_pstrdup(context, "blocking"); + break; + } + case 1: { + args[2] = apr_pstrdup(context, "nonblocking"); + break; + } + case 2: { + args[2] = apr_pstrdup(context, "timeout"); + break; + } + } + args[3] = NULL; + s2 = apr_proc_create(&proc2, "./sendfile", args, NULL, attr2, context); + + if (s1 != APR_SUCCESS || s2 != APR_SUCCESS) { + fprintf(stderr, "Problem spawning new process\n"); + exit(-1); + } + + while ((s1 = apr_proc_wait(&proc1, NULL, NULL, APR_NOWAIT)) == APR_CHILD_NOTDONE && + (s2 = apr_proc_wait(&proc2, NULL, NULL, APR_NOWAIT)) == APR_CHILD_NOTDONE) { + continue; + } + + if (s1 == APR_SUCCESS) { + apr_proc_kill(&proc2, SIGTERM); + while (apr_proc_wait(&proc2, NULL, NULL, APR_WAIT) == APR_CHILD_NOTDONE); + } + else { + apr_proc_kill(&proc1, SIGTERM); + while (apr_proc_wait(&proc1, NULL, NULL, APR_WAIT) == APR_CHILD_NOTDONE); + } + fprintf(stdout, "Network test completed.\n"); + + return 1; +} + +int main(int argc, char *argv[]) +{ + apr_pool_t *context = NULL; + + fprintf(stdout, "Initializing........."); + if (apr_initialize() != APR_SUCCESS) { + fprintf(stderr, "Something went wrong\n"); + exit(-1); + } + fprintf(stdout, "OK\n"); + atexit(apr_terminate); + + fprintf(stdout, "Creating context......."); + if (apr_pool_create(&context, NULL) != APR_SUCCESS) { + fprintf(stderr, "Could not create context\n"); + exit(-1); + } + fprintf(stdout, "OK\n"); + + fprintf(stdout, "This test relies on the process test working. Please\n"); + fprintf(stdout, "run that test first, and only run this test when it\n"); + fprintf(stdout, "completes successfully. Alternatively, you could run\n"); + fprintf(stdout, "server and client by yourself.\n"); + run_basic_test(context); + run_sendfile(context, 0); + run_sendfile(context, 1); + run_sendfile(context, 2); + + return 0; +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testsockets.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testsockets.c new file mode 100644 index 00000000..a03327a8 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testsockets.c @@ -0,0 +1,174 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_network_io.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_lib.h" +#include "test_apr.h" + +#if APR_HAVE_IPV6 +#define US "::1" +#define FAMILY APR_INET6 +#else +#define US "127.0.0.1" +#define FAMILY APR_INET +#endif + +#define STRLEN 21 + +static void tcp_socket(CuTest *tc) +{ + apr_status_t rv; + apr_socket_t *sock = NULL; + + rv = apr_socket_create(&sock, APR_INET, SOCK_STREAM, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, sock); + apr_socket_close(sock); +} + +static void udp_socket(CuTest *tc) +{ + apr_status_t rv; + apr_socket_t *sock = NULL; + + rv = apr_socket_create(&sock, APR_INET, SOCK_DGRAM, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, sock); + apr_socket_close(sock); +} + +static void tcp6_socket(CuTest *tc) +{ +#if APR_HAVE_IPV6 + apr_status_t rv; + apr_socket_t *sock = NULL; + + rv = apr_socket_create(&sock, APR_INET6, SOCK_STREAM, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, sock); + apr_socket_close(sock); +#else + CuNotImpl(tc, "IPv6"); +#endif +} + +static void udp6_socket(CuTest *tc) +{ +#if APR_HAVE_IPV6 + apr_status_t rv; + apr_socket_t *sock = NULL; + + rv = apr_socket_create(&sock, APR_INET6, SOCK_DGRAM, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, sock); + apr_socket_close(sock); +#else + CuNotImpl(tc, "IPv6"); +#endif +} + +static void sendto_receivefrom(CuTest *tc) +{ + apr_status_t rv; + apr_socket_t *sock = NULL; + apr_socket_t *sock2 = NULL; + char sendbuf[STRLEN] = "APR_INET, SOCK_DGRAM"; + char recvbuf[80]; + char *ip_addr; + apr_port_t fromport; + apr_sockaddr_t *from; + apr_sockaddr_t *to; + apr_size_t len = 30; + + rv = apr_socket_create(&sock, FAMILY, SOCK_DGRAM, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_socket_create(&sock2, FAMILY, SOCK_DGRAM, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_sockaddr_info_get(&to, US, APR_UNSPEC, 7772, 0, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_sockaddr_info_get(&from, US, APR_UNSPEC, 7771, 0, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_socket_bind(sock, to); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_socket_bind(sock2, from); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + len = STRLEN; + rv = apr_socket_sendto(sock2, to, 0, sendbuf, &len); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, STRLEN, len); + + len = 80; + rv = apr_socket_recvfrom(from, sock, 0, recvbuf, &len); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, STRLEN, len); + CuAssertStrEquals(tc, "APR_INET, SOCK_DGRAM", recvbuf); + + apr_sockaddr_ip_get(&ip_addr, from); + apr_sockaddr_port_get(&fromport, from); + CuAssertStrEquals(tc, US, ip_addr); + CuAssertIntEquals(tc, 7771, fromport); + + apr_socket_close(sock); + apr_socket_close(sock2); +} + +static void socket_userdata(CuTest *tc) +{ + apr_socket_t *sock1, *sock2; + apr_status_t rv; + char *data; + const char *key = "GENERICKEY"; + + rv = apr_socket_create(&sock1, AF_INET, SOCK_STREAM, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_socket_create(&sock2, AF_INET, SOCK_STREAM, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_socket_data_set(sock1, "SOCK1", key, NULL); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_socket_data_set(sock2, "SOCK2", key, NULL); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_socket_data_get((void **)&data, key, sock1); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, "SOCK1", data); + rv = apr_socket_data_get((void **)&data, key, sock2); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertStrEquals(tc, "SOCK2", data); +} + +CuSuite *testsockets(void) +{ + CuSuite *suite = CuSuiteNew("Socket Creation"); + + SUITE_ADD_TEST(suite, tcp_socket); + SUITE_ADD_TEST(suite, udp_socket); + + SUITE_ADD_TEST(suite, tcp6_socket); + SUITE_ADD_TEST(suite, udp6_socket); + + SUITE_ADD_TEST(suite, sendto_receivefrom); + + SUITE_ADD_TEST(suite, socket_userdata); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testsockopt.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testsockopt.c new file mode 100644 index 00000000..40cce1f6 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testsockopt.c @@ -0,0 +1,137 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_network_io.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_lib.h" +#include "test_apr.h" + +static apr_socket_t *sock = NULL; + +static void create_socket(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_socket_create(&sock, APR_INET, SOCK_STREAM, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, sock); +} + +static void set_keepalive(CuTest *tc) +{ + apr_status_t rv; + apr_int32_t ck; + + rv = apr_socket_opt_set(sock, APR_SO_KEEPALIVE, 1); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_socket_opt_get(sock, APR_SO_KEEPALIVE, &ck); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, 1, ck); +} + +static void set_debug(CuTest *tc) +{ + apr_status_t rv1, rv2; + apr_int32_t ck; + + /* On some platforms APR_SO_DEBUG can only be set as root; just test + * for get/set consistency of this option. */ + rv1 = apr_socket_opt_set(sock, APR_SO_DEBUG, 1); + rv2 = apr_socket_opt_get(sock, APR_SO_DEBUG, &ck); + apr_assert_success(tc, "get SO_DEBUG option", rv2); + if (APR_STATUS_IS_SUCCESS(rv1)) { + CuAssertIntEquals(tc, 1, ck); + } else { + CuAssertIntEquals(tc, 0, ck); + } +} + +static void remove_keepalive(CuTest *tc) +{ + apr_status_t rv; + apr_int32_t ck; + + rv = apr_socket_opt_get(sock, APR_SO_KEEPALIVE, &ck); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, 1, ck); + + rv = apr_socket_opt_set(sock, APR_SO_KEEPALIVE, 0); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_socket_opt_get(sock, APR_SO_KEEPALIVE, &ck); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, 0, ck); +} + +static void corkable(CuTest *tc) +{ +#if !APR_HAVE_CORKABLE_TCP + CuNotImpl(tc, "TCP isn't corkable"); +#else + apr_status_t rv; + apr_int32_t ck; + + rv = apr_socket_opt_set(sock, APR_TCP_NODELAY, 1); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, 1, ck); + + rv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 1); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_socket_opt_get(sock, APR_TCP_NOPUSH, &ck); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, 1, ck); + + rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, 0, ck); + + rv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, 1, ck); +#endif +} + +static void close_socket(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_socket_close(sock); + CuAssertIntEquals(tc, APR_SUCCESS, rv); +} + +CuSuite *testsockopt(void) +{ + CuSuite *suite = CuSuiteNew("Socket Options"); + + SUITE_ADD_TEST(suite, create_socket); + SUITE_ADD_TEST(suite, set_keepalive); + SUITE_ADD_TEST(suite, set_debug); + SUITE_ADD_TEST(suite, remove_keepalive); + SUITE_ADD_TEST(suite, corkable); + SUITE_ADD_TEST(suite, close_socket); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/teststr.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/teststr.c new file mode 100644 index 00000000..b23251d1 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/teststr.c @@ -0,0 +1,307 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test_apr.h" + +#include <assert.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "apr_general.h" +#include "apr_strings.h" +#include "apr_errno.h" + +/* I haven't bothered to check for APR_ENOTIMPL here, AFAIK, all string + * functions exist on all platforms. + */ + +static void test_strtok(CuTest *tc) +{ + struct { + char *input; + char *sep; + } + cases[] = { + { + "", + "Z" + }, + { + " asdf jkl; 77889909 \r\n\1\2\3Z", + " \r\n\3\2\1" + }, + { + NULL, /* but who cares if apr_strtok() segfaults? */ + " \t" + }, +#if 0 /* don't do this... you deserve to segfault */ + { + "a b c ", + NULL + }, +#endif + { + " a b c ", + "" + }, + { + "a b c ", + " " + } + }; + int curtc; + + for (curtc = 0; curtc < sizeof cases / sizeof cases[0]; curtc++) { + char *retval1, *retval2; + char *str1, *str2; + char *state; + + str1 = apr_pstrdup(p, cases[curtc].input); + str2 = apr_pstrdup(p, cases[curtc].input); + + do { + retval1 = apr_strtok(str1, cases[curtc].sep, &state); + retval2 = strtok(str2, cases[curtc].sep); + + if (!retval1) { + CuAssertTrue(tc, retval2 == NULL); + } + else { + CuAssertTrue(tc, retval2 != NULL); + CuAssertStrEquals(tc, retval2, retval1); + } + + str1 = str2 = NULL; /* make sure we pass NULL on subsequent calls */ + } while (retval1); + } +} + +static void snprintf_noNULL(CuTest *tc) +{ + char buff[100]; + char *testing = apr_palloc(p, 10); + + testing[0] = 't'; + testing[1] = 'e'; + testing[2] = 's'; + testing[3] = 't'; + testing[4] = 'i'; + testing[5] = 'n'; + testing[6] = 'g'; + + /* If this test fails, we are going to seg fault. */ + apr_snprintf(buff, sizeof(buff), "%.*s", 7, testing); + CuAssertStrNEquals(tc, buff, testing, 7); +} + +static void snprintf_0NULL(CuTest *tc) +{ + int rv; + + rv = apr_snprintf(NULL, 0, "%sBAR", "FOO"); + CuAssertIntEquals(tc, 6, rv); +} + +static void snprintf_0nonNULL(CuTest *tc) +{ + int rv; + char *buff = "testing"; + + rv = apr_snprintf(buff, 0, "%sBAR", "FOO"); + CuAssertIntEquals(tc, 6, rv); + CuAssert(tc, "buff unmangled", strcmp(buff, "FOOBAR") != 0); +} + +static void snprintf_int64(CuTest *tc) +{ + char buf[100]; + apr_int64_t i = APR_INT64_C(-42); + apr_uint64_t ui = APR_INT64_C(42); /* no APR_UINT64_C */ + apr_uint64_t big = APR_INT64_C(3141592653589793238); + + apr_snprintf(buf, sizeof buf, "%" APR_INT64_T_FMT, i); + CuAssertStrEquals(tc, buf, "-42"); + + apr_snprintf(buf, sizeof buf, "%" APR_UINT64_T_FMT, ui); + CuAssertStrEquals(tc, buf, "42"); + + apr_snprintf(buf, sizeof buf, "%" APR_UINT64_T_FMT, big); + CuAssertStrEquals(tc, buf, "3141592653589793238"); +} + +static void snprintf_underflow(CuTest *tc) +{ + char buf[20]; + int rv; + + rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.0001); + CuAssertIntEquals(tc, 4, rv); + CuAssertStrEquals(tc, "0.00", buf); + + rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.001); + CuAssertIntEquals(tc, 4, rv); + CuAssertStrEquals(tc, "0.00", buf); + + rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.01); + CuAssertIntEquals(tc, 4, rv); + CuAssertStrEquals(tc, "0.01", buf); +} + +static void string_error(CuTest *tc) +{ + char buf[128], *rv; + apr_status_t n; + + buf[0] = '\0'; + rv = apr_strerror(APR_ENOENT, buf, sizeof buf); + CuAssertPtrEquals(tc, buf, rv); + CuAssertTrue(tc, strlen(buf) > 0); + + rv = apr_strerror(APR_TIMEUP, buf, sizeof buf); + CuAssertPtrEquals(tc, buf, rv); + CuAssertStrEquals(tc, "The timeout specified has expired", buf); + + /* throw some randomish numbers at it to check for robustness */ + for (n = 1; n < 1000000; n *= 2) { + apr_strerror(n, buf, sizeof buf); + } +} + +#define SIZE 180000 +static void string_long(CuTest *tc) +{ + char s[SIZE + 1]; + + memset(s, 'A', SIZE); + s[SIZE] = '\0'; + + apr_psprintf(p, "%s", s); +} + +/* ### FIXME: apr.h/apr_strings.h should provide these! */ +#define MY_LLONG_MAX (APR_INT64_C(9223372036854775807)) +#define MY_LLONG_MIN (-MY_LLONG_MAX - APR_INT64_C(1)) + +static void string_strtoi64(CuTest *tc) +{ + static const struct { + int errnum, base; + const char *in, *end; + apr_int64_t result; + } ts[] = { + + /* base 10 tests */ + { 0, 10, "123545", NULL, APR_INT64_C(123545) }, + { 0, 10, " 123545", NULL, APR_INT64_C(123545) }, + { 0, 10, " +123545", NULL, APR_INT64_C(123545) }, + { 0, 10, "-123545", NULL, APR_INT64_C(-123545) }, + { 0, 10, " 00000123545", NULL, APR_INT64_C(123545) }, + { 0, 10, "123545ZZZ", "ZZZ", APR_INT64_C(123545) }, + { 0, 10, " 123545 ", " ", APR_INT64_C(123545) }, + + /* base 16 tests */ + { 0, 16, "1E299", NULL, APR_INT64_C(123545) }, + { 0, 16, "1e299", NULL, APR_INT64_C(123545) }, + { 0, 16, "0x1e299", NULL, APR_INT64_C(123545) }, + { 0, 16, "0X1E299", NULL, APR_INT64_C(123545) }, + { 0, 16, "+1e299", NULL, APR_INT64_C(123545) }, + { 0, 16, "-1e299", NULL, APR_INT64_C(-123545) }, + { 0, 16, " -1e299", NULL, APR_INT64_C(-123545) }, + + /* automatic base detection tests */ + { 0, 0, "123545", NULL, APR_INT64_C(123545) }, + { 0, 0, "0x1e299", NULL, APR_INT64_C(123545) }, + { 0, 0, " 0x1e299", NULL, APR_INT64_C(123545) }, + { 0, 0, "+0x1e299", NULL, APR_INT64_C(123545) }, + { 0, 0, "-0x1e299", NULL, APR_INT64_C(-123545) }, + + /* large number tests */ + { 0, 10, "8589934605", NULL, APR_INT64_C(8589934605) }, + { 0, 10, "-8589934605", NULL, APR_INT64_C(-8589934605) }, + { 0, 16, "0x20000000D", NULL, APR_INT64_C(8589934605) }, + { 0, 16, "-0x20000000D", NULL, APR_INT64_C(-8589934605) }, + { 0, 16, " 0x20000000D", NULL, APR_INT64_C(8589934605) }, + { 0, 16, " 0x20000000D", NULL, APR_INT64_C(8589934605) }, + + /* error cases */ + { ERANGE, 10, "999999999999999999999999999999999", "", MY_LLONG_MAX }, + { ERANGE, 10, "-999999999999999999999999999999999", "", MY_LLONG_MIN }, + +#if 0 + /* C99 doesn't require EINVAL for an invalid range. */ + { EINVAL, 99, "", (void *)-1 /* don't care */, 0 }, +#endif + + /* some strtoll implementations give EINVAL when no conversion + * is performed. */ + { -1 /* don't care */, 10, "zzz", "zzz", APR_INT64_C(0) }, + { -1 /* don't care */, 10, "", NULL, APR_INT64_C(0) } + + }; + int n; + + for (n = 0; n < sizeof(ts)/sizeof(ts[0]); n++) { + char *end = "end ptr not changed"; + apr_int64_t result; + int errnum; + + errno = 0; + result = apr_strtoi64(ts[n].in, &end, ts[n].base); + errnum = errno; + + CuAssert(tc, + apr_psprintf(p, "for '%s': result was %" APR_INT64_T_FMT + " not %" APR_INT64_T_FMT, ts[n].in, + result, ts[n].result), + result == ts[n].result); + + if (ts[n].errnum != -1) { + CuAssert(tc, + apr_psprintf(p, "for '%s': errno was %d not %d", ts[n].in, + errnum, ts[n].errnum), + ts[n].errnum == errnum); + } + + if (ts[n].end == NULL) { + /* end must point to NUL terminator of .in */ + CuAssertPtrEquals(tc, ts[n].in + strlen(ts[n].in), end); + } else if (ts[n].end != (void *)-1) { + CuAssert(tc, + apr_psprintf(p, "for '%s', end was '%s' not '%s'", + ts[n].in, end, ts[n].end), + strcmp(ts[n].end, end) == 0); + } + } +} + +CuSuite *teststr(void) +{ + CuSuite *suite = CuSuiteNew("Strings"); + + SUITE_ADD_TEST(suite, snprintf_0NULL); + SUITE_ADD_TEST(suite, snprintf_0nonNULL); + SUITE_ADD_TEST(suite, snprintf_noNULL); + SUITE_ADD_TEST(suite, snprintf_int64); + SUITE_ADD_TEST(suite, snprintf_underflow); + SUITE_ADD_TEST(suite, test_strtok); + SUITE_ADD_TEST(suite, string_error); + SUITE_ADD_TEST(suite, string_long); + SUITE_ADD_TEST(suite, string_strtoi64); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testtable.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testtable.c new file mode 100644 index 00000000..60123db0 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testtable.c @@ -0,0 +1,168 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test_apr.h" +#include "apr.h" +#include "apr_strings.h" +#include "apr_general.h" +#include "apr_pools.h" +#include "apr_tables.h" +#if APR_HAVE_STDIO_H +#include <stdio.h> +#endif +#if APR_HAVE_STDLIB_H +#include <stdlib.h> +#endif +#if APR_HAVE_STRING_H +#include <string.h> +#endif + +static apr_table_t *t1 = NULL; + +static void table_make(CuTest *tc) +{ + t1 = apr_table_make(p, 5); + CuAssertPtrNotNull(tc, t1); +} + +static void table_get(CuTest *tc) +{ + const char *val; + + apr_table_set(t1, "foo", "bar"); + val = apr_table_get(t1, "foo"); + CuAssertStrEquals(tc, val, "bar"); +} + +static void table_set(CuTest *tc) +{ + const char *val; + + apr_table_set(t1, "setkey", "bar"); + apr_table_set(t1, "setkey", "2ndtry"); + val = apr_table_get(t1, "setkey"); + CuAssertStrEquals(tc, val, "2ndtry"); +} + +static void table_getnotthere(CuTest *tc) +{ + const char *val; + + val = apr_table_get(t1, "keynotthere"); + CuAssertPtrEquals(tc, NULL, (void *)val); +} + +static void table_add(CuTest *tc) +{ + const char *val; + + apr_table_add(t1, "addkey", "bar"); + apr_table_add(t1, "addkey", "foo"); + val = apr_table_get(t1, "addkey"); + CuAssertStrEquals(tc, val, "bar"); + +} + +static void table_nelts(CuTest *tc) +{ + const char *val; + apr_table_t *t = apr_table_make(p, 1); + + apr_table_set(t, "abc", "def"); + apr_table_set(t, "def", "abc"); + apr_table_set(t, "foo", "zzz"); + val = apr_table_get(t, "foo"); + CuAssertStrEquals(tc, val, "zzz"); + val = apr_table_get(t, "abc"); + CuAssertStrEquals(tc, val, "def"); + val = apr_table_get(t, "def"); + CuAssertStrEquals(tc, val, "abc"); + CuAssertIntEquals(tc, 3, apr_table_elts(t)->nelts); +} + +static void table_clear(CuTest *tc) +{ + apr_table_clear(t1); + CuAssertIntEquals(tc, 0, apr_table_elts(t1)->nelts); +} + +static void table_unset(CuTest *tc) +{ + const char *val; + apr_table_t *t = apr_table_make(p, 1); + + apr_table_set(t, "a", "1"); + apr_table_set(t, "b", "2"); + apr_table_unset(t, "b"); + CuAssertIntEquals(tc, 1, apr_table_elts(t)->nelts); + val = apr_table_get(t, "a"); + CuAssertStrEquals(tc, val, "1"); + val = apr_table_get(t, "b"); + CuAssertPtrEquals(tc, (void *)val, (void *)NULL); +} + +static void table_overlap(CuTest *tc) +{ + const char *val; + apr_table_t *t1 = apr_table_make(p, 1); + apr_table_t *t2 = apr_table_make(p, 1); + + apr_table_addn(t1, "a", "0"); + apr_table_addn(t1, "g", "7"); + apr_table_addn(t2, "a", "1"); + apr_table_addn(t2, "b", "2"); + apr_table_addn(t2, "c", "3"); + apr_table_addn(t2, "b", "2.0"); + apr_table_addn(t2, "d", "4"); + apr_table_addn(t2, "e", "5"); + apr_table_addn(t2, "b", "2."); + apr_table_addn(t2, "f", "6"); + apr_table_overlap(t1, t2, APR_OVERLAP_TABLES_SET); + + CuAssertIntEquals(tc, apr_table_elts(t1)->nelts, 7); + val = apr_table_get(t1, "a"); + CuAssertStrEquals(tc, val, "1"); + val = apr_table_get(t1, "b"); + CuAssertStrEquals(tc, val, "2."); + val = apr_table_get(t1, "c"); + CuAssertStrEquals(tc, val, "3"); + val = apr_table_get(t1, "d"); + CuAssertStrEquals(tc, val, "4"); + val = apr_table_get(t1, "e"); + CuAssertStrEquals(tc, val, "5"); + val = apr_table_get(t1, "f"); + CuAssertStrEquals(tc, val, "6"); + val = apr_table_get(t1, "g"); + CuAssertStrEquals(tc, val, "7"); +} + +CuSuite *testtable(void) +{ + CuSuite *suite = CuSuiteNew("Table"); + + SUITE_ADD_TEST(suite, table_make); + SUITE_ADD_TEST(suite, table_get); + SUITE_ADD_TEST(suite, table_set); + SUITE_ADD_TEST(suite, table_getnotthere); + SUITE_ADD_TEST(suite, table_add); + SUITE_ADD_TEST(suite, table_nelts); + SUITE_ADD_TEST(suite, table_clear); + SUITE_ADD_TEST(suite, table_unset); + SUITE_ADD_TEST(suite, table_overlap); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testthread.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testthread.c new file mode 100644 index 00000000..d1d0de22 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testthread.c @@ -0,0 +1,133 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_thread_proc.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "errno.h" +#include "apr_time.h" +#include "test_apr.h" + +#if APR_HAS_THREADS + +static apr_thread_mutex_t *thread_lock; +static apr_thread_once_t *control = NULL; +static int x = 0; +static int value = 0; + +static apr_thread_t *t1; +static apr_thread_t *t2; +static apr_thread_t *t3; +static apr_thread_t *t4; + +/* just some made up number to check on later */ +static apr_status_t exit_ret_val = 123; + +static void init_func(void) +{ + value++; +} + +static void * APR_THREAD_FUNC thread_func1(apr_thread_t *thd, void *data) +{ + int i; + + apr_thread_once(control, init_func); + + for (i = 0; i < 10000; i++) { + apr_thread_mutex_lock(thread_lock); + x++; + apr_thread_mutex_unlock(thread_lock); + } + apr_thread_exit(thd, exit_ret_val); + return NULL; +} + +static void thread_init(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_thread_once_init(&control, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_thread_mutex_create(&thread_lock, APR_THREAD_MUTEX_DEFAULT, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); +} + +static void create_threads(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_thread_create(&t1, NULL, thread_func1, NULL, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_thread_create(&t2, NULL, thread_func1, NULL, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_thread_create(&t3, NULL, thread_func1, NULL, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + rv = apr_thread_create(&t4, NULL, thread_func1, NULL, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); +} + +static void join_threads(CuTest *tc) +{ + apr_status_t s; + + apr_thread_join(&s, t1); + CuAssertIntEquals(tc, exit_ret_val, s); + apr_thread_join(&s, t2); + CuAssertIntEquals(tc, exit_ret_val, s); + apr_thread_join(&s, t3); + CuAssertIntEquals(tc, exit_ret_val, s); + apr_thread_join(&s, t4); + CuAssertIntEquals(tc, exit_ret_val, s); +} + +static void check_locks(CuTest *tc) +{ + CuAssertIntEquals(tc, 40000, x); +} + +static void check_thread_once(CuTest *tc) +{ + CuAssertIntEquals(tc, 1, value); +} + +#else + +static void threads_not_impl(CuTest *tc) +{ + CuNotImpl(tc, "Threads not implemented on this platform"); +} + +#endif + +CuSuite *testthread(void) +{ + CuSuite *suite = CuSuiteNew("Threads"); + +#if !APR_HAS_THREADS + SUITE_ADD_TEST(suite, threads_not_impl); +#else + SUITE_ADD_TEST(suite, thread_init); + SUITE_ADD_TEST(suite, create_threads); + SUITE_ADD_TEST(suite, join_threads); + SUITE_ADD_TEST(suite, check_locks); + SUITE_ADD_TEST(suite, check_thread_once); +#endif + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testtime.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testtime.c new file mode 100644 index 00000000..1e3e87fa --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testtime.c @@ -0,0 +1,305 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_time.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_lib.h" +#include "test_apr.h" +#include "apr_strings.h" +#include <time.h> + +#define STR_SIZE 45 + +/* The time value is used throughout the tests, so just make this a global. + * Also, we need a single value that we can test for the positive tests, so + * I chose the number below, it corresponds to: + * 2002-08-14 12:05:36.186711 -25200 [257 Sat]. + * Which happens to be when I wrote the new tests. + */ +static apr_time_t now = APR_INT64_C(1032030336186711); + +static char* print_time (apr_pool_t *pool, const apr_time_exp_t *xt) +{ + return apr_psprintf (pool, + "%04d-%02d-%02d %02d:%02d:%02d.%06d %+05d [%d %s]%s", + xt->tm_year + 1900, + xt->tm_mon, + xt->tm_mday, + xt->tm_hour, + xt->tm_min, + xt->tm_sec, + xt->tm_usec, + xt->tm_gmtoff, + xt->tm_yday + 1, + apr_day_snames[xt->tm_wday], + (xt->tm_isdst ? " DST" : "")); +} + + +static void test_now(CuTest *tc) +{ + apr_time_t timediff; + apr_time_t current; + time_t os_now; + + current = apr_time_now(); + time(&os_now); + + timediff = os_now - (current / APR_USEC_PER_SEC); + /* Even though these are called so close together, there is the chance + * that the time will be slightly off, so accept anything between -1 and + * 1 second. + */ + CuAssert(tc, "apr_time and OS time do not agree", + (timediff > -2) && (timediff < 2)); +} + +static void test_gmtstr(CuTest *tc) +{ + apr_status_t rv; + apr_time_exp_t xt; + + rv = apr_time_exp_gmt(&xt, now); + if (rv == APR_ENOTIMPL) { + CuNotImpl(tc, "apr_time_exp_gmt"); + } + CuAssertTrue(tc, rv == APR_SUCCESS); + CuAssertStrEquals(tc, "2002-08-14 19:05:36.186711 +0000 [257 Sat]", + print_time(p, &xt)); +} + +static void test_exp_lt(CuTest *tc) +{ + apr_status_t rv; + apr_time_exp_t xt; + time_t posix_secs = (time_t)apr_time_sec(now); + struct tm *posix_exp = localtime(&posix_secs); + + rv = apr_time_exp_lt(&xt, now); + if (rv == APR_ENOTIMPL) { + CuNotImpl(tc, "apr_time_exp_lt"); + } + CuAssertTrue(tc, rv == APR_SUCCESS); + +#define CHK_FIELD(f) \ + CuAssert(tc, "Mismatch in " #f, posix_exp->f == xt.f) + + CHK_FIELD(tm_sec); + CHK_FIELD(tm_min); + CHK_FIELD(tm_hour); + CHK_FIELD(tm_mday); + CHK_FIELD(tm_mon); + CHK_FIELD(tm_year); + CHK_FIELD(tm_wday); + CHK_FIELD(tm_yday); + CHK_FIELD(tm_isdst); +#undef CHK_FIELD +} + +static void test_exp_get_gmt(CuTest *tc) +{ + apr_status_t rv; + apr_time_exp_t xt; + apr_time_t imp; + apr_int64_t hr_off_64; + + rv = apr_time_exp_gmt(&xt, now); + CuAssertTrue(tc, rv == APR_SUCCESS); + rv = apr_time_exp_get(&imp, &xt); + if (rv == APR_ENOTIMPL) { + CuNotImpl(tc, "apr_time_exp_get"); + } + CuAssertTrue(tc, rv == APR_SUCCESS); + hr_off_64 = (apr_int64_t) xt.tm_gmtoff * APR_USEC_PER_SEC; + CuAssertTrue(tc, now + hr_off_64 == imp); +} + +static void test_exp_get_lt(CuTest *tc) +{ + apr_status_t rv; + apr_time_exp_t xt; + apr_time_t imp; + apr_int64_t hr_off_64; + + rv = apr_time_exp_lt(&xt, now); + CuAssertTrue(tc, rv == APR_SUCCESS); + rv = apr_time_exp_get(&imp, &xt); + if (rv == APR_ENOTIMPL) { + CuNotImpl(tc, "apr_time_exp_get"); + } + CuAssertTrue(tc, rv == APR_SUCCESS); + hr_off_64 = (apr_int64_t) xt.tm_gmtoff * APR_USEC_PER_SEC; + CuAssertTrue(tc, now + hr_off_64 == imp); +} + +static void test_imp_gmt(CuTest *tc) +{ + apr_status_t rv; + apr_time_exp_t xt; + apr_time_t imp; + + rv = apr_time_exp_gmt(&xt, now); + CuAssertTrue(tc, rv == APR_SUCCESS); + rv = apr_time_exp_gmt_get(&imp, &xt); + if (rv == APR_ENOTIMPL) { + CuNotImpl(tc, "apr_time_exp_gmt_get"); + } + CuAssertTrue(tc, rv == APR_SUCCESS); + CuAssertTrue(tc, now == imp); +} + +static void test_rfcstr(CuTest *tc) +{ + apr_status_t rv; + char str[STR_SIZE]; + + rv = apr_rfc822_date(str, now); + if (rv == APR_ENOTIMPL) { + CuNotImpl(tc, "apr_rfc822_date"); + } + CuAssertTrue(tc, rv == APR_SUCCESS); + CuAssertStrEquals(tc, "Sat, 14 Sep 2002 19:05:36 GMT", str); +} + +static void test_ctime(CuTest *tc) +{ + apr_status_t rv; + char apr_str[STR_SIZE]; + char libc_str[STR_SIZE]; + time_t posix_sec = (time_t)apr_time_sec(now); + + rv = apr_ctime(apr_str, now); + if (rv == APR_ENOTIMPL) { + CuNotImpl(tc, "apr_ctime"); + } + CuAssertTrue(tc, rv == APR_SUCCESS); + strcpy(libc_str, ctime(&posix_sec)); + *strchr(libc_str, '\n') = '\0'; + + CuAssertStrEquals(tc, libc_str, apr_str); +} + +static void test_strftime(CuTest *tc) +{ + apr_status_t rv; + apr_time_exp_t xt; + char *str = NULL; + apr_size_t sz; + + rv = apr_time_exp_gmt(&xt, now); + str = apr_palloc(p, STR_SIZE + 1); + rv = apr_strftime(str, &sz, STR_SIZE, "%R %A %d %B %Y", &xt); + if (rv == APR_ENOTIMPL) { + CuNotImpl(tc, "apr_strftime"); + } + CuAssertTrue(tc, rv == APR_SUCCESS); + CuAssertStrEquals(tc, "19:05 Saturday 14 September 2002", str); +} + +static void test_strftimesmall(CuTest *tc) +{ + apr_status_t rv; + apr_time_exp_t xt; + char str[STR_SIZE]; + apr_size_t sz; + + rv = apr_time_exp_gmt(&xt, now); + rv = apr_strftime(str, &sz, STR_SIZE, "%T", &xt); + if (rv == APR_ENOTIMPL) { + CuNotImpl(tc, "apr_strftime"); + } + CuAssertTrue(tc, rv == APR_SUCCESS); + CuAssertStrEquals(tc, "19:05:36", str); +} + +static void test_exp_tz(CuTest *tc) +{ + apr_status_t rv; + apr_time_exp_t xt; + apr_int32_t hr_off = -5 * 3600; /* 5 hours in seconds */ + + rv = apr_time_exp_tz(&xt, now, hr_off); + if (rv == APR_ENOTIMPL) { + CuNotImpl(tc, "apr_time_exp_tz"); + } + CuAssertTrue(tc, rv == APR_SUCCESS); + CuAssertTrue(tc, (xt.tm_usec == 186711) && + (xt.tm_sec == 36) && + (xt.tm_min == 5) && + (xt.tm_hour == 14) && + (xt.tm_mday == 14) && + (xt.tm_mon == 8) && + (xt.tm_year == 102) && + (xt.tm_wday == 6) && + (xt.tm_yday == 256)); +} + +static void test_strftimeoffset(CuTest *tc) +{ + apr_status_t rv; + apr_time_exp_t xt; + char str[STR_SIZE]; + apr_size_t sz; + apr_int32_t hr_off = -5 * 3600; /* 5 hours in seconds */ + + apr_time_exp_tz(&xt, now, hr_off); + rv = apr_strftime(str, &sz, STR_SIZE, "%T", &xt); + if (rv == APR_ENOTIMPL) { + CuNotImpl(tc, "apr_strftime"); + } + CuAssertTrue(tc, rv == APR_SUCCESS); +} + +/* 0.9.4 and earlier rejected valid dates in 2038 */ +static void test_2038(CuTest *tc) +{ + apr_time_exp_t xt; + apr_time_t t; + + /* 2038-01-19T03:14:07.000000Z */ + xt.tm_year = 138; + xt.tm_mon = 0; + xt.tm_mday = 19; + xt.tm_hour = 3; + xt.tm_min = 14; + xt.tm_sec = 7; + + apr_assert_success(tc, "explode January 19th, 2038", + apr_time_exp_get(&t, &xt)); +} + +CuSuite *testtime(void) +{ + CuSuite *suite = CuSuiteNew("Time"); + + SUITE_ADD_TEST(suite, test_now); + SUITE_ADD_TEST(suite, test_gmtstr); + SUITE_ADD_TEST(suite, test_exp_lt); + SUITE_ADD_TEST(suite, test_exp_get_gmt); + SUITE_ADD_TEST(suite, test_exp_get_lt); + SUITE_ADD_TEST(suite, test_imp_gmt); + SUITE_ADD_TEST(suite, test_rfcstr); + SUITE_ADD_TEST(suite, test_ctime); + SUITE_ADD_TEST(suite, test_strftime); + SUITE_ADD_TEST(suite, test_strftimesmall); + SUITE_ADD_TEST(suite, test_exp_tz); + SUITE_ADD_TEST(suite, test_strftimeoffset); + SUITE_ADD_TEST(suite, test_2038); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testud.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testud.c new file mode 100644 index 00000000..3b62cb5d --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testud.c @@ -0,0 +1,91 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdio.h> +#include <stdlib.h> +#include "apr_file_io.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_lib.h" +#include "apr_strings.h" +#include "test_apr.h" + +static apr_pool_t *pool; +static char *testdata; +static int cleanup_called = 0; + +static apr_status_t string_cleanup(void *data) +{ + cleanup_called = 1; + return APR_SUCCESS; +} + +static void set_userdata(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_pool_userdata_set(testdata, "TEST", string_cleanup, pool); + CuAssertIntEquals(tc, rv, APR_SUCCESS); +} + +static void get_userdata(CuTest *tc) +{ + apr_status_t rv; + char *retdata; + + rv = apr_pool_userdata_get((void **)&retdata, "TEST", pool); + CuAssertIntEquals(tc, rv, APR_SUCCESS); + CuAssertStrEquals(tc, retdata, testdata); +} + +static void get_nonexistkey(CuTest *tc) +{ + apr_status_t rv; + char *retdata; + + rv = apr_pool_userdata_get((void **)&retdata, "DOESNTEXIST", pool); + CuAssertIntEquals(tc, rv, APR_SUCCESS); + CuAssertPtrEquals(tc, retdata, NULL); +} + +static void post_pool_clear(CuTest *tc) +{ + apr_status_t rv; + char *retdata; + + rv = apr_pool_userdata_get((void **)&retdata, "DOESNTEXIST", pool); + CuAssertIntEquals(tc, rv, APR_SUCCESS); + CuAssertPtrEquals(tc, retdata, NULL); +} + +CuSuite *testud(void) +{ + CuSuite *suite = CuSuiteNew("User Data"); + + apr_pool_create(&pool, p); + testdata = apr_pstrdup(pool, "This is a test\n"); + + SUITE_ADD_TEST(suite, set_userdata); + SUITE_ADD_TEST(suite, get_userdata); + SUITE_ADD_TEST(suite, get_nonexistkey); + + apr_pool_clear(pool); + + SUITE_ADD_TEST(suite, post_pool_clear); + + return suite; +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testuser.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testuser.c new file mode 100644 index 00000000..6cfeb61d --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testuser.c @@ -0,0 +1,171 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test_apr.h" +#include "apr_errno.h" +#include "apr_general.h" +#include "apr_user.h" + +#if APR_HAS_USER +static void uid_current(CuTest *tc) +{ + apr_uid_t uid; + apr_gid_t gid; + apr_status_t rv; + + rv = apr_uid_current(&uid, &gid, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); +} + +static void username(CuTest *tc) +{ + apr_uid_t uid; + apr_gid_t gid; + apr_uid_t retreived_uid; + apr_gid_t retreived_gid; + apr_status_t rv; + char *uname = NULL; + + rv = apr_uid_current(&uid, &gid, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_uid_name_get(&uname, uid, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, uname); + + rv = apr_uid_get(&retreived_uid, &retreived_gid, uname, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + CuAssertIntEquals(tc, APR_SUCCESS, apr_uid_compare(uid, retreived_uid)); +#ifdef WIN32 + /* ### this fudge was added for Win32 but makes the test return NotImpl + * on Unix if run as root, when !gid is also true. */ + if (!gid || !retreived_gid) { + /* The function had no way to recover the gid (this would have been + * an ENOTIMPL if apr_uid_ functions didn't try to double-up and + * also return apr_gid_t values, which was bogus. + */ + if (!gid) { + CuNotImpl(tc, "Groups from apr_uid_current"); + } + else { + CuNotImpl(tc, "Groups from apr_uid_get"); + } + } + else { +#endif + CuAssertIntEquals(tc, APR_SUCCESS, apr_gid_compare(gid, retreived_gid)); +#ifdef WIN32 + } +#endif +} + +static void groupname(CuTest *tc) +{ + apr_uid_t uid; + apr_gid_t gid; + apr_gid_t retreived_gid; + apr_status_t rv; + char *gname = NULL; + + rv = apr_uid_current(&uid, &gid, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_gid_name_get(&gname, gid, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertPtrNotNull(tc, gname); + + rv = apr_gid_get(&retreived_gid, gname, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + CuAssertIntEquals(tc, APR_SUCCESS, apr_gid_compare(gid, retreived_gid)); +} + +#ifndef WIN32 + +static void fail_userinfo(CuTest *tc) +{ + apr_uid_t uid; + apr_gid_t gid; + apr_status_t rv; + char *tmp; + + errno = 0; + gid = uid = 9999999; + tmp = NULL; + rv = apr_uid_name_get(&tmp, uid, p); + CuAssert(tc, "apr_uid_name_get should fail or " + "return a user name", + rv != APR_SUCCESS || tmp != NULL); + + errno = 0; + tmp = NULL; + rv = apr_gid_name_get(&tmp, gid, p); + CuAssert(tc, "apr_gid_name_get should fail or " + "return a group name", + rv != APR_SUCCESS || tmp != NULL); + + gid = 424242; + errno = 0; + rv = apr_gid_get(&gid, "I_AM_NOT_A_GROUP", p); + CuAssert(tc, "apr_gid_get should fail or " + "set a group number", + rv != APR_SUCCESS || gid == 424242); + + gid = uid = 424242; + errno = 0; + rv = apr_uid_get(&uid, &gid, "I_AM_NOT_A_USER", p); + CuAssert(tc, "apr_gid_get should fail or " + "set a user and group number", + rv != APR_SUCCESS || uid == 424242 || gid == 4242442); + + errno = 0; + tmp = NULL; + rv = apr_uid_homepath_get(&tmp, "I_AM_NOT_A_USER", p); + CuAssert(tc, "apr_uid_homepath_get should fail or " + "set a path name", + rv != APR_SUCCESS || tmp != NULL); +} + +#else +static void fail_userinfo(CuTest *tc) +{ + CuNotImpl(tc, "Intregal uid/gid not present on this platform"); +} +#endif + +#else +static void users_not_impl(CuTest *tc) +{ + CuNotImpl(tc, "Users not implemented on this platform"); +} +#endif + +CuSuite *testuser(void) +{ + CuSuite *suite = CuSuiteNew("Users"); + +#if !APR_HAS_USER + SUITE_ADD_TEST(suite, users_not_impl); +#else + SUITE_ADD_TEST(suite, uid_current); + SUITE_ADD_TEST(suite, username); + SUITE_ADD_TEST(suite, groupname); + SUITE_ADD_TEST(suite, fail_userinfo); +#endif + + return suite; +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/test/testvsn.c b/rubbos/app/httpd-2.0.64/srclib/apr/test/testvsn.c new file mode 100644 index 00000000..f04f1587 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/test/testvsn.c @@ -0,0 +1,49 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdio.h> + +#include "test_apr.h" +#include "apr_version.h" +#include "apr_general.h" + + +static void test_strings(CuTest *tc) +{ + CuAssertStrEquals(tc, APR_VERSION_STRING, apr_version_string()); +} + +static void test_ints(CuTest *tc) +{ + apr_version_t vsn; + + apr_version(&vsn); + + CuAssertIntEquals(tc, APR_MAJOR_VERSION, vsn.major); + CuAssertIntEquals(tc, APR_MINOR_VERSION, vsn.minor); + CuAssertIntEquals(tc, APR_PATCH_VERSION, vsn.patch); +} + +CuSuite *testvsn(void) +{ + CuSuite *suite = CuSuiteNew("Versioning"); + + SUITE_ADD_TEST(suite, test_strings); + SUITE_ADD_TEST(suite, test_ints); + + return suite; +} + |