Salome HOME
spns #8471 : add Windows case to launch tests with the command 'sat test'
[tools/sat.git] / src / test_module.py
index 51ea543299734b215b98c776fe5c4e51b27db584..765b1e35573d5db07b8aff494f2af5b40588f719 100644 (file)
@@ -40,6 +40,8 @@ import src
 # directories not considered as test grids
 C_IGNORE_GRIDS = ['.git', '.svn', 'RESSOURCES']
 
+DEFAULT_TIMEOUT = 150
+
 # Get directory to be used for the temporary files.
 #
 def getTmpDirDEFAULT():
@@ -170,7 +172,13 @@ class Test:
             cmd = cmd % { 'user': user,
                          'base': testbase_base,
                          'dir': testbase_name }
-
+            
+            # Get the application environment
+            self.logger.write(_("Set the application environment\n"), 5)
+            env_appli = src.environment.SalomeEnviron(self.config,
+                                      src.environment.Environ(dict(os.environ)))
+            env_appli.set_application_env(self.logger)
+            
             self.logger.write("> %s\n" % cmd, 5)
             if src.architecture.is_windows():
                 # preexec_fn not supported on windows platform
@@ -185,7 +193,8 @@ class Test:
                                 shell=True,
                                 preexec_fn=set_signal,
                                 stdout=self.logger.logTxtFile,
-                                stderr=subprocess.PIPE)
+                                stderr=subprocess.PIPE,
+                                env=env_appli.environ.environ,)
 
             if res != 0:
                 raise src.SatException(_("Error: unable to get test base '%(nam"
@@ -422,21 +431,44 @@ class Test:
             launcherDir = os.path.dirname(self.launcher)
             if launcherName == 'runAppli':
                 # Old application
-                cmd = "for i in " + launcherDir + "/env.d/*.sh; do source ${i};"
-                " done ; echo $KERNEL_ROOT_DIR"
+                cmd = ("for i in " + launcherDir + "/env.d/*.sh; do source ${i};"
+                       " done ; echo $KERNEL_ROOT_DIR")
             else:
                 # New application
                 cmd = ("echo -e 'import os\nprint os.environ[\"KERNEL_" + 
                        "ROOT_DIR\"]' > tmpscript.py; %s shell" + 
                        " tmpscript.py") % self.launcher
-            root_dir = subprocess.Popen(cmd,
+
+            # OP 14/11/2017 Ajout de traces pour essayer de decouvrir le pb
+            #               de remontee de log des tests
+            #root_dir = subprocess.Popen(cmd,
+            #                stdout=subprocess.PIPE,
+            #                shell=True,
+            #                executable='/bin/bash').communicate()[0].split()[-1]
+            # OP Add Windows case
+            if src.architecture.is_windows():
+                subproc_res = subprocess.Popen(cmd,
+                            stdout=subprocess.PIPE,
+                            shell=True).communicate()
+                pass
+            else:
+                subproc_res = subprocess.Popen(cmd,
                             stdout=subprocess.PIPE,
                             shell=True,
-                            executable='/bin/bash').communicate()[0].split()[-1]
+                            executable='/bin/bash').communicate()
+                pass
+            #print "TRACES OP - test_module.py/Test.get_tmp_dir() subproc_res = "
+            #for resLine in subproc_res:
+            #    print "- '#%s#'" %resLine
+            
+            root_dir = subproc_res[0].split()[-1]
+
+        # OP 14/11/2017 Ajout de traces pour essayer de decouvrir le pb
+        #               de remontee de log des tests
+        #print "TRACES OP - test_module.py/Test.get_tmp_dir() root_dir = '#%s#'" %root_dir
         
         # import grid salome_utils from KERNEL that gives 
         # the right getTmpDir function
-        
         (file_, pathname, description) = imp.find_module("salome_utils",
                                                          [os.path.join(root_dir,
                                                                     'bin',
@@ -522,22 +554,11 @@ class Test:
             return binSalome, binPython, killSalome
         
         # Case where SALOME has the launcher that uses the SalomeContext API
-        if VersionSalome >= 730:            
-            if 'profile' not in self.config.APPLICATION:
-                # Before revision of application concept
-                launcher_name = self.config.APPLI.launch_alias_name
-                binSalome = os.path.join(self.config.APPLICATION.workdir,
-                                         appdir,
-                                         launcher_name)
-            else:
-                # After revision of application concept
-                launcher_name = self.config.APPLICATION.profile.launcher_name
-                binSalome = os.path.join(self.config.APPLICATION.workdir,
-                                         launcher_name)
+        else:            
+            launcher_name = src.get_launcher_name(self.config)
+            binSalome = os.path.join(self.config.APPLICATION.workdir,
+                                     launcher_name)
             
-            if src.architecture.is_windows():
-                binSalome += '.bat'
-
             binPython = binSalome + ' shell'
             killSalome = binSalome + ' killall'
             return binSalome, binPython, killSalome
@@ -553,11 +574,9 @@ class Test:
                                 self.currentsession)
         sessionname = "%s/%s" % (self.currentgrid, self.currentsession)
         time_out = self.get_test_timeout(sessionname,
-                                         self.config.SITE.test.timeout)
+                                         DEFAULT_TIMEOUT)
 
-        time_out_salome = src.get_cfg_param(self.config.SITE.test,
-                                            "timeout_app",
-                                            self.config.SITE.test.timeout)
+        time_out_salome = DEFAULT_TIMEOUT
 
         # generate wrapper script
         script_path = os.path.join(out_path, 'wrapperScript.py')
@@ -680,6 +699,7 @@ class Test:
                 self.nb_run -= 1
             elif script_info.res == "?":
                 self.nb_not_run += 1
+                
 
         self.config.TESTS.append(test_info, '')
 
@@ -775,7 +795,7 @@ class Test:
             self.settings.clear()
 
         # read known failures pyconf
-        if "testerror" in self.config.SITE:
+        if "testerror" in self.config.LOCAL:
             #import testerror
             #self.known_errors = testerror.read_test_failures(
             #                            self.config.TOOLS.testerror.file_path,
@@ -853,8 +873,6 @@ class Test:
         self.logger.write("\n", 2, False)
 
         # evaluate results
-        res_count = "%d / %d" % (self.nb_succeed,
-                                 self.nb_run - self.nb_acknoledge)
 
         res_out = _("Tests Results: %(succeed)d / %(total)d\n") % \
             { 'succeed': self.nb_succeed, 'total': self.nb_run }
@@ -866,10 +884,10 @@ class Test:
 
         if self.nb_timeout > 0:
             self.logger.write(_("%d tests TIMEOUT\n") % self.nb_timeout, 1)
-            res_count += " TO: %d" % self.nb_timeout
         if self.nb_not_run > 0:
             self.logger.write(_("%d tests not executed\n") % self.nb_not_run, 1)
-            res_count += " NR: %d" % self.nb_not_run
+        if self.nb_acknoledge > 0:
+            self.logger.write(_("%d tests known failures\n") % self.nb_acknoledge, 1)
 
         status = src.OK_STATUS
         if self.nb_run - self.nb_succeed - self.nb_acknoledge > 0: