7 import concurrent.futures
12 # preparation calls for the examples
15 def prep_eina_file_02():
16 f = tempfile.NamedTemporaryFile(delete=False)
17 f.write(b"Simulation")
18 return [f.name, "/tmp/copy_file"]
20 def prep_eina_xattr_01():
21 f = tempfile.NamedTemporaryFile(delete=False)
22 f.write(b"Simulation")
23 return ["list", f.name]
25 def 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]
32 def 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]
39 def 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]
46 def 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"]
53 def 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"]
60 example_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,
72 # Holds up the state of the ran examples
76 def __init__(self, examples):
80 self.count_success = 0
81 self.count_err_output = 0
82 print("Found "+str(self.max_n)+" Examples")
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))
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
94 def print_summary(self):
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))
101 # this simulates the startup of the example, and the closing after 1s
104 def simulate_example(example):
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,
115 outs, errs = run.communicate(timeout=2)
116 except Exception as e:
118 return (example, True, -1)
120 return (example, True if b'ERR' in outs or b'ERR' in errs else False, run.poll())
123 parser = argparse.ArgumentParser(description='Run the examples of efl')
124 parser.add_argument('builddir', metavar='build', help='the path where to find the meson build directory')
126 G = parser.parse_args()
127 #Run meson to fetch all examples
128 meson_introspect = subprocess.Popen(["meson", "introspect", G.builddir, "--targets"],
129 stdout = subprocess.PIPE,
130 stderr = subprocess.PIPE,
132 meson_introspect.poll()
133 build_targets = json.loads(meson_introspect.stdout.read())
134 examples = [b["filename"] for b in build_targets if "examples" in b["filename"] and b["type"] == "executable"]
135 state = State(len(examples))
136 #simulate all examples in parallel with up to 5 runners
137 with 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])
142 state.print_summary()