summaryrefslogtreecommitdiff
path: root/examples_checks.py
blob: 2a51c808192555a7d52d33fb7aeb8e8ca46bcce0 (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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/python3
import os
import sys
import subprocess
import json
import time
import concurrent.futures
import argparse
import tempfile

#
# preparation calls for the examples
#

def prep_eina_file_02():
  f = tempfile.NamedTemporaryFile(delete=False)
  f.write(b"Simulation")
  return [f.name, "/tmp/copy_file"]

def prep_eina_xattr_01():
  f = tempfile.NamedTemporaryFile(delete=False)
  f.write(b"Simulation")
  return ["list", f.name]

def prep_eina_xattr_02():
  f1 = tempfile.NamedTemporaryFile(delete=False)
  f1.write(b"Simulation")
  f2 = tempfile.NamedTemporaryFile(delete=False)
  f2.write(b"Simulation2")
  return [f1.name, f2.name]

def prep_eet_data_simple():
  f1 = tempfile.NamedTemporaryFile(delete=False)
  f1.write(b"Simulation")
  f2 = tempfile.NamedTemporaryFile(delete=False)
  f2.write(b"Simulation2")
  return [f1.name, f2.name]

def prep_eet_data_nested():
  f1 = tempfile.NamedTemporaryFile(delete=False)
  f1.write(b"Simulation")
  f2 = tempfile.NamedTemporaryFile(delete=False)
  f2.write(b"Simulation2")
  return [f1.name, f2.name]

def prep_eet_data_file_descriptor_01():
  f1 = tempfile.NamedTemporaryFile(delete=False)
  f1.write(b"Simulation")
  f2 = tempfile.NamedTemporaryFile(delete=False)
  f2.write(b"Simulation2")
  return [f1.name, f2.name, "acc", "Example-Simulation"]

def prep_eet_data_file_descriptor_02():
  f1 = tempfile.NamedTemporaryFile(delete=False)
  f1.write(b"Simulation")
  f2 = tempfile.NamedTemporaryFile(delete=False)
  f2.write(b"Simulation2")
  return [f1.name, f2.name, "union", "5", "Example-Simulation"]

example_preparation = {
  "eina_file_02" : prep_eina_file_02,
  "eina_xattr_01" : prep_eina_xattr_01,
  "eina_xattr_02" : prep_eina_xattr_02,
  "eet-data-simple" : prep_eet_data_simple,
  "eet-data-nested" : prep_eet_data_nested,
  "eet-data-simple" : prep_eet_data_simple,
  "eet-data-file_descriptor_01" : prep_eet_data_file_descriptor_01,
  "eet-data-file_descriptor_02" : prep_eet_data_file_descriptor_02,
}

#
# Holds up the state of the ran examples
#

class State:
  def __init__(self, examples):
    self.max_n = examples
    self.n = 1
    self.count_fail = 0
    self.count_success = 0
    self.count_err_output = 0
    print("Found "+str(self.max_n)+" Examples")

  def add_run(self, command, error_in_output, exitcode):
    print("{}/{} {} {} {} ".format(self.n, self.max_n, ("SUCCESS" if exitcode == 0 else "FAIL"), ("CLEAN" if error_in_output == False else "ERR"), command))
    self.n = self.n + 1
    if exitcode != 0:
      self.count_fail += 1
    if error_in_output == True:
      self.count_err_output += 1
    if exitcode == 0 and error_in_output == False:
      self.count_success += 1

  def print_summary(self):
    print("Summary")
    print("  Failed: "+str(self.count_fail)+"/"+str(self.max_n))
    print("  Errored: "+str(self.count_err_output)+"/"+str(self.max_n))
    print("  Success: "+str(self.count_success)+"/"+str(self.max_n))

#
# this simulates the startup of the example, and the closing after 1s
#

def simulate_example(example):
  args = []
  if os.path.basename(example) in example_preparation:
    args = example_preparation[os.path.basename(example)]()

  #meson changed behaviour from 0.49 to 0.50 so we need this:
  if os.path.isabs(example):
    example_dir = example
  else:
    example_dir = os.path.join(G.builddir, example)

  run = subprocess.Popen([example_dir] + args,
      stdout = subprocess.PIPE,
      stderr = subprocess.PIPE,
  )
  time.sleep(1)
  run.terminate()
  try:
    outs, errs = run.communicate(timeout=2)
  except Exception as e:
    run.kill()
    return (example, True, -1)
  else:
    return (example, True if b'ERR' in outs or b'ERR' in errs else False, run.poll())

#meson changed behaviour from 0.49 to 0.50 so we need this:
def meson_fetch_filename(filename_object):
  if isinstance(filename_object, str):
    return filename_object
  else:
    return filename_object[0]


parser = argparse.ArgumentParser(description='Run the examples of efl')
parser.add_argument('builddir', metavar='build', help='the path where to find the meson build directory')


G = parser.parse_args()
#Run meson to fetch all examples
meson_introspect = subprocess.Popen(["meson", "introspect", G.builddir, "--targets"],
      stdout = subprocess.PIPE,
      stderr = subprocess.PIPE,
)
meson_introspect.poll()
build_targets = json.loads(meson_introspect.stdout.read())
examples = [meson_fetch_filename(b["filename"]) for b in build_targets if "examples" in meson_fetch_filename(b["filename"]) and b["type"] == "executable"]
state = State(len(examples))
#simulate all examples in parallel with up to 5 runners
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
  futures = [executor.submit(simulate_example, example) for example in examples]
  for future in concurrent.futures.as_completed(futures):
    example_run = future.result()
    state.add_run(example_run[0], example_run[1], example_run[2])
state.print_summary()