blob: 0ae28a33741b604a7b7a1fe3edf5ffea315faa3d [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The GN environments specified by test authors in the Fuchsia source
// correspond directly to the Environment struct defined here.
//
// Note that by "platforms" we mean a specific group of dimension sets which
// correspond to the currently available test platforms supported by the
// infrastructure.
package testexec
import (
"encoding/json"
"io/ioutil"
)
// Environment describes the full environment a test requires.
type Environment struct {
// Dimensions gives the Swarming dimensions a test wishes to target.
Dimensions DimensionSet `json:"dimensions"`
}
// Name returns a name calculated from its specfied properties.
// In the first iteration, this just returns the device type.
func (env Environment) Name() string {
return env.Dimensions.DeviceType
}
// DimensionSet encapsulate the Swarming dimensions a test wishes to target.
type DimensionSet struct {
// DeviceType represents the class of device the test should run on.
// This is a required field.
DeviceType string `json:"device_type"`
}
// ResolvesTo gives a partial ordering on DimensionSets in which one resolves to
// another if the former's dimensions are given the latter.
func (dims DimensionSet) resolvesTo(other DimensionSet) bool {
if dims.DeviceType != "" && dims.DeviceType != other.DeviceType {
return false
}
return true
}
// LoadPlatforms loads the list of test platform dimension sets specified as a
// JSON list at a given filepath.
func LoadPlatforms(platformManifestPath string) ([]DimensionSet, error) {
bytes, err := ioutil.ReadFile(platformManifestPath)
if err != nil {
return nil, err
}
var platforms []DimensionSet
if err = json.Unmarshal(bytes, &platforms); err != nil {
return nil, err
}
return platforms, err
}