f44efd53cadcee7a82ec13071e0bab19ce613c54
[platform/core/dotnet/launcher.git] / tests / TCs / 1_AOT / AOT.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 = "AOT"
11
12 # The `Launcher_TC_AOT_01` application does not generate native image.
13 def TC_01():
14     if "OK" not in create_spc_ni():
15         return f"FAIL : Create native image for {SPC_DLL}"
16
17     sln_name = "Launcher_TC_AOT_01.Tizen"
18
19     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
20     if tpk_path == None:
21         return f"FAIL : Get the tpk path for {sln_name}"
22
23     if "OK" not in app_install(f"{tpk_path}"):
24         return f"FAIL : Install the application for {tpk_path}"
25
26     pkg_id = "org.tizen.example.Launcher_TC_AOT_01.Tizen"
27
28     root_path = get_root_path(f"{pkg_id}")
29     if root_path == "None":
30         return f"FAIL : Get the root path for {pkg_id}"
31
32     raw = cmd(f"shell find {root_path}/bin/ -name .native_image")
33     if ".native_image" in raw:
34         return "FAIL : The .native_image folder should not exist"
35
36     raw = cmd(f"shell find {root_path}/bin/ -name *.ni.dll")
37     lines = [l for l in raw.splitlines()]
38     if len(lines) != 0:
39         return "FAIL : The .ni.dll files should not exist"
40
41     return "PASS"
42
43 # The `Launcher_TC_AOT_02` application generates native image.
44 def TC_02():
45     if "OK" not in create_spc_ni():
46         return f"FAIL : Create native image for {SPC_DLL}"
47
48     sln_name = "Launcher_TC_AOT_02.Tizen"
49
50     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
51     if tpk_path == None:
52         return f"FAIL : Get the tpk path for {sln_name}"
53
54     if "OK" not in app_install(f"{tpk_path}"):
55         return f"FAIL : Install the application for {tpk_path}"
56
57     pkg_id = "org.tizen.example.Launcher_TC_AOT_02.Tizen"
58
59     root_path = get_root_path(f"{pkg_id}")
60     if root_path == "None":
61         return f"FAIL : Get the root path for {pkg_id}"
62
63     raw = cmd(f"shell find {root_path}/bin/ -name .native_image")
64     if ".native_image" not in raw:
65         return "FAIL : The .native_image folder should exist"
66
67     raw = cmd(f"shell find {root_path}/bin/.native_image/ -name *.ni.dll")
68     lines1 = [l for l in raw.splitlines()]
69     raw = cmd(f"shell find {root_path}/bin/ -maxdepth 1 -name *.dll -not -name *.ni.dll")
70     lines2 = [l for l in raw.splitlines()]
71     if len(lines1) != len(lines2):
72         return "FAIL : The number of .dll and .ni.dll must match in the application"
73
74     for ni in lines1:
75         is_same = False
76         for dll in lines2:
77             if Path(ni).name.replace(".ni.dll", "") == Path(dll).name.replace(".dll", ""):
78                 is_same = True
79                 break
80         if not is_same:
81             return "FAIL : The file name of .dll and .ni.dll must match in the application"
82
83     return "PASS"
84
85 # The `Launcher_TC_AOT_03` application does not generate native image.
86 def TC_03():
87     if "OK" not in remove_system_ni():
88         return "FAIL : Remove the platform native image"
89
90     sln_name = "Launcher_TC_AOT_03.Tizen"
91
92     tpk_path = get_tpk_path(tpk_list, f"{sln_name}")
93     if tpk_path == None:
94         return f"FAIL : Get the tpk path for {sln_name}"
95
96     if "OK" not in app_install(f"{tpk_path}"):
97         return f"FAIL : Install the application for {tpk_path}"
98
99     pkg_id = "org.tizen.example.Launcher_TC_AOT_03.Tizen"
100
101     root_path = get_root_path(f"{pkg_id}")
102     if root_path == "None":
103         return f"FAIL : Get the root path for {pkg_id}"
104
105     raw = cmd(f"shell find {root_path}/bin/ -name .native_image")
106     if ".native_image" in raw:
107         return "FAIL : The .native_image folder should not exist"
108
109     raw = cmd(f"shell find {root_path}/bin/ -name *.ni.dll")
110     lines = [l for l in raw.splitlines()]
111     if len(lines) != 0:
112         return "FAIL : The .ni.dll files should not exist"
113
114     return "PASS"
115
116 # Run the test
117 def run():
118     cmd(f"root on")
119     cmd(f"shell mount -o remount,rw /")
120
121     global tpk_list
122     tpk_list = search_tpk(f"{module_name}")
123
124     p = run_tc_array(module_name, tc_array)
125     f = len(tc_array) - p
126     r = round(((p / len(tc_array)) * 100), 2)
127     print(f"--- {module_name} TCT Result ---\nFAIL : [{f}] / PASS : [{p}] - [{r}%]\n")
128
129 # Uninstall the application and restore to original state
130 def clean():
131     cmd(f"uninstall org.tizen.example.Launcher_TC_AOT_01.Tizen")
132     cmd(f"uninstall org.tizen.example.Launcher_TC_AOT_02.Tizen")
133     cmd(f"uninstall org.tizen.example.Launcher_TC_AOT_03.Tizen")
134
135     create_spc_ni()
136
137 # Main entry point
138 def main():
139     parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter)
140     parser.add_argument("TC_NUMBER", type=str, nargs="*", help="Individual excution")
141     args = parser.parse_args()
142
143     global tc_array
144     if "TC_" in args.TC_NUMBER[0]:
145         tc_array = []
146         for tc_num in args.TC_NUMBER:
147             if tc_num not in funcMap:
148                 print(f"There is no {tc_num} test.")
149                 exit(1)
150             else:
151                 tc_array.append(funcMap[tc_num])
152     else:
153         tc_array = [TC_01, TC_02, TC_03]
154
155     global serial
156     if len(sys.argv) >= 2 and "TC_" not in sys.argv[1]:
157         serial = read_serial(sys.argv[1])
158     else:
159         serial = read_serial(None)
160
161     if serial is None:
162         print("No connected device(s).")
163         exit(1)
164
165     device = get_device_type()
166     print(f"=== Dotnet-Launcher [{device}] Test Case - ({module_name}) ===")
167
168     run()
169     clean()
170
171
172 funcMap = {
173 'TC_01': TC_01, 'TC_02': TC_02, 'TC_03': TC_03,
174 'AOT_TC_01': TC_01, 'AOT_TC_02': TC_02, 'AOT_TC_03': TC_03
175 }
176
177
178 if __name__ == "__main__":
179     try:
180         main()
181     except KeyboardInterrupt:
182         print("\nExit (Pressed Ctrl+C)")
183         exit(1)