better integration with winmo/ce, example winmo.cfg, and prun/pps polling to avoid prun -w flag issues on tegra
authorJoel Maher <joel.maher@gmail.com>
Wed, 02 Sep 2009 17:17:51 -0400
changeset 7 66b33bdac429170aeb3158671db60040e2b2fda6
parent 6 b83403dbc009f122667476f5faefebda857a3092
child 8 7b4193f6c7101594740b5709d676568f868d77bb
push id8
push userjmaher@mozilla.com
push dateWed, 02 Sep 2009 21:18:04 +0000
better integration with winmo/ce, example winmo.cfg, and prun/pps polling to avoid prun -w flag issues on tegra
maemkit-winmo.cfg
maemkit.py
mochidriver.py
new file mode 100755
--- /dev/null
+++ b/maemkit-winmo.cfg
@@ -0,0 +1,63 @@
+[general]
+xre-path = c:\desktop\firefox
+appname = \tests\fennec\fennec.exe
+client-number = 1
+logdir = maemkit_logs
+ostype = wince
+debug = 1
+profiledir = mochitesttestingprofile
+timeout-log = timeout-tests.txt
+remote-logdir = \tests
+remote-webserver = 192.168.55.100:8888
+remote-exec = c:\tools\prun.exe
+remote-del = c:\tools\pdel.exe
+remote-kill = c:\tools\pkill.exe
+remote-copyup = c:\tools\pget.exe
+remote-copydown = c:\tools\pput.exe
+remote-mkdir = c:\tools\pmkdir.exe
+
+[mochitest]
+autorun = True
+close-when-done = True
+test-path = 
+utility-path = c:\desktop\bin
+certificate-path = c:\desktop\certs
+split-directories = "toolkit/content/tests/widgets","content/canvas/test","content/html/content/test","layout/style/test","content/base/test","dom/tests/mochitest/dom-level1-core","dom/tests/mochitest/dom-level2-core"
+split-percentage = 20
+testroot = c:\desktop\mochitest
+log-file = log_mochitest.txt
+profiledir = mochitesttestingprofile
+verbose = 1
+
+[chrome]
+autorun = True
+close-when-done = True
+utility-path = /media/mmc1/release/bin
+certificate-path = /media/mmc1/release/certs
+backupdir = chrome.bak
+testroot = /media/mmc1/release/mochitest
+log-file = /media/mmc1/release/log_chrome.txt
+verbose = 0
+
+[reftest]
+split-directories = "layout/reftests/bugs/reftest.list","modules/libpr0n/test/reftest/reftest.list"
+split-percentage = 100
+testroot = /media/mmc1/release/reftest/tests
+utility-path = /media/mmc1/release/reftest
+manifest = /media/mmc1/release/reftest/tests/layout/reftests/reftest.list
+log-file = /media/mmc1/release/log_reftest.txt
+verbose = 1
+
+[crashtest]
+testroot = /media/mmc1/release/reftest/tests
+utility-path = /media/mmc1/release/reftest
+manifest = /media/mmc1/release/reftest/tests/testing/crashtest/crashtests.list
+log-file = /media/mmc1/release/log_crashtest.txt
+verbose = 1
+
+[xpcshell]
+testroot = /media/mmc1/release/xpcshell/tests
+utility-path = /media/mmc1/release/xpcshell
+manifest = /media/mmc1/release/xpcshell/tests/all-test-dirs.list
+log-file = /media/mmc1/release/log_xpcshell.txt
+verbose = 1
--- a/maemkit.py
+++ b/maemkit.py
@@ -5,28 +5,29 @@ import datetime, time, subprocess, comma
 class MaemKit(object):
   config_options = {}
   default_options = {}
   testtype = "mochitest"
   testdriver = ""
   config_file = "maemkit.cfg"
   dirtype = "/"
   debug = 0
