Documentation
¶
Overview ¶
Package priority provides tools for selecting between boards to test.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoardInfo ¶
type BoardInfo = floatPriority
BoardInfo represents a (chosen) board and its index in the original input boards list. This is done by exposing relevant floatPriority fields to external packages. Index is needed for multi-dut tests where the input may have repeating boards for different multi-dut combinations.
type RandomWeightedSelector ¶
type RandomWeightedSelector struct {
// contains filtered or unexported fields
}
RandomWeightedSelector selects from a list of boards, with a random choice weighted by BoardPriorities. The algorithm is as follows:
- The sign of priorities is flipped, so that the board with the most negative configured priority now has the most positive priority.
- If a priority is not defined for a board, it is implicitly 0, as defined in the BoardPriority proto comment.
- Priorities are shifted so that the minimum priority is 1.
- Priorities are divided by the sum of the shifted priorities. At this point, the priorities form a probability distribution (each is in the range (0, 1], and they sum to 1). Each board's probability is proportional to its original configured priority, i.e. the board with the most negative configured priority has the highest probability.
- Sample a board from the probability distribution.
func NewRandomWeightedSelector ¶
func NewRandomWeightedSelector(rand *rand.Rand, boardPriorityList *testplans.BoardPriorityList) *RandomWeightedSelector
NewRandomWeightedSelector returns a RandomWeightedSelector based on boardPriorityList.
func (*RandomWeightedSelector) Select ¶
func (rw *RandomWeightedSelector) Select(ctx context.Context, pool string, boards []string) (string, error)
Select is a wrapper of SelectPriority. TODO(mingkong): remove the wrapper once the code is fully migrated to the new method signature.
func (*RandomWeightedSelector) SelectPriority ¶
func (rw *RandomWeightedSelector) SelectPriority(ctx context.Context, pool string, boards []string) (BoardInfo, error)
SelectPriority randomly chooses a board from boards, with the probability a board is chosen proportional to its configured probability. Returns a BoardInfo object that contains the board name and its index in the input boards list. The index can be used to choose the board for companions accordingly to the board selection of the primary device in multi-dut tests. It is likely that multi-dut config to have repeating values in the input boards list, which means the priority for repeating boards is double weighted using the existing algorithm. TODO(mingkong) evaluate the side effect and check if global priority config (http://shortn/_NmJHlrSPiZ) should be used by multi-dut tests, which has its own specialized pools.