2 import os, subprocess, sys
3 sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
6 from pathlib import Path
9 RUNTIME_DIR = "/usr/share/dotnet.tizen/netcoreapp/"
10 FRAMEWORK_DIR = "/usr/share/dotnet.tizen/framework/"
11 PRELOAD_DIR = "/usr/share/dotnet.tizen/preload/"
12 IBCDATA_DIR = "/usr/share/dotnet.tizen/ibcdata/"
13 DOTNET_DIR = "/opt/usr/dotnet/"
14 OWNER_DIR = "/home/owner/"
15 SPC_DLL = "System.Private.CoreLib.dll"
17 # Check the sdb connection status and get a device serial number
18 def read_serial(serial):
21 if serial is not None:
25 raw = subprocess.run("sdb devices".split(), encoding="utf-8", stdout=subprocess.PIPE).stdout
26 lines = [l for l in raw.splitlines() if not l.startswith("* ")]
30 serial_num = lines[1].split(" ")[0].split(":")[0].strip()
33 for idx in range(1, len(lines)):
34 serial = lines[idx].split(" ")[0].split(":")[0].replace("device", "").strip()
35 serials.append(serial)
36 print(f"[{idx}] {serial} - {lines[idx].split(' ')[2].strip()}")
37 choice = input(f"Select a device [1-{len(lines) - 1}]: ")
38 serial_num = serials[int(choice) - 1].strip() if choice.isdigit() else None
41 # Execute a command and return the output as a string.
43 return subprocess.run((f"sdb -s {serial_num} " + command).split(), encoding="utf-8", stdout=subprocess.PIPE).stdout
45 # Search the generated .tpk
47 def search_tpk(module, dirname=None):
49 if os.path.isdir(os.path.join(os.getcwd(), "../../Apps")):
50 dirname = "../../Apps"
51 elif os.path.isdir(os.path.join(os.getcwd(), "../Apps")):
53 elif os.path.isdir(os.path.join(os.getcwd(), "./Apps")):
56 dirname = "./tests/Apps"
58 filenames = os.listdir(dirname)
59 for filename in filenames:
60 full_filename = os.path.join(dirname, filename)
61 if os.path.isdir(full_filename):
62 search_tpk(module, full_filename)
64 ext = os.path.splitext(full_filename)[-1]
65 if ext == ".tpk" and f"{module}" in full_filename:
66 tpk_lists.append(full_filename)
70 def get_tpk_path(tpk_list, sln_name):
76 # Install the application
77 def app_install(tpk_path):
78 raw = cmd(f"push {tpk_path} {OWNER_DIR}")
79 if "1 file(s) pushed. 0 file(s) skipped." not in raw:
82 tpk_name = Path(tpk_path).name
83 raw = cmd(f"shell pkgcmd -i -t tpk -p {OWNER_DIR}{tpk_name}")
84 if "key[end] val[ok]" not in raw:
85 cmd(f"shell rm {OWNER_DIR}{tpk_name}")
88 cmd(f"shell rm {OWNER_DIR}{tpk_name}")
91 # Get the root path of the application
92 def get_root_path(pkg_id):
93 raw = cmd(f"shell pkginfo --pkg {pkg_id} | grep root_path")
94 lines = [l for l in raw.splitlines()]
97 return raw.split(": ")[1].strip()
99 # Application launch and get the pid
100 def launch_and_get_pid(mode, app_id):
101 raw = cmd(f"shell app_launcher {mode} {app_id}")
103 if "successfully launched pid" not in raw:
105 return raw[raw.index("pid") + 6:raw.index("with") - 1]
107 # Get the device type
108 def get_device_type():
109 raw = cmd(f"shell cat /etc/config/model-config.xml | grep tizen.org/feature/profile")
110 return raw.split(">")[1].split("<")[0]
112 # Create the System.Private.CoreLib native image
114 raw = cmd(f"shell find {RUNTIME_DIR} -name {SPC_DLL}.Backup")
115 if f"{RUNTIME_DIR}{SPC_DLL}.Backup" not in raw:
116 raw = cmd(f"shell dotnettool --ni-dll {RUNTIME_DIR}{SPC_DLL}")
117 if "System.Private.CoreLib.ni.dll generated successfully." not in raw:
120 raw = cmd(f"shell find {RUNTIME_DIR} -name {SPC_DLL}.Backup")
121 if f"{RUNTIME_DIR}{SPC_DLL}.Backup" not in raw:
125 # Remove the platform native image
126 def remove_system_ni():
127 cmd(f"shell dotnettool --ni-reset-system")
128 raw = cmd(f"shell find {RUNTIME_DIR} -name {SPC_DLL}.Backup")
129 if f"{RUNTIME_DIR}{SPC_DLL}.Backup" in raw:
133 # Prepare the candidate process
134 def prepare_candidate_process(loader, pkg_id):
135 cmd(f"shell killall dotnet-launcher {loader}")
138 raw = cmd(f"shell ps -ef | grep {loader}")
139 if f"/usr/bin/{loader}" not in raw:
140 cmd(f"shell app_launcher -s {pkg_id}")
142 cmd(f"shell app_launcher -t {pkg_id}")
144 raw = cmd(f"shell ps -ef | grep {loader}")
145 if f"/usr/bin/{loader}" not in raw:
151 # Get the device arch
152 def get_device_arch():
153 raw = cmd("capability")
154 line = [l for l in raw.splitlines() if "cpu_arch" in l]
155 return line[0].split(":")[1]
157 # Check the library type
158 def check_library_arch(rootpath, library):
159 raw = cmd(f"pull {rootpath}/bin/{library} {library}")
160 if "1 file(s) pulled. 0 file(s) skipped." not in raw:
163 raw = subprocess.run((f"file ./{library}").split(), encoding="utf-8", stdout=subprocess.PIPE).stdout
164 subprocess.run((f"rm ./{library}").split(), encoding="utf-8", stdout=subprocess.PIPE).stdout
166 device_arch = get_device_arch()
167 if "armv7" == device_arch:
170 elif "x86" == device_arch:
171 if "Intel 80386" not in raw:
178 # Check if the file or directory exists
180 raw = cmd(f"shell find {path}")
181 if "No such file or directory" in raw:
187 def run_tc_array(module_name, tc_array):
192 print(f">{module_name}_{tc.__name__}...", end="\r")
194 print(f">{module_name}_{tc.__name__} : {ret}")
195 if "NONE" in ret: n += 1
196 if "FAIL" in ret: f += 1
197 if "PASS" == ret: p += 1
199 return str(n) + ":" + str(f) + ":" + str(p)
201 def check_tc_support():
202 if "armv8" == get_device_arch():