diff options
Diffstat (limited to 'pjlib/src/pjlib-test')
-rw-r--r-- | pjlib/src/pjlib-test/ioq_perf.c | 17 | ||||
-rw-r--r-- | pjlib/src/pjlib-test/ioq_udp.c | 7 | ||||
-rw-r--r-- | pjlib/src/pjlib-test/ioq_unreg.c | 7 | ||||
-rw-r--r-- | pjlib/src/pjlib-test/main_symbian.cpp | 193 | ||||
-rw-r--r-- | pjlib/src/pjlib-test/sock.c | 76 | ||||
-rw-r--r-- | pjlib/src/pjlib-test/sock_perf.c | 4 | ||||
-rw-r--r-- | pjlib/src/pjlib-test/string.c | 9 | ||||
-rw-r--r-- | pjlib/src/pjlib-test/test.h | 34 | ||||
-rw-r--r-- | pjlib/src/pjlib-test/udp_echo_srv_ioqueue.c | 2 |
9 files changed, 311 insertions, 38 deletions
diff --git a/pjlib/src/pjlib-test/ioq_perf.c b/pjlib/src/pjlib-test/ioq_perf.c index adffc11c..cb8e8270 100644 --- a/pjlib/src/pjlib-test/ioq_perf.c +++ b/pjlib/src/pjlib-test/ioq_perf.c @@ -72,7 +72,7 @@ static void on_read_complete(pj_ioqueue_key_t *key, pj_ioqueue_op_key_t *op_key, pj_ssize_t bytes_read) { - test_item *item = pj_ioqueue_get_user_data(key); + test_item *item = (test_item*)pj_ioqueue_get_user_data(key); pj_status_t rc; int data_is_available = 1; @@ -150,7 +150,7 @@ static void on_write_complete(pj_ioqueue_key_t *key, pj_ioqueue_op_key_t *op_key, pj_ssize_t bytes_sent) { - test_item *item = pj_ioqueue_get_user_data(key); + test_item *item = (test_item*) pj_ioqueue_get_user_data(key); //TRACE_((THIS_FILE, " write complete: sent = %d", bytes_sent)); @@ -188,7 +188,7 @@ struct thread_arg /* The worker thread. */ static int worker_thread(void *p) { - struct thread_arg *arg = p; + struct thread_arg *arg = (struct thread_arg*) p; const pj_time_val timeout = {0, 100}; int rc; @@ -249,8 +249,9 @@ static int perform_test(int sock_type, const char *type_name, if (!pool) return -10; - items = pj_pool_alloc(pool, sockpair_cnt*sizeof(test_item)); - thread = pj_pool_alloc(pool, thread_cnt*sizeof(pj_thread_t*)); + items = (test_item*) pj_pool_alloc(pool, sockpair_cnt*sizeof(test_item)); + thread = (pj_thread_t**) + pj_pool_alloc(pool, thread_cnt*sizeof(pj_thread_t*)); TRACE_((THIS_FILE, " creating ioqueue..")); rc = pj_ioqueue_create(pool, sockpair_cnt*2, &ioqueue); @@ -265,8 +266,8 @@ static int perform_test(int sock_type, const char *type_name, items[i].ioqueue = ioqueue; items[i].buffer_size = buffer_size; - items[i].outgoing_buffer = pj_pool_alloc(pool, buffer_size); - items[i].incoming_buffer = pj_pool_alloc(pool, buffer_size); + items[i].outgoing_buffer = (char*) pj_pool_alloc(pool, buffer_size); + items[i].incoming_buffer = (char*) pj_pool_alloc(pool, buffer_size); items[i].bytes_recv = items[i].bytes_sent = 0; /* randomize outgoing buffer. */ @@ -331,7 +332,7 @@ static int perform_test(int sock_type, const char *type_name, for (i=0; i<thread_cnt; ++i) { struct thread_arg *arg; - arg = pj_pool_zalloc(pool, sizeof(*arg)); + arg = (thread_arg*) pj_pool_zalloc(pool, sizeof(*arg)); arg->id = i; arg->ioqueue = ioqueue; arg->counter = 0; diff --git a/pjlib/src/pjlib-test/ioq_udp.c b/pjlib/src/pjlib-test/ioq_udp.c index 4ccf30f9..e6f4c0f9 100644 --- a/pjlib/src/pjlib-test/ioq_udp.c +++ b/pjlib/src/pjlib-test/ioq_udp.c @@ -328,7 +328,7 @@ static void on_read_complete(pj_ioqueue_key_t *key, pj_ioqueue_op_key_t *op_key, pj_ssize_t bytes_read) { - unsigned *p_packet_cnt = pj_ioqueue_get_user_data(key); + unsigned *p_packet_cnt = (unsigned*) pj_ioqueue_get_user_data(key); PJ_UNUSED_ARG(op_key); PJ_UNUSED_ARG(bytes_read); @@ -510,8 +510,9 @@ static int many_handles_test(void) if (!pool) return PJ_ENOMEM; - key = pj_pool_alloc(pool, MAX*sizeof(pj_ioqueue_key_t*)); - sock = pj_pool_alloc(pool, MAX*sizeof(pj_sock_t)); + key = (pj_ioqueue_key_t**) + pj_pool_alloc(pool, MAX*sizeof(pj_ioqueue_key_t*)); + sock = (pj_sock_t*) pj_pool_alloc(pool, MAX*sizeof(pj_sock_t)); /* Create IOQueue */ rc = pj_ioqueue_create(pool, MAX, &ioqueue); diff --git a/pjlib/src/pjlib-test/ioq_unreg.c b/pjlib/src/pjlib-test/ioq_unreg.c index 1f7a98e7..ef50d048 100644 --- a/pjlib/src/pjlib-test/ioq_unreg.c +++ b/pjlib/src/pjlib-test/ioq_unreg.c @@ -123,7 +123,7 @@ static void on_read_complete(pj_ioqueue_key_t *key, static int worker_thread(void *arg) { - pj_ioqueue_t *ioqueue = arg; + pj_ioqueue_t *ioqueue = (pj_ioqueue_t*) arg; while (!thread_quitting) { pj_time_val timeout = { 0, 20 }; @@ -210,9 +210,10 @@ static int perform_unreg_test(pj_ioqueue_t *ioqueue, /* Initialize test data */ sock_data.pool = pj_pool_create(mem, "sd", 1000, 1000, NULL); - sock_data.buffer = pj_pool_alloc(sock_data.pool, 128); + sock_data.buffer = (char*) pj_pool_alloc(sock_data.pool, 128); sock_data.bufsize = 128; - sock_data.op_key = pj_pool_alloc(sock_data.pool, + sock_data.op_key = (pj_ioqueue_op_key_t*) + pj_pool_alloc(sock_data.pool, sizeof(*sock_data.op_key)); sock_data.received = 0; sock_data.unregistered = 0; diff --git a/pjlib/src/pjlib-test/main_symbian.cpp b/pjlib/src/pjlib-test/main_symbian.cpp new file mode 100644 index 00000000..c2c808b8 --- /dev/null +++ b/pjlib/src/pjlib-test/main_symbian.cpp @@ -0,0 +1,193 @@ +//Auto-generated file. Please do not modify. +//#include <e32cmn.h> + +//#pragma data_seg(".SYMBIAN") +//__EMULATOR_IMAGE_HEADER2 (0x1000007a,0x00000000,0x00000000,EPriorityForeground,0x00000000u,0x00000000u,0x00000000,0x00000000,0x00000000,0) +//#pragma data_seg() + +#include "test.h" +#include <stdlib.h> +#include <pj/errno.h> +#include <pj/os.h> +#include <pj/log.h> +#include <pj/unicode.h> +#include <stdio.h> + +#include <e32std.h> + +#if 0 +int main() +{ + int err = 0; + int exp = 0; + + err = test_main(); + //err = test_main(); + + if (err) + return err; + return exp; + //return 0; +} + +#else +#include <pj/os.h> + +#include <e32base.h> +#include <e32std.h> +#include <e32cons.h> // Console + + + +// Global Variables + +LOCAL_D CConsoleBase* console; // write all messages to this + + +// Local Functions + +LOCAL_C void MainL() +{ + // + // add your program code here, example code below + // + int rc = test_main(); + + console->Printf(_L(" [press any key]\n")); + console->Getch(); + + CActiveScheduler::Stop(); +} + +class MyScheduler : public CActiveScheduler +{ +public: + MyScheduler() + {} + + void Error(TInt aError) const; +}; + +void MyScheduler::Error(TInt aError) const +{ + PJ_UNUSED_ARG(aError); +} + +class ProgramStarter : public CActive +{ +public: + static ProgramStarter *NewL(); + void Start(); + +protected: + ProgramStarter(); + void ConstructL(); + virtual void RunL(); + virtual void DoCancel(); + TInt RunError(TInt aError); + +private: + RTimer timer_; +}; + +ProgramStarter::ProgramStarter() +: CActive(EPriorityNormal) +{ +} + +void ProgramStarter::ConstructL() +{ + timer_.CreateLocal(); + CActiveScheduler::Add(this); +} + +ProgramStarter *ProgramStarter::NewL() +{ + ProgramStarter *self = new (ELeave) ProgramStarter; + CleanupStack::PushL(self); + + self->ConstructL(); + + CleanupStack::Pop(self); + return self; +} + +void ProgramStarter::Start() +{ + timer_.After(iStatus, 0); + SetActive(); +} + +void ProgramStarter::RunL() +{ + MainL(); +} + +void ProgramStarter::DoCancel() +{ +} + +TInt ProgramStarter::RunError(TInt aError) +{ + PJ_UNUSED_ARG(aError); + return KErrNone; +} + + +LOCAL_C void DoStartL() + { + // Create active scheduler (to run active objects) + CActiveScheduler* scheduler = new (ELeave) MyScheduler; + CleanupStack::PushL(scheduler); + CActiveScheduler::Install(scheduler); + + ProgramStarter *starter = ProgramStarter::NewL(); + starter->Start(); + + CActiveScheduler::Start(); + } + + +// Global Functions + +static void log_writer(int level, const char *buf, int len) +{ + wchar_t buf16[PJ_LOG_MAX_SIZE]; + + PJ_UNUSED_ARG(level); + + pj_ansi_to_unicode(buf, len, buf16, PJ_ARRAY_SIZE(buf16)); + + TPtrC16 aBuf((const TUint16*)buf16, (TInt)len); + console->Write(aBuf); +} + + +GLDEF_C TInt E32Main() + { + // Create cleanup stack + __UHEAP_MARK; + CTrapCleanup* cleanup = CTrapCleanup::New(); + + // Create output console + TRAPD(createError, console = Console::NewL(_L("Console"), TSize(KConsFullScreen,KConsFullScreen))); + if (createError) + return createError; + + pj_log_set_log_func(&log_writer); + + // Run application code inside TRAP harness, wait keypress when terminated + TRAPD(mainError, DoStartL()); + if (mainError) + console->Printf(_L(" failed, leave code = %d"), mainError); + console->Printf(_L(" [press any key]\n")); + console->Getch(); + + delete console; + delete cleanup; + __UHEAP_MARKEND; + return KErrNone; + } + +#endif /* if 0 */ + diff --git a/pjlib/src/pjlib-test/sock.c b/pjlib/src/pjlib-test/sock.c index a3df9b63..044b0f13 100644 --- a/pjlib/src/pjlib-test/sock.c +++ b/pjlib/src/pjlib-test/sock.c @@ -63,13 +63,8 @@ #define UDP_PORT 51234 #define TCP_PORT (UDP_PORT+10) -#define BIG_DATA_LEN 9000 +#define BIG_DATA_LEN 8192 #define ADDRESS "127.0.0.1" -#define A0 127 -#define A1 0 -#define A2 0 -#define A3 1 - static char bigdata[BIG_DATA_LEN]; static char bigbuffer[BIG_DATA_LEN]; @@ -82,6 +77,12 @@ static int format_test(void) char zero[64]; pj_sockaddr_in addr2; const pj_str_t *hostname; +#if defined(PJ_SYMBIAN) && PJ_SYMBIAN!=0 + /* Symbian IP address is saved in host order */ + unsigned char A[] = {1, 0, 0, 127}; +#else + unsigned char A[] = {127, 0, 0, 1}; +#endif PJ_LOG(3,("test", "...format_test()")); @@ -91,7 +92,7 @@ static int format_test(void) /* Check the result. */ p = (unsigned char*)&addr; - if (p[0]!=A0 || p[1]!=A1 || p[2]!=A2 || p[3]!=A3) { + if (p[0]!=A[0] || p[1]!=A[1] || p[2]!=A[2] || p[3]!=A[3]) { PJ_LOG(3,("test", " error: mismatched address. p0=%d, p1=%d, " "p2=%d, p3=%d", p[0] & 0xFF, p[1] & 0xFF, p[2] & 0xFF, p[3] & 0xFF)); @@ -368,6 +369,8 @@ static int udp_test(void) if (rc != 0) goto on_error; +// This test will fail on S60 3rd Edition MR2 +#if 0 /* connect() the sockets. */ rc = pj_sock_connect(cs, &dstaddr, sizeof(dstaddr)); if (rc != 0) { @@ -385,6 +388,7 @@ static int udp_test(void) sizeof(srcaddr)); if (rc != 0) goto on_error; +#endif on_error: retval = rc; @@ -459,12 +463,70 @@ static int gethostbyname_test(void) return 0; } +#if 0 +#include "../pj/os_symbian.h" +static int connect_test() +{ + RSocketServ rSockServ; + RSocket rSock; + TInetAddr inetAddr; + TRequestStatus reqStatus; + char buffer[16]; + TPtrC8 data((const TUint8*)buffer, (TInt)sizeof(buffer)); + int rc; + + rc = rSockServ.Connect(); + if (rc != KErrNone) + return rc; + + rc = rSock.Open(rSockServ, KAfInet, KSockDatagram, KProtocolInetUdp); + if (rc != KErrNone) + { + rSockServ.Close(); + return rc; + } + + inetAddr.Init(KAfInet); + inetAddr.Input(_L("127.0.0.1")); + inetAddr.SetPort(80); + + rSock.Connect(inetAddr, reqStatus); + User::WaitForRequest(reqStatus); + + if (reqStatus != KErrNone) { + rSock.Close(); + rSockServ.Close(); + return rc; + } + + rSock.Send(data, 0, reqStatus); + User::WaitForRequest(reqStatus); + + if (reqStatus!=KErrNone) { + rSock.Close(); + rSockServ.Close(); + return rc; + } + + rSock.Close(); + rSockServ.Close(); + return KErrNone; +} +#endif + int sock_test() { int rc; pj_create_random_string(bigdata, BIG_DATA_LEN); +// Enable this to demonstrate the error witn S60 3rd Edition MR2 +#if 0 + rc = connect_test(); + if (rc != 0) + return rc; +#endif + rc = format_test(); if (rc != 0) return rc; diff --git a/pjlib/src/pjlib-test/sock_perf.c b/pjlib/src/pjlib-test/sock_perf.c index efb8f065..1fa12082 100644 --- a/pjlib/src/pjlib-test/sock_perf.c +++ b/pjlib/src/pjlib-test/sock_perf.c @@ -69,8 +69,8 @@ static int sock_producer_consumer(int sock_type, } /* Create buffers. */ - outgoing_buffer = pj_pool_alloc(pool, buf_size); - incoming_buffer = pj_pool_alloc(pool, buf_size); + outgoing_buffer = (char*) pj_pool_alloc(pool, buf_size); + incoming_buffer = (char*) pj_pool_alloc(pool, buf_size); /* Start loop. */ pj_get_timestamp(&start); diff --git a/pjlib/src/pjlib-test/string.c b/pjlib/src/pjlib-test/string.c index dd3649cc..d8bc54fd 100644 --- a/pjlib/src/pjlib-test/string.c +++ b/pjlib/src/pjlib-test/string.c @@ -236,6 +236,9 @@ static int stricmp_test(void) //return -700; } + /* Avoid division by zero */ + if (c2 == 0) c2=1; + PJ_LOG(3, ("", " time: stricmp=%u, stricmp_alnum=%u (speedup=%d.%02dx)", c1, c2, (c1 * 100 / c2) / 100, @@ -328,7 +331,7 @@ int string_test(void) /* * pj_strcpy(), pj_strcat() */ - s3.ptr = pj_pool_alloc(pool, 256); + s3.ptr = (char*) pj_pool_alloc(pool, 256); if (!s3.ptr) return -200; pj_strcpy(&s3, &s2); @@ -348,7 +351,7 @@ int string_test(void) /* * pj_utoa() */ - s5.ptr = pj_pool_alloc(pool, 16); + s5.ptr = (char*) pj_pool_alloc(pool, 16); if (!s5.ptr) return -270; s5.slen = pj_utoa(UL_VALUE, s5.ptr); @@ -392,7 +395,7 @@ int string_test(void) for (i=0; i<RCOUNT; ++i) { int j; - random[i].ptr = pj_pool_alloc(pool, RLEN); + random[i].ptr = (char*) pj_pool_alloc(pool, RLEN); if (!random[i].ptr) return -320; diff --git a/pjlib/src/pjlib-test/test.h b/pjlib/src/pjlib-test/test.h index ab86eacc..b30ba9f5 100644 --- a/pjlib/src/pjlib-test/test.h +++ b/pjlib/src/pjlib-test/test.h @@ -21,13 +21,21 @@ #include <pj/types.h> -#define GROUP_LIBC 1 -#define GROUP_OS 1 -#define GROUP_DATA_STRUCTURE 1 +#define GROUP_LIBC 0 +#define GROUP_OS 0 +#define GROUP_DATA_STRUCTURE 0 #define GROUP_NETWORK 1 -#define GROUP_FILE 1 - -#define INCLUDE_ERRNO_TEST GROUP_LIBC +#if defined(PJ_SYMBIAN) +# define GROUP_FILE 0 +#else +# define GROUP_FILE 1 +#endif + +#if defined(PJ_SYMBIAN) +# define INCLUDE_ERRNO_TEST 0 +#else +# define INCLUDE_ERRNO_TEST GROUP_LIBC +#endif #define INCLUDE_TIMESTAMP_TEST GROUP_OS #define INCLUDE_EXCEPTION_TEST GROUP_LIBC #define INCLUDE_RAND_TEST GROUP_LIBC @@ -39,16 +47,20 @@ #define INCLUDE_RBTREE_TEST GROUP_DATA_STRUCTURE #define INCLUDE_TIMER_TEST GROUP_DATA_STRUCTURE #define INCLUDE_ATOMIC_TEST GROUP_OS -#define INCLUDE_MUTEX_TEST GROUP_OS +#define INCLUDE_MUTEX_TEST (PJ_HAS_THREADS && GROUP_OS) #define INCLUDE_SLEEP_TEST GROUP_OS -#define INCLUDE_THREAD_TEST GROUP_OS +#define INCLUDE_THREAD_TEST (PJ_HAS_THREADS && GROUP_OS) #define INCLUDE_SOCK_TEST GROUP_NETWORK -#define INCLUDE_SOCK_PERF_TEST GROUP_NETWORK +#if defined(PJ_SYMBIAN) +# define INCLUDE_SOCK_PERF_TEST 0 +#else +# define INCLUDE_SOCK_PERF_TEST GROUP_NETWORK +#endif #define INCLUDE_SELECT_TEST GROUP_NETWORK #define INCLUDE_UDP_IOQUEUE_TEST GROUP_NETWORK #define INCLUDE_TCP_IOQUEUE_TEST GROUP_NETWORK -#define INCLUDE_IOQUEUE_PERF_TEST GROUP_NETWORK -#define INCLUDE_IOQUEUE_UNREG_TEST GROUP_NETWORK +#define INCLUDE_IOQUEUE_PERF_TEST (PJ_HAS_THREADS && GROUP_NETWORK) +#define INCLUDE_IOQUEUE_UNREG_TEST (PJ_HAS_THREADS && GROUP_NETWORK) #define INCLUDE_FILE_TEST GROUP_FILE #define INCLUDE_ECHO_SERVER 0 diff --git a/pjlib/src/pjlib-test/udp_echo_srv_ioqueue.c b/pjlib/src/pjlib-test/udp_echo_srv_ioqueue.c index 0e29bbd2..d2d2246a 100644 --- a/pjlib/src/pjlib-test/udp_echo_srv_ioqueue.c +++ b/pjlib/src/pjlib-test/udp_echo_srv_ioqueue.c @@ -117,7 +117,7 @@ static void on_write_complete(pj_ioqueue_key_t *key, static int worker_thread(void *arg) { - pj_ioqueue_t *ioqueue = arg; + pj_ioqueue_t *ioqueue = (pj_ioqueue_t*) arg; struct op_key read_op, write_op; char recv_buf[512], send_buf[512]; pj_ssize_t length; |