ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Bazel Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | package com.google.devtools.build.lib.actions; |
| 15 | |
ruperts | 52d7778 | 2017-11-09 16:12:45 +0100 | [diff] [blame] | 16 | import static com.google.common.truth.Truth8.assertThat; |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 17 | |
ruperts | 7967f33 | 2017-11-21 16:37:13 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 19 | import java.time.Duration; |
ruperts | 7967f33 | 2017-11-21 16:37:13 -0800 | [diff] [blame] | 20 | import java.util.List; |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 21 | import org.junit.Test; |
| 22 | import org.junit.runner.RunWith; |
| 23 | import org.junit.runners.JUnit4; |
| 24 | |
| 25 | /** Unit tests for {@link ActionResult}. */ |
| 26 | @RunWith(JUnit4.class) |
| 27 | public final class ActionResultTest { |
| 28 | |
| 29 | @Test |
ruperts | 02fb4bb | 2017-11-04 06:40:14 +0100 | [diff] [blame] | 30 | public void testCumulativeCommandExecutionTime_NoSpawnResults() { |
ruperts | 7967f33 | 2017-11-21 16:37:13 -0800 | [diff] [blame] | 31 | List<SpawnResult> spawnResults = ImmutableList.of(); |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 32 | ActionResult actionResult = ActionResult.create(spawnResults); |
ruperts | 52d7778 | 2017-11-09 16:12:45 +0100 | [diff] [blame] | 33 | assertThat(actionResult.cumulativeCommandExecutionWallTime()).isEmpty(); |
ruperts | 26bc282 | 2017-12-01 15:55:38 -0800 | [diff] [blame] | 34 | assertThat(actionResult.cumulativeCommandExecutionCpuTime()).isEmpty(); |
ruperts | 52d7778 | 2017-11-09 16:12:45 +0100 | [diff] [blame] | 35 | assertThat(actionResult.cumulativeCommandExecutionUserTime()).isEmpty(); |
| 36 | assertThat(actionResult.cumulativeCommandExecutionSystemTime()).isEmpty(); |
ruperts | f35c8a0 | 2017-12-08 14:19:30 -0800 | [diff] [blame] | 37 | assertThat(actionResult.cumulativeCommandExecutionBlockOutputOperations()).isEmpty(); |
| 38 | assertThat(actionResult.cumulativeCommandExecutionBlockInputOperations()).isEmpty(); |
| 39 | assertThat(actionResult.cumulativeCommandExecutionInvoluntaryContextSwitches()).isEmpty(); |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | @Test |
ruperts | 02fb4bb | 2017-11-04 06:40:14 +0100 | [diff] [blame] | 43 | public void testCumulativeCommandExecutionTime_OneSpawnResult() { |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 44 | SpawnResult spawnResult = |
| 45 | new SpawnResult.Builder() |
ruperts | 02fb4bb | 2017-11-04 06:40:14 +0100 | [diff] [blame] | 46 | .setWallTime(Duration.ofMillis(1984)) |
| 47 | .setUserTime(Duration.ofMillis(225)) |
| 48 | .setSystemTime(Duration.ofMillis(42)) |
ruperts | f35c8a0 | 2017-12-08 14:19:30 -0800 | [diff] [blame] | 49 | .setNumBlockOutputOperations(10) |
| 50 | .setNumBlockInputOperations(20) |
| 51 | .setNumInvoluntaryContextSwitches(30) |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 52 | .setStatus(SpawnResult.Status.SUCCESS) |
Googler | 4dd6f00 | 2018-03-27 08:15:39 -0700 | [diff] [blame] | 53 | .setRunnerName("test") |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 54 | .build(); |
ruperts | 7967f33 | 2017-11-21 16:37:13 -0800 | [diff] [blame] | 55 | List<SpawnResult> spawnResults = ImmutableList.of(spawnResult); |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 56 | ActionResult actionResult = ActionResult.create(spawnResults); |
ruperts | 52d7778 | 2017-11-09 16:12:45 +0100 | [diff] [blame] | 57 | assertThat(actionResult.cumulativeCommandExecutionWallTime()).hasValue(Duration.ofMillis(1984)); |
ruperts | 26bc282 | 2017-12-01 15:55:38 -0800 | [diff] [blame] | 58 | assertThat(actionResult.cumulativeCommandExecutionCpuTime()).hasValue(Duration.ofMillis(267)); |
ruperts | 52d7778 | 2017-11-09 16:12:45 +0100 | [diff] [blame] | 59 | assertThat(actionResult.cumulativeCommandExecutionUserTime()).hasValue(Duration.ofMillis(225)); |
ruperts | 52d7778 | 2017-11-09 16:12:45 +0100 | [diff] [blame] | 60 | assertThat(actionResult.cumulativeCommandExecutionSystemTime()).hasValue(Duration.ofMillis(42)); |
ruperts | f35c8a0 | 2017-12-08 14:19:30 -0800 | [diff] [blame] | 61 | assertThat(actionResult.cumulativeCommandExecutionBlockOutputOperations()).hasValue(10L); |
| 62 | assertThat(actionResult.cumulativeCommandExecutionBlockInputOperations()).hasValue(20L); |
| 63 | assertThat(actionResult.cumulativeCommandExecutionInvoluntaryContextSwitches()).hasValue(30L); |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Test |
ruperts | 02fb4bb | 2017-11-04 06:40:14 +0100 | [diff] [blame] | 67 | public void testCumulativeCommandExecutionTime_ManySpawnResults() { |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 68 | SpawnResult spawnResult1 = |
| 69 | new SpawnResult.Builder() |
ruperts | 02fb4bb | 2017-11-04 06:40:14 +0100 | [diff] [blame] | 70 | .setWallTime(Duration.ofMillis(1979)) |
| 71 | .setUserTime(Duration.ofMillis(1)) |
| 72 | .setSystemTime(Duration.ofMillis(33)) |
ruperts | f35c8a0 | 2017-12-08 14:19:30 -0800 | [diff] [blame] | 73 | .setNumBlockOutputOperations(10) |
| 74 | .setNumBlockInputOperations(20) |
| 75 | .setNumInvoluntaryContextSwitches(30) |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 76 | .setStatus(SpawnResult.Status.SUCCESS) |
Googler | 4dd6f00 | 2018-03-27 08:15:39 -0700 | [diff] [blame] | 77 | .setRunnerName("test") |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 78 | .build(); |
| 79 | SpawnResult spawnResult2 = |
| 80 | new SpawnResult.Builder() |
ruperts | 02fb4bb | 2017-11-04 06:40:14 +0100 | [diff] [blame] | 81 | .setWallTime(Duration.ofMillis(4)) |
| 82 | .setUserTime(Duration.ofMillis(1)) |
| 83 | .setSystemTime(Duration.ofMillis(7)) |
ruperts | f35c8a0 | 2017-12-08 14:19:30 -0800 | [diff] [blame] | 84 | .setNumBlockOutputOperations(100) |
| 85 | .setNumBlockInputOperations(200) |
| 86 | .setNumInvoluntaryContextSwitches(300) |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 87 | .setStatus(SpawnResult.Status.SUCCESS) |
Googler | 4dd6f00 | 2018-03-27 08:15:39 -0700 | [diff] [blame] | 88 | .setRunnerName("test") |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 89 | .build(); |
| 90 | SpawnResult spawnResult3 = |
| 91 | new SpawnResult.Builder() |
ruperts | 02fb4bb | 2017-11-04 06:40:14 +0100 | [diff] [blame] | 92 | .setWallTime(Duration.ofMillis(1)) |
| 93 | .setUserTime(Duration.ofMillis(2)) |
| 94 | .setSystemTime(Duration.ofMillis(2)) |
ruperts | f35c8a0 | 2017-12-08 14:19:30 -0800 | [diff] [blame] | 95 | .setNumBlockOutputOperations(1000) |
| 96 | .setNumBlockInputOperations(2000) |
| 97 | .setNumInvoluntaryContextSwitches(3000) |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 98 | .setStatus(SpawnResult.Status.SUCCESS) |
Googler | 4dd6f00 | 2018-03-27 08:15:39 -0700 | [diff] [blame] | 99 | .setRunnerName("test") |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 100 | .build(); |
ruperts | 7967f33 | 2017-11-21 16:37:13 -0800 | [diff] [blame] | 101 | List<SpawnResult> spawnResults = ImmutableList.of(spawnResult1, spawnResult2, spawnResult3); |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 102 | ActionResult actionResult = ActionResult.create(spawnResults); |
ruperts | 52d7778 | 2017-11-09 16:12:45 +0100 | [diff] [blame] | 103 | assertThat(actionResult.cumulativeCommandExecutionWallTime()).hasValue(Duration.ofMillis(1984)); |
ruperts | 26bc282 | 2017-12-01 15:55:38 -0800 | [diff] [blame] | 104 | assertThat(actionResult.cumulativeCommandExecutionCpuTime()).hasValue(Duration.ofMillis(46)); |
ruperts | 52d7778 | 2017-11-09 16:12:45 +0100 | [diff] [blame] | 105 | assertThat(actionResult.cumulativeCommandExecutionUserTime()).hasValue(Duration.ofMillis(4)); |
ruperts | 52d7778 | 2017-11-09 16:12:45 +0100 | [diff] [blame] | 106 | assertThat(actionResult.cumulativeCommandExecutionSystemTime()).hasValue(Duration.ofMillis(42)); |
ruperts | f35c8a0 | 2017-12-08 14:19:30 -0800 | [diff] [blame] | 107 | assertThat(actionResult.cumulativeCommandExecutionBlockOutputOperations()).hasValue(1110L); |
| 108 | assertThat(actionResult.cumulativeCommandExecutionBlockInputOperations()).hasValue(2220L); |
| 109 | assertThat(actionResult.cumulativeCommandExecutionInvoluntaryContextSwitches()).hasValue(3330L); |
ruperts | 02fb4bb | 2017-11-04 06:40:14 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Test |
| 113 | public void testCumulativeCommandExecutionTime_ManyEmptySpawnResults() { |
| 114 | SpawnResult spawnResult1 = |
Googler | 4dd6f00 | 2018-03-27 08:15:39 -0700 | [diff] [blame] | 115 | new SpawnResult.Builder() |
| 116 | .setStatus(SpawnResult.Status.SUCCESS) |
| 117 | .setRunnerName("test") |
| 118 | .build(); |
ruperts | 02fb4bb | 2017-11-04 06:40:14 +0100 | [diff] [blame] | 119 | SpawnResult spawnResult2 = |
Googler | 4dd6f00 | 2018-03-27 08:15:39 -0700 | [diff] [blame] | 120 | new SpawnResult.Builder() |
| 121 | .setStatus(SpawnResult.Status.SUCCESS) |
| 122 | .setRunnerName("test") |
| 123 | .build(); |
ruperts | 02fb4bb | 2017-11-04 06:40:14 +0100 | [diff] [blame] | 124 | SpawnResult spawnResult3 = |
Googler | 4dd6f00 | 2018-03-27 08:15:39 -0700 | [diff] [blame] | 125 | new SpawnResult.Builder() |
| 126 | .setStatus(SpawnResult.Status.SUCCESS) |
| 127 | .setRunnerName("test") |
| 128 | .build(); |
ruperts | 7967f33 | 2017-11-21 16:37:13 -0800 | [diff] [blame] | 129 | List<SpawnResult> spawnResults = ImmutableList.of(spawnResult1, spawnResult2, spawnResult3); |
ruperts | 02fb4bb | 2017-11-04 06:40:14 +0100 | [diff] [blame] | 130 | ActionResult actionResult = ActionResult.create(spawnResults); |
ruperts | 52d7778 | 2017-11-09 16:12:45 +0100 | [diff] [blame] | 131 | assertThat(actionResult.cumulativeCommandExecutionWallTime()).isEmpty(); |
ruperts | 26bc282 | 2017-12-01 15:55:38 -0800 | [diff] [blame] | 132 | assertThat(actionResult.cumulativeCommandExecutionCpuTime()).isEmpty(); |
ruperts | 52d7778 | 2017-11-09 16:12:45 +0100 | [diff] [blame] | 133 | assertThat(actionResult.cumulativeCommandExecutionUserTime()).isEmpty(); |
| 134 | assertThat(actionResult.cumulativeCommandExecutionSystemTime()).isEmpty(); |
ruperts | f35c8a0 | 2017-12-08 14:19:30 -0800 | [diff] [blame] | 135 | assertThat(actionResult.cumulativeCommandExecutionBlockOutputOperations()).isEmpty(); |
| 136 | assertThat(actionResult.cumulativeCommandExecutionBlockInputOperations()).isEmpty(); |
| 137 | assertThat(actionResult.cumulativeCommandExecutionInvoluntaryContextSwitches()).isEmpty(); |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 138 | } |
ruperts | 26bc282 | 2017-12-01 15:55:38 -0800 | [diff] [blame] | 139 | |
| 140 | @Test |
| 141 | public void testCumulativeCommandExecutionTime_ManySpawnResults_ButOnlyUserTime() { |
| 142 | SpawnResult spawnResult1 = |
| 143 | new SpawnResult.Builder() |
| 144 | .setUserTime(Duration.ofMillis(2)) |
| 145 | .setStatus(SpawnResult.Status.SUCCESS) |
Googler | 4dd6f00 | 2018-03-27 08:15:39 -0700 | [diff] [blame] | 146 | .setRunnerName("test") |
ruperts | 26bc282 | 2017-12-01 15:55:38 -0800 | [diff] [blame] | 147 | .build(); |
| 148 | SpawnResult spawnResult2 = |
| 149 | new SpawnResult.Builder() |
| 150 | .setUserTime(Duration.ofMillis(3)) |
| 151 | .setStatus(SpawnResult.Status.SUCCESS) |
Googler | 4dd6f00 | 2018-03-27 08:15:39 -0700 | [diff] [blame] | 152 | .setRunnerName("test") |
ruperts | 26bc282 | 2017-12-01 15:55:38 -0800 | [diff] [blame] | 153 | .build(); |
| 154 | SpawnResult spawnResult3 = |
| 155 | new SpawnResult.Builder() |
| 156 | .setUserTime(Duration.ofMillis(4)) |
| 157 | .setStatus(SpawnResult.Status.SUCCESS) |
Googler | 4dd6f00 | 2018-03-27 08:15:39 -0700 | [diff] [blame] | 158 | .setRunnerName("test") |
ruperts | 26bc282 | 2017-12-01 15:55:38 -0800 | [diff] [blame] | 159 | .build(); |
| 160 | List<SpawnResult> spawnResults = ImmutableList.of(spawnResult1, spawnResult2, spawnResult3); |
| 161 | ActionResult actionResult = ActionResult.create(spawnResults); |
| 162 | assertThat(actionResult.cumulativeCommandExecutionCpuTime()).hasValue(Duration.ofMillis(9)); |
| 163 | assertThat(actionResult.cumulativeCommandExecutionUserTime()).hasValue(Duration.ofMillis(9)); |
| 164 | } |
| 165 | |
| 166 | @Test |
| 167 | public void testCumulativeCommandExecutionTime_ManySpawnResults_ButOnlySystemTime() { |
| 168 | SpawnResult spawnResult1 = |
| 169 | new SpawnResult.Builder() |
| 170 | .setSystemTime(Duration.ofMillis(33)) |
| 171 | .setStatus(SpawnResult.Status.SUCCESS) |
Googler | 4dd6f00 | 2018-03-27 08:15:39 -0700 | [diff] [blame] | 172 | .setRunnerName("test") |
ruperts | 26bc282 | 2017-12-01 15:55:38 -0800 | [diff] [blame] | 173 | .build(); |
| 174 | SpawnResult spawnResult2 = |
| 175 | new SpawnResult.Builder() |
| 176 | .setSystemTime(Duration.ofMillis(7)) |
| 177 | .setStatus(SpawnResult.Status.SUCCESS) |
Googler | 4dd6f00 | 2018-03-27 08:15:39 -0700 | [diff] [blame] | 178 | .setRunnerName("test") |
ruperts | 26bc282 | 2017-12-01 15:55:38 -0800 | [diff] [blame] | 179 | .build(); |
| 180 | SpawnResult spawnResult3 = |
| 181 | new SpawnResult.Builder() |
| 182 | .setSystemTime(Duration.ofMillis(2)) |
| 183 | .setStatus(SpawnResult.Status.SUCCESS) |
Googler | 4dd6f00 | 2018-03-27 08:15:39 -0700 | [diff] [blame] | 184 | .setRunnerName("test") |
ruperts | 26bc282 | 2017-12-01 15:55:38 -0800 | [diff] [blame] | 185 | .build(); |
| 186 | List<SpawnResult> spawnResults = ImmutableList.of(spawnResult1, spawnResult2, spawnResult3); |
| 187 | ActionResult actionResult = ActionResult.create(spawnResults); |
| 188 | assertThat(actionResult.cumulativeCommandExecutionCpuTime()).hasValue(Duration.ofMillis(42)); |
| 189 | assertThat(actionResult.cumulativeCommandExecutionSystemTime()).hasValue(Duration.ofMillis(42)); |
| 190 | } |
ruperts | 89d13b8 | 2017-10-21 02:20:24 +0200 | [diff] [blame] | 191 | } |