diff options
Diffstat (limited to 'src/test/java/com/android/vts/util')
7 files changed, 0 insertions, 541 deletions
diff --git a/src/test/java/com/android/vts/util/LocalDatastoreExtension.java b/src/test/java/com/android/vts/util/LocalDatastoreExtension.java deleted file mode 100644 index b06303c..0000000 --- a/src/test/java/com/android/vts/util/LocalDatastoreExtension.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * 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.android.vts.util; - -import com.google.cloud.datastore.testing.LocalDatastoreHelper; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.extension.BeforeAllCallback; -import org.junit.jupiter.api.extension.BeforeEachCallback; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.ExtensionContext.Namespace; - -/** Sets up and tears down the Local Datastore emulator, defaults to strong consistency */ -@RequiredArgsConstructor -@Slf4j -public class LocalDatastoreExtension implements BeforeAllCallback, BeforeEachCallback { - - private final double consistency; - - public LocalDatastoreExtension() { - this(1.0); - } - - @Override - public void beforeAll(final ExtensionContext context) throws Exception { - if (getHelper(context) == null) { - log.info("Creating new LocalDatastoreHelper"); - - final LocalDatastoreHelper helper = LocalDatastoreHelper.create(consistency); - context.getRoot().getStore(Namespace.GLOBAL).put(LocalDatastoreHelper.class, helper); - helper.start(); - } - } - - @Override - public void beforeEach(final ExtensionContext context) throws Exception { - final LocalDatastoreHelper helper = getHelper(context); - helper.reset(); - } - - /** Get the helper created in beforeAll; it should be global so there will one per test run */ - public static LocalDatastoreHelper getHelper(final ExtensionContext context) { - return context.getRoot() - .getStore(Namespace.GLOBAL) - .get(LocalDatastoreHelper.class, LocalDatastoreHelper.class); - } -} diff --git a/src/test/java/com/android/vts/util/MockitoExtension.java b/src/test/java/com/android/vts/util/MockitoExtension.java deleted file mode 100644 index 821574f..0000000 --- a/src/test/java/com/android/vts/util/MockitoExtension.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * 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.android.vts.util; - -import org.junit.jupiter.api.extension.BeforeEachCallback; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.mockito.MockitoAnnotations; - -/** - * This will enable mockito annotations programmatically, by invoking MockitoAnnotations.initMocks() - */ -public class MockitoExtension implements BeforeEachCallback { - - @Override - public void beforeEach(final ExtensionContext context) throws Exception { - final Object testInstance = context.getTestInstance().get(); - - MockitoAnnotations.initMocks(testInstance); - } -} diff --git a/src/test/java/com/android/vts/util/ObjectifyExtension.java b/src/test/java/com/android/vts/util/ObjectifyExtension.java deleted file mode 100644 index a60ba0e..0000000 --- a/src/test/java/com/android/vts/util/ObjectifyExtension.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * 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.android.vts.util; - -import com.google.cloud.datastore.Datastore; -import com.googlecode.objectify.ObjectifyFactory; -import com.googlecode.objectify.ObjectifyService; -import com.googlecode.objectify.util.Closeable; -import org.junit.jupiter.api.extension.AfterEachCallback; -import org.junit.jupiter.api.extension.BeforeEachCallback; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.ExtensionContext.Namespace; - -/** Sets up and tears down the GAE local unit test harness environment */ -public class ObjectifyExtension implements BeforeEachCallback, AfterEachCallback { - - private static final Namespace NAMESPACE = Namespace.create(ObjectifyExtension.class); - - @Override - public void beforeEach(final ExtensionContext context) throws Exception { - final Datastore datastore = - LocalDatastoreExtension.getHelper(context).getOptions().getService(); - - ObjectifyService.init(new ObjectifyFactory(datastore)); - - final Closeable rootService = ObjectifyService.begin(); - - context.getStore(NAMESPACE).put(Closeable.class, rootService); - } - - @Override - public void afterEach(final ExtensionContext context) throws Exception { - final Closeable rootService = - context.getStore(NAMESPACE).get(Closeable.class, Closeable.class); - - rootService.close(); - } -} diff --git a/src/test/java/com/android/vts/util/ObjectifyTestBase.java b/src/test/java/com/android/vts/util/ObjectifyTestBase.java deleted file mode 100644 index 0b3b5e8..0000000 --- a/src/test/java/com/android/vts/util/ObjectifyTestBase.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * 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.android.vts.util; - -import com.google.cloud.datastore.Datastore; -import com.google.cloud.datastore.EntityValue; -import com.google.cloud.datastore.FullEntity; -import com.google.cloud.datastore.IncompleteKey; -import com.google.cloud.datastore.Value; -import com.googlecode.objectify.Key; -import com.googlecode.objectify.cache.MemcacheService; -import com.googlecode.objectify.impl.AsyncDatastore; -import org.junit.jupiter.api.extension.ExtendWith; - -import static com.googlecode.objectify.ObjectifyService.factory; -import static com.googlecode.objectify.ObjectifyService.ofy; - -/** All tests should extend this class to set up the GAE environment. */ -@ExtendWith({ - MockitoExtension.class, - LocalDatastoreExtension.class, - ObjectifyExtension.class, -}) -public class ObjectifyTestBase { - /** Set embedded entity with property name */ - protected Value<FullEntity<?>> makeEmbeddedEntityWithProperty( - final String name, final Value<?> value) { - return EntityValue.of(FullEntity.newBuilder().set(name, value).build()); - } - - /** Get datastore instance */ - protected Datastore datastore() { - return factory().datastore(); - } - - /** Get memcache instance */ - protected MemcacheService memcache() { - return factory().memcache(); - } - - /** Get asynchronous datastore instance */ - protected AsyncDatastore asyncDatastore() { - return factory().asyncDatastore(); - } - - /** Save an entity and clear cache data and return entity by finding the key */ - protected <E> E saveClearLoad(final E thing) { - final Key<E> key = ofy().save().entity(thing).now(); - ofy().clear(); - return ofy().load().key(key).now(); - } - - /** Get the entity instance from class type */ - protected FullEntity.Builder<?> makeEntity(final Class<?> kind) { - return makeEntity(Key.getKind(kind)); - } - - /** Get the entity instance from class name */ - protected FullEntity.Builder<?> makeEntity(final String kind) { - final IncompleteKey incompleteKey = - factory().datastore().newKeyFactory().setKind(kind).newKey(); - return FullEntity.newBuilder(incompleteKey); - } -} diff --git a/src/test/java/com/android/vts/util/ProfilingPointSummaryTest.java b/src/test/java/com/android/vts/util/ProfilingPointSummaryTest.java deleted file mode 100644 index e44a1b0..0000000 --- a/src/test/java/com/android/vts/util/ProfilingPointSummaryTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2016 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.android.vts.util; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import com.android.vts.entity.ProfilingPointEntity; -import com.android.vts.entity.ProfilingPointSummaryEntity; -import com.android.vts.proto.VtsReportMessage.VtsProfilingRegressionMode; -import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; -import com.google.appengine.tools.development.testing.LocalServiceTestHelper; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class ProfilingPointSummaryTest { - private final LocalServiceTestHelper helper = - new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()); - private static String[] labels = new String[] {"label1", "label2", "label3"}; - private static long[] values = new long[] {1, 2, 3}; - private static ProfilingPointSummary summary; - - /** - * Helper method for creating ProfilingPointSummaryEntity objects. - * - * @param labels The list of data labels. - * @param values The list of data values. Must be equal in size to the labels list. - * @param regressionMode The regression mode. - * @return A ProfilingPointSummaryEntity with specified data. - */ - private static ProfilingPointSummaryEntity createProfilingReport( - String[] labels, long[] values, VtsProfilingRegressionMode regressionMode) { - List<String> labelList = Arrays.asList(labels); - StatSummary globalStats = new StatSummary("global", regressionMode); - Map<String, StatSummary> labelStats = new HashMap<>(); - for (int i = 0; i < labels.length; ++i) { - StatSummary stat = new StatSummary(labels[i], regressionMode); - stat.updateStats(values[i]); - labelStats.put(labels[i], stat); - globalStats.updateStats(values[i]); - } - return new ProfilingPointSummaryEntity( - ProfilingPointEntity.createKey("test", "pp"), - globalStats, - labelList, - labelStats, - "branch", - "build", - null, - 0); - } - - @Before - public void setUp() { - helper.setUp(); - VtsProfilingRegressionMode mode = VtsProfilingRegressionMode.VTS_REGRESSION_MODE_INCREASING; - summary = new ProfilingPointSummary("x", "y", mode); - ProfilingPointSummaryEntity pt = createProfilingReport(labels, values, mode); - summary.update(pt); - } - - @After - public void tearDown() { - helper.tearDown(); - } - - /** Test that all labels are found by hasLabel. */ - @Test - public void testHasLabel() { - for (String label : labels) { - assertTrue(summary.hasLabel(label)); - } - } - - /** Test that invalid labels are not found by hasLabel. */ - @Test - public void testInvalidHasLabel() { - assertFalse(summary.hasLabel("bad label")); - } - - /** Test that all stat summaries can be retrieved by profiling point label. */ - @Test - public void testGetStatSummary() { - for (String label : labels) { - StatSummary stats = summary.getStatSummary(label); - assertNotNull(stats); - assertEquals(label, stats.getLabel()); - } - } - - /** Test that the getStatSummary method returns null when the label is not present. */ - @Test - public void testInvalidGetStatSummary() { - StatSummary stats = summary.getStatSummary("bad label"); - assertNull(stats); - } - - /** Test that StatSummary objects are iterated in the order that the labels were provided. */ - @Test - public void testIterator() { - VtsProfilingRegressionMode mode = VtsProfilingRegressionMode.VTS_REGRESSION_MODE_INCREASING; - ProfilingPointSummaryEntity pt = createProfilingReport(labels, values, mode); - summary.update(pt); - - int i = 0; - for (StatSummary stats : summary) { - assertEquals(labels[i++], stats.getLabel()); - } - } - - /** Test that the updateLabel method updates the StatSummary for just the label provided. */ - @Test - public void testUpdateLabelGrouped() { - VtsProfilingRegressionMode mode = VtsProfilingRegressionMode.VTS_REGRESSION_MODE_INCREASING; - summary = new ProfilingPointSummary("x", "y", mode); - ProfilingPointSummaryEntity pt = createProfilingReport(labels, values, mode); - summary.updateLabel(pt, labels[0]); - - // Ensure the label specified is present and has been updated for each data point. - assertTrue(summary.hasLabel(labels[0])); - assertNotNull(summary.getStatSummary(labels[0])); - assertEquals(summary.getStatSummary(labels[0]).getCount(), labels.length); - - // Check that the other labels were not updated. - for (int i = 1; i < labels.length; i++) { - assertFalse(summary.hasLabel(labels[i])); - } - } -} diff --git a/src/test/java/com/android/vts/util/StatSummaryTest.java b/src/test/java/com/android/vts/util/StatSummaryTest.java deleted file mode 100644 index a5a4f76..0000000 --- a/src/test/java/com/android/vts/util/StatSummaryTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2016 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.android.vts.util; - -import static org.junit.Assert.assertEquals; - -import com.android.vts.proto.VtsReportMessage.VtsProfilingRegressionMode; -import java.util.Random; -import org.junit.Before; -import org.junit.Test; - -public class StatSummaryTest { - private static double threshold = 0.0000000001; - private StatSummary test; - - @Before - public void setUp() { - test = new StatSummary("label", VtsProfilingRegressionMode.VTS_REGRESSION_MODE_DECREASING); - } - - /** Test computation of average. */ - @Test - public void testAverage() { - int n = 1000; - double mean = (n - 1) / 2.0; - for (int i = 0; i < n; i++) { - test.updateStats(i); - } - assertEquals(n, test.getCount(), threshold); - assertEquals(mean, test.getMean(), threshold); - } - - /** Test computation of minimum. */ - @Test - public void testMin() { - double min = Double.MAX_VALUE; - int n = 1000; - Random rand = new Random(); - for (int i = 0; i < n; i++) { - double value = rand.nextInt(1000); - if (value < min) min = value; - test.updateStats(value); - } - assertEquals(n, test.getCount(), threshold); - assertEquals(min, test.getMin(), threshold); - } - - /** Test computation of maximum. */ - @Test - public void testMax() { - double max = Double.MIN_VALUE; - int n = 1000; - Random rand = new Random(); - for (int i = 0; i < n; i++) { - double value = rand.nextInt(1000); - if (value > max) max = value; - test.updateStats(value); - } - assertEquals(max, test.getMax(), threshold); - } - - /** Test computation of standard deviation. */ - @Test - public void testStd() { - int n = 1000; - double[] values = new double[n]; - Random rand = new Random(); - double sum = 0.0; - for (int i = 0; i < n; i++) { - values[i] = rand.nextInt(1000); - sum += values[i]; - test.updateStats(values[i]); - } - double mean = sum / n; - double sumSq = 0; - for (int i = 0; i < n; i++) { - sumSq += (values[i] - mean) * (values[i] - mean); - } - double std = Math.sqrt(sumSq / (n - 1)); - assertEquals(std, test.getStd(), threshold); - } - - /** Test computation of standard deviation. */ - @Test - public void testMerge() { - StatSummary test2 = - new StatSummary("label", VtsProfilingRegressionMode.VTS_REGRESSION_MODE_DECREASING); - StatSummary all = - new StatSummary("label", VtsProfilingRegressionMode.VTS_REGRESSION_MODE_DECREASING); - int n1 = 1000; - int n2 = 2000; - Random rand = new Random(); - for (int i = 0; i < n1; i++) { - int value = rand.nextInt(1000); - test.updateStats(value); - all.updateStats(value); - } - for (int i = 0; i < n2; i++) { - int value = rand.nextInt(1000); - test2.updateStats(value); - all.updateStats(value); - } - - test.merge(test2); - assertEquals(all.getCount(), test.getCount()); - assertEquals(all.getStd(), test.getStd(), threshold); - assertEquals(all.getMean(), test.getMean(), threshold); - } -} diff --git a/src/test/java/com/android/vts/util/TimeUtilTest.java b/src/test/java/com/android/vts/util/TimeUtilTest.java deleted file mode 100644 index 439991d..0000000 --- a/src/test/java/com/android/vts/util/TimeUtilTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * 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.android.vts.util; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class TimeUtilTest { - - /** Test that date/time strings are formatted correctly. */ - @Test - public void testFormatDateTime() { - long time = 1504286976352052l; - String expected = "2017-09-01 10:29:36 (PDT)"; - String timeString = TimeUtil.getDateTimeZoneString(time); - assertEquals(expected, timeString); - } - - /** Test that date strings are formatted correctly. */ - @Test - public void testFormatDate() { - long time = 1504248634455491l; - String expected = "2017-08-31"; - String timeString = TimeUtil.getDateString(time); - assertEquals(expected, timeString); - } -} |