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