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