def test_nooutputfiles(self):
        fd, file1 = tempfile.mkstemp()
        fd, file2 = tempfile.mkstemp()
        fd, file3 = tempfile.mkstemp()
        os.remove(file3)

        with open(file1, 'w') as fd:
            print('hello file1', file=fd)
        with open(file2, 'w') as fd:
            print('hello file2', file=fd)
        time.sleep(0.01)

        ob = taskrun.FileCleanupObserver()
        tm = taskrun.TaskManager(observers=[ob])
        t1 = taskrun.ProcessTask(tm, 't1', 'false'.format(file1, file2, file3))
        t1.add_condition(
            taskrun.FileModificationCondition([file1, file2], [file3]))

        tm.run_tasks()
        self.assertTrue(os.path.isfile(file1))
        self.assertTrue(os.path.isfile(file2))
        self.assertFalse(os.path.isfile(file3))

        # remove all files
        os.remove(file1)
        os.remove(file2)
    def test_noinputfiles(self):
        fd, file1 = tempfile.mkstemp()
        fd, file2 = tempfile.mkstemp()
        fd, file3 = tempfile.mkstemp()
        os.remove(file1)
        os.remove(file2)
        os.remove(file3)

        time.sleep(0.01)

        ob = taskrun.FileCleanupObserver()
        tm = taskrun.TaskManager(observers=[ob])
        t1 = taskrun.ProcessTask(tm, 't1', 'false'.format(file1, file2, file3))
        t1.add_condition(
            taskrun.FileModificationCondition([file1, file2], [file3]))

        tm.run_tasks()
        self.assertFalse(os.path.isfile(file1))
        self.assertFalse(os.path.isfile(file2))
        self.assertFalse(os.path.isfile(file3))
示例#3
0
ap.add_argument('--supersim', type=str, default='bin/supersim',
                help='supersim binary to run')
ap.add_argument('--ssparse', type=str, default='../ssparse/',
                help='ssparse directory')
ap.add_argument('--settings', type=str, default='json/fattree_iq_blast.json',
                help='settings file to use')
args = ap.parse_args()

# get the current amount of resources
cpus = os.cpu_count()
mem = taskrun.MemoryResource.current_available_memory_gib();

# build the task manager
rm = taskrun.ResourceManager(taskrun.CounterResource('cpus', 9999, cpus),
                             taskrun.MemoryResource('mem', 9999, mem))
cob = taskrun.FileCleanupObserver()
vob = taskrun.VerboseObserver(description=False, summary=True)
tm = taskrun.TaskManager(resource_manager=rm,
                 observers=[cob, vob],
                 failure_mode=taskrun.FailureMode.AGGRESSIVE_FAIL)

# output directory
out_dir = args.directory
if not os.path.isdir(out_dir):
  os.mkdir(out_dir)

# create task and resources function
def set_task_function(tm, name, cmd, console_out, task_type, config):
  task = taskrun.ProcessTask(tm, name, cmd)
  if console_out:
    task.stdout_file = console_out
示例#4
0
文件: run_all.py 项目: phrb/supersim
def main(args):
  total_cpus = args.cpus
  if total_cpus == None:
    total_cpus = os.cpu_count()

  total_mem = args.mem
  if total_mem == None:
    psmem = psutil.virtual_memory()
    total_mem = math.floor((psmem.free + psmem.cached) / (1024 * 1024 * 1024))

  print('using up to {0} CPUs'.format(total_cpus))
  print('using up to {0} GiB of memory'.format(total_mem))

  if args.check:
    subprocess.check_call('valgrind -h', shell=True,
                          stdout=subprocess.PIPE, stderr=subprocess.PIPE)

  rm = taskrun.ResourceManager(
    taskrun.CounterResource('cpu', 9999, total_cpus),
    taskrun.MemoryResource('mem', 9999, total_mem))
  vob = taskrun.VerboseObserver()
  cob = taskrun.FileCleanupObserver()
  tm = taskrun.TaskManager(resource_manager=rm,
                           observers=[vob,cob],
                           failure_mode='passive_fail')

  # find all files
  settingsFiles = glob.glob('json/{0}.json'.format(args.glob))
  print('config files to test: {0}'.format(settingsFiles))

  # generate all tasks
  for settingsFile in settingsFiles:
    cmd = 'bin/supersim {0}'.format(settingsFile)
    if args.check:
      cmd = ('valgrind --log-fd=1 --leak-check=full --show-reachable=yes '
             '--track-origins=yes --track-fds=yes {0}'.format(cmd))
    log = logFile(settingsFile)
    if not args.skip:
      try:
        os.remove(log)
      except OSError:
        pass
    cmd = '{0} 2>&1 | tee {1}'.format(cmd, log)
    task = taskrun.ProcessTask(tm, settingsFile, cmd)
    task.resources = {'cpu': 1, 'mem': 10 if args.check else 3}

  # run tasks
  if args.skip:
    print('skipping simulations')
  else:
    print('running simulations')
    tm.run_tasks()
    print('done')

  # check output for failures
  anyError = False
  for settingsFile in settingsFiles:
    error = False
    print('analyzing {0} output'.format(settingsFile))

    # read in text
    log = logFile(settingsFile)
    with open(log, 'r') as fd:
      lines = fd.readlines();

    # analyze output
    simComplete = False
    for idx, line in enumerate(lines):

      if line.find('Simulation complete') >= 0:
        simComplete = True
      if args.check:
        if (line.find('Open file descriptor') >= 0 and
            lines[idx+1].find('inherited from parent') < 0):
          error = True
          bad('open file descriptor')
        if line.find('blocks are definitely lost') >= 0:
          error = True
          bad('definitely lost memory')
        if line.find('blocks are indirectly lost') >= 0:
          error = True
          bad('indirectly lost memory')
        if (line.find('blocks are still reachable') >= 0 and
            # TODO(nic): REMOVE ME WHEN G++ STOPS SUCKING
            not line.find('72,704 bytes') >= 0):
          error = True
          bad('still reachable memory')
        if line.find('depends on uninitialised value') >= 0:
          error = True
          bad('depends on uninitialised value')

    if not simComplete:
      error = True;
      bad('no "Simulation complete" message')

    # show status
    if error:
      anyError = True
    else:
      good('passed all tests')

  return 0 if not anyError else -1