More ticket #543: updated automated tests to run on Unix

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@2028 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip-apps/src/test-pjsua/run.py b/pjsip-apps/src/test-pjsua/run.py
index ecc872f..0b374de 100644
--- a/pjsip-apps/src/test-pjsua/run.py
+++ b/pjsip-apps/src/test-pjsua/run.py
@@ -1,14 +1,46 @@
-# $Id:$
+# $Id$
 import sys
 import imp
 import re
+import os
 import subprocess
+import random
 import time
 
 import inc_const as const
 
-# Defaults
-G_EXE="..\\..\\bin\\pjsua_vc6d.exe"
+# Get the pjsua executable name
+if sys.platform.find("win32")!=-1:
+    e = "../../bin/pjsua_vc6d.exe"
+    st1 = os.stat(e)
+    if st1 != None:
+	G_EXE = e
+    e = "../../bin/pjsua_vc6d.exe"
+    st2 = os.stat(e)
+    if st2 != None and st2.st_mtime > st1.st_mtime:
+	G_EXE = e
+	st1 = st2
+    if G_EXE=="":
+	print "Unable to find valid pjsua. Please build pjsip first"
+	sys.exit(1)
+    G_INUNIX = False
+else:
+    f = open("../../../build.mak", "r")
+    while True:
+	line = f.readline()
+	if not line:
+	    break
+	if line.find("TARGET_NAME")!=-1:
+	    print line
+	    G_EXE="../../bin/pjsua-" + line.split(":= ")[1]
+	    break
+    if G_EXE=="":
+	print "Unable to find ../../../build.mak. Please build pjsip first"
+	sys.exit(1)
+    G_INUNIX = True
+
+
+G_EXE = G_EXE.rstrip("\n\r \t")
 
 ###################################
 # TestError exception
@@ -35,7 +67,7 @@
 		self.trace_enabled = inst_param.trace_enabled
 		fullcmd = G_EXE + " " + inst_param.arg + " --stdout-refresh=5 --stdout-refresh-text=" + const.STDOUT_REFRESH
 		self.trace("Popen " + fullcmd)
-		self.proc = subprocess.Popen(fullcmd, bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True)
+		self.proc = subprocess.Popen(fullcmd, shell=G_INUNIX, bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True)
 	def send(self, cmd):
 		self.trace("send " + cmd)
 		self.proc.stdin.writelines(cmd + "\n")
@@ -108,6 +140,9 @@
 # Import the test script
 script = imp.load_source("script", sys.argv[1])  
 
+# Init random seed
+random.seed()
+
 # Validate
 if script.test == None:
 	print "Error: no test defined"
@@ -119,6 +154,8 @@
 
 # Instantiate pjsuas
 print "====== Running " + script.test.title + " ======"
+print "Using " + G_EXE + " as pjsua executable"
+
 for inst_param in script.test.inst_params:
 	try:
 		# Create pjsua's Expect instance from the param
diff --git a/pjsip-apps/src/test-pjsua/runall.py b/pjsip-apps/src/test-pjsua/runall.py
index 4165634..dc1119d 100644
--- a/pjsip-apps/src/test-pjsua/runall.py
+++ b/pjsip-apps/src/test-pjsua/runall.py
@@ -2,6 +2,10 @@
 import os
 import sys
 
+# Usage:
+#  runall.py [test-to-resume]
+
+
 # Initialize test list
 tests = []
 
@@ -28,8 +32,25 @@
 for pat in excluded_tests:
     tests = [t for t in tests if t.find(pat)==-1]
 
+# Resume test?
+resume_script=""
+if len(sys.argv) > 1:
+    if sys.argv[1][0]=='-' or sys.argv[1][0]=='/':
+        print "Usage:"
+	print "  runall.py [RESUME]"
+	print "where"
+	print "  RESUME is string/substring to specify where to resume tests."
+	print "  If this argument is omited, tests will start from the beginning."
+	sys.exit(0)
+    resume_script=sys.argv[1]
+
+
 # Now run the tests
 for t in tests:
+	if resume_script!="" and t.find(resume_script)==-1:
+	    print "Skipping " + t +".."
+	    continue
+	resume_script=""
 	cmdline = "python run.py " + t
 	print "Running " + cmdline
 	ret = os.system(cmdline + " > output.log")
