summaryrefslogtreecommitdiff
path: root/workflow_sources/test/util.star
blob: 2c6d3485640cad8f87fb560f83c418d6da791253 (plain)
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
def is_unique(l):
  return len(l) == len(set(l))
end

def merge(dicts):
  r = {}
  for d in dicts:
    r.update(**d)
  end
  return r
end

def name(suites):
  if len(suites) == 1:
    return suites[0].name
  else:
    return suites[0].name + "-plus-" + str(len(suites) - 1) + "-more"
  end
end

def sum(ints):
  s = 0
  for i in ints:
    s += i
  end
  return s
end

def partition(target, groups, suites):
  if len(suites) == 0:
    return groups
  end
  group = []
  rest = []
  for suite in sorted(suites, key=lambda suite: suite.time):
    if sum([suite2.time for suite2 in group]) + suite.time <= target:
      group.append(suite)
    else:
      rest.append(suite)
    end
  end
  return partition(target, groups + [group], rest)
end

def group_by_time(suites):
  longest = max([suite.time for suite in suites])
  groups = partition(longest, [], suites)
  return [{"name": name(suites), "suites": [suite.name for suite in suites]} for suites in groups]
end

# Used when we don't actually want multiple ct-suites per job
def group_by_one(suites):
  return [{"name": suite.name, "suites": [suite.name]} for suite in suites]
end

def to_build_args(d):
  return ",".join(['{0}={1}'.format(k,d[k]) for k in d.keys()])
end