test.py
changeset 5273 c95bd39cc980
parent 5257 fc9fd5cbc007
child 5274 8723fb3b377b
equal deleted inserted replaced
5264:6dc651e00339 5273:c95bd39cc980
    19 
    19 
    20 import os
    20 import os
    21 import sys
    21 import sys
    22 import optparse
    22 import optparse
    23 import subprocess
    23 import subprocess
    24 import multiprocessing
       
    25 import threading
    24 import threading
    26 import Queue
    25 import Queue
    27 import signal
    26 import signal
    28 import random
    27 import random
    29 import xml.dom.minidom
    28 import xml.dom.minidom
   614     #
   613     #
   615     # We now have a possibly large number of test suites to run, so we want to
   614     # We now have a possibly large number of test suites to run, so we want to
   616     # run them in parallel.  We're going to spin up a number of worker threads
   615     # run them in parallel.  We're going to spin up a number of worker threads
   617     # that will run our test jobs for us.
   616     # that will run our test jobs for us.
   618     #
   617     #
   619     # XXX Need to figure out number of CPUs without the multiprocessing 
       
   620     # dependency since multiprocessing is not standard `till Python 2.6
       
   621     #
       
   622     input_queue = Queue.Queue(0)
   618     input_queue = Queue.Queue(0)
   623     output_queue = Queue.Queue(0)
   619     output_queue = Queue.Queue(0)
   624 
   620 
   625     jobs = 0
   621     jobs = 0
   626     threads=[]
   622     threads=[]
   627 
   623 
   628     processors = multiprocessing.cpu_count()
   624     #
       
   625     # In Python 2.6 you can just use multiprocessing module, but we don't want
       
   626     # to introduce that dependency yet; so we jump through a few hoops.
       
   627     #
       
   628     processors = 1
       
   629 
       
   630     if 'SC_NPROCESSORS_ONLN'in os.sysconf_names:
       
   631         processors = os.sysconf('SC_NPROCESSORS_ONLN')
       
   632     else:
       
   633         proc = subprocess.Popen("sysctl -n hw.ncpu", shell = True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
       
   634         stdout_results, stderr_results = proc.communicate()
       
   635         if len(stderr_results) == 0:
       
   636             processors = int(stdout_results)
       
   637 
       
   638     #
       
   639     # Now, spin up one thread per processor which will eventually mean one test
       
   640     # per processor running concurrently.
       
   641     #
   629     for i in range(processors):
   642     for i in range(processors):
   630         thread = worker_thread(input_queue, output_queue)
   643         thread = worker_thread(input_queue, output_queue)
   631         threads.append(thread)
   644         threads.append(thread)
   632         thread.start()
   645         thread.start()
   633 
   646