| load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") |
| load("//bazel/private:zephyr_transition.bzl", "resolve_board_id") |
| |
| def _transition_test_impl(ctx): |
| env = unittest.begin(ctx) |
| |
| package_to_boards = { |
| "boards": ["native_sim", "board1"], |
| "boards/sub": ["sub"], |
| "boards/soc": ["board2/soc2", "board3/soc3"], |
| "boards/single": ["board2"], |
| "boards/fallback": ["my_board"], |
| } |
| |
| def make_label(name, pkg): |
| return struct(name = name, package = pkg) |
| |
| def check_resolve(expected, name, pkg): |
| asserts.equals( |
| env, |
| expected, |
| resolve_board_id( |
| make_label(name, pkg), |
| pkg, |
| package_to_boards.get(pkg, []), |
| package_to_boards, |
| ), |
| ) |
| |
| # Rule A: Default Shortcut (exactly one board) |
| check_resolve("board2", "default", "boards/single") |
| |
| # Rule B: SoC/Variant Match (explicit ends-with) |
| check_resolve("board2/soc2", "soc2", "boards/soc") |
| |
| # Rule B: SoC/Variant Match - Fallback for single base board |
| check_resolve("my_board/my_soc", "my_soc", "boards/fallback") |
| |
| return unittest.end(env) |
| |
| transition_test = unittest.make(_transition_test_impl) |
| |
| def transition_test_suite(name): |
| unittest.suite( |
| name, |
| transition_test, |
| ) |