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