aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/test/TestProvider.java
blob: d24fe6bb77f2f30b9c354a6b10487978a0892c57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright 2014 Google Inc. All rights reserved.
//
// 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
//
//    http://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.

package com.google.devtools.build.lib.rules.test;

import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.packages.TestTimeout;

import java.util.List;

/**
 * A {@link TransitiveInfoProvider} for configured targets that implement test rules.
 */
@Immutable
public final class TestProvider implements TransitiveInfoProvider {
  private final TestParams testParams;
  private final ImmutableList<String> testTags;

  public TestProvider(TestParams testParams, ImmutableList<String> testTags) {
    this.testParams = testParams;
    this.testTags = testTags;
  }

  /**
   * Returns the {@link TestParams} object for the test represented by the corresponding configured
   * target.
   */
  public TestParams getTestParams() {
    return testParams;
  }

  /**
   * Temporary hack to allow dependencies on test_suite targets to continue to work for the time
   * being.
   */
  public List<String> getTestTags() {
    return testTags;
  }

  /**
   * Returns the test status artifacts for a specified configured target
   *
   * @param target the configured target. Should belong to a test rule.
   * @return the test status artifacts
   */
  public static ImmutableList<Artifact> getTestStatusArtifacts(TransitiveInfoCollection target) {
    return target.getProvider(TestProvider.class).getTestParams().getTestStatusArtifacts();
  }

  /**
   * A value class describing the properties of a test.
   */
  public static class TestParams {
    private final int runs;
    private final int shards;
    private final TestTimeout timeout;
    private final String testRuleClass;
    private final ImmutableList<Artifact> testStatusArtifacts;
    private final ImmutableList<Artifact> coverageArtifacts;
    private final Artifact coverageReportGenerator;

    /**
     * Don't call this directly. Instead use {@link TestActionBuilder}.
     */
    TestParams(int runs, int shards, TestTimeout timeout, String testRuleClass,
        ImmutableList<Artifact> testStatusArtifacts,
        ImmutableList<Artifact> coverageArtifacts,
        Artifact coverageReportGenerator) {
      this.runs = runs;
      this.shards = shards;
      this.timeout = timeout;
      this.testRuleClass = testRuleClass;
      this.testStatusArtifacts = testStatusArtifacts;
      this.coverageArtifacts = coverageArtifacts;
      this.coverageReportGenerator = coverageReportGenerator;
    }

    /**
     * Returns the number of times this test should be run.
     */
    public int getRuns() {
      return runs;
    }

    /**
     * Returns the number of shards for this test.
     */
    public int getShards() {
      return shards;
    }

    /**
     * Returns the timeout of this test.
     */
    public TestTimeout getTimeout() {
      return timeout;
    }

    /**
     * Returns the test rule class.
     */
    public String getTestRuleClass() {
      return testRuleClass;
    }

    /**
     * Returns a list of test status artifacts that represent serialized test status protobuffers
     * produced by testing this target.
     */
    public ImmutableList<Artifact> getTestStatusArtifacts() {
      return testStatusArtifacts;
    }

    /**
     * Returns the coverageArtifacts
     */
    public ImmutableList<Artifact> getCoverageArtifacts() {
      return coverageArtifacts;
    }

    /**
     * Returns the coverage report generator tool.
     */
    public Artifact getCoverageReportGenerator() {
      return coverageReportGenerator;
    }
  }
}