6 import concurrent.futures
11 # preparation calls for the examples
14 def prep_eina_file_02():
15 f = tempfile.NamedTemporaryFile(delete=False)
16 f.write(b"Simulation")
17 return [f.name, "/tmp/copy_file"]
19 def prep_eina_xattr_01():
20 f = tempfile.NamedTemporaryFile(delete=False)
21 f.write(b"Simulation")
22 return ["list", f.name]
24 def prep_eina_xattr_02():
25 f1 = tempfile.NamedTemporaryFile(delete=False)
26 f1.write(b"Simulation")
27 f2 = tempfile.NamedTemporaryFile(delete=False)
28 f2.write(b"Simulation2")
29 return [f1.name, f2.name]
31 def prep_eet_data_simple():
32 f1 = tempfile.NamedTemporaryFile(delete=False)
33 f1.write(b"Simulation")
34 f2 = tempfile.NamedTemporaryFile(delete=False)
35 f2.write(b"Simulation2")
36 return [f1.name, f2.name]
38 def prep_eet_data_nested():
39 f1 = tempfile.NamedTemporaryFile(delete=False)
40 f1.write(b"Simulation")
41 f2 = tempfile.NamedTemporaryFile(delete=False)
42 f2.write(b"Simulation2")
43 return [f1.name, f2.name]
45 def prep_eet_data_file_descriptor_01():
46 f1 = tempfile.NamedTemporaryFile(delete=False)
47 f1.write(b"Simulation")
48 f2 = tempfile.NamedTemporaryFile(delete=False)
49 f2.write(b"Simulation2")
50 return [f1.name, f2.name, "acc", "Example-Simulation"]
52 def prep_eet_data_file_descriptor_02():
53 f1 = tempfile.NamedTemporaryFile(delete=False)
54 f1.write(b"Simulation")
55 f2 = tempfile.NamedTemporaryFile(delete=False)
56 f2.write(b"Simulation2")
57 return [f1.name, f2.name, "union", "5", "Example-Simulation"]
59 def prep_ecore_getopt_example():
60 return ["string-1", "120", "apple", "none-optional-arg"]
62 def prep_eio_file_copy():
63 f1 = tempfile.NamedTemporaryFile(delete=False)
64 f1.write(b"Simulation")
65 return [f1.name, "/tmp/eio_dst_file"]
67 def prep_eio_file_ls():
70 def prep_edje_color_class():
71 return ["beta", "red", "green", "blue"]
73 def prep_ecore_con_url_headers_example():
74 return ["GET", "www.enlightenment.org"]
76 def prep_ecore_con_url_download_example():
77 return ["www.enlightenment.org"]
79 def prep_ecore_con_url_cookies_example():
80 return ["www.enlightenment.org"]
82 def prep_ecore_con_client_example():
83 return ["enlightenment.org", "80"]
85 def prep_ecore_con_lookup_example():
86 return ["enlightenment.org"]
88 def prep_ecore_con_server_example():
89 return ["enlightenment.org", "1234"]
91 def prep_ecore_con_client_simple_example():
92 return ["enlightenment.org", "80"]
94 example_preparation = {
95 "eina_file_02" : prep_eina_file_02,
96 "eina_xattr_01" : prep_eina_xattr_01,
97 "eina_xattr_02" : prep_eina_xattr_02,
98 "eet-data-simple" : prep_eet_data_simple,
99 "eet-data-nested" : prep_eet_data_nested,
100 "eet-data-simple" : prep_eet_data_simple,
101 "eet-data-file_descriptor_01" : prep_eet_data_file_descriptor_01,
102 "eet-data-file_descriptor_02" : prep_eet_data_file_descriptor_02,
103 "ecore_getopt_example" : prep_ecore_getopt_example,
104 "eio_file_copy" : prep_eio_file_copy,
105 "eio_file_ls" : prep_eio_file_ls,
106 "edje-color-class" : prep_edje_color_class,
107 "ecore_con_url_headers_example" : prep_ecore_con_url_headers_example,
108 "ecore_con_url_download_example" : prep_ecore_con_url_download_example,
109 "ecore_con_url_cookies_example" : prep_ecore_con_url_cookies_example,
110 "ecore_con_client_example" : prep_ecore_con_client_example,
111 "ecore_con_lookup_example" : prep_ecore_con_lookup_example,
112 "ecore_con_server_example" : prep_ecore_con_server_example,
113 "ecore_con_client_simple_example" : prep_ecore_con_client_simple_example,
117 # Holds up the state of the ran examples
121 def __init__(self, examples):
122 self.max_n = examples
125 self.count_success = 0
126 self.count_err_output = 0
127 print("Found "+str(self.max_n)+" Examples")
129 def add_run(self, command, error_in_output, exitcode):
130 print("{}/{} {} {} {} ".format(self.n, self.max_n, ("SUCCESS" if exitcode == 0 else "FAIL"), ("CLEAN" if error_in_output == False else "ERR"), command))
134 if error_in_output == True:
135 self.count_err_output += 1
136 if exitcode == 0 and error_in_output == False:
137 self.count_success += 1
139 def print_summary(self):
141 print(" Failed: "+str(self.count_fail)+"/"+str(self.max_n))
142 print(" Errored: "+str(self.count_err_output)+"/"+str(self.max_n))
143 print(" Success: "+str(self.count_success)+"/"+str(self.max_n))
146 # this simulates the startup of the example, and the closing after 1s
149 def simulate_example(example):
151 if os.path.basename(example) in example_preparation:
152 args = example_preparation[os.path.basename(example)]()
154 #meson changed behaviour from 0.49 to 0.50 so we need this:
155 if os.path.isabs(example):
156 example_dir = example
158 example_dir = os.path.join(G.builddir, example)
160 run = subprocess.Popen([example_dir] + args,
161 stdout = subprocess.PIPE,
162 stderr = subprocess.PIPE,
167 outs, errs = run.communicate(timeout=2)
168 except Exception as e:
170 return (example, True, -1)
172 return (example, True if b'ERR' in outs or b'ERR' in errs else False, run.poll())
174 #meson changed behaviour from 0.49 to 0.50 so we need this:
175 def meson_fetch_filename(filename_object):
176 if isinstance(filename_object, str):
177 return filename_object
179 return filename_object[0]
182 parser = argparse.ArgumentParser(description='Run the examples of efl')
183 parser.add_argument('builddir', metavar='build', help='the path where to find the meson build directory')
186 G = parser.parse_args()
187 #Run meson to fetch all examples
188 meson_introspect = subprocess.Popen(["meson", "introspect", G.builddir, "--targets"],
189 stdout = subprocess.PIPE,
190 stderr = subprocess.PIPE,
192 meson_introspect.poll()
193 build_targets = json.loads(meson_introspect.stdout.read())
194 examples = [meson_fetch_filename(b["filename"]) for b in build_targets if "examples" in meson_fetch_filename(b["filename"]) and b["type"] == "executable"]
195 state = State(len(examples))
196 #simulate all examples in parallel with up to 5 runners
197 with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
198 futures = [executor.submit(simulate_example, example) for example in examples]
199 for future in concurrent.futures.as_completed(futures):
200 example_run = future.result()
201 state.add_run(example_run[0], example_run[1], example_run[2])
202 state.print_summary()