Ported PJLIB and PJLIB-TEST to Symbian!

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1238 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/src/pjlib-test/errno.c b/pjlib/src/pjlib-test/errno.c
index 6a8dc96..fd06af3 100644
--- a/pjlib/src/pjlib-test/errno.c
+++ b/pjlib/src/pjlib-test/errno.c
@@ -102,7 +102,7 @@
     /*
      * Unix errors
      */
-#   ifdef EINVAL
+#   if defined(EINVAL) && !defined(PJ_SYMBIAN)
     rc = PJ_STATUS_FROM_OS(EINVAL);
     pj_set_os_error(rc);
 
diff --git a/pjlib/src/pjlib-test/ioq_tcp.c b/pjlib/src/pjlib-test/ioq_tcp.c
index 3ac086f..fc280de 100644
--- a/pjlib/src/pjlib-test/ioq_tcp.c
+++ b/pjlib/src/pjlib-test/ioq_tcp.c
@@ -536,7 +536,11 @@
  */
 static int compliance_test_2(void)
 {
+#if defined(PJ_SYMBIAN) && PJ_SYMBIAN!=0
+    enum { MAX_PAIR = 1, TEST_LOOP = 2 };
+#else
     enum { MAX_PAIR = 4, TEST_LOOP = 2 };
+#endif
 
     struct listener
     {
diff --git a/pjlib/src/pjlib-test/pool_perf.c b/pjlib/src/pjlib-test/pool_perf.c
index 6fb341e..c65b6e4 100644
--- a/pjlib/src/pjlib-test/pool_perf.c
+++ b/pjlib/src/pjlib-test/pool_perf.c
@@ -60,6 +60,35 @@
     return 0;
 }
 
+/* Symbian doesn't have malloc()/free(), so we use new/delete instead */
+#if defined(PJ_SYMBIAN) && PJ_SYMBIAN != 0
+
+static int pool_test_malloc_free()
+{
+    int i; /* must be signed */
+
+    for (i=0; i<COUNT; ++i) {
+	p[i] = new char[sizes[i]];
+	if (!p[i]) {
+	    PJ_LOG(3,(THIS_FILE,"   error: malloc failed to allocate %d bytes",
+		      sizes[i]));
+	    --i;
+	    while (i >= 0)
+		delete [] p[i], --i;
+	    return -1;
+	}
+	*p[i] = '\0';
+    }
+
+    for (i=0; i<COUNT; ++i) {
+	delete [] p[i];
+    }
+
+    return 0;
+}
+
+#else	/* PJ_SYMBIAN */
+
 static int pool_test_malloc_free()
 {
     int i; /* must be signed */
@@ -84,6 +113,8 @@
     return 0;
 }
 
+#endif /* PJ_SYMBIAN */
+
 int pool_perf_test()
 {
     unsigned i;
@@ -140,6 +171,10 @@
 	best = pool_time, worst = pool_time2;
     else
 	best = pool_time2, worst = pool_time;
+    
+    /* avoid division by zero */
+    if (best==0) best=1;
+    if (worst==0) worst=1;
 
     PJ_LOG(3, (THIS_FILE, "..pool speedup over malloc best=%dx, worst=%dx", 
 			  (int)(malloc_time/best),
diff --git a/pjlib/src/pjlib-test/sock.c b/pjlib/src/pjlib-test/sock.c
index 044b0f1..4ccad78 100644
--- a/pjlib/src/pjlib-test/sock.c
+++ b/pjlib/src/pjlib-test/sock.c
@@ -369,8 +369,11 @@
     if (rc != 0)
 	goto on_error;
 
-// This test will fail on S60 3rd Edition MR2
-#if 0
+    /* Disable this test on Symbian since UDP connect()/send() failed
+     * with S60 3rd edition (including MR2).
+     * See http://www.pjsip.org/trac/ticket/264
+     */    
+#if !defined(PJ_SYMBIAN) || PJ_SYMBIAN==0
     /* connect() the sockets. */
     rc = pj_sock_connect(cs, &dstaddr, sizeof(dstaddr));
     if (rc != 0) {
diff --git a/pjlib/src/pjlib-test/sock_perf.c b/pjlib/src/pjlib-test/sock_perf.c
index 1fa1208..a5420af 100644
--- a/pjlib/src/pjlib-test/sock_perf.c
+++ b/pjlib/src/pjlib-test/sock_perf.c
@@ -158,11 +158,17 @@
 
     PJ_LOG(3,("", "...benchmarking socket "
                   "(2 sockets, packet=512, single threaded):"));
-    
+
+    /* Disable this test on Symbian since UDP connect()/send() failed
+     * with S60 3rd edition (including MR2).
+     * See http://www.pjsip.org/trac/ticket/264
+     */    
+#if !defined(PJ_SYMBIAN) || PJ_SYMBIAN==0
     /* Benchmarking UDP */
     rc = sock_producer_consumer(PJ_SOCK_DGRAM, 512, LOOP, &bandwidth);
     if (rc != 0) return rc;
     PJ_LOG(3,("", "....bandwidth UDP = %d KB/s", bandwidth));
+#endif
 
     /* Benchmarking TCP */
     rc = sock_producer_consumer(PJ_SOCK_STREAM, 512, LOOP, &bandwidth);
diff --git a/pjlib/src/pjlib-test/test.h b/pjlib/src/pjlib-test/test.h
index b30ba9f..327fb0e 100644
--- a/pjlib/src/pjlib-test/test.h
+++ b/pjlib/src/pjlib-test/test.h
@@ -21,9 +21,9 @@
 
 #include <pj/types.h>
 
-#define GROUP_LIBC                  0
-#define GROUP_OS                    0
-#define GROUP_DATA_STRUCTURE        0
+#define GROUP_LIBC                  1
+#define GROUP_OS                    1
+#define GROUP_DATA_STRUCTURE        1
 #define GROUP_NETWORK               1
 #if defined(PJ_SYMBIAN)
 #   define GROUP_FILE               0
@@ -31,17 +31,13 @@
 #   define GROUP_FILE               1
 #endif
 
-#if defined(PJ_SYMBIAN)
-#   define INCLUDE_ERRNO_TEST       0
-#else
-#   define INCLUDE_ERRNO_TEST       GROUP_LIBC
-#endif
+#define INCLUDE_ERRNO_TEST          GROUP_LIBC
 #define INCLUDE_TIMESTAMP_TEST      GROUP_OS
 #define INCLUDE_EXCEPTION_TEST	    GROUP_LIBC
 #define INCLUDE_RAND_TEST	    GROUP_LIBC
 #define INCLUDE_LIST_TEST	    GROUP_DATA_STRUCTURE
 #define INCLUDE_POOL_TEST	    GROUP_LIBC
-#define INCLUDE_POOL_PERF_TEST	    (PJ_HAS_MALLOC && GROUP_LIBC)
+#define INCLUDE_POOL_PERF_TEST	    GROUP_LIBC
 #define INCLUDE_STRING_TEST	    GROUP_DATA_STRUCTURE
 #define INCLUDE_FIFOBUF_TEST	    0	// GROUP_DATA_STRUCTURE
 #define INCLUDE_RBTREE_TEST	    GROUP_DATA_STRUCTURE
@@ -51,11 +47,7 @@
 #define INCLUDE_SLEEP_TEST          GROUP_OS
 #define INCLUDE_THREAD_TEST         (PJ_HAS_THREADS && GROUP_OS)
 #define INCLUDE_SOCK_TEST	    GROUP_NETWORK
-#if defined(PJ_SYMBIAN)
-#   define INCLUDE_SOCK_PERF_TEST   0
-#else
-#   define INCLUDE_SOCK_PERF_TEST   GROUP_NETWORK
-#endif
+#define INCLUDE_SOCK_PERF_TEST	    GROUP_NETWORK
 #define INCLUDE_SELECT_TEST	    GROUP_NETWORK
 #define INCLUDE_UDP_IOQUEUE_TEST    GROUP_NETWORK
 #define INCLUDE_TCP_IOQUEUE_TEST    GROUP_NETWORK