MCPcopy Create free account
hub / github.com/EmbeddedRPC/erpc / CTests

Class CTests

test/run_unit_tests.py:432–544  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

430
431
432class CTests(AbstractTests):
433
434 def __init__(self, c_compiler: str | None = None, cxx_compiler: str | None = None, target: str | None = None,
435 build_all: bool = False, conf_file: str | None = None, menuconfig: bool = False,
436 **kwargs: dict[str, Any]) -> None:
437 super().__init__(**kwargs)
438
439 self.menuconfig = menuconfig
440 self.c_compiler = c_compiler
441 self.cxx_compiler = cxx_compiler
442 self.target = target
443 self.build_all = build_all
444 self.conf_file = Path(conf_file).absolute() if conf_file else self.test_dir.joinpath("prj.conf")
445
446 def init_tests(self) -> bool:
447 """
448 Generate cmake project and build test one by one or all together if --build/-b is selected.
449 If --menuconfig is enabled, show menu config before build.
450 @return: set of built tests
451 """
452 if self.pristine and self.build_dir.exists():
453 print(f"{bcolors.ORANGE}Pristine enabled, removing {self.build_dir}.{bcolors.ENDC}")
454 shutil.rmtree(self.build_dir)
455
456 if not self.build_dir.exists():
457 self.build_dir.mkdir()
458
459 if self.cmake_generate() != 0:
460 print(f"{bcolors.RED}CMake project generation FAILED.{bcolors.ENDC}")
461 return False
462
463 if self.menuconfig:
464 if self.cmake_build_target("menuconfig") != 0:
465 print(f"{bcolors.RED}Building menuconfig for Kconfig FAILED.{bcolors.ENDC}")
466 return False
467
468 if self.build_all:
469 if self.cmake_build_target("test_all") != 0:
470 print(f"{bcolors.RED}Tests build FAILED.{bcolors.ENDC}")
471 return False
472 else:
473 for test_case in self.test_cases:
474 print(f"{bcolors.BLUE}Building: {test_case}{bcolors.ENDC}")
475 if self.cmake_build_target(test_case) != 0:
476 print(f"{bcolors.RED}Test'{test_case}' build FAILED.{bcolors.ENDC}")
477
478 return True
479
480 def test_case_client_exist(self, test_case: str) -> bool:
481 return self.executable_exists(self.get_test_executable(test_case, "client", self.transport))
482
483 def test_case_server_exist(self, test_case: str) -> bool:
484 return self.executable_exists(self.get_test_executable(test_case, "server", self.transport))
485
486 def client(self) -> None:
487 result_file = self.get_result_file()
488 client_executable = self.get_test_executable(self.test_case, "client", self.transport)
489

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by 1

mainFunction · 0.68