blob: d453453f28f900418021e261ba9ebf21fd53363a [file] [edit]
# Copyright 2026 The Pigweed 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
#
# https://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.
"""Example usage of the pw_coverage solver."""
# DOCSTAG: [pw_coverage-examples-quick_start]
from pw_coverage.config_solver import (
CoverageSolver,
TestModel,
Parameter,
Option,
Exclusion,
CoverageGoal,
)
def main() -> None:
"""Example usage of the pw_coverage solver."""
# 1. Define the parameters of your build matrix
model = TestModel(
parameters=[
Parameter(
"OS",
[
Option("Linux", cost=1),
Option("Windows", cost=5), # Windows is expensive!
Option("Mac", cost=5),
],
),
Parameter("Compiler", [Option("GCC"), Option("Clang")]),
],
# 2. Define constraints (what is invalid?)
constraints=[
Exclusion(
criteria={"OS": "Windows"}, forbidden={"Compiler": {"GCC"}}
)
],
# 3. Define what you MUST cover
coverage_goals=[
CoverageGoal(["OS"]) # We must test at least one config for each OS
],
)
# 4. Solve!
solver = CoverageSolver(model)
result = solver.solve()
for i, config in enumerate(result.selected_configurations):
print(f"Test {i+1}: {config}")
# DOCSTAG: [pw_coverage-examples-quick_start]
if __name__ == '__main__':
main()