Example #1
0
def main():
   (options, args) = parser.parse_args()
   if options.gdb or options.valgrind:
      options.notimeout = True

   tempdir = None
   if options.local:
      tempdir = tempfile.mkdtemp()
      if not options.print_list:
         shutil.copytree(src=options.project_path, dst=tempdir + "/p")
      project_path = tempdir + "/p"
   else:
      project_path = options.project_path

   log = sys.stdout
   if options.quiet:
      log = open("/dev/null", "w")
   all_tests = test_list(project_path, options.tester_path, log)

   _list = list()
   if options.build:
      _list.append(build_test)
   if len(args) == 0:
      _list.extend(all_tests)
   for test_name in args:
      if test_name == "all":
         _list.extend(all_tests)
      if test_name == "build":
         _list.append(build_test)
      else:
         match = None
         for test in all_tests:
            if test.name == test_name:
               match = test
               break
         if match is not None:
            _list.append(match)
         else:
            sys.stderr.write(test_name + " is not a valid test\n")
            exit(2)


   if options.print_list:
      for test in _list:
         print test.name, "-", test.description
      sys.exit(0)

   ran = list()
   tests_passed = 0
   tests_skipped = 0
   quitnow = False
   for tester in _list:
      test = tester(project_path, log=log, use_gdb=options.gdb,
            use_valgrind=options.valgrind, test_path=os.path.abspath(options.tester_path))

      log.write("\n")
      log.write("*" * 70 + "\n")
      log.write("\n")
      log.write("Test " + test.name + "\n")
      log.write(test.description + "\n")
      log.write("\n")
      log.write("*" * 70 + "\n")
      log.flush()

      # run the test in a new process
      result_queue = multiprocessing.Queue()
      p = multiprocessing.Process(target=run_test, args=(test,result_queue))
      p.start()
      if options.notimeout:
         timeout = None
      else:
         timeout = test.timeout * float(options.factor)
      try:
         # wait for the test result
         result = result_queue.get(block=True, timeout=timeout)
         p.join()
      except Queue.Empty:
         # timeout - kill process group of tester
         try:
            os.killpg(p.pid, signal.SIGKILL)
         except OSError:
            pass
         test.fail("Timelimit (" + str(timeout) + "s) exceeded")
         result = test
      except KeyboardInterrupt:
         test.fail("User interrupted test")
         result = test
         quitnow = True
      result_queue.close()

      try:
         result.log = log
         result.after()
      except Exception as e:
         (type, value, tb) = sys.exc_info()
         traceback.print_exception(type, value, tb)

      try:
         os.killpg(p.pid, signal.SIGKILL)
      except OSError as e:
         pass


      ran.append(result)

      log.flush()
      if not result.is_failed():
         tests_passed += 1

      log.write("\n")
      log.write("\n")
      log.write(str(result) + "\n")

      if result.is_failed() and not options._continue or quitnow:
         tests_skipped = len(_list) - len(ran)
         break

   log.write("*" * 70 + "\n")
   log.write("Summary:\n")

   for test in ran:
      log.write(str(test) + "\n")

   log.write("Passed " + str(tests_passed) + " of " + str(len(ran)) +
         " tests.\n")
   if tests_skipped > 0:
      log.write("Skipped " + str(tests_skipped) + " tests.\n")

   log.write("Overall " + str(tests_passed) + " of " + str(len(_list)) + "\n")

   if options.quiet:
      for test in ran:
         print str(test)

      print "Overall " + str(tests_passed) + " of " + str(len(_list))

   if tempdir is not None:
      shutil.rmtree(tempdir)

   if tests_passed == len(_list):
      sys.exit(0)
   else:
      sys.exit(1)
