summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/utils/stc/src/main/java/org
diff options
context:
space:
mode:
authorAshlee Young <ashlee@onosfw.com>2015-09-22 12:49:09 -0700
committerAshlee Young <ashlee@onosfw.com>2015-09-22 12:49:09 -0700
commit81391595dca425ae58e2294898f09f11d9a32dbc (patch)
treef5d65c39a732150b2b29daa8de98a35d1236d3fb /framework/src/onos/utils/stc/src/main/java/org
parent0aa37e73dcb3a55b8d889b0c32ff74055551b1f3 (diff)
bringing src to commit tag 65d551b50e782b0c1ea76c1a9ed1c5a801a5a7e4
Change-Id: Ib2da78962eaef856f418636c31b0f5c84286244f
Diffstat (limited to 'framework/src/onos/utils/stc/src/main/java/org')
-rw-r--r--framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Coordinator.java9
-rw-r--r--framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Main.java24
-rw-r--r--framework/src/onos/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java25
3 files changed, 53 insertions, 5 deletions
diff --git a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Coordinator.java b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Coordinator.java
index 8e3aad5b..ef1c31f3 100644
--- a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Coordinator.java
+++ b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Coordinator.java
@@ -109,6 +109,15 @@ public class Coordinator {
}
/**
+ * Returns number of milliseconds it took to execute.
+ *
+ * @return number of millis elapsed during the run
+ */
+ public long duration() {
+ return store.endTime() - store.startTime();
+ }
+
+ /**
* Returns a list of steps that match the specified list of patterns.
*
* @param runToPatterns list of patterns
diff --git a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Main.java b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Main.java
index 09b89456..bc10ec7a 100644
--- a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Main.java
+++ b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Main.java
@@ -44,11 +44,12 @@ public final class Main {
private static final String GREEN = "\u001B[32;1m";
private static final String BLUE = "\u001B[36m";
- private static final String SUCCESS_SUMMARY = "%sPassed! %d steps succeeded%s";
+ private static final String SUCCESS_SUMMARY =
+ "%s %sPassed! %d steps succeeded%s";
private static final String MIXED_SUMMARY =
"%s%d steps succeeded; %s%d steps failed; %s%d steps skipped%s";
- private static final String FAILURE_SUMMARY = "%sFailed! " + MIXED_SUMMARY;
- private static final String ABORTED_SUMMARY = "%sAborted! " + MIXED_SUMMARY;
+ private static final String FAILURE_SUMMARY = "%s %sFailed! " + MIXED_SUMMARY;
+ private static final String ABORTED_SUMMARY = "%s %sAborted! " + MIXED_SUMMARY;
private boolean isReported = false;
@@ -180,6 +181,7 @@ public final class Main {
private void processList() {
coordinator.getRecords()
.forEach(event -> logStatus(event.time(), event.name(), event.status(), event.command()));
+ printSummary(0, false);
System.exit(0);
}
@@ -201,14 +203,15 @@ public final class Main {
if (!isReported) {
isReported = true;
Set<Step> steps = coordinator.getSteps();
+ String duration = formatDuration((int) (coordinator.duration() / 1_000));
int count = steps.size();
if (exitCode == 0) {
- print(SUCCESS_SUMMARY, color(SUCCEEDED), count, color(null));
+ print(SUCCESS_SUMMARY, duration, color(SUCCEEDED), count, color(null));
} else {
long success = steps.stream().filter(s -> coordinator.getStatus(s) == SUCCEEDED).count();
long failed = steps.stream().filter(s -> coordinator.getStatus(s) == FAILED).count();
long skipped = steps.stream().filter(s -> coordinator.getStatus(s) == SKIPPED).count();
- print(isAborted ? ABORTED_SUMMARY : FAILURE_SUMMARY,
+ print(isAborted ? ABORTED_SUMMARY : FAILURE_SUMMARY, duration,
color(FAILED), color(SUCCEEDED), success,
color(FAILED), failed, color(SKIPPED), skipped, color(null));
}
@@ -281,6 +284,17 @@ public final class Main {
}
}
+ // Formats time duration
+ private static String formatDuration(int totalSeconds) {
+ int seconds = totalSeconds % 60;
+ int totalMinutes = totalSeconds / 60;
+ int minutes = totalMinutes % 60;
+ int hours = totalMinutes / 60;
+ return hours > 0 ?
+ String.format("%d:%02d:%02d", hours, minutes, seconds) :
+ String.format("%d:%02d", minutes, seconds);
+ }
+
// Shutdown hook to report status even when aborted.
private class ShutdownHook extends Thread {
@Override
diff --git a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java
index d37222b1..7313462e 100644
--- a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java
+++ b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java
@@ -43,6 +43,9 @@ class ScenarioStore {
private final List<StepEvent> events = Lists.newArrayList();
private final Map<String, Status> statusMap = Maps.newConcurrentMap();
+ private long startTime = Long.MAX_VALUE;
+ private long endTime = Long.MIN_VALUE;
+
/**
* Creates a new scenario store for the specified process flow.
*
@@ -69,6 +72,8 @@ class ScenarioStore {
PropertiesConfiguration cfg = new PropertiesConfiguration(storeFile);
cfg.clear();
cfg.save();
+ startTime = Long.MAX_VALUE;
+ endTime = Long.MIN_VALUE;
} catch (ConfigurationException e) {
print("Unable to store file %s", storeFile);
}
@@ -156,6 +161,8 @@ class ScenarioStore {
private synchronized void add(StepEvent event) {
events.add(event);
statusMap.put(event.name(), event.status());
+ startTime = Math.min(startTime, event.time());
+ endTime = Math.max(endTime, event.time());
}
/**
@@ -198,4 +205,22 @@ class ScenarioStore {
}
}
+ /**
+ * Returns the scenario run start time.
+ *
+ * @return start time in mills since start of epoch
+ */
+ public long startTime() {
+ return startTime;
+ }
+
+ /**
+ * Returns the scenario run end time or current time if the scenario
+ * is still running.
+ *
+ * @return end time (or current time) in mills since start of epoch
+ */
+ public long endTime() {
+ return endTime > 0 ? endTime : System.currentTimeMillis();
+ }
}