[TC Fixed] Change the 'find' command
[platform/core/dotnet/launcher.git] / tests / TCs / 2_PLUGIN / PLUGIN.py
1 #!/usr/bin/env python3
2 import os, subprocess, sys, argparse
3 sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
4
5 from time import sleep
6 from Utils import *
7
8
9 module_name = "PLUGIN"
10
11 # The `Launcher_TC_PLUGIN_01` application should not have a library of other OS.
12 def TC_01():
13     sln_name = "Launcher_TC_PLUGIN_01.Tizen"
14
15     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
16     if tpk_path == None:
17         return f"FAIL : Get the tpk path for {sln_name}"
18
19     if "OK" not in app_install(f"{tpk_path}"):
20         return f"FAIL : Install the application for {tpk_path}"
21
22     pkg_id = f"org.tizen.example.Launcher_TC_PLUGIN_01.Tizen"
23
24     root_path = get_root_path(f"{pkg_id}")
25     if root_path == "None":
26         return f"FAIL : Get the root path for {pkg_id}"
27
28     raw = cmd(f"shell ls {root_path}/bin/")
29     if ("libHarfBuzzSharp.dylib" in raw) or ("libHarfBuzzSharp.dll" in raw):
30         return "FAIL : Library of other OS should not exist"
31
32     return "PASS"
33
34 # The `Launcher_TC_PLUGIN_02` application must have a library of Tizen OS.
35 def TC_02():
36     sln_name = "Launcher_TC_PLUGIN_02.Tizen"
37
38     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
39     if tpk_path == None:
40         return f"FAIL : Get the tpk path for {sln_name}"
41
42     if "OK" not in app_install(f"{tpk_path}"):
43         return f"FAIL : Install the application for {tpk_path}"
44
45     pkg_id = f"org.tizen.example.Launcher_TC_PLUGIN_02.Tizen"
46
47     root_path = get_root_path(f"{pkg_id}")
48     if root_path == "None":
49         return f"FAIL : Get the root path for {pkg_id}"
50
51     if not exist(f"{root_path}/bin/libSkiaSharp.so"):
52         return "FAIL : The libSkiaSharp.so library should exist in the application"
53
54     if "OK" not in check_library_arch(f"{root_path}", "libSkiaSharp.so"):
55         return "FAIL : The arch of the target and the arch of the library must match"
56
57     return "PASS"
58
59 # The `Launcher_TC_PLUGIN_03` application does not generate native image.
60 def TC_03():
61     if "OK" not in create_spc_ni():
62         return f"FAIL : Create native image for {SPC_DLL}"
63
64     sln_name = "Launcher_TC_PLUGIN_03.Tizen"
65
66     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
67     if tpk_path == None:
68         return f"FAIL : Get the tpk path for {sln_name}"
69
70     if "OK" not in app_install(f"{tpk_path}"):
71         return f"FAIL : Install the application for {tpk_path}"
72
73     pkg_id = f"org.tizen.example.Launcher_TC_PLUGIN_03.Tizen"
74
75     root_path = get_root_path(f"{pkg_id}")
76     if root_path == "None":
77         return f"FAIL : Get the root path for {pkg_id}"
78
79     if exist(f"{root_path}/bin/.native_image"):
80         return "FAIL : The .native_image folder should not exist"
81
82     raw = cmd(f"shell find {root_path}/bin/ -name *.ni.dll")
83     lines = [l for l in raw.splitlines()]
84     if len(lines) != 0:
85         return "FAIL : The .ni.dll files should not exist"
86
87     return "PASS"
88
89 # The `Launcher_TC_PLUGIN_04` application generates native image.
90 def TC_04():
91     if "OK" not in create_spc_ni():
92         return f"FAIL : Create native image for {SPC_DLL}"
93
94     sln_name = "Launcher_TC_PLUGIN_04.Tizen"
95
96     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
97     if tpk_path == None:
98         return f"FAIL : Get the tpk path for {sln_name}"
99
100     if "OK" not in app_install(f"{tpk_path}"):
101         return f"FAIL : Install the application for {tpk_path}"
102
103     pkg_id = f"org.tizen.example.Launcher_TC_PLUGIN_04.Tizen"
104
105     root_path = get_root_path(f"{pkg_id}")
106     if root_path == "None":
107         return f"FAIL : Get the root path for {pkg_id}"
108
109     if not exist(f"{root_path}/bin/.native_image"):
110         return "FAIL : The .native_image folder should exist"
111
112     raw = cmd(f"shell find {root_path}/bin/.native_image/ -name *.ni.dll")
113     lines1 = [l for l in raw.splitlines()]
114     raw = cmd(f"shell find {root_path}/bin/ -maxdepth 1 -name *.dll -not -name *.ni.dll")
115     lines2 = [l for l in raw.splitlines()]
116     if len(lines1) != len(lines2):
117         return "FAIL : The number of .dll and .ni.dll must match in the application"
118
119     for ni in lines1:
120         is_same = False
121         for dll in lines2:
122             if Path(ni).name.replace(".ni.dll", "") == Path(dll).name.replace(".dll", ""):
123                 is_same = True
124                 break
125         if not is_same:
126             return "FAIL : The file name of .dll and .ni.dll must match in the application"
127
128     return "PASS"
129
130 # The `Launcher_TC_PLUGIN_05` application must not have TAC applied.
131 def TC_05():
132     sln_name = "Launcher_TC_PLUGIN_05.Tizen"
133
134     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
135     if tpk_path == None:
136         return f"FAIL : Get the tpk path for {sln_name}"
137
138     if "OK" not in app_install(f"{tpk_path}"):
139         return f"FAIL : Install the application for {tpk_path}"
140
141     pkg_id = f"org.tizen.example.Launcher_TC_PLUGIN_05.Tizen"
142
143     root_path = get_root_path(f"{pkg_id}")
144     if root_path == "None":
145         return f"FAIL : Get the root path for {pkg_id}"
146
147     if exist(f"{root_path}/bin/.tac_symlink"):
148         return "FAIL : The .tac_symlink folder should not exist"
149
150     return "PASS"
151
152 # The `Launcher_TC_PLUGIN_06` application must have TAC applied.
153 def TC_06():
154     sln_name = "Launcher_TC_PLUGIN_06.Tizen"
155
156     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
157     if tpk_path == None:
158         return f"FAIL : Get the tpk path for {sln_name}"
159
160     if "OK" not in app_install(f"{tpk_path}"):
161         return f"FAIL : Install the application for {tpk_path}"
162
163     pkg_id = f"org.tizen.example.Launcher_TC_PLUGIN_06.Tizen"
164
165     root_path = get_root_path(f"{pkg_id}")
166     if root_path == "None":
167         return f"FAIL : Get the root path for {pkg_id}"
168
169     if not exist(f"{root_path}/bin/.tac_symlink"):
170         return "FAIL : The .tac_symlink folder should exist"
171
172     raw = cmd(f"shell find {root_path}/bin/.tac_symlink/ -name *.dll -not -name *.ni.dll")
173     lines1 = [l for l in raw.splitlines()]
174     raw = cmd(f"shell find {DOTNET_DIR}Xamarin.Forms/4.6.0.967/ -name *.dll -not -name *.ni.dll")
175     lines2 = [l for l in raw.splitlines()]
176     if len(lines1) != len(lines2):
177         return "FAIL : The number of .dll in the .tac_symlink and .dll in the TAC must match"
178
179     raw = cmd(f"shell ls -alZ {root_path}/bin/.tac_symlink/*.dll")
180     lines = [l for l in raw.splitlines() if ".ni.dll" not in l]
181     for dll in lines:
182         origin_path = dll.split("->")[1].strip()
183         if not exist(f"{origin_path}"):
184             return "FAIL : The original file of the symbolic link must exist"
185
186     return "PASS"
187
188 # The `Launcher_TC_PLUGIN_07` application must not have TLC applied.
189 def TC_07():
190     sln_name = "Launcher_TC_PLUGIN_07.Tizen"
191
192     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
193     if tpk_path == None:
194         return f"FAIL : Get the tpk path for {sln_name}"
195
196     if "OK" not in app_install(f"{tpk_path}"):
197         return f"FAIL : Install the application for {tpk_path}"
198
199     pkg_id = f"org.tizen.example.Launcher_TC_PLUGIN_07.Tizen"
200
201     root_path = get_root_path(f"{pkg_id}")
202     if root_path == "None":
203         return f"FAIL : Get the root path for {pkg_id}"
204
205     if not exist(f"{root_path}/bin/libSkiaSharp.so"):
206         return "FAIL : The libSkiaSharp.so library should exist only in the application"
207
208     raw = cmd(f"shell ls -alZ {root_path}/bin/libSkiaSharp.so")
209     if "->" in raw:
210         return "FAIL : The libSkiaSharp.so library should not be a symbolic link"
211
212     if "OK" not in check_library_arch(f"{root_path}", "libSkiaSharp.so"):
213         return "FAIL : The arch of the target and the arch of the library must match"
214
215     return "PASS"
216
217 # The `Launcher_TC_PLUGIN_08` application must have TLC applied.
218 def TC_08():
219     sln_name = "Launcher_TC_PLUGIN_08.Tizen"
220
221     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
222     if tpk_path == None:
223         return f"FAIL : Get the tpk path for {sln_name}"
224
225     if "OK" not in app_install(f"{tpk_path}"):
226         return f"FAIL : Install the application for {tpk_path}"
227
228     pkg_id = f"org.tizen.example.Launcher_TC_PLUGIN_08.Tizen"
229
230     root_path = get_root_path(f"{pkg_id}")
231     if root_path == "None":
232         return f"FAIL : Get the root path for {pkg_id}"
233
234     if not exist(f"{root_path}/bin/libSkiaSharp.so"):
235         return "FAIL : The libSkiaSharp.so library should exist in the application"
236
237     raw = cmd(f"shell ls -alZ {root_path}/bin/libSkiaSharp.so")
238     if (f"{root_path}/bin/libSkiaSharp.so" not in raw) or \
239        (f"{DOTNET_DIR}Libraries/libSkiaSharp.so.." not in raw):
240         return "FAIL : The libSkiaSharp.so library should exist or be a symbolic link"
241
242     sha = raw.split("..")[1].rstrip()
243
244     raw = cmd(f"shell find {DOTNET_DIR}Libraries/ -name libSkiaSharp.so*")
245     if sha not in raw:
246         return f"FAIL : The libSkiaSharp.so library should exist in {DOTNET_DIR}"
247
248     if "OK" not in check_library_arch(f"{root_path}", "libSkiaSharp.so"):
249         return "FAIL : The arch of the target and the arch of the library must match"
250
251     return "PASS"
252
253 # Run the test
254 def run():
255     cmd(f"root on")
256     cmd(f"shell mount -o remount,rw /")
257
258     global tpk_list
259     tpk_list = search_tpk(f"{module_name}")
260
261     p = run_tc_array(module_name, tc_array)
262     f = len(tc_array) - p
263     r = round(((p / len(tc_array)) * 100), 2)
264     print(f"--- {module_name} TCT Result ---\nFAIL : [{f}] / PASS : [{p}] - [{r}%]\n")
265
266 # Uninstall the application and restore to original state
267 def clean():
268     cmd(f"uninstall org.tizen.example.Launcher_TC_PLUGIN_01.Tizen")
269     cmd(f"uninstall org.tizen.example.Launcher_TC_PLUGIN_02.Tizen")
270     cmd(f"uninstall org.tizen.example.Launcher_TC_PLUGIN_03.Tizen")
271     cmd(f"uninstall org.tizen.example.Launcher_TC_PLUGIN_04.Tizen")
272     cmd(f"uninstall org.tizen.example.Launcher_TC_PLUGIN_05.Tizen")
273     cmd(f"uninstall org.tizen.example.Launcher_TC_PLUGIN_06.Tizen")
274     cmd(f"uninstall org.tizen.example.Launcher_TC_PLUGIN_07.Tizen")
275     cmd(f"uninstall org.tizen.example.Launcher_TC_PLUGIN_08.Tizen")
276
277 # Main entry point
278 def main():
279     parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter)
280     parser.add_argument("TC_NUMBER", type=str, nargs="*", help="Individual excution")
281     args = parser.parse_args()
282
283     global tc_array
284     if args.TC_NUMBER and "TC_" in args.TC_NUMBER[0]:
285         tc_array = []
286         for tc_num in args.TC_NUMBER:
287             if tc_num not in funcMap:
288                 print(f"There is no {tc_num} test.")
289                 exit(1)
290             else:
291                 tc_array.append(funcMap[tc_num])
292     else:
293         tc_array = [TC_01, TC_02, TC_03, TC_04, TC_05, TC_06, TC_07, TC_08]
294
295     global serial
296     if len(sys.argv) >= 2 and "TC_" not in sys.argv[1]:
297         serial = read_serial(sys.argv[1])
298     else:
299         serial = read_serial(None)
300
301     if serial is None:
302         print("No connected device(s).")
303         exit(1)
304
305     device = get_device_type()
306     print(f"=== Dotnet-Launcher [{device}] Test Case - ({module_name}) ===")
307
308     run()
309     clean()
310
311
312 funcMap = {
313 'TC_01': TC_01, 'TC_02': TC_02, 'TC_03': TC_03, 'TC_04': TC_04, 'TC_05': TC_05, 'TC_06': TC_06, 'TC_07': TC_07, 'TC_08': TC_08,
314 'PLUGIN_TC_01': TC_01, 'PLUGIN_TC_02': TC_02, 'PLUGIN_TC_03': TC_03, 'PLUGIN_TC_04': TC_04,
315 'PLUGIN_TC_05': TC_05, 'PLUGIN_TC_06': TC_06, 'PLUGIN_TC_07': TC_07, 'PLUGIN_TC_08': TC_08
316 }
317
318
319 if __name__ == "__main__":
320     try:
321         main()
322     except KeyboardInterrupt:
323         print("\nExit (Pressed Ctrl+C)")
324         exit(1)