Add options to support crossgen2 (#351)
[platform/core/dotnet/launcher.git] / tests / TCs / 6_TOOL / TOOL.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 pathlib import Path
7 from Utils import *
8
9
10 module_name = "TOOL"
11
12 # The `dotnettool` works normally.
13 def TC_01():
14     if not exist("/usr/bin/dotnettool"):
15         return "FAIL : The dotnettool works normally"
16
17     raw = cmd(f"shell dotnettool")
18     if "Dotnet Tool Version: 1.0" not in raw:
19         return "FAIL : The dotnettool works normally"
20
21     return "PASS"
22
23 # The `native image` is generated normally.
24 def TC_02():
25     cmd(f"shell dotnettool --ni-system")
26
27     if not exist(f"{RUNTIME_DIR}{SPC_DLL}.Backup"):
28         return "FAIL : Create the platform native image"
29
30     raw = cmd(f"shell find {RUNTIME_DIR} -name *.ni.dll")
31     lines1 = [l for l in raw.splitlines()]
32     len1 = len(lines1) + 1 # System.Private.CoreLib.dll
33     raw = cmd(f"shell find {RUNTIME_DIR} -maxdepth 1 -name *.dll -not -name *.ni.dll")
34     lines2 = [l for l in raw.splitlines()]
35     len2 = len(lines2)
36     if len1 != len2:
37         return f"FAIL : The number of .dll({len2}) and .ni.dll({len1}) must match in the {RUNTIME_DIR}"
38
39     raw = cmd(f"shell find {FRAMEWORK_DIR} -name *.ni.dll")
40     lines1 = [l for l in raw.splitlines()]
41     len1 = len(lines1)
42     raw = cmd(f"shell find {FRAMEWORK_DIR} -name *.dll -not -name *.ni.dll")
43     lines2 = [l for l in raw.splitlines() if "/ref/" not in l]
44     len2 = len(lines2)
45     if len1 != len2:
46         return f"FAIL : The number of .dll({len2}) and .ni.dll({len1}) must match in the {FRAMEWORK_DIR}"
47
48     for ni in lines1:
49         is_same = False
50         for dll in lines2:
51             if Path(ni).name.replace(".ni.dll", "") == Path(dll).name.replace(".dll", ""):
52                 is_same = True
53                 break
54         if not is_same:
55             return "FAIL : The file name of .dll and .ni.dll must match in the platform"
56
57     return "PASS"
58
59 # Remove the `platform` native image.
60 def TC_03():
61     cmd(f"shell dotnettool --ni-reset-system")
62
63     if exist(f"{RUNTIME_DIR}{SPC_DLL}.Backup"):
64         return "FAIL : Remove the platform native image"
65
66     return "PASS"
67
68 # Create native image for `System.Private.CoreLib.dll`.
69 def TC_04():
70     if exist(f"{RUNTIME_DIR}{SPC_DLL}.Backup"):
71         cmd(f"shell rm {RUNTIME_DIR}{SPC_DLL}")
72         cmd(f"shell mv {RUNTIME_DIR}{SPC_DLL}.Backup {RUNTIME_DIR}{SPC_DLL}")
73
74     raw = cmd(f"shell dotnettool --ni-dll {RUNTIME_DIR}{SPC_DLL}")
75     if (f"{SPC_DLL}" not in raw) or \
76        ("System.Private.CoreLib.dll generated successfully." not in raw):
77         return f"FAIL : Create native image for {SPC_DLL}"
78
79     if not exist(f"{RUNTIME_DIR}{SPC_DLL}.Backup"):
80         return f"FAIL : Create native image for {SPC_DLL}"
81
82     return "PASS"
83
84 # The file name of `.dll` and `.ni.dll` must match in the framework.
85 def TC_05():
86     cmd(f"shell dotnettool --ni-dir {FRAMEWORK_DIR}")
87     raw = cmd(f"shell find {FRAMEWORK_DIR} -name *.ni.dll")
88     lines1 = [l for l in raw.splitlines()]
89     raw = cmd(f"shell find {FRAMEWORK_DIR} -name *.dll -not -name *.ni.dll")
90     lines2 = [l for l in raw.splitlines() if "/ref/" not in l]
91     if len(lines1) != len(lines2):
92         return "FAIL : The number of .dll and .ni.dll must match"
93
94     for ni in lines1:
95         is_same = False
96         for dll in lines2:
97             if Path(ni).name.replace(".ni.dll", "") == Path(dll).name.replace(".dll", ""):
98                 is_same = True
99                 break
100         if not is_same:
101             return "FAIL : The file name of .dll and .ni.dll must match in the {FRAMEWORK_DIR}"
102
103     return "PASS"
104
105 # The `.ni.dll` files should not exist in the framework.
106 def TC_06():
107     cmd(f"shell dotnettool --ni-reset-dir {FRAMEWORK_DIR}")
108     raw = cmd(f"shell find {FRAMEWORK_DIR} -name *.ni.dll")
109     lines = [l for l in raw.splitlines()]
110     if len(lines) != 0:
111         return "FAIL : The .ni.dll files should not exist"
112
113     return "PASS"
114
115 # Create native image for Tizen.dll in `R2R` mode.
116 def TC_07():
117     raw = cmd(f"shell dotnettool --r2r --ni-dll {FRAMEWORK_DIR}Tizen.dll")
118     if ("Tizen.dll" not in raw) or \
119        ("Tizen.ni.dll generated successfully." not in raw):
120         return "FAIL : Create native image for Tizen.dll in R2R mode"
121
122     return "PASS"
123
124 # Displays detailed information while creating native image for Tizen.Log.dll.
125 def TC_08():
126     raw = cmd(f"shell dotnettool --verbose --ni-dll {FRAMEWORK_DIR}Tizen.Log.dll")
127     if ("Tizen.Log.ni.dll generated successfully." not in raw):
128         return "FAIL : Displays detailed information while creating native image for Tizen.Log.dll"
129
130     return "PASS"
131
132 # Create a native image for netstandard.dll by specifying the directory containing the IBC files.
133 def TC_09():
134     packaging_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../packaging"))
135     ibcdata_zip = ""
136
137     raw = cmd("capability")
138     line = [l for l in raw.splitlines() if "cpu_arch" in l]
139     target_arch = line[0].split(":")[1]
140     if ("armv7" == target_arch) or \
141        ("x86" == target_arch):
142         ibcdata_zip = "ibcdata_arm.zip"
143     else:
144         ibcdata_zip = "ibcdata_aarch64.zip"
145
146     cmd(f"push {packaging_path}/{ibcdata_zip} /tmp")
147     cmd(f"shell unzip /tmp/{ibcdata_zip} -d {IBCDATA_DIR}")
148     cmd(f"shell chsmack -a _ {IBCDATA_DIR} -r")
149
150     if not exist(f"{IBCDATA_DIR}netstandard.ibc"):
151         return "FAIL : The netstandard.ibc file should exist"
152
153     raw = cmd(f"shell dotnettool --ibc-dir /usr/share/dotnet.tizen/ibcdata/ --ni-dll {RUNTIME_DIR}netstandard.dll")
154     if ("netstandard.dll" not in raw) or \
155        ("netstandard.ni.dll generated successfully." not in raw):
156         return "FAIL : Create native image for netstandard.dll"
157
158     return "PASS"
159
160 # The `Launcher_TC_TOOL_01` application does not have native image.
161 def TC_10():
162     sln_name = "Launcher_TC_TOOL_01.Tizen"
163
164     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
165     if tpk_path == None:
166         return f"FAIL : Get the tpk path for {sln_name}"
167
168     if "OK" not in app_install(f"{tpk_path}"):
169         return f"FAIL : Install the application for {tpk_path}"
170
171     pkg_id = f"org.tizen.example.Launcher_TC_TOOL_01.Tizen"
172
173     root_path = get_root_path(f"{pkg_id}")
174     if root_path == "None":
175         return f"FAIL : Get the root path for {pkg_id}"
176
177     if not exist(f"{root_path}/bin/.native_image"):
178         return "FAIL : The .native_image folder should exist"
179
180     cmd(f"shell dotnettool --ni-reset-pkg {pkg_id}")
181
182     if exist(f"{root_path}/bin/.native_image"):
183         return "FAIL : The .native_image folder should not exist"
184
185     raw = cmd(f"shell find {root_path}/bin/ -name *.ni.dll")
186     lines = [l for l in raw.splitlines()]
187     if len(lines) != 0:
188         return "FAIL : The .ni.dll files should not exist"
189
190     return "PASS"
191
192 # The `Launcher_TC_TOOL_02` application generates native image.
193 def TC_11():
194     sln_name = "Launcher_TC_TOOL_02.Tizen"
195
196     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
197     if tpk_path == None:
198         return f"FAIL : Get the tpk path for {sln_name}"
199
200     if "OK" not in app_install(f"{tpk_path}"):
201         return f"FAIL : Install the application for {tpk_path}"
202
203     pkg_id = f"org.tizen.example.Launcher_TC_TOOL_02.Tizen"
204
205     root_path = get_root_path(f"{pkg_id}")
206     if root_path == "None":
207         return f"FAIL : Get the root path for {pkg_id}"
208
209     if exist(f"{root_path}/bin/.native_image"):
210         return "FAIL : The .native_image folder not should exist"
211
212     cmd(f"shell dotnettool --ni-pkg {pkg_id}")
213
214     if not exist(f"{root_path}/bin/.native_image"):
215         return "FAIL : The .native_image folder should exist"
216
217     raw = cmd(f"shell find {root_path}/bin/.native_image/ -name *.ni.dll")
218     lines1 = [l for l in raw.splitlines()]
219     raw = cmd(f"shell find {root_path}/bin/ -maxdepth 1 -name *.dll -not -name *.ni.dll")
220     lines2 = [l for l in raw.splitlines()]
221     if len(lines1) != len(lines2):
222         return "FAIL : The number of .dll and .ni.dll must match in the application"
223
224     for ni in lines1:
225         is_same = False
226         for dll in lines2:
227             if Path(ni).name.replace(".ni.dll", "") == Path(dll).name.replace(".dll", ""):
228                 is_same = True
229                 break
230         if not is_same:
231             return "FAIL : The file name of .dll and .ni.dll must match in the application"
232
233     return "PASS"
234
235 # The `prefer_dotnet_aot` metadata value of `true` will regenerates the native image in all .NET applications.
236 def TC_12():
237     sln_name = "Launcher_TC_TOOL_03.Tizen"
238
239     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
240     if tpk_path == None:
241         return f"FAIL : Get the tpk path for {sln_name}"
242
243     if "OK" not in app_install(f"{tpk_path}"):
244         return f"FAIL : Install the application for {tpk_path}"
245
246     cmd(f"shell dotnettool --ni-regen-all-app")
247
248     raw = subprocess.run((f"sdb -s {serial} shell pkginfo --metadata-flt").split(), stdout=subprocess.PIPE, input=f"http://tizen.org/metadata/prefer_dotnet_aot\ntrue\n", encoding="utf-8").stdout
249     lines = [l for l in raw.splitlines() if "appid" in l]
250     for app in lines:
251         pkg_id = app.split(": ")[1]
252         raw = subprocess.run((f"sdb -s {serial} shell pkginfo --pkg {pkg_id}").split(), stdout=subprocess.PIPE, encoding="utf-8").stdout
253         readonly = [l for l in raw.splitlines() if "Readonly" in l]
254         if "0" == readonly[0].split(": ")[1]:
255             path = [l for l in raw.splitlines() if "root_path" in l]
256             root_path = path[0].split(": ")[1]
257             raw = cmd(f"shell find {root_path}/bin/.native_image/ -name *.ni.dll")
258             lines1 = [l for l in raw.splitlines()]
259             raw = cmd(f"shell find {root_path}/bin/ -maxdepth 1 -name *.dll -not -name *.ni.dll")
260             lines2 = [l for l in raw.splitlines()]
261             if len(lines1) != len(lines2):
262                 return "FAIL : The number of .dll and .ni.dll must match in the application"
263
264             for ni in lines1:
265                 is_same = False
266                 for dll in lines2:
267                     if Path(ni).name.replace(".ni.dll", "") == Path(dll).name.replace(".dll", ""):
268                         is_same = True
269                         break
270                 if not is_same:
271                     return "FAIL : The file name of .dll and .ni.dll must match in the application"
272
273     return "PASS"
274
275 # The `prefer_nuget_cache` metadata value of `true` will regenerates the native image in the `TAC`.
276 def TC_13():
277     sln_name = "Launcher_TC_TOOL_04.Tizen"
278
279     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
280     if tpk_path == None:
281         return f"FAIL : Get the tpk path for {sln_name}"
282
283     if "OK" not in app_install(f"{tpk_path}"):
284         return f"FAIL : Install the application for {tpk_path}"
285
286     raw = cmd(f"shell dotnettool --tac-regen-all")
287     if (".dll" not in raw) or \
288        (".ni.dll generated successfully." not in raw):
289         return "FAIL : Create native image for TAC"
290
291     return "PASS"
292
293 # The `Launcher_TC_TOOL_05` application must not have `TAC` applied.
294 def TC_14():
295     sln_name = "Launcher_TC_TOOL_05.Tizen"
296
297     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
298     if tpk_path == None:
299         return f"FAIL : Get the tpk path for {sln_name}"
300
301     if "OK" not in app_install(f"{tpk_path}"):
302         return f"FAIL : Install the application for {tpk_path}"
303
304     pkg_id = f"org.tizen.example.Launcher_TC_TOOL_05.Tizen"
305
306     root_path = get_root_path(f"{pkg_id}")
307     if root_path == "None":
308         return f"FAIL : Get the root path for {pkg_id}"
309
310     if not exist(f"{root_path}/bin/.tac_symlink"):
311         return "FAIL : The .tac_symlink folder should exist"
312
313     raw = cmd(f"shell find {root_path}/bin/.tac_symlink/ -name *.dll -not -name *.ni.dll")
314     lines1 = [l for l in raw.splitlines()]
315     raw = cmd(f"shell find {DOTNET_DIR}Xamarin.Forms/4.6.0.967/ -name *.dll -not -name *.ni.dll")
316     lines2 = [l for l in raw.splitlines()]
317     if len(lines1) != len(lines2):
318         return "FAIL : The number of .dll in the .tac_symlink and .dll in the TAC must match"
319
320     raw = cmd(f"shell ls -alZ {root_path}/bin/.tac_symlink/*.dll")
321     lines = [l for l in raw.splitlines() if ".ni.dll" not in l]
322     for dll in lines:
323         origin_path = dll.split("->")[1].strip()
324         if not exist(f"{origin_path}"):
325             return "FAIL : The original file of the symbolic link must exist"
326
327     cmd(f"shell dotnettool --tac-disable-pkg {pkg_id}")
328
329     if exist(f"{root_path}/bin/.tac_symlink"):
330         return "FAIL : The .tac_symlink folder should not exist"
331
332     raw = cmd(f"shell find {root_path}/bin/ -maxdepth 1 -name *.dll -not -name *.ni.dll")
333     lines = [l for l in raw.splitlines()]
334     if len(lines) != 6:
335         return "FAIL : The number of .dll must exist correctly in the bin folder"
336
337     return "PASS"
338
339 # The `Launcher_TC_TOOL_06` application must have `TAC` applied.
340 def TC_15():
341     sln_name = "Launcher_TC_TOOL_06.Tizen"
342
343     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
344     if tpk_path == None:
345         return f"FAIL : Get the tpk path for {sln_name}"
346
347     if "OK" not in app_install(f"{tpk_path}"):
348         return f"FAIL : Install the application for {tpk_path}"
349
350     pkg_id = f"org.tizen.example.Launcher_TC_TOOL_06.Tizen"
351
352     root_path = get_root_path(f"{pkg_id}")
353     if root_path == "None":
354         return f"FAIL : Get the root path for {pkg_id}"
355
356     cmd(f"shell dotnettool --tac-disable-pkg {pkg_id}")
357
358     if exist(f"{root_path}/bin/.tac_symlink"):
359         return "FAIL : The .tac_symlink folder should not exist"
360
361     raw = cmd(f"shell find {root_path}/bin/ -maxdepth 1 -name *.dll -not -name *.ni.dll")
362     lines = [l for l in raw.splitlines()]
363     if len(lines) != 6:
364         return "FAIL : The number of .dll must exist correctly in the bin folder"
365
366     cmd(f"shell dotnettool --tac-enable-pkg {pkg_id}")
367
368     if not exist(f"{root_path}/bin/.tac_symlink"):
369         return "FAIL : The .tac_symlink folder should exist"
370
371     raw = cmd(f"shell find {root_path}/bin/.tac_symlink/ -name *.dll -not -name *.ni.dll")
372     lines1 = [l for l in raw.splitlines()]
373     raw = cmd(f"shell find {DOTNET_DIR}Xamarin.Forms/4.6.0.967/ -name *.dll -not -name *.ni.dll")
374     lines2 = [l for l in raw.splitlines()]
375     if len(lines1) != len(lines2):
376         return "FAIL : The number of .dll in the .tac_symlink and .dll in the TAC must match"
377
378     raw = cmd(f"shell ls -alZ {root_path}/bin/.tac_symlink/*.dll")
379     lines = [l for l in raw.splitlines() if ".ni.dll" not in l]
380     for dll in lines:
381         origin_path = dll.split("->")[1].strip()
382         if not exist(f"{origin_path}"):
383             return "FAIL : The original file of the symbolic link must exist"
384
385     return "PASS"
386
387 # The `DB` of the restored `TAC` and `TLC` must be a valid value.
388 def TC_16():
389     sln_name = "Launcher_TC_TOOL_07.Tizen"
390
391     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
392     if tpk_path == None:
393         return f"FAIL : Get the tpk path for {sln_name}"
394
395     if "OK" not in app_install(f"{tpk_path}"):
396         return f"FAIL : Install the application for {tpk_path}"
397
398     cmd(f"shell rm {DOTNET_DIR}.TAC.App.list.db*")
399     cmd(f"shell rm {DOTNET_DIR}.TLC.App.list.db*")
400
401     cmd(f"shell dotnettool --tac-restore-db")
402
403     pkg_id = f"org.tizen.example.Launcher_TC_TOOL_07.Tizen"
404
405     raw = subprocess.run((f"sdb -s {serial} shell sqlite3 {DOTNET_DIR}.TAC.App.list.db").split(), stdout=subprocess.PIPE, input=f"select * from TAC;\n.q\n", encoding="utf-8").stdout
406     lines = [l for l in raw.splitlines() if f"{pkg_id}" in l]
407     for rcd in lines:
408         is_exist = False
409         if ("SkiaSharp/2.80.2" in rcd) or \
410            ("Xamarin.Forms/4.6.0.967" in rcd):
411             is_exist = True
412             continue
413         if not is_exist:
414             return "FAIL : TAC database must have a valid value"
415
416     raw = subprocess.run((f"sdb -s {serial} shell sqlite3 {DOTNET_DIR}.TLC.App.list.db").split(), stdout=subprocess.PIPE, input=f"select * from TLC;\n.q\n", encoding="utf-8").stdout
417     lines = [l for l in raw.splitlines() if f"{pkg_id}" in l]
418     for rcd in lines:
419         if "libSkiaSharp.so..8e2fcc43f9c49b2de7b6212ff5ed914b319bc92f125715b9fe1f35786df82f98" not in rcd:
420             return "FAIL : TLC database must have a valid value"
421
422     return "PASS"
423
424 # The prefer_dotnet_aot metadata value of true will regenerates the native image in all .NET applications of read-only type.
425 def TC_17():
426     sln_name = "Launcher_TC_TOOL_08.Tizen"
427
428     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
429     if tpk_path == None:
430         return f"FAIL : Get the tpk path for {sln_name}"
431
432     cmd(f"shell mount -o remount,rw /")
433
434     raw = cmd(f"push {tpk_path} /usr/apps/.preload-tpk/")
435     if "1 file(s) pushed. 0 file(s) skipped." in raw:
436         cmd(f"shell install_preload_pkg")
437
438     cmd(f"shell mount -o remount,ro /")
439
440     cmd(f"shell dotnettool --ni-regen-all-app")
441
442     raw = subprocess.run((f"sdb -s {serial} shell pkginfo --metadata-flt").split(), stdout=subprocess.PIPE, input=f"http://tizen.org/metadata/prefer_dotnet_aot\ntrue\n", encoding="utf-8").stdout
443     lines = [l for l in raw.splitlines() if "appid" in l]
444     for app in lines:
445         pkg_id = app.split(": ")[1]
446         raw = subprocess.run((f"sdb -s {serial} shell pkginfo --pkg {pkg_id}").split(), stdout=subprocess.PIPE, encoding="utf-8").stdout
447         readonly = [l for l in raw.splitlines() if "Readonly" in l]
448         if "1" == readonly[0].split(": ")[1]:
449             path = [l for l in raw.splitlines() if "root_path" in l]
450             root_path = path[0].split(": ")[1]
451             raw = cmd(f"shell find {DOTNET_DIR}apps/{pkg_id}/bin/.native_image/ -name *.ni.dll")
452             lines1 = [l for l in raw.splitlines()]
453             raw = cmd(f"shell find {root_path}/bin/ -maxdepth 1 -name *.dll -not -name *.ni.dll")
454             lines2 = [l for l in raw.splitlines()]
455             if len(lines1) != len(lines2):
456                 return "FAIL : The number of .dll and .ni.dll must match in the application"
457
458             for ni in lines1:
459                 is_same = False
460                 for dll in lines2:
461                     if Path(ni).name.replace(".ni.dll", "") == Path(dll).name.replace(".dll", ""):
462                         is_same = True
463                         break
464                 if not is_same:
465                     return "FAIL : The file name of .dll and .ni.dll must match in the application"
466
467     return "PASS"
468
469 # The `Launcher_TC_TOOL_08` application should load the newly generated native image.
470 def TC_18():
471     pkg_id = f"org.tizen.example.Launcher_TC_TOOL_08.Tizen"
472
473     pid = launch_and_get_pid(f"-e", f"{pkg_id}")
474     if 0 == pid:
475         return f"FAIL : Get the pid for {pkg_id}"
476
477     raw = cmd(f"shell cat /proc/{pid}/smaps | grep Xamarin.Forms.*.dll")
478     if (f"{DOTNET_DIR}apps/{pkg_id}/bin/.native_image/Xamarin.Forms.Platform.Tizen.ni.dll" not in raw) or \
479        (f"{DOTNET_DIR}apps/{pkg_id}/bin/.native_image/Xamarin.Forms.Core.ni.dll" not in raw) or \
480        (f"{DOTNET_DIR}apps/{pkg_id}/bin/.native_image/Xamarin.Forms.Platform.ni.dll" not in raw):
481         return "FAIL : The Xamarin.Forms in the application should be loaded when running the application"
482
483     cmd(f"shell app_launcher -t {pkg_id}")
484
485     return "PASS"
486
487 # It should be done together for update test.
488 def TC_17_18():
489     ret = TC_17()
490     if "PASS" != ret:
491         return f"{ret}"
492
493     ret = TC_18()
494     if  "PASS" != ret:
495         return f"{ret}"
496
497     return "PASS"
498
499 # The `Launcher_TC_TOOL_09` application of read-only type generates native image.
500 def TC_19():
501     sln_name = "Launcher_TC_TOOL_09.Tizen"
502
503     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
504     if tpk_path == None:
505         return f"FAIL : Get the tpk path for {sln_name}"
506
507     cmd(f"shell mount -o remount,rw /")
508     raw = cmd(f"push {tpk_path} /usr/apps/.preload-tpk/")
509     if "1 file(s) pushed. 0 file(s) skipped." in raw:
510         cmd(f"shell install_preload_pkg")
511     cmd(f"shell mount -o remount,ro /")
512
513     pkg_id = f"org.tizen.example.Launcher_TC_TOOL_09.Tizen"
514
515     root_path = get_root_path(f"{pkg_id}")
516     if root_path == "None":
517         return f"FAIL : Get the root path for {pkg_id}"
518
519     if exist(f"{root_path}/bin/.native_image"):
520         return "FAIL : The .native_image folder not should exist"
521
522     cmd(f"shell dotnettool --ni-pkg {pkg_id}")
523
524     if not exist(f"{DOTNET_DIR}apps/{pkg_id}/bin/.native_image"):
525         return "FAIL : The .native_image folder should exist"
526
527     raw = cmd(f"shell find {DOTNET_DIR}apps/{pkg_id}/bin/.native_image/ -name *.ni.dll")
528     lines1 = [l for l in raw.splitlines()]
529     raw = cmd(f"shell find {root_path}/bin/ -maxdepth 1 -name *.dll -not -name *.ni.dll")
530     lines2 = [l for l in raw.splitlines()]
531     if len(lines1) != len(lines2):
532         return "FAIL : The number of .dll and .ni.dll must match in the application"
533
534     for ni in lines1:
535         is_same = False
536         for dll in lines2:
537             if Path(ni).name.replace(".ni.dll", "") == Path(dll).name.replace(".dll", ""):
538                 is_same = True
539                 break
540         if not is_same:
541             return "FAIL : The file name of .dll and .ni.dll must match in the application"
542
543     return "PASS"
544
545 #def TC_20():
546 #dotnettool --resolve-all-app
547
548
549 # Run the test
550 def run():
551     cmd(f"root on")
552     cmd(f"shell mount -o remount,rw /")
553
554     global tpk_list
555     tpk_list = search_tpk(f"{module_name}")
556
557     pn = run_tc_array(module_name, tc_array)
558     n = int(pn.split(":")[0])
559     f = int(pn.split(":")[1])
560     p = int(pn.split(":")[2])
561     r = 0.0
562     if (len(tc_array) - n) != 0:
563         r = round(((p / (len(tc_array) - n)) * 100), 2)
564     print(f"--- {module_name} TCT Result ---\nNONE : [{n}] / FAIL : [{f}] / PASS : [{p}] - [{r}%]\n")
565
566 # Uninstall the application and restore to original state
567 def clean():
568     cmd(f"uninstall org.tizen.example.Launcher_TC_TOOL_01.Tizen")
569     cmd(f"uninstall org.tizen.example.Launcher_TC_TOOL_02.Tizen")
570     cmd(f"uninstall org.tizen.example.Launcher_TC_TOOL_03.Tizen")
571     cmd(f"uninstall org.tizen.example.Launcher_TC_TOOL_04.Tizen")
572     cmd(f"uninstall org.tizen.example.Launcher_TC_TOOL_05.Tizen")
573     cmd(f"uninstall org.tizen.example.Launcher_TC_TOOL_06.Tizen")
574     cmd(f"uninstall org.tizen.example.Launcher_TC_TOOL_07.Tizen")
575
576     cmd(f"shell rm {FRAMEWORK_DIR}Tizen.ni.dll")
577     cmd(f"shell rm {FRAMEWORK_DIR}Tizen.Log.ni.dll")
578     cmd(f"shell rm {RUNTIME_DIR}netstandard.ni.dll")
579
580     cmd(f"shell rm -rf {IBCDATA_DIR}")
581
582     cmd(f"shell rm -rf {DOTNET_DIR}apps/org.tizen.example.Launcher_TC_TOOL_08.Tizen")
583     cmd(f"shell rm -rf {DOTNET_DIR}apps/org.tizen.example.Launcher_TC_TOOL_09.Tizen")
584
585 # Main entry point
586 def main():
587     parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter)
588     parser.add_argument("TC_NUMBER", type=str, nargs="*", help="Individual excution")
589     args = parser.parse_args()
590
591     global tc_array
592     if args.TC_NUMBER and "TC_" in args.TC_NUMBER[0]:
593         tc_array = []
594         for tc_num in args.TC_NUMBER:
595             if tc_num not in funcMap:
596                 print(f"There is no {tc_num} test.")
597                 exit(1)
598             else:
599                 tc_array.append(funcMap[tc_num])
600     else:
601         # skip TC_07 (--r2r), TC_09 (--ibc-dir)
602         tc_array = [TC_01, TC_02, TC_03, TC_04, TC_05, TC_06, TC_08, TC_10, TC_11, TC_12, TC_13, TC_14, TC_15, TC_16, TC_17, TC_18, TC_19]
603
604     global serial
605     if len(sys.argv) >= 2 and "TC_" not in sys.argv[1]:
606         serial = read_serial(sys.argv[1])
607     else:
608         serial = read_serial(None)
609
610     if serial is None:
611         print("No connected device(s).")
612         exit(1)
613
614     device = get_device_type()
615     print(f"=== Dotnet-Launcher [{device}] Test Case - ({module_name}) ===")
616
617     run()
618     clean()
619
620
621 funcMap = {
622 'TC_01': TC_01, 'TC_02': TC_02, 'TC_03': TC_03, 'TC_04': TC_04, 'TC_05': TC_05, 'TC_06': TC_06,
623 'TC_07': TC_07, 'TC_08': TC_08, 'TC_09': TC_09, 'TC_10': TC_10, 'TC_11': TC_11, 'TC_12': TC_12,
624 'TC_13': TC_13, 'TC_14': TC_14, 'TC_15': TC_15, 'TC_16': TC_16, 'TC_17': TC_17, 'TC_18': TC_17_18, 'TC_19': TC_19,
625 'TOOL_TC_01': TC_01, 'TOOL_TC_02': TC_02, 'TOOL_TC_03': TC_03, 'TOOL_TC_04': TC_04, 'TOOL_TC_05': TC_05, 'TOOL_TC_06': TC_06,
626 'TOOL_TC_07': TC_07, 'TOOL_TC_08': TC_08, 'TOOL_TC_09': TC_09, 'TOOL_TC_10': TC_10, 'TOOL_TC_11': TC_11, 'TOOL_TC_12': TC_12,
627 'TOOL_TC_13': TC_13, 'TOOL_TC_14': TC_14, 'TOOL_TC_15': TC_15, 'TOOL_TC_16': TC_16, 'TOOL_TC_17': TC_17, 'TOOL_TC_18': TC_17_18, 'TOOL_TC_19': TC_19
628 }
629
630
631 if __name__ == "__main__":
632     try:
633         main()
634     except KeyboardInterrupt:
635         print("\nExit (Pressed Ctrl+C)")
636         exit(1)