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