-  singletest = False
+  singletest = True
 
   testtypes = ["mochitest","chrome","reftest","crashtest","xpcshell"]
 
   def __init__(self):
     self.defaultOptions()
     self.getConfig()
     self.getCli()
     ostype = self.config_options[self.testtype]["ostype"]
     if (ostype == "linux"): self.dirtype = "/"
     if (ostype == "macos"): self.dirtype = "/"
     if (ostype == "windows"): self.dirtype = "\\\\"
+    if (ostype == "wince"): self.dirtype = "\\"
 
   def defaultOptions(self):
     self.default_options["debug"] = 0
     self.default_options["ostype"] = "linux"
     self.default_options["close-when-done"] = False
     self.default_options["utility-path"] = "."
     self.default_options["xre-path"] = "."
     self.default_options["certificate-path"] = "certs"
@@ -113,17 +114,17 @@ class MaemKit(object):
     myenv["TOPSRCDIR"] = testroot
     myenv["MOZILLA_FIVE_HOME"] = xrepath
     myenv["LD_LIBRARY_PATH"] = xrepath
 
     parts = []
     for cmd in newcmd.split(" "):
       if (cmd.strip() != ""):
         parts.append(cmd.strip())
-    if (self.debug >= 1): print " ".join(parts)
+    if (self.debug >= 0): print " ".join(parts)
     sub_proc = subprocess.Popen(parts, bufsize=-1, env=myenv, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
     starttime = datetime.datetime.now()
 
     retVal = ""
     std_out = ""
     std_err = ""
 
     while (datetime.datetime.now() - starttime < datetime.timedelta(minutes=timeout)):
@@ -137,16 +138,45 @@ class MaemKit(object):
         break
       time.sleep(1)
     retVal = std_out + "\n" + std_err
 
     if (datetime.datetime.now() - starttime >= datetime.timedelta(minutes=timeout)):
       retVal = "*** TIMEOUT ***"
     return retVal
 
+  def addCommandWinCE(self, newcmd, retry=False, timeout=60):
+      parts = []
+      for cmd in newcmd.split(" "):
+          if (cmd.strip() != ""):
+              parts.append(cmd.strip())
+      if (self.debug >= 0): print " ".join(parts)
+      sub_proc = subprocess.Popen(parts, bufsize=-1)
+      starttime = datetime.datetime.now()
+
+      retVal = ""
+      p = re.compile('.*fennec.*')
+      while (datetime.datetime.now() - starttime < datetime.timedelta(minutes=timeout)):
+          #TODO: this is hardcoded here, but in a WinCE specific funcion
+          ppsData = self.addCommand("c:\\tools\\pps.exe")
+          found = False
+          for line in ppsData.split("\n"):
+              if (p.match(line)):
+                  found = True
+                  break
+          if (found == True):
+              time.sleep(10)
+          else:
+              break
+
+      if (datetime.datetime.now() - starttime >= datetime.timedelta(minutes=timeout)):
+          retVal = "*** TIMEOUT ***"
+      return retVal
+
+
   #parse log files, tally results
   #TODO: test on all types of logs
   def stitchLogs(self):
     p = 0
     f = 0
     t = 0
     myre = re.compile('.*TEST\-([A-Z]+).*')
 
@@ -177,21 +207,22 @@ class MaemKit(object):
 
   def cleanup(self):
     #TODO: figure out a method for killing process on wince (custom program)
     #TODO: what if we are using firefox instead of fennec?
     terminate = "killall"
     if (self.dirtype == '\\\\'): terminate = "tskill"
 
     #TODO: if we are not using xda activesync tools, need a way to kill a process
-    if (self.options["ostype"] == "wince"): terminte = "pkill.exe -w "
+    if (self.options["ostype"] == "wince"):
+        terminate = self.options["remote-kill"]
 
     try:
       if (self.options["ostype"] == "wince"):
-        self.addcommand(terminate + " fennec.exe")
+        self.addCommand(terminate + " fennec.exe")
       else:
         self.addCommand(terminate + " fennec")
         self.addCommand(terminate + " ssltunnel")
         self.addCommand(terminate + " xpcshell")
     except:
       if (self.debug >= 1): print "error in cleanup() command"
       pass
 
--- a/mochidriver.py
+++ b/mochidriver.py
@@ -57,17 +57,17 @@ class MochiKit(maemkit.MaemKit):
 
     # get the smallest directories with test files in them
     p = re.compile(testFilePattern)
     for root, dirs, files in os.walk(aDir):
       for mFile in files:
         if(p.match(mFile)):
           #root will be self.options["testroot"]/tests/* and we want the *
           #assuming c:\\desktop\\mochitest\\tests\\*
-          count = self.options["testroot"].split(self.dirtype) + 1
+          count = len(self.options["testroot"].split(self.dirtype)) + 1
           roots = root.split(self.dirtype, count)
           self.directories.append(os.path.join(roots[count],mFile))
 
 
   #Put directory back to normal; not necessary, but good to have
   def stitchDirectory(self, aDir):
     dirlist = []
 
@@ -162,100 +162,132 @@ class MochiKit(maemkit.MaemKit):
       rootdir = os.path.normpath(os.path.join(self.options["testroot"], "tests"))
       if (self.options["test-path"] != None):
           rootdir = os.path.normpath(os.path.join(rootdir, self.options["test-path"]))
       if (self.singletest == True):
           self.getFiles(rootdir)
       else:
           self.getDirectories(rootdir)
 
-  def prepTests(self):
-
-    if (self.singletest == True):
+  def ignoreTimeouts(self):
+      ignore = []    
       temp = self.directories
-      ignore = []
-    
+      
       #build list of ignore files
-      if (file.exists("timeout-tests.txt"):
-          f = open("timeout-tests.txt", "r")
+      if (os.path.exists(self.options["timeout-log"])):
+          f = open(self.options["timeout-log"], "r")
           lines = f.read().split("\n")
           f.close()
           for line in lines:
               if (line.strip() != ""):
                   ignore.append(line.strip())
 
 
           #remove ignore files
           self.directories = temp
           for dir in ignore:
               try:
                   temp.remove(dir)
               except:
                   pass
-      print "new length: " + str(len(temp))
+      if (self.debug >= 1): 
+          print "new length: " + str(len(temp))
+  
+      self.directories = temp
 
-      self.directories = temp
+  def ignorePartialRun(self):
+      temp = self.directories
       for root, dirs, files in os.walk(self.options["logdir"]):
          for file in files:
              ref = file.strip()
              for dir in self.directories:
                  parts = dir.rsplit(self.dirtype, 1)
                  if (parts[1].strip() + ".log" == ref):
                      try: temp.remove(dir)
                      except: pass
-            
-      print "done preping tests: " + str(len(temp))
+
+      if (self.debug >=1 ):
+          print "done preping tests: " + str(len(temp))
       self.directories = temp
-      return
 
 
+  def prepTests(self):
+    if (self.singletest == True):
+      self.ignoreTimeouts()
+      self.ignorePartialRun()
+    else:
       # We need to copy to testdirs as self.splitDirectory modifies the self.directories variable
       testdirs = []
       for dir in self.directories: testdirs.append(dir)
 
       for dir in testdirs:
           try:
               if (self.options["split-directories"].index(dir) >= 0): self.splitDirectory(dir)
           except: continue
 
       self.directories = self.splitListParallel(self.directories, self.options)
 
+  def setupRemoteProfile(self):
+      self.mochitestCommand = ["python " + os.path.normpath(os.path.join(self.options["testroot"], "runtests.py")).replace("\\", "/") + " --setup-only "]
+      self.mochitestCommand.append("--remote-webserver=" + os.path.normpath(self.options["remote-webserver"]))
+      self.mochitestCommand.append("--appname=" + os.path.normpath(os.path.join(self.options["xre-path"], "xpcshell.exe")).replace("\\", "/"))
+      mCommand = " ".join(self.mochitestCommand)
+      self.addCommand(mCommand)
+
+      remoteProfile = os.path.join(self.options["remote-logdir"], self.options["profiledir"])
+      remotedir = self.options["remote-logdir"].split(self.dirtype)
+      for dir in remotedir:
+          self.addCommand(self.options["remote-mkdir"] + " " + dir)
+      self.addCommand(self.options["remote-mkdir"] + " " + remoteProfile)
+      localProfile = os.path.normpath(os.path.join(self.options["testroot"], self.options["profiledir"]))
+      self.addCommand(self.options["remote-copydown"] + " -r " + os.path.join(localProfile, "*") + " " + remoteProfile)  
+  
+  def setupLocalWebserver(self):
+      pass
+
+  def terminateWebserver(self):
+      pass
+
   def runTests(self):
       self.mkLogDir(self.options["logdir"])
 
       #TODO: figure out a method for utilizing all the other config/cli options available
       self.mochitestCommand = ["python " + os.path.normpath(os.path.join(self.options["testroot"], "runtests.py")) + " --autorun --close-when-done"]
       for option in ["utility-path","appname","xre-path","certificate-path"]:
           self.mochitestCommand.append("--" + option + "=" + os.path.normpath(self.options[option]))
       mCommand = " ".join(self.mochitestCommand)
 
-      singletest = ['prun.exe', '-w', self.options["appname"], '--environ:NO_EM_RESTART=1', '-no-remote', '-profile', '\\tests\\mochitesttestingprofile\\']
+      singletest = [self.options["remote-exec"], self.options["appname"], '--environ:NO_EM_RESTART=1', '-no-remote', '-profile', os.path.join(self.options["remote-logdir"], self.options["profiledir"]) ]
+      if (self.singletest == True):
+          self.setupRemoteProfile()
+          self.setupLocalWebserver()
+
       for directory in self.directories:
           if (self.singletest == True):
-  
-              #TODO: make this a remote webserver in the options
-              cmd = "http://192.168.55.100:8888/tests/"
+              cmd = "http://" + self.options["remote-webserver"] + "/tests/"
               cmd += directory.replace("\\", "/") + "?logFile="
-              #TODO: make this configurable...this is the location of the logfile on the device
-              logfile = "\\tests\\mochitest\\mochi.log"
-              cmd += logfile.replace("\\", "%5c")
-#              print " ".join(singletest) + " " + cmd
-
-              self.addCommand(" ".join(['pdel.exe', logfile]))
-              if (self.addCommand(" ".join(singletest) + " " + cmd, timeout=5) == "*** TIMEOUT ***"):
+              remoteLog = os.path.join(self.options["remote-logdir"], self.options["log-file"]).replace("\\", "%5c")
+              cmd += remoteLog
+              
+              self.addCommand(" ".join([self.options["remote-del"], remoteLog]))
+              if (self.addCommandWinCE(" ".join(singletest) + " " + cmd, timeout=2) == "*** TIMEOUT ***"):
                   self.cleanup()
-                  f = open("timeout-tests.txt", "a")
+                  f = open(self.options["timeout-log"], "a")
                   f.write(directory + "\n")
                   f.close()
-                  print "timed out: " + directory
-              tests = directory.rsplit("\\", 1)
+                  if (self.debug >= 1): 
+                      print "timed out: " + directory
+              tests = directory.rsplit(self.dirtype, 1)
               log = os.path.join(self.options["logdir"], tests[1] + '.log')
-              self.addCommand(" ".join(['pget.exe', logfile, log]))
+              self.addCommand(" ".join([self.options["remote-copyup"], remoteLog, log]))
+              self.cleanup()
           else:
               mydir = directory.replace('\\', '/')
               logfile = os.path.join(self.options["logdir"],  self.getLogFileName(directory))
               self.addCommand(mCommand + " --test-path=" + mydir + " --log-file=" + logfile)
               if self.options['verbose'] and os.path.exists(logfile):
                   print ''.join(open(logfile).readlines())
               self.cleanup() #just for safety measures
 
+      if (self.singletest == True):
+          self.terminateWebserver()
   def parseLogs(self):
       self.stitchLogs()