Example #2
0
def main():
    (options, args) = parser.parse_args()
    if options.gdb or options.valgrind:
        options.notimeout = True

    tempdir = None
    if options.local:
        tempdir = tempfile.mkdtemp()
        if not options.print_list:
            shutil.copytree(src=options.project_path, dst=tempdir + "/p")
        project_path = tempdir + "/p"
    else:
        project_path = options.project_path

    log = sys.stdout
    if options.quiet:
        log = open("/dev/null", "w")
    all_tests = test_list(project_path, options.tester_path, log)

    _list = list()
    if options.build:
        _list.append(build_test)
    if len(args) == 0:
        _list.extend(all_tests)
    for test_name in args:
        if test_name == "all":
            _list.extend(all_tests)
        if test_name == "build":
            _list.append(build_test)
        else:
            match = None
            for test in all_tests:
                if test.name == test_name:
                    match = test
                    break
            if match is not None:
                _list.append(match)
            else:
                sys.stderr.write(test_name + " is not a valid test\n")
                exit(2)

    if options.print_list:
        for test in _list:
            print test.name, "-", test.description
        sys.exit(0)

    ran = list()
    tests_passed = 0
    tests_skipped = 0
    quitnow = False
    for tester in _list:
        test = tester(project_path,
                      log=log,
                      use_gdb=options.gdb,
                      use_valgrind=options.valgrind,
                      test_path=options.tester_path)

        log.write("\n")
        log.write("*" * 70 + "\n")
        log.write("\n")
        log.write("Test " + test.name + "\n")
        log.write(test.description + "\n")
        log.write("\n")
        log.write("*" * 70 + "\n")
        log.flush()

        # run the test in a new process
        result_queue = multiprocessing.Queue()
        p = multiprocessing.Process(target=run_test, args=(test, result_queue))
        p.start()
        if options.notimeout:
            timeout = None
        else:
            timeout = test.timeout * float(options.factor)
        try:
            # wait for the test result
            result = result_queue.get(block=True, timeout=timeout)
            p.join()
        except Queue.Empty:
            # timeout - kill process group of tester
            try:
                os.killpg(p.pid, signal.SIGKILL)
            except OSError:
                pass
            test.fail("Timelimit (" + str(timeout) + "s) exceeded")
            result = test
        except KeyboardInterrupt:
            test.fail("User interrupted test")
            result = test
            quitnow = True
        result_queue.close()

        try:
            result.log = log
            result.after()
        except Exception as e:
            (type, value, tb) = sys.exc_info()
            traceback.print_exception(type, value, tb)

        try:
            os.killpg(p.pid, signal.SIGKILL)
        except OSError as e:
            pass

        ran.append(result)

        log.flush()
        if not result.is_failed():
            tests_passed += 1

        log.write("\n")
        log.write("\n")
        log.write(str(result) + "\n")

        if result.is_failed() and not options._continue or quitnow:
            tests_skipped = len(_list) - len(ran)
            break

    log.write("*" * 70 + "\n")
    log.write("Summary:\n")

    for test in ran:
        log.write(str(test) + "\n")

    log.write("Passed " + str(tests_passed) + " of " + str(len(ran)) +
              " tests.\n")
    if tests_skipped > 0:
        log.write("Skipped " + str(tests_skipped) + " tests.\n")

    log.write("Overall " + str(tests_passed) + " of " + str(len(_list)) + "\n")

    if options.quiet:
        for test in ran:
            print str(test)

        print "Overall " + str(tests_passed) + " of " + str(len(_list))

    if tempdir is not None:
        shutil.rmtree(tempdir)

    if tests_passed == len(_list):
        sys.exit(0)
    else:
        sys.exit(1)
Example #3
0
from server import *
from test_list import *
import sys, os, shutil

TEST_PATH = "/u/c/s/cs537-2/public/test_scripts/p4"
args = sys.argv
if len(args) != 3:
    print "Usage: ./run <test_name> <port>"
    exit()

test_name = args[1]
port = int(args[2])
project_path = os.getcwd()
all_tests = test_list(project_path, TEST_PATH, sys.stdout)
log = sys.stdout

for f in ["home.html", "1.cgi", "2.cgi", "3.cgi", "output.cgi", "in"]:
    if not os.path.isfile(os.path.join(project_path, f)):
        shutil.copy(os.path.join(TEST_PATH, "files", f), project_path)
    

if test_name == "build":
    _test = build_test
else:
    match = None
    for test in all_tests:
        if test.name == test_name:
            match = test
            break
    if match is not None:
        _test = match