Re #1202 (pjlib sysinfo): testing on OpenSolaris and added pjlib-test entry


git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@3426 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/src/pj/os_info.c b/pjlib/src/pj/os_info.c
index d82aea5..a10a95c 100644
--- a/pjlib/src/pj/os_info.c
+++ b/pjlib/src/pj/os_info.c
@@ -88,6 +88,8 @@
     if (si_initialized)
 	return &si;
 
+    si.machine.ptr = si.os_name.ptr = si.sdk_name.ptr = si.info.ptr = "";
+
 #define ALLOC_CP_STR(str,field)	\
 	do { \
 	    len = pj_ansi_strlen(str); \
@@ -108,8 +110,12 @@
 	char *tok;
 	int i, maxtok;
 
-	if (uname(&u) != 0)
+	/* Successful uname() returns zero on Linux and positive value
+	 * on OpenSolaris.
+	 */
+	if (uname(&u) == -1)
 	    goto get_sdk_info;
+
 	ALLOC_CP_STR(u.machine, machine);
 	ALLOC_CP_STR(u.sysname, os_name);
 
@@ -226,10 +232,12 @@
 	int cnt;
 
 	cnt = pj_ansi_snprintf(tmp, sizeof(tmp),
-			       "%s%s/%s/%s%s",
+			       "%s%s%s%s%s%s%s",
 			       si.os_name.ptr,
 			       ver_info(si.os_ver, os_ver),
+			       (si.machine.slen ? "/" : ""),
 			       si.machine.ptr,
+			       (si.sdk_name.slen ? "/" : ""),
 			       si.sdk_name.ptr,
 			       ver_info(si.sdk_ver, sdk_ver));
 	if (cnt > 0 && cnt < (int)sizeof(tmp)) {
diff --git a/pjlib/src/pjlib-test/os.c b/pjlib/src/pjlib-test/os.c
index e82ac24..2a28b92 100644
--- a/pjlib/src/pjlib-test/os.c
+++ b/pjlib/src/pjlib-test/os.c
@@ -17,4 +17,28 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
  */
+#include "test.h"
+#include <pj/log.h>
+#include <pj/os.h>
+
+#if INCLUDE_OS_TEST
+int os_test(void)
+{
+    const pj_sys_info *si;
+    int rc = 0;
+
+    si = pj_get_sys_info();
+    PJ_LOG(3,("", "   machine:  %s", si->machine.ptr));
+    PJ_LOG(3,("", "   os_name:  %s", si->os_name.ptr));
+    PJ_LOG(3,("", "   os_ver:   0x%x", si->os_ver));
+    PJ_LOG(3,("", "   sdk_name: %s", si->sdk_name.ptr));
+    PJ_LOG(3,("", "   sdk_ver:  0x%x", si->sdk_ver));
+    PJ_LOG(3,("", "   info:     %s", si->info.ptr));
+
+    return rc;
+}
+
+#else
 int dummy_os_var;
+#endif
+
diff --git a/pjlib/src/pjlib-test/test.c b/pjlib/src/pjlib-test/test.c
index 9d7c1ba..7983284 100644
--- a/pjlib/src/pjlib-test/test.c
+++ b/pjlib/src/pjlib-test/test.c
@@ -75,6 +75,10 @@
     DO_TEST( exception_test() );
 #endif
 
+#if INCLUDE_OS_TEST
+    DO_TEST( os_test() );
+#endif
+
 #if INCLUDE_RAND_TEST
     DO_TEST( rand_test() );
 #endif
diff --git a/pjlib/src/pjlib-test/test.h b/pjlib/src/pjlib-test/test.h
index 2d65d15..d33a9ba 100644
--- a/pjlib/src/pjlib-test/test.h
+++ b/pjlib/src/pjlib-test/test.h
@@ -47,6 +47,7 @@
 #define INCLUDE_ATOMIC_TEST         GROUP_OS
 #define INCLUDE_MUTEX_TEST	    (PJ_HAS_THREADS && GROUP_OS)
 #define INCLUDE_SLEEP_TEST          GROUP_OS
+#define INCLUDE_OS_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
@@ -78,6 +79,7 @@
 extern int rand_test(void);
 extern int list_test(void);
 extern int hash_test(void);
+extern int os_test(void);
 extern int pool_test(void);
 extern int pool_perf_test(void);
 extern int string_test(void);