apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject cvs commit: apr/test testsock.h Makefile.in Makefile.win test_apr.h testall.c testsock.c client.c server.c
Date Sun, 14 Mar 2004 20:27:14 GMT
rbb         2004/03/14 12:27:14

  Modified:    test     Makefile.in Makefile.win test_apr.h testall.c
                        testsock.c
  Added:       test     testsock.h
  Removed:     test     client.c server.c
  Log:
  Port testsock to the unified framework.  This doesn't include the
  sendfile tests, those are next.  Also, instead of having a server and
  client, testsock.c implements the server, and sockchild.c implements the
  client.  I have also removed the part of the test that relied on
  apr_poll().  That is tested in testpoll, and just makes this code more
  confusing than it needs to be.
  
  Revision  Changes    Path
  1.151     +6 -13     apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.in,v
  retrieving revision 1.150
  retrieving revision 1.151
  diff -u -r1.150 -r1.151
  --- Makefile.in	13 Mar 2004 21:41:04 -0000	1.150
  +++ Makefile.in	14 Mar 2004 20:27:14 -0000	1.151
  @@ -11,7 +11,6 @@
   #   or with special parameters
   
   STDTEST_PORTABLE = \
  -	testsock@EXEEXT@ \
   	testlockperf@EXEEXT@ \
   	testshmproducer@EXEEXT@ \
   	testshmconsumer@EXEEXT@ \
  @@ -34,7 +33,7 @@
   LOCAL_LIBS=../lib@APR_LIBNAME@.la
   
   CLEAN_TARGETS = testfile.tmp mod_test.slo proc_child@EXEEXT@ occhild@EXEEXT@ \
  -readchild@EXEEXT@ tryread@EXEEXT@
  +readchild@EXEEXT@ tryread@EXEEXT@ sockchid@EXEEXT@
   CLEAN_SUBDIRS = internal
   
   INCDIR=../include
  @@ -56,6 +55,9 @@
   occhild@EXEEXT@: occhild.lo $(LOCAL_LIBS)
   	$(LINK_PROG) occhild.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  +sockchild@EXEEXT@: sockchild.lo $(LOCAL_LIBS)
  +	$(LINK_PROG) sockchild.lo $(LOCAL_LIBS) $(ALL_LIBS)
  +        
   readchild@EXEEXT@: readchild.lo $(LOCAL_LIBS)
   	$(LINK_PROG) readchild.lo $(LOCAL_LIBS) $(ALL_LIBS)
           
  @@ -78,15 +80,6 @@
   testlockperf@EXEEXT@: testlockperf.lo $(LOCAL_LIBS)
   	$(LINK_PROG) testlockperf.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  -testsock@EXEEXT@: testsock.lo client@EXEEXT@ server@EXEEXT@ sendfile@EXEEXT@ $(LOCAL_LIBS)
  -	$(LINK_PROG) testsock.lo $(LOCAL_LIBS) $(ALL_LIBS)
  -
  -client@EXEEXT@: client.lo $(LOCAL_LIBS)
  -	$(LINK_PROG) client.lo $(LOCAL_LIBS) $(ALL_LIBS)
  -
  -server@EXEEXT@: server.lo $(LOCAL_LIBS)
  -	$(LINK_PROG) server.lo $(LOCAL_LIBS) $(ALL_LIBS)
  -
   sendfile@EXEEXT@: sendfile.lo $(LOCAL_LIBS)
   	$(LINK_PROG) sendfile.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  @@ -112,11 +105,11 @@
   	testpoll.lo testlock.lo testsockopt.lo testpipe.lo testthread.lo \
   	testhash.lo testargs.lo testnames.lo testuser.lo testpath.lo \
   	testenv.lo testprocmutex.lo testrand2.lo testfnmatch.lo \
  -        testatomic.lo testflock.lo testshm.lo
  +        testatomic.lo testflock.lo testshm.lo testsock.lo
   
   testall: $(TESTS) mod_test.la libmod_test.la occhild@EXEEXT@ \
   	 readchild@EXEEXT@ CuTest.lo proc_child@EXEEXT@ \
  -         tryread@EXEEXT@ $(LOCAL_LIBS)
  +         tryread@EXEEXT@ sockchild@EXEEXT@ $(LOCAL_LIBS)
   	$(LINK_PROG) $(TESTS) CuTest.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
   
  
  
  
  1.16      +4 -12     apr/test/Makefile.win
  
  Index: Makefile.win
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.win,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Makefile.win	13 Mar 2004 21:41:04 -0000	1.15
  +++ Makefile.win	14 Mar 2004 20:27:14 -0000	1.16
  @@ -5,13 +5,11 @@
   	testglobalmutex.exe
   
   PROGRAMS = \
  -	client.exe \
   	sendfile.exe \
  -	server.exe \
   	proc_child.exe \
           tryread.exe \
   	occhild.exe\
  -	testsock.exe \
  +	sockchild.exe \
   	testlockperf.exe \
   	testshmproducer.exe \
   	testshmconsumer.exe \
  @@ -58,14 +56,8 @@
   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)
  +sockchild.exe: sockchild.obj $(LOCAL_LIBS)
  +	$(LINK) sockchild.obj $(LOCAL_LIBS) $(ALL_LIBS)
   
   sendfile.exe: sendfile.obj $(LOCAL_LIBS)
   	$(LINK) sendfile.obj $(LOCAL_LIBS) $(ALL_LIBS)
  @@ -95,7 +87,7 @@
   	testpoll.obj testlock.obj testsockopt.obj testpipe.obj testthread.obj \
   	testhash.obj testargs.obj testnames.obj testuser.obj testpath.obj \
   	testenv.obj testprocmutex.obj testrand2.obj testfnmatch.obj \
  -        testatomic.obj testflock.obj testshm.obj
  +        testatomic.obj testflock.obj testshm.obj testsock.obj
   
   testall.exe: $(TESTS) CuTest.obj $(LOCAL_LIBS)
   	$(LINK) /debug /subsystem:console /machine:I386 $(TESTS) CuTest.obj \
  
  
  
  1.51      +1 -0      apr/test/test_apr.h
  
  Index: test_apr.h
  ===================================================================
  RCS file: /home/cvs/apr/test/test_apr.h,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- test_apr.h	14 Mar 2004 13:16:06 -0000	1.50
  +++ test_apr.h	14 Mar 2004 20:27:14 -0000	1.51
  @@ -63,6 +63,7 @@
   CuSuite *testrand2(void);
   CuSuite *testsleep(void);
   CuSuite *testshm(void);
  +CuSuite *testsock(void);
   CuSuite *testsockets(void);
   CuSuite *testsockopt(void);
   CuSuite *teststr(void);
  
  
  
  1.55      +1 -0      apr/test/testall.c
  
  Index: testall.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testall.c,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- testall.c	13 Mar 2004 21:41:04 -0000	1.54
  +++ testall.c	14 Mar 2004 20:27:14 -0000	1.55
  @@ -66,6 +66,7 @@
       {"testrand2", testrand2},
       {"testsleep", testsleep},
       {"testshm", testshm},
  +    {"testsock", testsock},
       {"testsockets", testsockets},
       {"testsockopt", testsockopt},
       {"teststr", teststr},
  
  
  
  1.28      +187 -148  apr/test/testsock.c
  
  Index: testsock.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testsock.c,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- testsock.c	13 Feb 2004 09:38:34 -0000	1.27
  +++ testsock.c	14 Mar 2004 20:27:14 -0000	1.28
  @@ -13,162 +13,201 @@
    * limitations under the License.
    */
   
  -#include <stdio.h>
  -#include <stdlib.h>
  -#include <signal.h>
  +#include "test_apr.h"
  +#include "testsock.h"
   #include "apr_thread_proc.h"
  +#include "apr_network_io.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)
  +static apr_proc_t launch_child(CuTest *tc, const char *arg1)
   {
  -    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;
  +    apr_proc_t proc = {0};
  +    apr_procattr_t *procattr;
       const char *args[2];
  +    apr_status_t rv;
   
  -    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);
  +    rv = apr_procattr_create(&procattr, p);
  +    apr_assert_success(tc, "Couldn't create procattr", rv);
   
  -    return 0;
  +    rv = apr_procattr_io_set(procattr, APR_NO_PIPE, APR_NO_PIPE,
  +            APR_NO_PIPE);
  +    apr_assert_success(tc, "Couldn't set io in procattr", rv);
  +
  +    rv = apr_procattr_error_check_set(procattr, 1);
  +    apr_assert_success(tc, "Couldn't set error check in procattr", rv);
  +
  +    args[0] = "sockchild" EXTENSION;
  +    args[1] = arg1;
  +    args[2] = NULL;
  +    rv = apr_proc_create(&proc, "./sockchild" EXTENSION, args, NULL,
  +                         procattr, p);
  +    apr_assert_success(tc, "Couldn't launch program", rv);
  +    return proc;
   }
  +
  +static int wait_child(CuTest *tc, apr_proc_t proc) 
  +{
  +    int exitcode;
  +    apr_exit_why_e why;
  +
  +    CuAssert(tc, "Error waiting for child process",
  +            apr_proc_wait(&proc, &exitcode, &why, APR_WAIT) == APR_CHILD_DONE);
  +
  +    CuAssert(tc, "child terminated normally", why == APR_PROC_EXIT);
  +    return exitcode;
  +}
  +
  +static void test_addr_info(CuTest *tc)
  +{
  +    apr_status_t rv;
  +    apr_sockaddr_t *sa;
  +
  +    rv = apr_sockaddr_info_get(&sa, APR_LOCAL, APR_UNSPEC, 80, 0, p);
  +    apr_assert_success(tc, "Problem generating sockaddr", rv);
  +
  +    rv = apr_sockaddr_info_get(&sa, "127.0.0.1", APR_UNSPEC, 80, 0, p);
  +    apr_assert_success(tc, "Problem generating sockaddr", rv);
  +    CuAssertStrEquals(tc, "127.0.0.1", sa->hostname);
  +}
  +
  +static apr_socket_t *setup_socket(CuTest *tc)
  +{
  +    apr_status_t rv;
  +    apr_sockaddr_t *sa;
  +    apr_socket_t *sock;
  +
  +    rv = apr_sockaddr_info_get(&sa, APR_LOCAL, APR_INET, 8021, 0, p);
  +    apr_assert_success(tc, "Problem generating sockaddr", rv);
  +
  +    rv = apr_socket_create(&sock, sa->family, SOCK_STREAM, APR_PROTO_TCP, p);
  +    apr_assert_success(tc, "Problem creating socket", rv);
  +    
  +    rv = apr_socket_bind(sock, sa);
  +    apr_assert_success(tc, "Problem binding to port", rv);
  +    
  +    rv = apr_socket_listen(sock, 5);
  +    apr_assert_success(tc, "Problem listening on socket", rv);
  +
  +    return sock;
  +}
  +
  +static void test_create_bind_listen(CuTest *tc)
  +{
  +    apr_status_t rv;
  +    apr_socket_t *sock = setup_socket(tc);
  +    
  +    rv = apr_socket_close(sock);
  +    apr_assert_success(tc, "Problem closing socket", rv);
  +}
  +
  +static void test_send(CuTest *tc)
  +{
  +    apr_status_t rv;
  +    apr_socket_t *sock;
  +    apr_socket_t *sock2;
  +    apr_proc_t proc;
  +    int protocol;
  +    int length;
  +    
  +    sock = setup_socket(tc);
  +
  +    proc = launch_child(tc, "read");
  +    
  +    rv = apr_socket_accept(&sock2, sock, p);
  +    apr_assert_success(tc, "Problem with receiving connection", rv);
  +
  +    apr_socket_protocol_get(sock2, &protocol);
  +    CuAssertIntEquals(tc, APR_PROTO_TCP, protocol);
  +    
  +    length = strlen(DATASTR);
  +    apr_socket_send(sock2, DATASTR, &length);
  +
  +    /* Make sure that the client received the data we sent */
  +    CuAssertIntEquals(tc, strlen(DATASTR), wait_child(tc, proc));
  +
  +    rv = apr_socket_close(sock2);
  +    apr_assert_success(tc, "Problem closing connected socket", rv);
  +    rv = apr_socket_close(sock);
  +    apr_assert_success(tc, "Problem closing socket", rv);
  +}
  +
  +static void test_recv(CuTest *tc)
  +{
  +    apr_status_t rv;
  +    apr_socket_t *sock;
  +    apr_socket_t *sock2;
  +    apr_proc_t proc;
  +    int protocol;
  +    int length = STRLEN;
  +    char datastr[STRLEN];
  +    
  +    sock = setup_socket(tc);
  +
  +    proc = launch_child(tc, "write");
  +    
  +    rv = apr_socket_accept(&sock2, sock, p);
  +    apr_assert_success(tc, "Problem with receiving connection", rv);
  +
  +    apr_socket_protocol_get(sock2, &protocol);
  +    CuAssertIntEquals(tc, APR_PROTO_TCP, protocol);
  +    
  +    length = strlen(DATASTR);
  +    apr_socket_recv(sock2, datastr, &length);
  +
  +    /* Make sure that the server received the data we sent */
  +    CuAssertStrEquals(tc, DATASTR, datastr);
  +    CuAssertIntEquals(tc, strlen(datastr), wait_child(tc, proc));
  +
  +    rv = apr_socket_close(sock2);
  +    apr_assert_success(tc, "Problem closing connected socket", rv);
  +    rv = apr_socket_close(sock);
  +    apr_assert_success(tc, "Problem closing socket", rv);
  +}
  +
  +static void test_timeout(CuTest *tc)
  +{
  +    apr_status_t rv;
  +    apr_socket_t *sock;
  +    apr_socket_t *sock2;
  +    apr_proc_t proc;
  +    int protocol;
  +    int exit;
  +    
  +    sock = setup_socket(tc);
  +
  +    proc = launch_child(tc, "read");
  +    
  +    rv = apr_socket_accept(&sock2, sock, p);
  +    apr_assert_success(tc, "Problem with receiving connection", rv);
  +
  +    apr_socket_protocol_get(sock2, &protocol);
  +    CuAssertIntEquals(tc, APR_PROTO_TCP, protocol);
  +    
  +    exit = wait_child(tc, proc);    
  +    CuAssertIntEquals(tc, SOCKET_TIMEOUT, exit);
  +
  +    /* We didn't write any data, so make sure the child program returns
  +     * an error.
  +     */
  +    rv = apr_socket_close(sock2);
  +    apr_assert_success(tc, "Problem closing connected socket", rv);
  +    rv = apr_socket_close(sock);
  +    apr_assert_success(tc, "Problem closing socket", rv);
  +}
  +
  +CuSuite *testsock(void)
  +{
  +    CuSuite *suite = CuSuiteNew("Socket operations");
  +
  +    SUITE_ADD_TEST(suite, test_addr_info);
  +    SUITE_ADD_TEST(suite, test_create_bind_listen);
  +    SUITE_ADD_TEST(suite, test_send);
  +    SUITE_ADD_TEST(suite, test_recv);
  +    SUITE_ADD_TEST(suite, test_timeout);
  +
  +    return suite;
  +}
  +
  
  
  
  1.1                  apr/test/testsock.h
  
  Index: testsock.h
  ===================================================================
  /* Copyright 2000-2004 The Apache Software Foundation
   *
   * Licensed 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 TESTSOCK_H
  #define TESTSOCK_H
  
  #define DATASTR "This is a test"
  #define STRLEN 8092
  
  /* This is a hack.  We can't return APR_TIMEOUT from sockchild, because
   * Unix OSes only return the least significant 8 bits of the return code,
   * which means that instead of receiving 70007, testsock gets 119.  But,
   * we also don't want to return -1, because we use that value for general
   * errors from sockchild.  So, we define 1 to mean that the read/write
   * operation timed out.  This means that we can't write a test that tries
   * to send a single character between ends of the socket.
   */
  #define SOCKET_TIMEOUT 1
  
  #endif
  
  
  
  

Mime
View raw message