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-nested" : prep_eet_data_nested,
99 "eet-data-simple" : prep_eet_data_simple,
100 "eet-data-file_descriptor_01" : prep_eet_data_file_descriptor_01,
101 "eet-data-file_descriptor_02" : prep_eet_data_file_descriptor_02,
102 "ecore_getopt_example" : prep_ecore_getopt_example,
103 "eio_file_copy" : prep_eio_file_copy,
104 "eio_file_ls" : prep_eio_file_ls,
105 "edje-color-class" : prep_edje_color_class,
106 "ecore_con_url_headers_example" : prep_ecore_con_url_headers_example,
107 "ecore_con_url_download_example" : prep_ecore_con_url_download_example,
108 "ecore_con_url_cookies_example" : prep_ecore_con_url_cookies_example,
109 "ecore_con_client_example" : prep_ecore_con_client_example,
110 "ecore_con_lookup_example" : prep_ecore_con_lookup_example,
111 "ecore_con_server_example" : prep_ecore_con_server_example,
112 "ecore_con_client_simple_example" : prep_ecore_con_client_simple_example,
116 # Holds up the state of the ran examples
120 def __init__(self, examples):
121 self.max_n = examples
124 self.count_success = 0
125 self.count_err_output = 0
126 print("Found "+str(self.max_n)+" Examples")
128 def add_run(self, command, error_in_output, exitcode):
129 print("{}/{} {} {} {} ".format(self.n, self.max_n, ("SUCCESS" if exitcode == 0 else "FAIL"), ("CLEAN" if error_in_output == False else "ERR"), command))
133 if error_in_output == True:
134 self.count_err_output += 1
135 if exitcode == 0 and error_in_output == False:
136 self.count_success += 1
138 def print_summary(self):
140 print(" Failed: "+str(self.count_fail)+"/"+str(self.max_n))
141 print(" Errored: "+str(self.count_err_output)+"/"+str(self.max_n))
142 print(" Success: "+str(self.count_success)+"/"+str(self.max_n))
145 # this simulates the startup of the example, and the closing after 1s
148 def simulate_example(example):
150 if os.path.basename(example) in example_preparation:
151 args = example_preparation[os.path.basename(example)]()
153 #meson changed behaviour from 0.49 to 0.50 so we need this:
154 if os.path.isabs(example):
155 example_dir = example
157 example_dir = os.path.join(G.builddir, example)
159 run = subprocess.Popen([example_dir] + args,
160 stdout = subprocess.PIPE,
161 stderr = subprocess.PIPE,
166 outs, errs = run.communicate(timeout=2)
167 except Exception as e:
169 return (example, True, -1)
171 return (example, True if b'ERR' in outs or b'ERR' in errs else False, run.poll())
173 #meson changed behaviour from 0.49 to 0.50 so we need this:
174 def meson_fetch_filename(filename_object):
175 if isinstance(filename_object, str):
176 return filename_object
178 return filename_object[0]
181 parser = argparse.ArgumentParser(description='Run the examples of efl')
182 parser.add_argument('builddir', metavar='build', help='the path where to find the meson build directory')
185 G = parser.parse_args()
186 #Run meson to fetch all examples
187 meson_introspect = subprocess.Popen(["meson", "introspect", G.builddir, "--targets"],
188 stdout = subprocess.PIPE,
189 stderr = subprocess.PIPE,
191 meson_introspect.poll()
192 build_targets = json.loads(meson_introspect.stdout.read())
193 examples = [meson_fetch_filename(b["filename"]) for b in build_targets if "examples" in meson_fetch_filename(b["filename"]) and b["type"] == "executable"]
194 state = State(len(examples))
195 #simulate all examples in parallel with up to 5 runners
196 with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
197 futures = [executor.submit(simulate_example, example) for example in examples]
198 for future in concurrent.futures.as_completed(futures):
199 example_run = future.result()
200 state.add_run(example_run[0], example_run[1], example_run[2])
201 state.print_summary()