diff --git a/pjsip-apps/src/test-pjsua/scripts-call/200_tcp.py b/pjsip-apps/src/test-pjsua/scripts-call/200_tcp.py
index 52b5f35..3414f17 100644
--- a/pjsip-apps/src/test-pjsua/scripts-call/200_tcp.py
+++ b/pjsip-apps/src/test-pjsua/scripts-call/200_tcp.py
@@ -6,7 +6,7 @@
 test_param = TestParam(
 		"TCP transport",
 		[
-			InstanceParam("callee", "--null-audio --no-udp", uri_param=";transport=tcp --max-calls=1"),
+			InstanceParam("callee", "--null-audio --no-udp --max-calls=1", uri_param=";transport=tcp"),
 			InstanceParam("caller", "--null-audio --no-udp --max-calls=1")
 		]
 		)
diff --git a/pjsip-apps/src/test-pjsua/scripts-pres/200_publish.py b/pjsip-apps/src/test-pjsua/scripts-pres/200_publish.py
index f73ffa5..50308a5 100644
--- a/pjsip-apps/src/test-pjsua/scripts-pres/200_publish.py
+++ b/pjsip-apps/src/test-pjsua/scripts-pres/200_publish.py
@@ -1,4 +1,4 @@
-# $Id:$
+# $Id$
 #
 from inc_cfg import *
 
@@ -8,24 +8,24 @@
 		[
 			InstanceParam(	"ua1", 
 					"--null-audio"+
-						" --id=<sip:test1@pjsip.org>"+
+						" --id=\"<sip:test1@pjsip.org>\""+
 						" --registrar=sip:sip.pjsip.org" +
 						" --username=test1" +
 						" --password=test1" +
 						" --realm=*" +
-						" --proxy=sip:sip.pjsip.org;lr" +
+						" --proxy=\"sip:sip.pjsip.org;lr\"" +
 						" --publish",
 					uri="<sip:test1@pjsip.org>",
 					have_reg=True,
 					have_publish=True),
 			InstanceParam(	"ua2", 
 					"--null-audio"+
-						" --id=<sip:test2@pjsip.org>"+
+						" --id=\"<sip:test2@pjsip.org>\""+
 						" --registrar=sip:sip.pjsip.org" +
 						" --username=test2" +
 						" --password=test2" +
 						" --realm=*" +
-						" --proxy=sip:sip.pjsip.org;lr" +
+						" --proxy=\"sip:sip.pjsip.org;lr\"" +
 						" --publish",
 					uri="<sip:test2@pjsip.org>",
 					have_reg=True,
diff --git a/pjsip-apps/src/test-pjsua/scripts-run/100_simple.py b/pjsip-apps/src/test-pjsua/scripts-run/100_simple.py
index f1e13cf..7ab96ef 100644
--- a/pjsip-apps/src/test-pjsua/scripts-run/100_simple.py
+++ b/pjsip-apps/src/test-pjsua/scripts-run/100_simple.py
@@ -1,4 +1,4 @@
-# $Id:$
+# $Id$
 #
 # Just about the simple pjsua command line parameter, which should
 # never fail in any circumstances
@@ -7,7 +7,7 @@
 test_param = TestParam(
 		"Basic run", 
 		[
-			InstanceParam("pjsua", "--null-audio --local-port 0 --rtp-port 0")
+			InstanceParam("pjsua", "--null-audio --rtp-port 0")
 		]
 		)
 
diff --git a/pjsip-apps/src/test-pjsua/scripts-run/200_register.py b/pjsip-apps/src/test-pjsua/scripts-run/200_register.py
index 34f837c..3f4338d 100644
--- a/pjsip-apps/src/test-pjsua/scripts-run/200_register.py
+++ b/pjsip-apps/src/test-pjsua/scripts-run/200_register.py
@@ -1,4 +1,4 @@
-# $Id:$
+# $Id$
 #
 from inc_cfg import *
 
@@ -8,7 +8,7 @@
 		[
 			InstanceParam(	"client", 
 					"--null-audio"+
-						" --id=<sip:test1@pjsip.org>"+
+						" --id=\"<sip:test1@pjsip.org>\""+
 						" --registrar=sip:sip.pjsip.org" +
 						" --username=test1" +
 						" --password=test1" +