blob: 3d2914728cc12c77d52db7b25db1c0786752e45c [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"
"path/filepath"
"fuchsia.googlesource.com/infra/infra/fuchsia"
)
// 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"`
// Label is a label given to an environment on which the testsharder may filter.
Label string `json:"label"`
}
// 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 platforms specified as a JSON list
// produced by a build, given the root of the build directory.
func LoadPlatforms(fuchsiaBuildDir string) ([]DimensionSet, error) {
platformManifestPath := filepath.Join(fuchsiaBuildDir, fuchsia.PlatformManifestName)
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
}