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