Skip to content

Commit

Permalink
Uniform way for testing targets
Browse files Browse the repository at this point in the history
  • Loading branch information
DamMicSzm authored and arkq committed Feb 2, 2023
1 parent fbf362a commit a04dabd
Show file tree
Hide file tree
Showing 15 changed files with 521 additions and 67 deletions.
13 changes: 13 additions & 0 deletions examples/all-clusters-app/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
Expand All @@ -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" ]
}
17 changes: 17 additions & 0 deletions examples/all-clusters-minimal-app/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
Expand All @@ -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" ]
}
14 changes: 14 additions & 0 deletions examples/lighting-app/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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" ]
}
Empty file modified scripts/bootstrap.sh
100644 → 100755
Empty file.
123 changes: 102 additions & 21 deletions scripts/build/build/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,40 +195,77 @@ 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-"),
TargetPart(name='shell', app=HostApp.LIGHT).OnlyIfRe("-(x64|arm64)-"),
])
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:
Expand All @@ -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:
Expand All @@ -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.
Expand All @@ -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):
Expand All @@ -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

Expand All @@ -319,21 +400,21 @@ 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.
"""
suffix = _HasVariantPrefix(value, self.name)
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

Expand Down
Loading

0 comments on commit a04dabd

Please sign in to comment.