350c5bd060c0015033c2abd37611799933284340
[platform/core/dotnet/launcher.git] / tests / TCs / 3_PRELOAD / PRELOAD.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 = "PRELOAD"
10
11 # All the `.dlls` in the .preload file must be loaded in the memory.
12 def TC_01():
13     sln_name = "Launcher_TC_PRELOAD_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_PRELOAD_01.Tizen"
23
24     raw = prepare_candidate_process(f"dotnet-loader", f"{pkg_id}")
25     if "OK" not in raw:
26         return f"FAIL : Candidate process should have dotnet-loader"
27
28     pid = raw.split(":")[1].strip()
29
30     raw = cmd(f"shell find {PRELOAD_DIR} -name *.preload")
31     lines = [l for l in raw.splitlines() if "NUI" not in l]
32     if len(lines) == 0:
33         return "FAIL : The .preload file should exist"
34
35     raw = cmd(f"shell cat /proc/{pid}/smaps | grep {FRAMEWORK_DIR}")
36     if len([l for l in raw.splitlines()]) == 0:
37         return "FAIL : The assembly of .preload file should be loaded in the candidate process"
38
39     for preload in lines:
40         if ("XSF" in preload) and (f"{FRAMEWORK_DIR}XSF." not in raw):
41             return "FAIL : The assembly of XSF.preload file should be loaded in the candidate process"
42
43     if (f"{FRAMEWORK_DIR}Tizen.Runtime." not in raw) or \
44        (f"{FRAMEWORK_DIR}Tizen." not in raw) or \
45        (f"{FRAMEWORK_DIR}ElmSharp." not in raw) or \
46        (f"{FRAMEWORK_DIR}Tizen.Applications.Common." not in raw) or \
47        (f"{FRAMEWORK_DIR}Tizen.Applications.UI." not in raw) or \
48        (f"{FRAMEWORK_DIR}Tizen.Log." not in raw) or \
49        (f"{FRAMEWORK_DIR}Tizen.System.Information." not in raw):
50         return "FAIL : The assembly of .preload file should be loaded in the candidate process"
51
52     return "PASS"
53
54 # All the `.dlls` in the .preload file must be loaded in the memory.
55 def TC_02():
56     sln_name = "Launcher_TC_PRELOAD_02"
57
58     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
59     if tpk_path == None:
60         return f"FAIL : Get the tpk path for {sln_name}"
61
62     if "OK" not in app_install(f"{tpk_path}"):
63         return f"FAIL : Install the application for {tpk_path}"
64
65     pkg_id = f"org.tizen.example.Launcher_TC_PRELOAD_02"
66
67     raw = prepare_candidate_process(f"dotnet-nui-loader", f"{pkg_id}")
68     if "OK" not in raw:
69         return f"FAIL : Candidate process should have dotnet-nui-loader"
70
71     pid = raw.split(":")[1].strip()
72
73     raw = cmd(f"shell find {PRELOAD_DIR} -name *.preload")
74     lines = [l for l in raw.splitlines() if "XSF" not in l and "ElmSharp" not in l]
75     if len(lines) == 0:
76         return "FAIL : The .preload file should exist"
77
78     raw = cmd(f"shell cat /proc/{pid}/smaps | grep {FRAMEWORK_DIR}")
79     if len([l for l in raw.splitlines()]) == 0:
80         return "FAIL : The assembly of .preload file should be loaded in the candidate process"
81
82     if (f"{FRAMEWORK_DIR}Tizen.Runtime." not in raw) or \
83        (f"{FRAMEWORK_DIR}Tizen." not in raw) or \
84        (f"{FRAMEWORK_DIR}Tizen.Applications.Common." not in raw) or \
85        (f"{FRAMEWORK_DIR}Tizen.Applications.UI." not in raw) or \
86        (f"{FRAMEWORK_DIR}Tizen.Log." not in raw) or \
87        (f"{FRAMEWORK_DIR}Tizen.NUI." not in raw) or \
88        (f"{FRAMEWORK_DIR}Tizen.System.Information." not in raw):
89         return "FAIL : The assembly of .preload file should be loaded in the candidate process"
90
91     return "PASS"
92
93 # Run the test
94 def run():
95     cmd(f"root on")
96     cmd(f"shell mount -o remount,rw /")
97
98     global tpk_list
99     tpk_list = search_tpk(f"{module_name}")
100
101     pn = run_tc_array(module_name, tc_array)
102     n = int(pn.split(":")[0])
103     f = int(pn.split(":")[1])
104     p = int(pn.split(":")[2])
105     r = 0.0
106     if (len(tc_array) - n) != 0:
107         r = round(((p / (len(tc_array) - n)) * 100), 2)
108     print(f"--- {module_name} TCT Result ---\nNONE : [{n}] / FAIL : [{f}] / PASS : [{p}] - [{r}%]\n")
109
110 # Uninstall the application and restore to original state
111 def clean():
112     cmd(f"uninstall org.tizen.example.Launcher_TC_PRELOAD_01.Tizen")
113     cmd(f"uninstall org.tizen.example.Launcher_TC_PRELOAD_02")
114
115 # Main entry point
116 def main():
117     parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter)
118     parser.add_argument("TC_NUMBER", type=str, nargs="*", help="Individual excution")
119     args = parser.parse_args()
120
121     global tc_array
122     if args.TC_NUMBER and "TC_" in args.TC_NUMBER[0]:
123         tc_array = []
124         for tc_num in args.TC_NUMBER:
125             if tc_num not in funcMap:
126                 print(f"There is no {tc_num} test.")
127                 exit(1)
128             else:
129                 tc_array.append(funcMap[tc_num])
130     else:
131         tc_array = [TC_01, TC_02]
132
133     global serial
134     if len(sys.argv) >= 2 and "TC_" not in sys.argv[1]:
135         serial = read_serial(sys.argv[1])
136     else:
137         serial = read_serial(None)
138
139     if serial is None:
140         print("No connected device(s).")
141         exit(1)
142
143     device = get_device_type()
144     print(f"=== Dotnet-Launcher [{device}] Test Case - ({module_name}) ===")
145
146     run()
147     clean()
148
149
150 funcMap = {
151 'TC_01': TC_01, 'TC_02': TC_02,
152 'PRELOAD_TC_01': TC_01, 'PRELOAD_TC_02': TC_02
153 }
154
155
156 if __name__ == "__main__":
157     try:
158         main()
159     except KeyboardInterrupt:
160         print("\nExit (Pressed Ctrl+C)")
161         exit(1)