File: split_tests.py

package info (click to toggle)
openmolcas 25.02-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 170,204 kB
  • sloc: f90: 498,088; fortran: 139,779; python: 13,587; ansic: 5,745; sh: 745; javascript: 660; pascal: 460; perl: 325; makefile: 17
file content (107 lines) | stat: -rwxr-xr-x 2,823 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
# -*- coding: utf-8 -*-

#***********************************************************************
# This file is part of OpenMolcas.                                     *
#                                                                      *
# OpenMolcas is free software; you can redistribute it and/or modify   *
# it under the terms of the GNU Lesser General Public License, v. 2.1. *
# OpenMolcas is distributed in the hope that it will be useful, but it *
# is provided "as is" and without any express or implied warranties.   *
# For more details see the full text of the license in the file        *
# LICENSE or in <http://www.gnu.org/licenses/>.                        *
#                                                                      *
# Copyright (C) 2019, Ignacio Fdez. Galván                             *
#***********************************************************************
#
# Split a list of tests in sets taking roughly the same running time
#
# ./split_tests.py flatlist total_number selected_number

from __future__ import (division, print_function)
import sys, os, re

# default running time for tests with no estimate
default_time = 60

# this file location
path = os.path.dirname(os.path.abspath(__file__))

# flatlist
try:
  flatlist = sys.argv[1]
except IndexError:
  sys.exit()

# total sets
try:
  numsets = int(sys.argv[2])
  assert numsets > 0
except:
  numsets = 1

# this set
try:
  thisnum = int(sys.argv[3])
  assert 0 < thisnum <= numsets
except:
  thisnum = 1

# read running time estimates
timest = {}
trust_skip = False # by default, do not trust timing of skipped tests
try:
  with open(os.path.join(path, 'timing.data'), 'r') as f:
    while True:
      try:
        line = next(f)
        if line.strip() == 'trust_skip':
          trust_skip = True
          continue
        match = re.match(r'--- (\S*)( .)?', line)
        if match:
          test = match.group(1)
          timest[test] = float(next(f))
          if not trust_skip and match.group(2):
            timest[test] = max(timest[test], default_time)
      except StopIteration:
        break
except IOError:
  pass

# read test list
testlist = []
with open(flatlist, 'r') as f:
  for l in f:
    testlist.append(l.strip())

# compute total time
total = 0
for i in testlist:
  total += timest.get(i, default_time)

# split in sets
set_time = total / numsets
sets = []
this_set = []
this_time = 0
for i in testlist:
  this_set.append(i)
  this_time += timest.get(i, default_time)
  if this_time > set_time:
    sets.append(this_set[:])
    this_set = []
    this_time = 0
if (len(sets) < numsets):
  sets.append(this_set[:])

# print selected set
nothing = True
try:
  for i in sets[thisnum-1]:
    nothing = False
    print(i)
except IndexError:
  pass
if nothing:
  print ('.none')