runTestSuite.in 4.02 KB
Newer Older
Boxiang Sun's avatar
Boxiang Sun committed
1
#!${buildout:directory}/bin/${eggs:interpreter}
2 3 4 5 6
# BEWARE: This file is operated by slapgrid
# BEWARE: It will be overwritten automatically
"""
  Script to run Cython test suite using Nexedi's test node framework.
"""
Boxiang Sun's avatar
Boxiang Sun committed
7 8 9 10
import argparse, os, re, shutil, subprocess, sys, traceback
from erp5.util import taskdistribution
from time import gmtime, strftime
from subprocess import check_output
11 12
import importlib
import datetime
13 14

def main():
Boxiang Sun's avatar
Boxiang Sun committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
  parser = argparse.ArgumentParser(description='Run a test suite.')
  parser.add_argument('--test_suite', help='The test suite name')
  parser.add_argument('--test_suite_title', help='The test suite title')
  parser.add_argument('--test_node_title', help='The test node title')
  parser.add_argument('--project_title', help='The project title')
  parser.add_argument('--revision', help='The revision to test',
                      default='dummy_revision')
  parser.add_argument('--node_quantity', help='ignored', type=int)
  parser.add_argument('--master_url',
                      help='The Url of Master controling many suites')
  parser.add_argument('--frontend_url',
                      help='The url of frontend of the test suite')

  args = parser.parse_args()

  is_browser_running = False
  try:
    test_suite_title = args.test_suite_title or args.test_suite
    test_suite = args.test_suite
    revision = args.revision

    test_line_dict = {}

    date = strftime("%Y/%m/%d %H:%M:%S", gmtime())


    ##########################
    # Run all tests
    ##########################
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

    path_var = os.pathsep.join([os.environ.get('PATH', os.defpath), '${python3.5:location}/bin/python3/bin/'])
    env = dict(os.environ, PATH=path_var)

    test_list = ['basic_test', 'lwan_coro_test']

    failed = 0
    result_string = None
    duration = 0
    test_line_dict = {}
    for test_name in test_list:
      failed = 0
      result_string = None
      duration = 0

      try:
        sys.path.append('${cython_nogil:location}/nogil_test/')
        test_module = importlib.import_module(test_name)
      except ImportError as e:
          failed = 1
          stdout = str(e)
      else:
        start_time = datetime.datetime.now()
        result_string = test_module.run(env, '${python3.5:location}/bin/python3')
        end_time = datetime.datetime.now()
        duration = (end_time - start_time).total_seconds()
        failed = result_string['failed']
        stdout = result_string['stdout']

      test_line_dict['%s: %s' % ('Cython test', test_name)] = {
          'test_count': 1,
          'error_count': 0,
          'failure_count': failed,
          'skip_count': 0,
          'duration': duration,
          'command': '',
          'stdout': stdout,
          'stderr': '',
          'html_test_result': '',
        }
Boxiang Sun's avatar
Boxiang Sun committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

    # Send results
    tool = taskdistribution.TaskDistributor(portal_url=args.master_url)
    test_result = tool.createTestResult(revision = revision,
                                        test_name_list = test_line_dict.keys(),
                                        node_title = args.test_node_title,
                                        test_title = test_suite_title,
                                        project_title = args.project_title)
    if test_result is None or not hasattr(args, 'master_url'):
      return
    # report test results
    while 1:
      test_result_line = test_result.start()
      if not test_result_line:
        print 'No test result anymore.'
        break

      print 'Submitting: "%s"' % test_result_line.name
102
      print test_line_dict
Boxiang Sun's avatar
Boxiang Sun committed
103 104 105 106 107 108 109 110 111 112 113 114 115
      # report status back to Nexedi ERP5
      test_result_line.stop(**test_line_dict[test_result_line.name])

  except:
    # Catch any exception here, to warn user instead of being silent,
    # by generating fake error result
    print traceback.format_exc()
    result = dict(status_code=-1,
                  command='python3 -c "import test"', # url
                  stderr=traceback.format_exc(),
                  stdout='')
    # XXX: inform test node master of error
    raise EnvironmentError(result)
116 117 118

if __name__ == "__main__":
    main()