From a04dabda4d07f770e5eb8c2e2ed3eecad3ca8e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Michalak-Szmaci=C5=84ski?= Date: Thu, 8 Sep 2022 11:31:49 +0200 Subject: [PATCH] Uniform way for testing targets --- examples/all-clusters-app/tizen/BUILD.gn | 13 ++ .../all-clusters-minimal-app/tizen/BUILD.gn | 17 ++ examples/lighting-app/tizen/BUILD.gn | 14 ++ scripts/bootstrap.sh | 0 scripts/build/build/target.py | 123 +++++++++++--- scripts/build/build/targets.py | 111 +++++++------ scripts/build/build_examples.py | 10 +- scripts/build/builders/tizen.py | 6 + src/test_driver/tizen/.gn | 26 +++ src/test_driver/tizen/BUILD.gn | 29 ++++ src/test_driver/tizen/args.gni | 25 +++ src/test_driver/tizen/build_overrides | 1 + src/test_driver/tizen/run_qemu_test.py | 150 ++++++++++++++++++ src/test_driver/tizen/testing_process.sh | 62 ++++++++ .../tizen/third_party/connectedhomeip | 1 + 15 files changed, 521 insertions(+), 67 deletions(-) mode change 100644 => 100755 scripts/bootstrap.sh create mode 100644 src/test_driver/tizen/.gn create mode 100644 src/test_driver/tizen/BUILD.gn create mode 100644 src/test_driver/tizen/args.gni create mode 120000 src/test_driver/tizen/build_overrides create mode 100755 src/test_driver/tizen/run_qemu_test.py create mode 100755 src/test_driver/tizen/testing_process.sh create mode 120000 src/test_driver/tizen/third_party/connectedhomeip diff --git a/examples/all-clusters-app/tizen/BUILD.gn b/examples/all-clusters-app/tizen/BUILD.gn index ba1cf3a3ca51bd..5a1ba67587bec9 100644 --- a/examples/all-clusters-app/tizen/BUILD.gn +++ b/examples/all-clusters-app/tizen/BUILD.gn @@ -67,6 +67,14 @@ tizen_sdk_package("chip-all-clusters-app:tpk") { sign_security_profile = "CHIP" } +group("chip-all-clusters-app:test") { + testonly = true + deps = [ + ":chip-all-clusters-app", + ":chip-all-clusters-app:tpk", + ] +} + group("tizen") { deps = [ ":chip-all-clusters-app" ] } @@ -75,6 +83,11 @@ group("tizen:tpk") { deps = [ ":chip-all-clusters-app:tpk" ] } +group("tizen:test") { + testonly = true + deps = [ ":chip-all-clusters-app:test" ] +} + group("default") { deps = [ ":tizen" ] } diff --git a/examples/all-clusters-minimal-app/tizen/BUILD.gn b/examples/all-clusters-minimal-app/tizen/BUILD.gn index 138c6e9c2e6850..60dd2fbc24166a 100644 --- a/examples/all-clusters-minimal-app/tizen/BUILD.gn +++ b/examples/all-clusters-minimal-app/tizen/BUILD.gn @@ -67,6 +67,18 @@ tizen_sdk_package("chip-all-clusters-minimal-app:tpk") { sign_security_profile = "CHIP" } +qemu_test("chip-all-clusters-minimal-app:qemu-test") { + deps = [ ":chip-all-clusters-minimal-app:test" ] +} + +group("chip-all-clusters-minimal-app:test") { + testonly = true + deps = [ + ":chip-all-clusters-minimal-app", + ":chip-all-clusters-minimal-app:tpk", + ] +} + group("tizen") { deps = [ ":chip-all-clusters-minimal-app" ] } @@ -75,6 +87,11 @@ group("tizen:tpk") { deps = [ ":chip-all-clusters-minimal-app:tpk" ] } +group("tizen:test") { + testonly = true + deps = [ ":chip-all-clusters-minimal-app" ] +} + group("default") { deps = [ ":tizen" ] } diff --git a/examples/lighting-app/tizen/BUILD.gn b/examples/lighting-app/tizen/BUILD.gn index 4344f742f964c5..2a4fdaa2af0d58 100644 --- a/examples/lighting-app/tizen/BUILD.gn +++ b/examples/lighting-app/tizen/BUILD.gn @@ -46,6 +46,15 @@ tizen_sdk_package("chip-lighting-app:tpk") { ] manifest = "tizen-manifest.xml" sign_security_profile = "CHIP" + print("Tutaj:", target_name) +} + +group("chip-lighting-app:test") { + testonly = true + deps = [ + ":chip-lighting-app", + ":chip-lighting-app:tpk", + ] } group("tizen") { @@ -56,6 +65,11 @@ group("tizen:tpk") { deps = [ ":chip-lighting-app:tpk" ] } +group("tizen:test") { + testonly = true + deps = [ ":chip-lighting-app:test" ] +} + group("default") { deps = [ ":tizen" ] } diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh old mode 100644 new mode 100755 diff --git a/scripts/build/build/target.py b/scripts/build/build/target.py index 63c278a233cb57..899cbb05f3dbca 100644 --- a/scripts/build/build/target.py +++ b/scripts/build/build/target.py @@ -195,24 +195,41 @@ def __init__(self, name, builder_class, **kwargs): # - esp32-devkitc-light is OK # - esp32-light is NOT ok # - esp32-m5stack is NOT ok - self.fixed_targets: List[List[TargetPart]] = [] + self.board: List[TargetPart] = [] + self.apps: List[TargetPart] = [] + self.tests: List[TargetPart] = [] # a list of all available modifiers for this build target # Modifiers can be combined in any way self.modifiers: List[TargetPart] = [] - def AppendFixedTargets(self, parts: List[TargetPart]): - """Append a list of potential targets/variants. + def AppendBoard(self, parts: List[TargetPart]): + """Append a list of potential board-targets/variants. Example: target = BuildTarget('linux', LinuxBuilder) - target.AppendFixedTargets([ + target.AppendBoard([ TargetPart(name='x64', board=HostBoard.X64), TargetPart(name='x86', board=HostBoard.X86), TargetPart(name='arm64', board=HostBoard.ARM64), ]) + The above will accept: + linux-x64-{Apps} + linux-x86-{Apps} + linux-arm64-{Apps} + linux-x64-{Tests} + linux-x86-{Tests} + linux-arm64-{Tests} + """ + self.board.append(parts) + + def AppendAppsTargets(self, parts: List[TargetPart]): + """Append a list of potential targets/variants. + + Example: + target.AppendFixedTargets([ TargetPart(name='light', app=HostApp.LIGHT), TargetPart(name='lock', app=HostApp.LIGHT).ExceptIfRe("-arm64-"), @@ -220,15 +237,35 @@ def AppendFixedTargets(self, parts: List[TargetPart]): ]) The above will accept: - linux-x64-light - linux-x86-light - linux-arm64-light - linux-x64-lock - linux-x86-lock - linux-x64-shell - linux-arm64-shell + linux-(Boards)-light + linux-(Boards)-lock + linux-(Boards)-shell + linux-light + linux-lock + linux-shell + """ + self.apps.append(parts) + + def AppendTestsTargets(self, parts: List[TargetPart]): + """Append a list of potential testing-targets/variants. + + Example: + + target.AppendTestsTargets([ + TargetPart(name='qemu', app=HostApp.LIGHT), + TargetPart(name='unity', app=HostApp.LIGHT).ExceptIfRe("-arm64-"), + TargetPart(name='raw', app=HostApp.LIGHT).OnlyIfRe("-(x64|arm64)-"), + ]) + + The above will accept: + linux-(Boards)-qemu + linux-(Boards)-unity + linux-(Boards)-raw + linux-qemu + linux-unity + linux-raw """ - self.fixed_targets.append(parts) + self.tests.append(parts) def AppendModifier(self, name: str, **kargs): """Appends a specific modifier to a build target. For example: @@ -253,7 +290,13 @@ def HumanString(self): foo-bar-{a,b,c}[-m1][-m2] """ result = self.name - for fixed in self.fixed_targets: + for fixed in self.board: + if len(fixed) > 1: + result += '-(' + ",".join(map(lambda x: x.name, fixed)) + ')' + else: + result += '-' + fixed[0].name + + for fixed in self.apps: if len(fixed) > 1: result += '-{' + ",".join(map(lambda x: x.name, fixed)) + '}' else: @@ -264,6 +307,43 @@ def HumanString(self): return result + def HumanStringTestingTargets(self): + result = self.name + if not self.tests: + return None + + for fixed in self.board: + if len(fixed) > 1: + result += '-(' + ",".join(map(lambda x: x.name, fixed)) + ')' + else: + result += '-' + fixed[0].name + + for fixed in self.tests: + if len(fixed) > 1: + result += '-{' + ",".join(map(lambda x: x.name, fixed)) + '}' + else: + result += '-' + fixed[0].name + + for modifier in self.modifiers: + result += f"[-{modifier.name}]" + + return result + + def GetFixedTargets(self) -> List[List[TargetPart]]: + fixed_targets: List[List[TargetPart]] = [] + len_fixed_targets = len(fixed_targets) + + for fixed in [self.board, self.apps]: + fixed_targets.extend(fixed) + + if len(fixed_targets) <= 1: + fixed_targets.extend(self.tests) + else: + for test in self.tests: + fixed_targets[len(fixed_targets) - 1].extend(test) + + return fixed_targets + def AllVariants(self) -> Iterable[str]: """Returns all possible accepted variants by this target. @@ -286,12 +366,13 @@ def AllVariants(self) -> Iterable[str]: # - a valid combination of "fixed parts" # - a combination of modifiers - fixed_indices = [0]*len(self.fixed_targets) + fixed_targets = self.GetFixedTargets() + fixed_indices = [0]*len(fixed_targets) while True: prefix = "-".join(map( - lambda p: self.fixed_targets[p[0]][p[1]].name, enumerate(fixed_indices) + lambda p: fixed_targets[p[0]][p[1]].name, enumerate(fixed_indices) )) for n in range(len(self.modifiers) + 1): @@ -301,13 +382,13 @@ def AllVariants(self) -> Iterable[str]: suffix += "-" + m.name option = f"{self.name}-{prefix}{suffix}" - if self.StringIntoTargetParts(option) is not None: + if self.StringIntoTargetParts(option , fixed_targets) is not None: yield option # Move to the next index in fixed_indices or exit loop if we cannot move move_idx = len(fixed_indices) - 1 while move_idx >= 0: - if fixed_indices[move_idx] + 1 < len(self.fixed_targets[move_idx]): + if fixed_indices[move_idx] + 1 < len(fixed_targets[move_idx]): fixed_indices[move_idx] += 1 break @@ -319,7 +400,7 @@ def AllVariants(self) -> Iterable[str]: # done iterating through all return - def StringIntoTargetParts(self, value: str): + def StringIntoTargetParts(self, value: str, fixed_targets: List[List[TargetPart]]): """Given an input string, process through all the input rules and return the underlying list of target parts for the input. """ @@ -327,13 +408,13 @@ def StringIntoTargetParts(self, value: str): if not suffix: return None - return _StringIntoParts(value, suffix, self.fixed_targets, self.modifiers) + return _StringIntoParts(value, suffix, fixed_targets, self.modifiers) def Create(self, name: str, runner, repository_path: str, output_prefix: str, builder_options: BuilderOptions): - parts = self.StringIntoTargetParts(name) - + fixed_targets = self.GetFixedTargets() + parts = self.StringIntoTargetParts(name, fixed_targets) if not parts: return None diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index ef8d863e727d4e..8d3a41207a5941 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -43,11 +43,11 @@ def BuildHostTestRunnerTarget(): target = BuildTarget(HostBoard.NATIVE.PlatformName(), HostBuilder) - target.AppendFixedTargets([ + target.AppendBoard([ TargetPart(HostBoard.NATIVE.BoardName(), board=HostBoard.NATIVE), ]) - target.AppendFixedTargets([ + target.AppendTestsTargets([ TargetPart('efr32-test-runner', app=HostApp.EFR32_TEST_RUNNER) ]) @@ -59,11 +59,11 @@ def BuildHostTestRunnerTarget(): def BuildHostFakeTarget(): target = BuildTarget(HostBoard.NATIVE.PlatformName(), HostBuilder) - target.AppendFixedTargets([ + target.AppendBoard([ TargetPart('fake', board=HostBoard.FAKE), ]) - target.AppendFixedTargets([ + target.AppendTestsTargets([ TargetPart('tests', app=HostApp.TESTS), ]) @@ -93,7 +93,7 @@ def BuildHostTarget(): if cross_compile: board_parts.append(TargetPart('arm64', board=HostBoard.ARM64).OnlyIfRe('-(clang|nodeps)')) - target.AppendFixedTargets(board_parts) + target.AppendBoard(board_parts) # Add all the applications app_parts = [ @@ -114,15 +114,15 @@ def BuildHostTarget(): TargetPart('tv-casting-app', app=HostApp.TV_CASTING), TargetPart('bridge', app=HostApp.BRIDGE), TargetPart('dynamic-bridge', app=HostApp.DYNAMIC_BRIDGE), - TargetPart('tests', app=HostApp.TESTS), - TargetPart('chip-cert', app=HostApp.CERT_TOOL), + TargetPart('chip-cert', app=HostApp.CERT_TOOL), TargetPart('tests', app=HostApp.TESTS), TargetPart('address-resolve-tool', app=HostApp.ADDRESS_RESOLVE), ] if (HostBoard.NATIVE.PlatformName() == 'darwin'): app_parts.append(TargetPart('darwin-framework-tool', app=HostApp.CHIP_TOOL_DARWIN)) - target.AppendFixedTargets(app_parts) + target.AppendAppsTargets(app_parts) + target.AppendTestsTargets([TargetPart('tests', app=HostApp.TESTS), ]) target.AppendModifier('nodeps', enable_ble=False, enable_wifi=False, enable_thread=False, crypto_library=HostCryptoLibrary.MBEDTLS, use_clang=True).ExceptIfRe('-(clang|noble|boringssl|mbedtls)') @@ -155,7 +155,7 @@ def BuildEsp32Target(): target = BuildTarget('esp32', Esp32Builder) # boards - target.AppendFixedTargets([ + target.AppendBoard([ TargetPart('m5stack', board=Esp32Board.M5Stack).OnlyIfRe('-(all-clusters|ota-requestor)'), TargetPart('c3devkit', board=Esp32Board.C3DevKit), TargetPart('devkitc', board=Esp32Board.DevKitC), @@ -163,7 +163,7 @@ def BuildEsp32Target(): ]) # applications - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('all-clusters', app=Esp32App.ALL_CLUSTERS), TargetPart('all-clusters-minimal', app=Esp32App.ALL_CLUSTERS_MINIMAL), TargetPart('ota-provider', app=Esp32App.OTA_PROVIDER), @@ -174,6 +174,8 @@ def BuildEsp32Target(): TargetPart('bridge', app=Esp32App.BRIDGE), TargetPart('temperature-measurement', app=Esp32App.TEMPERATURE_MEASUREMENT), TargetPart('ota-requestor', app=Esp32App.OTA_REQUESTOR), + ]) + target.AppendTestsTargets([ TargetPart('tests', app=Esp32App.TESTS).OnlyIfRe('-qemu-'), ]) @@ -187,7 +189,7 @@ def BuildEfr32Target(): target = BuildTarget('efr32', Efr32Builder) # board - target.AppendFixedTargets([ + board_parts = [ TargetPart('brd4161a', board=Efr32Board.BRD4161A), TargetPart('brd4187c', board=Efr32Board.BRD4187C), TargetPart('brd4163a', board=Efr32Board.BRD4163A), @@ -197,17 +199,22 @@ def BuildEfr32Target(): TargetPart('brd4186a', board=Efr32Board.BRD4186A), TargetPart('brd4187a', board=Efr32Board.BRD4187A), TargetPart('brd4304a', board=Efr32Board.BRD4304A), - ]) + ] + target.AppendBoard(board_parts) # apps - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('window-covering', app=Efr32App.WINDOW_COVERING), TargetPart('switch', app=Efr32App.SWITCH), - TargetPart('unit-test', app=Efr32App.UNIT_TEST), TargetPart('light', app=Efr32App.LIGHT), TargetPart('lock', app=Efr32App.LOCK), ]) + # testing + target.AppendTestsTargets([ + TargetPart('unit-test', app=Efr32App.UNIT_TEST), + ]) + target.AppendModifier('rpc', enable_rpcs=True) target.AppendModifier('with-ota-requestor', enable_ota_requestor=True) target.AppendModifier('sed', enable_sed=True) @@ -233,8 +240,12 @@ def BuildEfr32Target(): def BuildNrfNativeTarget(): target = BuildTarget('nrf', NrfConnectBuilder) - target.AppendFixedTargets([ - TargetPart('native-posix-64-tests', board=NrfBoard.NATIVE_POSIX_64, app=NrfApp.UNIT_TESTS), + target.AppendBoard([ + TargetPart('native', board=NrfBoard.NATIVE_POSIX_64).OnlyIfRe('posix-64-tests'), + ]) + + target.AppendTestsTargets([ + TargetPart('posix-64-tests', app=NrfApp.UNIT_TESTS).OnlyIfRe('native'), ]) return target @@ -244,14 +255,14 @@ def BuildNrfTarget(): target = BuildTarget('nrf', NrfConnectBuilder) # board - target.AppendFixedTargets([ + target.AppendBoard([ TargetPart('nrf5340dk', board=NrfBoard.NRF5340DK), TargetPart('nrf52840dk', board=NrfBoard.NRF52840DK), TargetPart('nrf52840dongle').OnlyIfRe('-(all-clusters|light)'), ]) # apps - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('all-clusters', app=NrfApp.ALL_CLUSTERS), TargetPart('all-clusters-minimal', app=NrfApp.ALL_CLUSTERS_MINIMAL), TargetPart('lock', app=NrfApp.LOCK), @@ -272,7 +283,7 @@ def BuildAndroidTarget(): target = BuildTarget('android', AndroidBuilder) # board - target.AppendFixedTargets([ + board_parts = [ TargetPart('arm', board=AndroidBoard.ARM), TargetPart('arm64', board=AndroidBoard.ARM64), TargetPart('x86', board=AndroidBoard.X86), @@ -281,17 +292,23 @@ def BuildAndroidTarget(): TargetPart('androidstudio-arm64', board=AndroidBoard.AndroidStudio_ARM64).OnlyIfRe('chip-tool'), TargetPart('androidstudio-x86', board=AndroidBoard.AndroidStudio_X86).OnlyIfRe('chip-tool'), TargetPart('androidstudio-x64', board=AndroidBoard.AndroidStudio_X64).OnlyIfRe('chip-tool'), - ]) + ] + target.AppendBoard(board_parts) # apps - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('chip-tool', app=AndroidApp.CHIP_TOOL), - TargetPart('chip-test', app=AndroidApp.CHIP_TEST), TargetPart('tv-server', app=AndroidApp.TV_SERVER), TargetPart('tv-casting-app', app=AndroidApp.TV_CASTING_APP), TargetPart('java-matter-controller', app=AndroidApp.JAVA_MATTER_CONTROLLER), ]) + # testing + target.AppendTestsTargets([ + TargetPart('chip-test', app=AndroidApp.CHIP_TEST), + + ]) + return target @@ -299,12 +316,12 @@ def BuildMbedTarget(): target = BuildTarget('mbed', MbedBuilder) # board - target.AppendFixedTargets([ + target.AppendBoard([ TargetPart('CY8CPROTO_062_4343W', board=MbedBoard.CY8CPROTO_062_4343W), ]) # apps - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('lock', app=MbedApp.LOCK), TargetPart('light', app=MbedApp.LIGHT), TargetPart('all-clusters', app=MbedApp.ALL_CLUSTERS), @@ -325,12 +342,12 @@ def BuildInfineonTarget(): target = BuildTarget('infineon', InfineonBuilder) # board - target.AppendFixedTargets([ + target.AppendBoard([ TargetPart('psoc6', board=InfineonBoard.PSOC6BOARD) ]) # apps - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('lock', app=InfineonApp.LOCK), TargetPart('light', app=InfineonApp.LIGHT), TargetPart('all-clusters', app=InfineonApp.ALL_CLUSTERS), @@ -348,12 +365,12 @@ def BuildAmebaTarget(): target = BuildTarget('ameba', AmebaBuilder) # board - target.AppendFixedTargets([ + target.AppendBoard([ TargetPart('amebad', board=AmebaBoard.AMEBAD), ]) # apps - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('all-clusters', app=AmebaApp.ALL_CLUSTERS), TargetPart('all-clusters-minimal', app=AmebaApp.ALL_CLUSTERS_MINIMAL), TargetPart('light', app=AmebaApp.LIGHT), @@ -368,7 +385,7 @@ def BuildK32WTarget(): target = BuildTarget('k32w', K32WBuilder) # apps - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('light', app=K32WApp.LIGHT, release=True), TargetPart('shell', app=K32WApp.SHELL, release=True), TargetPart('lock', app=K32WApp.LOCK, release=True), @@ -388,7 +405,7 @@ def Buildcc13x2x7_26x2x7Target(): target = BuildTarget('cc13x2x7_26x2x7', cc13x2x7_26x2x7Builder) # apps - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('all-clusters', app=cc13x2x7_26x2x7App.ALL_CLUSTERS), TargetPart('all-clusters-minimal', app=cc13x2x7_26x2x7App.ALL_CLUSTERS_MINIMAL), TargetPart('lock', app=cc13x2x7_26x2x7App.LOCK), @@ -407,12 +424,12 @@ def BuildCyw30739Target(): target = BuildTarget('cyw30739', Cyw30739Builder) # board - target.AppendFixedTargets([ + target.AppendBoard([ TargetPart('cyw930739m2evb_01', board=Cyw30739Board.CYW930739M2EVB_01), ]) # apps - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('light', app=Cyw30739App.LIGHT), TargetPart('lock', app=Cyw30739App.LOCK), TargetPart('ota-requestor', app=Cyw30739App.OTA_REQUESTOR), @@ -427,12 +444,12 @@ def BuildQorvoTarget(): target = BuildTarget('qpg', QpgBuilder) # board - target.AppendFixedTargets([ + target.AppendBoard([ TargetPart('qpg6105', board=QpgBoard.QPG6105), ]) # apps - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('lock', app=QpgApp.LOCK), TargetPart('light', app=QpgApp.LIGHT), TargetPart('shell', app=QpgApp.SHELL), @@ -446,18 +463,22 @@ def BuildTizenTarget(): target = BuildTarget('tizen', TizenBuilder) # board - target.AppendFixedTargets([ + target.AppendBoard([ TargetPart('arm', board=TizenBoard.ARM), ]) - # apps - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('all-clusters', app=TizenApp.ALL_CLUSTERS), TargetPart('all-clusters-minimal', app=TizenApp.ALL_CLUSTERS_MINIMAL), TargetPart('chip-tool', app=TizenApp.CHIP_TOOL), TargetPart('light', app=TizenApp.LIGHT), ]) + # Testing + target.AppendTestsTargets([ + TargetPart('qemu-tests', app=TizenApp.CHIP_QEMU_TESTS).OnlyIfRe('-arm-'), + ]) + target.AppendModifier(name="no-ble", enable_ble=False) target.AppendModifier(name="no-wifi", enable_wifi=False) target.AppendModifier(name="asan", use_asan=True) @@ -470,7 +491,7 @@ def BuildBouffalolabTarget(): target = BuildTarget('bouffalolab', BouffalolabBuilder) # Boards - target.AppendFixedTargets([ + target.AppendBoard([ TargetPart('BL602-IoT-Matter-V1', board=BouffalolabBoard.BL602_IoT_Matter_V1, module_type="BL602"), TargetPart('BL602-IOT-DVK-3S', board=BouffalolabBoard.BL602_IOT_DVK_3S, module_type="BL602"), TargetPart('BL602-NIGHT-LIGHT', board=BouffalolabBoard.BL602_NIGHT_LIGHT, module_type="BL602"), @@ -480,7 +501,7 @@ def BuildBouffalolabTarget(): ]) # Apps - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('light', app=BouffalolabApp.LIGHT), ]) @@ -494,7 +515,7 @@ def BuildBouffalolabTarget(): def BuildIMXTarget(): target = BuildTarget('imx', IMXBuilder) - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('chip-tool', app=IMXApp.CHIP_TOOL), TargetPart('lighting-app', app=IMXApp.LIGHT), TargetPart('thermostat', app=IMXApp.THERMOSTAT), @@ -510,21 +531,21 @@ def BuildIMXTarget(): def BuildMW320Target(): target = BuildTarget('mw320', MW320Builder) - target.AppendFixedTargets([TargetPart('all-clusters-app', app=MW320App.ALL_CLUSTERS)]) + target.AppendAppsTargets([TargetPart('all-clusters-app', app=MW320App.ALL_CLUSTERS)]) return target def BuildGenioTarget(): target = BuildTarget('genio', GenioBuilder) - target.AppendFixedTargets([TargetPart('lighting-app', app=GenioApp.LIGHT)]) + target.AppendAppsTargets([TargetPart('lighting-app', app=GenioApp.LIGHT)]) return target def BuildTelinkTarget(): target = BuildTarget('telink', TelinkBuilder) - target.AppendFixedTargets([TargetPart('tlsr9518adk80d', board=TelinkBoard.TLSR9518ADK80D)]) + target.AppendBoard([TargetPart('tlsr9518adk80d', board=TelinkBoard.TLSR9518ADK80D)]) - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('all-clusters', app=TelinkApp.ALL_CLUSTERS), TargetPart('all-clusters-minimal', app=TelinkApp.ALL_CLUSTERS_MINIMAL), TargetPart('contact-sensor', app=TelinkApp.CONTACT_SENSOR), @@ -540,7 +561,7 @@ def BuildTelinkTarget(): def BuildOpenIotSdkTargets(): target = BuildTarget('openiotsdk', OpenIotSdkBuilder) - target.AppendFixedTargets([ + target.AppendAppsTargets([ TargetPart('shell', app=OpenIotSdkApp.SHELL), TargetPart('lock', app=OpenIotSdkApp.LOCK), ]) diff --git a/scripts/build/build_examples.py b/scripts/build/build_examples.py index c70a5da7981d49..1888d138e552da 100755 --- a/scripts/build/build_examples.py +++ b/scripts/build/build_examples.py @@ -179,18 +179,26 @@ def cmd_generate(context): 'targets', help=('List the targets that would be generated/built given ' 'the input arguments')) +@click.option( + '--testing', + default=False, + is_flag=True, + help='Show list available testing targets') @click.option( '--expand', default=False, is_flag=True, help='Expand all possible targets rather than the shorthand string') @click.pass_context -def cmd_targets(context, expand): +def cmd_targets(context, expand, testing): for target in build.targets.BUILD_TARGETS: if expand: build.target.report_rejected_parts = False for s in target.AllVariants(): print(s) + elif testing: + if target.HumanStringTestingTargets() is not None: + print(target.HumanStringTestingTargets()) else: print(target.HumanString()) diff --git a/scripts/build/builders/tizen.py b/scripts/build/builders/tizen.py index 71ae18e9f1cce6..48f8564c31e954 100644 --- a/scripts/build/builders/tizen.py +++ b/scripts/build/builders/tizen.py @@ -49,6 +49,12 @@ class TizenApp(Enum): ('chip-tool', 'chip-tool.map')) + CHIP_QEMU_TESTS = Tool( + 'chip-qemu-tests', + 'src/test_driver/tizen', + ('chip-qemu-tests', + 'chip-qemu-tests.map')) + @property def is_tpk(self): """If True, this app is a TPK.""" diff --git a/src/test_driver/tizen/.gn b/src/test_driver/tizen/.gn new file mode 100644 index 00000000000000..c50b81609edec2 --- /dev/null +++ b/src/test_driver/tizen/.gn @@ -0,0 +1,26 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/build.gni") + +# The location of the build configuration file. +buildconfig = "${build_root}/config/BUILDCONFIG.gn" + +# CHIP uses angle bracket includes. +check_system_includes = true + +default_args = { + target_os = "tizen" + import("//args.gni") +} diff --git a/src/test_driver/tizen/BUILD.gn b/src/test_driver/tizen/BUILD.gn new file mode 100644 index 00000000000000..8ba4f873c754b2 --- /dev/null +++ b/src/test_driver/tizen/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/chip.gni") +import("//build_overrides/tizen.gni") + +import("${chip_root}/build/chip/tools.gni") +import("${chip_root}/src/app/common_flags.gni") +import("${tizen_sdk_build_root}/tizen_sdk.gni") + +assert(chip_build_tools) + +qemu_test("chip-qemu-tests") { + deps = [ + "${chip_root}/examples/all-clusters-app/tizen/:chip-all-clusters-app:test", + "${chip_root}/examples/lighting-app/tizen/:chip-lighting-app:test", + ] +} diff --git a/src/test_driver/tizen/args.gni b/src/test_driver/tizen/args.gni new file mode 100644 index 00000000000000..35c6020ba95643 --- /dev/null +++ b/src/test_driver/tizen/args.gni @@ -0,0 +1,25 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/chip.gni") + +import("${chip_root}/config/standalone/args.gni") + +chip_device_project_config_include = "" +chip_project_config_include = "" +chip_system_project_config_include = "" + +chip_project_config_include_dirs = + [ "${chip_root}/examples/lighting-app/tizen/include" ] +chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ] diff --git a/src/test_driver/tizen/build_overrides b/src/test_driver/tizen/build_overrides new file mode 120000 index 00000000000000..f2758328a72777 --- /dev/null +++ b/src/test_driver/tizen/build_overrides @@ -0,0 +1 @@ +../../../examples/build_overrides \ No newline at end of file diff --git a/src/test_driver/tizen/run_qemu_test.py b/src/test_driver/tizen/run_qemu_test.py new file mode 100755 index 00000000000000..fc414dcbfb1b5a --- /dev/null +++ b/src/test_driver/tizen/run_qemu_test.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python3 +# Copyright (c) 2021 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import coloredlogs +import click +import logging +import os +import re +import sys +import subprocess +import glob +import shutil + +# Supported log levels, mapping string values required for argument +# parsing into logging constants +__LOG_LEVELS__ = { + 'debug': logging.DEBUG, + 'info': logging.INFO, + 'warn': logging.WARN, + 'fatal': logging.FATAL, +} + + +@click.command() +@click.option( + '--log-level', + default='INFO', + type=click.Choice(__LOG_LEVELS__.keys(), case_sensitive=False), + help='Determines the verbosity of script output.') +@click.option( + '--target', + default='tizen-arm-light-no-ble', + help='Select target application') +@click.option( + '--out-dir', + default='/opt/tizen-qemu', + help='Select directory where app.iso will be created for mount inside qemu') +@click.option( + '--images-dir', + default='/opt/tizen-qemu', + help='Select directory where located prepared system images for qemu') +@click.option( + '--verbose', + default=False, + is_flag=True, + help='More verbose output') +def main(images_dir, log_level, out_dir, target, verbose): + # Ensures somewhat pretty logging of what is going on + log_fmt = '%(asctime)s %(levelname)-7s %(message)s' + coloredlogs.install(level=__LOG_LEVELS__[log_level], fmt=log_fmt) + script_path = os.path.dirname(os.path.realpath(sys.argv[0])) + terget_dir = os.path.join(os.getenv('PW_PROJECT_ROOT'), "out", target) + + # Create an ISO witch target application and chip-tool + try: + if not os.path.exists('%s/apps' % out_dir): + os.makedirs('%s/apps' % out_dir) + + for src_files in glob.glob(r'%s/package/*-app' % terget_dir): + print(src_files) + for file in glob.glob(r'%s/package/out/*.tpk' % src_files): + print(file) + shutil.copy(file, '%s/apps' % out_dir) + + output = subprocess.run('cp -r %s/chip-tool %s/apps' % (terget_dir, out_dir), shell=True) + if output.returncode != 0: + raise Exception("Can't copy %s/chip-tool" % terget_dir) + + output = subprocess.run('cp -r %s/testing_process.sh %s/apps' % (script_path, out_dir), shell=True) + if output.returncode != 0: + raise Exception("Can't copy testing process script") + + output = subprocess.run(['mkisofs', "-o", + "%s/app.iso" % out_dir, + "-J", "-U", "-R", + "-input-charset", "default", + "-V", "CHIP", + "%s/apps" % out_dir], capture_output=True) + + if output.returncode != 0: + raise Exception("Can't create ISO file image") + + # Clean after create iso + shutil.rmtree('%s/apps' % out_dir) + + logging.info("Correct created %s/app.iso" % out_dir) + except subprocess.CalledProcessError as e: + print(e.output) + raise + + logging.info("Testing target: %s", target) + print("============== TEST BEGIN ================") + + with subprocess.Popen(['qemu-system-arm', + '-monitor', 'null', + '-serial', 'stdio', + '-display', 'none', + '-M', 'virt', + '-smp', '2', + '-m', '512M', + '-kernel', '%s/tizen-iot-virt-zImage' % images_dir, + '-append', "console=ttyAMA0 earlyprintk earlycon root=/dev/vda", + '-device', 'virtio-net-device,netdev=virtio-net', + '-device', 'virtio-blk-device,drive=virtio-blk3', + '-device', 'virtio-blk-device,drive=virtio-blk2', + '-device', 'virtio-blk-device,drive=virtio-blk1', + '-netdev', 'user,id=virtio-net', + '-drive', 'file=%s/tizen-iot-rootfs.img,id=virtio-blk1,if=none,format=raw' % images_dir, + '-drive', 'file=%s/tizen-iot-sysdata.img,id=virtio-blk2,if=none,format=raw' % images_dir, + '-drive', 'file=%s/app.iso,id=virtio-blk3,if=none,format=raw' % out_dir], + encoding="850", + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + universal_newlines=True) as proc: + status = proc + for line in proc.stdout.readlines(): + line = line.rstrip() + try: + if verbose: + print(line) + + if status.returncode is not None: + raise Exception("Target %s testing failed with code: " % target + str(status.returncode)) + + if re.match(r"^CHIP test(\s+([A-Za-z0-9]+\s+)+)status: [1-9]+$", line): + raise Exception("CHIP test FAILED: %s" % line) + + except Exception as e: + logging.fatal(e) + print("============== TEST END ================") + raise + + print("============== TEST END ================") + logging.info("Target %s PASSED", target) + + +if __name__ == '__main__': + main() diff --git a/src/test_driver/tizen/testing_process.sh b/src/test_driver/tizen/testing_process.sh new file mode 100755 index 00000000000000..9a58746775282f --- /dev/null +++ b/src/test_driver/tizen/testing_process.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +# +# Copyright (c) 2021 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# This script is only for running inside qemu machine with Tizen image +# The script contains a set of tasks that perform integration tests + +APP_DIR=/mnt/chip +CHECK_ALL=false + +# Function check status after execute +function check_status() { + echo "CHIP test $1 status: $2" + if [[ $2 != 0 ]] && ! "$CHECK_ALL"; then + echo o >/proc/sysrq-trigger + fi +} + +# Install application Matter on Tizen +pkgcmd -i -t tpk -p /mnt/chip/org.tizen.matter.* +check_status "install Matter app" $? + +# Start debug CHIP +dlogutil CHIP & + +# Run application +app_launcher -s org.tizen.matter.example.lighting +check_status "run application chip" $? + +# Testing +# ----------------------------------------------------------------------- +# For correct automatic verification of tests, complete the checking +# part in the run_qemu_test.py script +# ----------------------------------------------------------------------- +# Pair app +"$APP_DIR"/chip-tool pairing onnetwork 1 20202021 +check_status "pair app" $? + +# Test on cluster +"$APP_DIR"/chip-tool onoff on 1 1 +check_status "on cluster" $? + +# Test off cluster +"$APP_DIR"/chip-tool onoff off 1 1 +check_status "off cluster" $? + +# Fast Shutdown emulated system +echo o >/proc/sysrq-trigger diff --git a/src/test_driver/tizen/third_party/connectedhomeip b/src/test_driver/tizen/third_party/connectedhomeip new file mode 120000 index 00000000000000..c866b86874994d --- /dev/null +++ b/src/test_driver/tizen/third_party/connectedhomeip @@ -0,0 +1 @@ +../../../.. \ No newline at end of file