1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# 5# Copyright (c) 2024 Huawei Device Co., Ltd. 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19import os 20import subprocess 21import time 22from enum import Enum 23import inspect 24 25 26class RetStatus(Enum): 27 OK = 0 28 ERR = 255 29 30 31def get_idl(): 32 current_path = os.path.dirname(os.path.abspath(__file__)) 33 relative_path = os.path.join(current_path, "..", "..", "idl_tool_2", "idl-gen") 34 return os.path.realpath(relative_path) 35 36 37def get_caller_info(): 38 frame = inspect.currentframe().f_back.f_back 39 caller_function = frame.f_code.co_name 40 caller_lineno = frame.f_lineno 41 caller_class = None 42 if 'self' in frame.f_locals: 43 caller_class = frame.f_locals['self'].__class__.__name__ 44 return caller_class, caller_function, caller_lineno 45 46 47def get_time_stamp(): 48 return int(round(time.time() * 1000)) 49 50 51def print_success(info): 52 print("\033[32m{}\033[0m".format(info)) 53 54 55def print_failure(info): 56 print("\033[31m{}\033[0m".format(info)) 57 58 59def compare_file(first_file, second_file): 60 with open(first_file, 'r') as first_hash_file: 61 with open(second_file, 'r') as second_hash_file: 62 first_hash_info = first_hash_file.read() 63 second_hash_info = second_hash_file.read() 64 return first_hash_info == second_hash_info 65 66def file_exists(file_path): 67 return os.path.isfile(file_path) 68 69def exec_command_check(command, expect_result, exp_status): 70 status, exec_result = subprocess.getstatusoutput(command) 71 caller_class, caller_function, caller_lineno = get_caller_info() 72 if status != exp_status.value: 73 print_failure(f"[{caller_class}:{caller_function}:{caller_lineno}][{command}][{status}:{exp_status}]" 74 f"{exec_result}") 75 return False 76 77 if exec_result != expect_result: 78 print_success("=====expect=====\n" 79 f"[{caller_class}:{caller_function}:{caller_lineno}][{command}]{expect_result}") 80 print_failure("=====actual=====\n" 81 f"[{caller_class}:{caller_function}:{caller_lineno}][{command}]{exec_result}") 82 return False 83 84 return True 85 86class Test: 87 def __init__(self): 88 self.name = self.__class__.__name__ 89 self.cmd = get_idl() 90 91 def run(self): 92 # please add test code here 93 return False 94 95 def test(self): 96 print_success("[ RUN ] {}".format(self.name)) 97 start_time = get_time_stamp() 98 result = self.run() 99 end_time = get_time_stamp() 100 101 if result: 102 print_success("[ OK ] {} ({}ms)".format(self.name, end_time - start_time)) 103 else: 104 print_failure("[ FAILED ] {} ({}ms)".format(self.name, end_time - start_time)) 105 return result 106 107# print help info 108class TestCmdPrintHelp(Test): 109 def run(self): 110 expect_result = "Compile a .idl file and generate C/C++/Ts/Rust and Java codes.\n" 111 expect_result += "Usage: idl [options] file\n" 112 expect_result += "Options:\n" 113 expect_result += " -h, --help Display command line options\n" 114 expect_result += " -v, --version Display toolchain version information\n" 115 expect_result += \ 116 " --system <value> "\ 117 "Set system level 'mini','lite' or 'full', the default value is 'full', only support 'intf-type hdi'\n" 118 expect_result += \ 119 " -m, --mode <value> "\ 120 "Set generate code mode 'low', 'passthrough', 'ipc' or 'kernel', the default value is 'ipc', "\ 121 "only support 'intf-type hdi'\n" 122 expect_result += " -p, --package <package name> Set package of idl files, only support 'intf-type hdi'\n" 123 expect_result += " --dump-ast Display the AST of the compiled file\n" 124 expect_result += \ 125 " --dump-metadata "\ 126 "Display the metadata generated from the compiled file, only support 'intf-type sa'\n" 127 expect_result += \ 128 " --hash Generate hash info of idl files, only support 'intf-type hdi'\n" 129 expect_result += \ 130 " -r <rootPackage>:<rootPath> Set root path of root package, only support 'intf-type hdi'\n" 131 expect_result += " -c Compile the .idl file\n" 132 expect_result += " -D <directory> Directory of the idl file, only support 'intf-type hdi'\n" 133 expect_result += " -d <directory> Place generated codes into <directory>\n" 134 expect_result += \ 135 " -o <file> Place the output into <file>, only support 'intf-type hdi'\n" 136 expect_result += \ 137 " -s <file> Place the metadata into <file>, only support 'intf-type sa'\n" 138 expect_result += " --gen-c Generate C codes, only support 'intf-type hdi'\n" 139 expect_result += " --gen-cpp Generate C++ codes\n" 140 expect_result += " --gen-java Generate Java codes, only support 'intf-type hdi'\n" 141 expect_result += " --gen-rust Generate Rust codes, only support 'intf-type sa'\n" 142 expect_result += " --gen-ts Generate Ts codes, only support 'intf-type sa'\n" 143 expect_result += \ 144 " --log-domainid <domainid> "\ 145 "Place the service domain in <domainid>, Enable log(Pair with -log-tag), only support 'intf-type sa'\n" 146 expect_result += \ 147 " --log-tag <tag> "\ 148 "Place the subsystem name in <tag>, Enable log(Pair with -log-domainid), only support 'intf-type sa'\n" 149 expect_result += \ 150 " -t <hitrace tag> "\ 151 "Place the constant name from hitrace_meter.h file in <hitrace tag>, only support 'intf-type sa'\n" 152 expect_result += \ 153 " --intf-type <tag> Set type of generated codes 'sa' or 'hdi', default type is 'sa'" 154 command = f"{self.cmd} -h" 155 ret = exec_command_check(command, expect_result, RetStatus.OK) 156 command = f"{self.cmd} --help" 157 ret &= exec_command_check(command, expect_result, RetStatus.OK) 158 return ret 159 160 161# print version info 162class TestCmdPrintVersion(Test): 163 def run(self): 164 expect_result = "idl 1.0\n" 165 expect_result += "Copyright (c) Hua"\ 166 "wei Technologies Co., Ltd. 2024. All rights reserved.\n" 167 command = f"{self.cmd} -v" 168 ret = exec_command_check(command, expect_result, RetStatus.OK) 169 command = f"{self.cmd} --version" 170 ret &= exec_command_check(command, expect_result, RetStatus.OK) 171 return ret 172 173 174# exec not support cmd 175class TestCmdNotSupport(Test): 176 def run_sa(self): 177 expect_result = """[IDL-GEN]: The Option "-abc" is illegal.\n""" 178 expect_result += """Use "-h, --help" to show usage.""" 179 command = f"{self.cmd} -abc" 180 ret = exec_command_check(command, expect_result, RetStatus.ERR) 181 182 # sa not support cmd 183 expect_result = "[IDL-GEN]: Option 'intf-type sa' not support option 'system'.\n" 184 expect_result += """Use "-h, --help" to show usage.""" 185 command = f"{self.cmd} --system full" 186 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 187 188 expect_result = "[IDL-GEN]: Option 'intf-type sa' not support option 'm' or 'mode'.\n" 189 expect_result += """Use "-h, --help" to show usage.""" 190 command = f"{self.cmd} --mode ipc" 191 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 192 command = f"{self.cmd} -m ipc" 193 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 194 195 expect_result = "[IDL-GEN]: Option 'intf-type sa' not support option 'p' or 'package'.\n" 196 expect_result += """Use "-h, --help" to show usage.""" 197 command = f"{self.cmd} -p abc.test" 198 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 199 command = f"{self.cmd} --package abc.test" 200 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 201 202 expect_result = "[IDL-GEN]: Option 'intf-type sa' not support option 'hash'.\n" 203 expect_result += """Use "-h, --help" to show usage.""" 204 command = f"{self.cmd} --hash" 205 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 206 207 expect_result = "[IDL-GEN]: Option 'intf-type sa' not support option 'r'.\n" 208 expect_result += """Use "-h, --help" to show usage.""" 209 command = f"{self.cmd} -r abc:./" 210 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 211 212 expect_result = "[IDL-GEN]: Option 'intf-type sa' not support option 'o'.\n" 213 expect_result += """Use "-h, --help" to show usage.""" 214 command = f"{self.cmd} -o test.file" 215 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 216 217 expect_result = \ 218 "[IDL-GEN]: Option 'intf-type sa' only support language option 'gen-cpp', 'gen-rust' or 'gen-ts'.\n" 219 expect_result += """Use "-h, --help" to show usage.""" 220 command = f"{self.cmd} --gen-c" 221 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 222 return ret 223 224 def run_hdi(self): 225 # hdi not support cmd 226 expect_result = "[IDL-GEN]: Option 'intf-type hdi' not support option 'dump-metadata'.\n" 227 expect_result += """Use "-h, --help" to show usage.""" 228 command = f"{self.cmd} --intf-type hdi --dump-metadata" 229 ret = exec_command_check(command, expect_result, RetStatus.ERR) 230 231 expect_result = """[IDL-GEN]: The Option "-s" is illegal.\n""" 232 expect_result += """Use "-h, --help" to show usage.""" 233 command = f"{self.cmd} --intf-type hdi -s" 234 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 235 236 expect_result = \ 237 "[IDL-GEN]: Option 'intf-type hdi' only support language option 'gen-c', 'gen-cpp' or 'gen-java'.\n" 238 expect_result += """Use "-h, --help" to show usage.""" 239 command = f"{self.cmd} --intf-type hdi --gen-ts" 240 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 241 command = f"{self.cmd} --intf-type hdi --gen-rust" 242 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 243 return ret 244 245 def run(self): 246 ret = self.run_sa() 247 ret &= self.run_hdi() 248 return ret 249 250 251# set not support value 252class TestCmdNotSupportValue(Test): 253 def run(self): 254 expect_result = "[IDL-GEN]: The Option \"-abc\" is illegal.\n" 255 expect_result += """Use "-h, --help" to show usage.""" 256 command = f"{self.cmd} -abc" 257 ret = exec_command_check(command, expect_result, RetStatus.ERR) 258 return ret 259 260class TestCmdModeTypeTest(Test): 261 def run(self): 262 expect_result = "" 263 command = f"{self.cmd} --intf-type hdi --mode low" 264 ret = exec_command_check(command, expect_result, RetStatus.OK) 265 266 command = f"{self.cmd} --intf-type hdi -m passthrough" 267 ret &= exec_command_check(command, expect_result, RetStatus.OK) 268 269 command = f"{self.cmd} --intf-type hdi --mode ipc" 270 ret &= exec_command_check(command, expect_result, RetStatus.OK) 271 272 command = f"{self.cmd} --intf-type hdi -m kernel" 273 ret &= exec_command_check(command, expect_result, RetStatus.OK) 274 275 expect_result = "[IDL-GEN]: invalid generate mode set: 'abc', please input low/passthrough/ipc/kernel/sa." 276 command = f"{self.cmd} --intf-type hdi --mode abc" 277 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 278 return ret 279 280 281class TestCmdPackageTypeTest(Test): 282 def run(self): 283 expect_result = "" 284 command = f"{self.cmd} --intf-type hdi -p abc" 285 ret = exec_command_check(command, expect_result, RetStatus.OK) 286 287 return ret 288 289 290class TestCmdDumpAstTypeTest(Test): 291 def run(self): 292 expect_result = """[IDL-GEN]: no idl files.""" 293 command = f"{self.cmd} --intf-type hdi --dump-ast" 294 ret = exec_command_check(command, expect_result, RetStatus.ERR) 295 296 expect_result = """[IDL-GEN]: Option 'intf-type sa' must set idl file.""" 297 command = f"{self.cmd} --intf-type sa --dump-ast" 298 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 299 300 command = f"{self.cmd} --dump-ast" 301 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 302 303 return ret 304 305 306class TestCmdDumpMetaDataTest(Test): 307 def run(self): 308 expect_result = "[IDL-GEN]: Option 'intf-type hdi' not support option 'dump-metadata'.\n" 309 expect_result += """Use "-h, --help" to show usage.""" 310 command = f"{self.cmd} --intf-type hdi --dump-metadata" 311 ret = exec_command_check(command, expect_result, RetStatus.ERR) 312 313 expect_result = """[IDL-GEN]: Option 'intf-type sa' must set idl file.""" 314 command = f"{self.cmd} --intf-type sa --dump-metadata" 315 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 316 317 return ret 318 319 320class TestCmdHashTest(Test): 321 def run(self): 322 expect_result = "[IDL-GEN]: no idl files." 323 command = f"{self.cmd} --intf-type hdi --hash" 324 ret = exec_command_check(command, expect_result, RetStatus.ERR) 325 326 expect_result = "[IDL-GEN]: Option 'intf-type sa' not support option 'hash'.\n" 327 expect_result += """Use "-h, --help" to show usage.""" 328 command = f"{self.cmd} --hash" 329 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 330 331 return ret 332 333 334class TestCmdRootPackageTest(Test): 335 def run(self): 336 expect_result = """[IDL-GEN]: The Option "-r" is illegal.\n""" 337 expect_result += """Use "-h, --help" to show usage.""" 338 command = f"{self.cmd} --intf-type sa -r" 339 ret = exec_command_check(command, expect_result, RetStatus.ERR) 340 341 expect_result = "[IDL-GEN]: invalid path 'xx'." 342 command = f"{self.cmd} --intf-type sa -r x:xx" 343 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 344 345 expect_result = """[IDL-GEN]: Option 'intf-type sa' not support option 'r'.\n""" 346 expect_result += """Use "-h, --help" to show usage.""" 347 command = f"{self.cmd} --intf-type sa -r x:./" 348 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 349 350 expect_result = """[IDL-GEN]: The Option "-r" is illegal.\n""" 351 expect_result += """Use "-h, --help" to show usage.""" 352 command = f"{self.cmd} --intf-type hdi -r" 353 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 354 355 expect_result = "[IDL-GEN]: invalid path 'xx'." 356 command = f"{self.cmd} --intf-type hdi -r x:xx" 357 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 358 359 expect_result = "" 360 command = f"{self.cmd} --intf-type hdi -r x:./" 361 ret &= exec_command_check(command, expect_result, RetStatus.OK) 362 363 return ret 364 365 366class TestCmdDirectoryTest(Test): 367 def run(self): 368 expect_result = """[IDL-GEN]: The Option "-D" is illegal.\n""" 369 expect_result += """Use "-h, --help" to show usage.""" 370 command = f"{self.cmd} --intf-type sa -D" 371 ret = exec_command_check(command, expect_result, RetStatus.ERR) 372 373 expect_result = "[IDL-GEN]: Option 'intf-type sa' not support option 'D'.\n" 374 expect_result += """Use "-h, --help" to show usage.""" 375 command = f"{self.cmd} --intf-type sa -D ./" 376 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 377 378 expect_result = "[IDL-GEN]: failed to open './x/', errno:2\n" 379 expect_result += """[IDL-GEN]: Option 'intf-type sa' not support option 'D'.\n""" 380 expect_result += """Use "-h, --help" to show usage.""" 381 command = f"{self.cmd} --intf-type sa -D ./x" 382 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 383 384 expect_result = """[IDL-GEN]: The Option "-D" is illegal.\n""" 385 expect_result += """Use "-h, --help" to show usage.""" 386 command = f"{self.cmd} --intf-type hdi -D" 387 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 388 389 expect_result = "" 390 command = f"{self.cmd} --intf-type hdi -D {os.path.dirname(os.path.abspath(__file__))}" 391 ret &= exec_command_check(command, expect_result, RetStatus.OK) 392 393 expect_result = f"[IDL-GEN]: failed to open '{os.path.dirname(os.path.abspath(__file__))}/x/', errno:2" 394 command = f"{self.cmd} --intf-type hdi -D {os.path.dirname(os.path.abspath(__file__))}/x" 395 ret &= exec_command_check(command, expect_result, RetStatus.OK) 396 397 return ret 398 399 400class TestCmdPlaceGenerateDirectoryTest(Test): 401 def run(self): 402 expect_result = """[IDL-GEN]: The Option "-d" is illegal.\n""" 403 expect_result += """Use "-h, --help" to show usage.""" 404 command = f"{self.cmd} --intf-type sa -d" 405 ret = exec_command_check(command, expect_result, RetStatus.ERR) 406 407 expect_result = """[IDL-GEN]: Option 'intf-type sa' must set idl file.""" 408 command = f"{self.cmd} --intf-type sa -d ./" 409 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 410 411 expect_result = """[IDL-GEN]: Option 'intf-type sa' must set idl file.""" 412 command = f"{self.cmd} --intf-type sa -d x" 413 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 414 415 expect_result = """[IDL-GEN]: The Option "-d" is illegal.\n""" 416 expect_result += """Use "-h, --help" to show usage.""" 417 command = f"{self.cmd} --intf-type hdi -d" 418 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 419 420 expect_result = "[IDL-GEN]: no idl files." 421 command = f"{self.cmd} --intf-type hdi -d ./" 422 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 423 424 expect_result = "[IDL-GEN]: no idl files." 425 command = f"{self.cmd} --intf-type hdi -d x" 426 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 427 428 return ret 429 430 431class TestCmdPlaceOutputFileTest(Test): 432 def run(self): 433 expect_result = """[IDL-GEN]: The Option "-o" is illegal.\n""" 434 expect_result += """Use "-h, --help" to show usage.""" 435 command = f"{self.cmd} --intf-type sa -o" 436 ret = exec_command_check(command, expect_result, RetStatus.ERR) 437 438 expect_result = "[IDL-GEN]: Option 'intf-type sa' not support option 'o'.\n" 439 expect_result += """Use "-h, --help" to show usage.""" 440 command = f"{self.cmd} --intf-type sa -o xx" 441 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 442 443 expect_result = """[IDL-GEN]: The Option "-o" is illegal.\n""" 444 expect_result += """Use "-h, --help" to show usage.""" 445 command = f"{self.cmd} --intf-type hdi -o" 446 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 447 448 expect_result = "" 449 command = f"{self.cmd} --intf-type hdi -o xx" 450 ret &= exec_command_check(command, expect_result, RetStatus.OK) 451 452 return ret 453 454 455class TestCmdPlaceMetadataInfoTest(Test): 456 def run(self): 457 expect_result = """[IDL-GEN]: The Option "-s" is illegal.\n""" 458 expect_result += """Use "-h, --help" to show usage.""" 459 command = f"{self.cmd} --intf-type sa -s" 460 ret = exec_command_check(command, expect_result, RetStatus.ERR) 461 462 expect_result = "[IDL-GEN]: Option 'intf-type hdi' not support option '-s'.\n" 463 expect_result += """Use "-h, --help" to show usage.""" 464 command = f"{self.cmd} --intf-type hdi -s aaa" 465 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 466 467 return ret 468 469 470class TestCmdGenCTest(Test): 471 def run(self): 472 expect_result = \ 473 "[IDL-GEN]: Option 'intf-type sa' only support language option 'gen-cpp', 'gen-rust' or 'gen-ts'.\n" 474 expect_result += """Use "-h, --help" to show usage.""" 475 command = f"{self.cmd} --intf-type sa --gen-c" 476 ret = exec_command_check(command, expect_result, RetStatus.ERR) 477 478 expect_result = "[IDL-GEN]: no idl files." 479 command = f"{self.cmd} --intf-type hdi --gen-c" 480 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 481 482 return ret 483 484 485class TestCmdGenCppTest(Test): 486 def run(self): 487 expect_result = """[IDL-GEN]: Option 'intf-type sa' must set idl file.""" 488 command = f"{self.cmd} --intf-type sa --gen-cpp" 489 ret = exec_command_check(command, expect_result, RetStatus.ERR) 490 491 expect_result = "[IDL-GEN]: no idl files." 492 command = f"{self.cmd} --intf-type hdi --gen-cpp" 493 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 494 495 return ret 496 497 498class TestCmdGenJavaTest(Test): 499 def run(self): 500 expect_result = \ 501 "[IDL-GEN]: Option 'intf-type sa' only support language option 'gen-cpp', 'gen-rust' or 'gen-ts'.\n" 502 expect_result += """Use "-h, --help" to show usage.""" 503 command = f"{self.cmd} --intf-type sa --gen-java" 504 ret = exec_command_check(command, expect_result, RetStatus.ERR) 505 506 expect_result = "[IDL-GEN]: no idl files." 507 command = f"{self.cmd} --intf-type hdi --gen-java" 508 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 509 510 return ret 511 512class TestCmdGenRustTest(Test): 513 def run(self): 514 expect_result = """[IDL-GEN]: Option 'intf-type sa' must set idl file.""" 515 command = f"{self.cmd} --intf-type sa --gen-rust" 516 ret = exec_command_check(command, expect_result, RetStatus.ERR) 517 518 expect_result = \ 519 """[IDL-GEN]: Option 'intf-type hdi' only support language option 'gen-c', 'gen-cpp' or 'gen-java'.\n""" 520 expect_result += """Use "-h, --help" to show usage.""" 521 command = f"{self.cmd} --intf-type hdi --gen-rust" 522 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 523 524 return ret 525 526 527class TestCmdGenTsTest(Test): 528 def run(self): 529 expect_result = """[IDL-GEN]: Option 'intf-type sa' must set idl file.""" 530 command = f"{self.cmd} --intf-type sa --gen-ts" 531 ret = exec_command_check(command, expect_result, RetStatus.ERR) 532 533 expect_result = \ 534 "[IDL-GEN]: Option 'intf-type hdi' only support language option 'gen-c', 'gen-cpp' or 'gen-java'.\n" 535 expect_result += """Use "-h, --help" to show usage.""" 536 command = f"{self.cmd} --intf-type hdi --gen-ts" 537 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 538 539 return ret 540 541 542class TestCmdGenLogDomainIdTest(Test): 543 def run(self): 544 expect_result = """[IDL-GEN]: Option 'intf-type sa' must set idl file.""" 545 command = f"{self.cmd} --intf-type sa --log-domainid xx" 546 ret = exec_command_check(command, expect_result, RetStatus.ERR) 547 548 expect_result = "[IDL-GEN]: Option 'intf-type hdi' not support option '-t', '-log-domainid' or '-log-tag'.\n" 549 expect_result += """Use "-h, --help" to show usage.""" 550 command = f"{self.cmd} --intf-type hdi --log-domainid xx" 551 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 552 553 return ret 554 555 556class TestCmdGenLogDomainTagTest(Test): 557 def run(self): 558 expect_result = """[IDL-GEN]: The Option "--log-tag" is illegal.\n""" 559 expect_result += """Use "-h, --help" to show usage.""" 560 command = f"{self.cmd} --intf-type sa --log-tag" 561 ret = exec_command_check(command, expect_result, RetStatus.ERR) 562 563 expect_result = """[IDL-GEN]: Option 'intf-type sa' must set idl file.""" 564 command = f"{self.cmd} --intf-type sa --log-tag xx" 565 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 566 567 expect_result = """[IDL-GEN]: Option 'intf-type sa' must set idl file.""" 568 command = f"{self.cmd} --intf-type sa --log-domainid xx --log-tag xx" 569 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 570 571 expect_result = """[IDL-GEN]: The Option "---log-tag" is illegal.\n""" 572 expect_result += """Use "-h, --help" to show usage.""" 573 command = f"{self.cmd} --intf-type hdi ---log-tag xx" 574 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 575 576 return ret 577 578 579class TestCmdHiTraceTest(Test): 580 def run(self): 581 expect_result = """[IDL-GEN]: The Option "-t" is illegal.\n""" 582 expect_result += """Use "-h, --help" to show usage.""" 583 command = f"{self.cmd} --intf-type sa -t" 584 ret = exec_command_check(command, expect_result, RetStatus.ERR) 585 586 expect_result = """[IDL-GEN]: Option 'intf-type sa' must set idl file.""" 587 command = f"{self.cmd} --intf-type sa -t xx" 588 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 589 590 expect_result = """[IDL-GEN]: The Option "-t" is illegal.\n""" 591 expect_result += """Use "-h, --help" to show usage.""" 592 command = f"{self.cmd} --intf-type hdi -t" 593 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 594 595 expect_result = "[IDL-GEN]: Option 'intf-type hdi' not support option '-t', '-log-domainid' or '-log-tag'.\n" 596 expect_result += """Use "-h, --help" to show usage.""" 597 command = f"{self.cmd} --intf-type hdi -t xx" 598 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 599 600 return ret 601 602class TestCmdSystemTest(Test): 603 def run(self): 604 expect_result = """[IDL-GEN]: The Option "--system" is illegal.\n""" 605 expect_result += """Use "-h, --help" to show usage.""" 606 command = f"{self.cmd} --intf-type sa --system" 607 ret = exec_command_check(command, expect_result, RetStatus.ERR) 608 609 expect_result = "[IDL-GEN]: invalid system level set: 'xx', please input mini/lite/full" 610 command = f"{self.cmd} --intf-type sa --system xx" 611 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 612 613 expect_result = "[IDL-GEN]: Option 'intf-type sa' not support option 'system'.\n" 614 expect_result += """Use "-h, --help" to show usage.""" 615 command = f"{self.cmd} --intf-type sa --system mini" 616 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 617 618 expect_result = """[IDL-GEN]: The Option "--system" is illegal.\n""" 619 expect_result += """Use "-h, --help" to show usage.""" 620 command = f"{self.cmd} --intf-type hdi --system" 621 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 622 623 expect_result = "[IDL-GEN]: invalid system level set: 'xx', please input mini/lite/full" 624 command = f"{self.cmd} --intf-type hdi --system xx" 625 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 626 627 expect_result = "" 628 command = f"{self.cmd} --intf-type hdi --system mini" 629 ret &= exec_command_check(command, expect_result, RetStatus.OK) 630 631 command = f"{self.cmd} --intf-type hdi --system lite" 632 ret &= exec_command_check(command, expect_result, RetStatus.OK) 633 634 command = f"{self.cmd} --intf-type hdi --system full" 635 ret &= exec_command_check(command, expect_result, RetStatus.OK) 636 return ret 637 638class TestCmdIntfTypeTest(Test): 639 def run(self): 640 expect_result = """[IDL-GEN]: Option 'intf-type sa' must set idl file.""" 641 command = f"{self.cmd} --intf-type sa" 642 ret = exec_command_check(command, expect_result, RetStatus.ERR) 643 644 expect_result = "" 645 command = f"{self.cmd} --intf-type hdi" 646 ret &= exec_command_check(command, expect_result, RetStatus.OK) 647 648 expect_result = "[IDL-GEN]: invalid interface type set: 'xxx', please input hdi/sa." 649 command = f"{self.cmd} --intf-type xxx" 650 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 651 652 expect_result = """[IDL-GEN]: The Option "--intf-type" is illegal.\n""" 653 expect_result += """Use "-h, --help" to show usage.""" 654 command = f"{self.cmd} --intf-type" 655 ret &= exec_command_check(command, expect_result, RetStatus.ERR) 656 657 return ret 658 659def get_subclasses(cls): 660 return cls.__subclasses__() 661 662 663class Tests: 664 test_cases = get_subclasses(Test) 665 pass 666 667 @staticmethod 668 def set_up_test_case(): 669 hdi_gen_file = get_idl() 670 ret = file_exists(hdi_gen_file) 671 if not ret: 672 print_failure("[===========] no such file:{}".format(hdi_gen_file)) 673 return ret 674 675 @staticmethod 676 def set_down_test_case(): 677 pass 678 679 @staticmethod 680 def test(): 681 test_case_num = len(Tests.test_cases) 682 success_case_num = 0 683 print_success("[===========] start {} test".format(test_case_num)) 684 for test_case in Tests.test_cases: 685 obj = test_case() 686 if obj.test(): 687 success_case_num += 1 688 print_success("[ PASSED ] {} test".format(success_case_num)) 689 failure_case_num = test_case_num - success_case_num 690 if failure_case_num > 0: 691 print_failure("[ FAILED ] {} test".format(failure_case_num)) 692 693 694if __name__ == "__main__": 695 if not Tests.set_up_test_case(): 696 exit(-1) 697 Tests.test() 698 Tests.set_down_test_case() 699