summaryrefslogtreecommitdiff
path: root/examples_checks.py
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-03-08 08:30:52 -0500
committerMike Blumenkrantz <zmike@samsung.com>2019-03-08 08:30:53 -0500
commitc8b67cce988a651f50c6e67925952f75be5b5e8c (patch)
treebd6eb69908a58ccf7bb72a1fe6cdc9ae0b644fe4 /examples_checks.py
parentf4b69b9c4d850fb646e76f376032fbbbff26ca94 (diff)
build: add a new script helper
Summary: This script can be used to run all examples that have been build with meson, this is usefull in order to check if everything works, and checks if (due to some patches) errors are happening in the output. This is not meant as function checking of the whole example, just automatically checking the first-look-appearance. For now a few examples are setted up correctly, there might be more that need setups / custom arguments, they can be added over time. Reviewers: stefan_schmidt, zmike, cedric, q66, devilhorns, segfaultxavi Reviewed By: zmike Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D7979
Diffstat (limited to 'examples_checks.py')
-rwxr-xr-xexamples_checks.py142
1 files changed, 142 insertions, 0 deletions
diff --git a/examples_checks.py b/examples_checks.py
new file mode 100755
index 0000000..fa9badc
--- /dev/null
+++ b/examples_checks.py
@@ -0,0 +1,142 @@
1#!/usr/bin/python3
2import os
3import sys
4import subprocess
5import json
6import time
7import concurrent.futures
8import argparse
9import tempfile
10
11#
12# preparation calls for the examples
13#
14
15def prep_eina_file_02():
16 f = tempfile.NamedTemporaryFile(delete=False)
17 f.write(b"Simulation")
18 return [f.name, "/tmp/copy_file"]
19
20def prep_eina_xattr_01():
21 f = tempfile.NamedTemporaryFile(delete=False)
22 f.write(b"Simulation")
23 return ["list", f.name]
24
25def prep_eina_xattr_02():
26 f1 = tempfile.NamedTemporaryFile(delete=False)
27 f1.write(b"Simulation")
28 f2 = tempfile.NamedTemporaryFile(delete=False)
29 f2.write(b"Simulation2")
30 return [f1.name, f2.name]
31
32def prep_eet_data_simple():
33 f1 = tempfile.NamedTemporaryFile(delete=False)
34 f1.write(b"Simulation")
35 f2 = tempfile.NamedTemporaryFile(delete=False)
36 f2.write(b"Simulation2")
37 return [f1.name, f2.name]
38
39def prep_eet_data_nested():
40 f1 = tempfile.NamedTemporaryFile(delete=False)
41 f1.write(b"Simulation")
42 f2 = tempfile.NamedTemporaryFile(delete=False)
43 f2.write(b"Simulation2")
44 return [f1.name, f2.name]
45
46def prep_eet_data_file_descriptor_01():
47 f1 = tempfile.NamedTemporaryFile(delete=False)
48 f1.write(b"Simulation")
49 f2 = tempfile.NamedTemporaryFile(delete=False)
50 f2.write(b"Simulation2")
51 return [f1.name, f2.name, "acc", "Example-Simulation"]
52
53def prep_eet_data_file_descriptor_02():
54 f1 = tempfile.NamedTemporaryFile(delete=False)
55 f1.write(b"Simulation")
56 f2 = tempfile.NamedTemporaryFile(delete=False)
57 f2.write(b"Simulation2")
58 return [f1.name, f2.name, "union", "5", "Example-Simulation"]
59
60example_preparation = {
61 "eina_file_02" : prep_eina_file_02,
62 "eina_xattr_01" : prep_eina_xattr_01,
63 "eina_xattr_02" : prep_eina_xattr_02,
64 "eet-data-simple" : prep_eet_data_simple,
65 "eet-data-nested" : prep_eet_data_nested,
66 "eet-data-simple" : prep_eet_data_simple,
67 "eet-data-file_descriptor_01" : prep_eet_data_file_descriptor_01,
68 "eet-data-file_descriptor_02" : prep_eet_data_file_descriptor_02,
69}
70
71#
72# Holds up the state of the ran examples
73#
74
75class State:
76 def __init__(self, examples):
77 self.max_n = examples
78 self.n = 1
79 self.count_fail = 0
80 self.count_success = 0
81 self.count_err_output = 0
82 print("Found "+str(self.max_n)+" Examples")
83
84 def add_run(self, command, error_in_output, exitcode):
85 print("{}/{} {} {} {} ".format(self.n, self.max_n, ("SUCCESS" if exitcode == 0 else "FAIL"), ("CLEAN" if error_in_output == False else "ERR"), command))
86 self.n = self.n + 1
87 if exitcode != 0:
88 self.count_fail += 1
89 if error_in_output == True:
90 self.count_err_output += 1
91 if exitcode == 0 and error_in_output == False:
92 self.count_success += 1
93
94 def print_summary(self):
95 print("Summary")
96 print(" Failed: "+str(self.count_fail)+"/"+str(self.max_n))
97 print(" Errored: "+str(self.count_err_output)+"/"+str(self.max_n))
98 print(" Success: "+str(self.count_success)+"/"+str(self.max_n))
99
100#
101# this simulates the startup of the example, and the closing after 1s
102#
103
104def simulate_example(example):
105 args = []
106 if os.path.basename(example) in example_preparation:
107 args = example_preparation[os.path.basename(example)]()
108 run = subprocess.Popen([G.builddir + "/" + example] + args,
109 stdout = subprocess.PIPE,
110 stderr = subprocess.PIPE,
111 )
112 time.sleep(1)
113 run.terminate()
114 try:
115 outs, errs = run.communicate(timeout=2)
116 except Exception as e:
117 run.kill()
118 return (example, True, -1)
119 else:
120 return (example, True if b'ERR' in outs or b'ERR' in errs else False, run.poll())
121
122
123parser = argparse.ArgumentParser(description='Run the examples of efl')
124parser.add_argument('builddir', metavar='build', help='the path where to find the meson build directory')
125
126G = parser.parse_args()
127#Run meson to fetch all examples
128meson_introspect = subprocess.Popen(["meson", "introspect", G.builddir, "--targets"],
129 stdout = subprocess.PIPE,
130 stderr = subprocess.PIPE,
131)
132meson_introspect.poll()
133build_targets = json.loads(meson_introspect.stdout.read())
134examples = [b["filename"] for b in build_targets if "examples" in b["filename"] and b["type"] == "executable"]
135state = State(len(examples))
136#simulate all examples in parallel with up to 5 runners
137with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
138 futures = [executor.submit(simulate_example, example) for example in examples]
139 for future in concurrent.futures.as_completed(futures):
140 example_run = future.result()
141 state.add_run(example_run[0], example_run[1], example_run[2])
142state.print_summary()