# :NOTE: Under windows:
# netstat options -l and -t are unavailable
# grep command is unavailable
- from subprocess import Popen, PIPE
if sys.platform == "win32":
- out, _ = Popen(['netstat','-a','-n','-p tcp'], stdout=PIPE).communicate()
+ cmd = ['netstat','-a','-n','-p tcp']
else:
- out, _ = Popen(['netstat','-ant'], stdout=PIPE).communicate()
+ cmd = ['netstat','-ant']
+ pass
+
+ err = None
+ try:
+ from subprocess import Popen, PIPE, STDOUT
+ p = Popen(cmd, stdout=PIPE, stderr=STDOUT)
+ out, err = p.communicate()
+ except:
+ print "Error when trying to access active network connections."
+ if err: print err
+ import traceback
+ traceback.print_exc()
+ return False
+
import StringIO
buf = StringIO.StringIO(out)
ports = buf.readlines()
# Run test
def runTest(command):
print "Running:", " ".join(command)
- p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out, err = p.communicate()
+ p = subprocess.Popen(command)
+ p.communicate()
res = p.returncode
# About res value:
# A negative value -N indicates that the child was terminated by signal N (Unix only).
# On Unix, the value 11 generally corresponds to a segmentation fault.
- return res, out, err
-#
-
-# Display output and errors
-def processResult(res, out, err):
- if out:
- print out
- pass
- if err:
- print " ** Detected error **"
- print "Error code: ", res
- print err,
- print " ** end of message **"
- pass
return res
#
try:
salome_instance = SalomeInstance.start(shutdown_servers=True)
port = salome_instance.get_port()
- res, out, err = runTest(test_and_args)
- res = processResult(res, out, err)
+ res = runTest(test_and_args)
except TimeoutException:
print "FAILED : timeout(%s) is reached"%timeout_delay
except:
self.session(self.add3+self.add3+self.hello1)
self.assertLogFileContentsEqual(self.add3Msg+self.add3Msg+self.hello1Msg)
#
-# def testHello0Add3Hello0Add3Hello0(self):
-# self.session(self.hello1+self.add3+self.hello0+self.add3+self.hello0)
-# self.assertLogFileContentsEqual(self.hello1Msg+self.add3Msg+self.hello0Msg+self.add3Msg+self.hello0Msg)
+ def testHello0Add3Hello0Add3Hello0(self):
+ self.session(self.hello1+self.add3+self.hello0+self.add3+self.hello0)
+ self.assertLogFileContentsEqual(self.hello1Msg+self.add3Msg+self.hello0Msg+self.add3Msg+self.hello0Msg)
#
#
# tests must be in ${ABSOLUTE_APPLI_PATH}/${__testSubDir}/
__testSubDir = "bin/salome/test"
-def __runTest(command, workdir):
- p = subprocess.Popen(command, cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
-
- while True:
- try:
- out = p.stdout.readline()
- sys.stdout.write(out)
- except: # raised IOError or OSError if output is empty
- pass
-
- returncode = p.poll()
- if not returncode is None:
- sys.stdout.flush()
- break
- pass
-
- return p.returncode
-#
-
def runTests(args, exe=None):
args = __configureTests(args, exe)
testPath = os.path.join(appliPath, __testSubDir)
command = ["ctest"] + args
- res = __runTest(command, testPath)
-
- sys.exit(res)
+ p = subprocess.Popen(command, cwd=testPath)
+ p.communicate()
+ sys.exit(p.returncode)
#