diff options
Diffstat (limited to 'src/test/java/com/android/vts')
18 files changed, 0 insertions, 2126 deletions
diff --git a/src/test/java/com/android/vts/api/CoverageRestServletTest.java b/src/test/java/com/android/vts/api/CoverageRestServletTest.java deleted file mode 100644 index f900f79..0000000 --- a/src/test/java/com/android/vts/api/CoverageRestServletTest.java +++ /dev/null @@ -1,112 +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.api; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; -import static com.googlecode.objectify.ObjectifyService.factory; - -import com.android.vts.entity.ApiCoverageEntity; -import com.android.vts.entity.TestEntity; -import com.android.vts.entity.TestRunEntity; -import com.android.vts.util.ObjectifyTestBase; -import com.google.gson.Gson; -import com.google.gson.internal.LinkedTreeMap; -import com.googlecode.objectify.Key; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; - -import java.util.Arrays; -import java.util.List; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.BeforeEach; -import org.mockito.Mock; - -public class CoverageRestServletTest extends ObjectifyTestBase { - - private Gson gson; - - @Mock - private HttpServletRequest request; - - @Mock - private HttpServletResponse response; - - /** It be executed before each @Test method */ - @BeforeEach - void setUpExtra() { - gson = new Gson(); - - /******** - System.getenv().forEach((k,v) -> { - System.out.println("key => " + k); - System.out.println("value => " + v); - }); - *********/ - } - - @Test - public void testApiData() throws IOException, ServletException { - - factory().register(ApiCoverageEntity.class); - - List<String> halApi = Arrays.asList("allocate", "dumpDebugInfo"); - List<String> coveredHalApi = Arrays.asList("allocate", "dumpDebugInfo"); - - Key testParentKey = Key.create(TestEntity.class, "test1"); - Key testRunParentKey = Key.create(testParentKey, TestRunEntity.class, 1); - ApiCoverageEntity apiCoverageEntity = - new ApiCoverageEntity( - testRunParentKey, - "android.hardware.graphics.allocator", - 4, - 1, - "IAllocator", - halApi, - coveredHalApi); - apiCoverageEntity.save(); - - String key = apiCoverageEntity.getUrlSafeKey(); - - when(request.getPathInfo()).thenReturn("/api/data"); - - when(request.getParameter("key")).thenReturn(key); - - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - - when(response.getWriter()).thenReturn(pw); - - CoverageRestServlet coverageRestServlet = new CoverageRestServlet(); - coverageRestServlet.doGet(request, response); - String result = sw.getBuffer().toString().trim(); - - LinkedTreeMap resultMap = gson.fromJson(result, LinkedTreeMap.class); - - assertEquals(resultMap.get("halInterfaceName"), "IAllocator"); - assertEquals(resultMap.get("halPackageName"), "android.hardware.graphics.allocator"); - assertEquals(resultMap.get("halApi"), Arrays.asList("allocate", "dumpDebugInfo")); - assertEquals(resultMap.get("coveredHalApi"), Arrays.asList("allocate", "dumpDebugInfo")); - - } - -} diff --git a/src/test/java/com/android/vts/api/DataRestServletTest.java b/src/test/java/com/android/vts/api/DataRestServletTest.java deleted file mode 100644 index b01c761..0000000 --- a/src/test/java/com/android/vts/api/DataRestServletTest.java +++ /dev/null @@ -1,143 +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.api; - -import com.android.vts.entity.BranchEntity; -import com.android.vts.entity.BuildTargetEntity; -import com.android.vts.entity.DeviceInfoEntity; -import com.android.vts.entity.TestEntity; -import com.android.vts.entity.TestRunEntity; -import com.android.vts.util.ObjectifyTestBase; -import com.google.gson.Gson; -import com.googlecode.objectify.Key; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.Spy; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.LinkedList; - -import static com.googlecode.objectify.ObjectifyService.factory; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; - -public class DataRestServletTest extends ObjectifyTestBase { - - private Gson gson; - - @Spy private DataRestServlet servlet; - - @Mock private HttpServletRequest request; - - @Mock private HttpServletResponse response; - - /** It be executed before each @Test method */ - @BeforeEach - void setUpExtra() { - gson = new Gson(); - - factory().register(TestEntity.class); - factory().register(TestRunEntity.class); - factory().register(BranchEntity.class); - factory().register(BuildTargetEntity.class); - factory().register(DeviceInfoEntity.class); - - BranchEntity branchEntity1 = new BranchEntity("master"); - branchEntity1.save(); - BranchEntity branchEntity2 = new BranchEntity("pi"); - branchEntity2.save(); - - BuildTargetEntity buildTargetEntity1 = new BuildTargetEntity("aosp_arm64_ab-userdebug"); - buildTargetEntity1.save(); - BuildTargetEntity buildTargetEntity2 = new BuildTargetEntity("sailfish-userdebug"); - buildTargetEntity2.save(); - - Key testParentKey = Key.create(TestEntity.class, "test1"); - Key testRunParentKey = Key.create(testParentKey, TestRunEntity.class, 1); - DeviceInfoEntity deviceInfoEntity1 = - new DeviceInfoEntity( - testRunParentKey, - "pi", - "sailfish", - "sailfish-userdebug", - "4585723", - "64", - "arm64-v8a"); - deviceInfoEntity1.setId(2384723984L); - deviceInfoEntity1.save(); - - DeviceInfoEntity deviceInfoEntity2 = - new DeviceInfoEntity( - testRunParentKey, - "master", - "walleye", - "aosp_arm64_ab-userdebug", - "4585723", - "64", - "arm64-v8a"); - deviceInfoEntity2.setId(2384723422L); - deviceInfoEntity2.save(); - } - - @Test - public void testBranchData() throws IOException, ServletException { - - when(request.getPathInfo()).thenReturn("/branch"); - when(request.getParameter("schKey")).thenReturn("*"); - - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - - when(response.getWriter()).thenReturn(pw); - - servlet.doGet(request, response); - String result = sw.getBuffer().toString().trim(); - - LinkedList resultList = gson.fromJson(result, LinkedList.class); - - assertEquals(resultList.size(), 2); - assertEquals(resultList.get(0), "master"); - assertEquals(resultList.get(1), "pi"); - } - - @Test - public void testDeviceData() throws IOException, ServletException { - - when(request.getPathInfo()).thenReturn("/device"); - when(request.getParameter("schKey")).thenReturn("*"); - - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - - when(response.getWriter()).thenReturn(pw); - - servlet.doGet(request, response); - String result = sw.getBuffer().toString().trim(); - - LinkedList resultList = gson.fromJson(result, LinkedList.class); - - assertEquals(resultList.size(), 2); - assertEquals(resultList.get(0), "aosp_arm64_ab-userdebug"); - assertEquals(resultList.get(1), "sailfish-userdebug"); - } -} diff --git a/src/test/java/com/android/vts/api/VtsSpreadSheetSyncServletTest.java b/src/test/java/com/android/vts/api/VtsSpreadSheetSyncServletTest.java deleted file mode 100644 index 661ea9e..0000000 --- a/src/test/java/com/android/vts/api/VtsSpreadSheetSyncServletTest.java +++ /dev/null @@ -1,131 +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.api; - -import com.android.vts.entity.ApiCoverageExcludedEntity; -import com.android.vts.job.VtsSpreadSheetSyncServlet; -import com.android.vts.util.ObjectifyTestBase; -import com.google.api.client.extensions.appengine.datastore.AppEngineDataStoreFactory; -import com.google.api.services.sheets.v4.SheetsScopes; -import com.google.gson.Gson; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.Spy; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.Collections; -import java.util.List; -import java.util.Properties; - -import static com.googlecode.objectify.ObjectifyService.factory; -import static com.googlecode.objectify.ObjectifyService.ofy; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; - -@Slf4j -public class VtsSpreadSheetSyncServletTest extends ObjectifyTestBase { - - private Gson gson; - - @Spy private VtsSpreadSheetSyncServlet servlet; - - @Mock private HttpServletRequest request; - - @Mock private HttpServletResponse response; - - @Mock private ServletContext context; - - @Mock private ServletConfig servletConfig; - - @Mock private ServletOutputStream outputStream; - - private final AppEngineDataStoreFactory DATA_STORE_FACTORY = new AppEngineDataStoreFactory(); - - private final List<String> GOOGLE_API_SCOPES = - Collections.singletonList(SheetsScopes.SPREADSHEETS_READONLY); - - /** It be executed before each @Test method */ - @BeforeEach - void setUpExtra() { - - factory().register(ApiCoverageExcludedEntity.class); - - gson = new Gson(); - - Properties systemConfigProp = new Properties(); - - InputStream defaultInputStream = - VtsSpreadSheetSyncServletTest.class - .getClassLoader() - .getResourceAsStream("config.properties"); - - try { - systemConfigProp.load(defaultInputStream); - } catch (FileNotFoundException e) { - log.error(e.getMessage()); - } catch (IOException e) { - log.error(e.getMessage()); - } - - when(request.getServletContext()).thenReturn(context); - when(request.getServletContext().getAttribute("dataStoreFactory")) - .thenReturn(DATA_STORE_FACTORY); - when(request.getServletContext().getAttribute("googleApiScopes")) - .thenReturn(GOOGLE_API_SCOPES); - - when(servletConfig.getServletContext()).thenReturn(context); - when(servletConfig.getServletContext().getAttribute("systemConfigProp")) - .thenReturn(systemConfigProp); - - } - - @Test - public void testSyncServletJob() throws IOException, ServletException { - - when(request.getPathInfo()).thenReturn("/cron/vts_spreadsheet_sync_job"); - - when(servlet.getServletConfig()).thenReturn(servletConfig); - when(response.getOutputStream()).thenReturn(outputStream); - - servlet.init(servletConfig); - servlet.doGet(request, response); - String result = outputStream.toString().trim(); - - List<ApiCoverageExcludedEntity> apiCoverageExcludedEntityList = - ofy().load().type(ApiCoverageExcludedEntity.class).list(); - - assertEquals(apiCoverageExcludedEntityList.size(), 2); - assertEquals(apiCoverageExcludedEntityList.get(0).getApiName(), "getMasterMuteTest"); - assertEquals( - apiCoverageExcludedEntityList.get(0).getPackageName(), - "android.hardware.audio.test"); - assertEquals(apiCoverageExcludedEntityList.get(1).getApiName(), "getMasterVolumeTest"); - assertEquals( - apiCoverageExcludedEntityList.get(1).getPackageName(), - "android.hardware.video.test"); - } -} diff --git a/src/test/java/com/android/vts/entity/ApiCoverageExcludedEntityTest.java b/src/test/java/com/android/vts/entity/ApiCoverageExcludedEntityTest.java deleted file mode 100644 index 40d3af9..0000000 --- a/src/test/java/com/android/vts/entity/ApiCoverageExcludedEntityTest.java +++ /dev/null @@ -1,63 +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.entity; - -import com.android.vts.util.ObjectifyTestBase; -import com.googlecode.objectify.Key; -import org.junit.jupiter.api.Test; - -import static com.googlecode.objectify.ObjectifyService.factory; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public class ApiCoverageExcludedEntityTest extends ObjectifyTestBase { - - @Test - public void saveTest() { - factory().register(ApiCoverageExcludedEntity.class); - - String packageName = "android.hardware.audio"; - String apiName = "createTestPatch"; - String version = "2.1"; - ApiCoverageExcludedEntity apiCoverageExcludedEntity = - new ApiCoverageExcludedEntity( - packageName, version, "IDevice", apiName, "not testable"); - apiCoverageExcludedEntity.save(); - - assertEquals(apiCoverageExcludedEntity.getPackageName(), packageName); - assertEquals(apiCoverageExcludedEntity.getApiName(), apiName); - assertEquals(apiCoverageExcludedEntity.getMajorVersion(), 2); - assertEquals(apiCoverageExcludedEntity.getMinorVersion(), 1); - } - - @Test - public void getUrlSafeKeyTest() { - factory().register(CodeCoverageEntity.class); - factory().register(ApiCoverageExcludedEntity.class); - - Key testParentKey = Key.create(TestEntity.class, "test1"); - Key testRunParentKey = Key.create(testParentKey, TestRunEntity.class, 1); - - CodeCoverageEntity codeCoverageEntity = - new CodeCoverageEntity(testRunParentKey, 1000, 3500); - codeCoverageEntity.save(); - - String urlKey = - "kind%3A+%22Test%22%0A++name%3A+%22test1%22%0A%7D%0Apath+%7B%0A++kind%3A+%22TestRun%22%0A++id%3A+1%0A%7D%0Apath+%7B%0A++kind%3A+%22CodeCoverage%22%0A++id%3A+1%0A%7D%0A"; - assertTrue(codeCoverageEntity.getUrlSafeKey().endsWith(urlKey)); - } -} diff --git a/src/test/java/com/android/vts/entity/CodeCoverageEntityTest.java b/src/test/java/com/android/vts/entity/CodeCoverageEntityTest.java deleted file mode 100644 index 06cad28..0000000 --- a/src/test/java/com/android/vts/entity/CodeCoverageEntityTest.java +++ /dev/null @@ -1,59 +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.entity; - -import com.android.vts.util.ObjectifyTestBase; -import com.googlecode.objectify.Key; -import org.junit.jupiter.api.Test; - - -import static com.googlecode.objectify.ObjectifyService.factory; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public class CodeCoverageEntityTest extends ObjectifyTestBase { - - @Test - public void saveTest() { - factory().register(CodeCoverageEntity.class); - - Key testParentKey = Key.create(TestEntity.class, "test1"); - Key testRunParentKey = Key.create(testParentKey, TestRunEntity.class, 1); - - CodeCoverageEntity codeCoverageEntity = new CodeCoverageEntity(testRunParentKey, 1000, 3500); - codeCoverageEntity.save(); - - assertEquals(codeCoverageEntity.getCoveredLineCount(), 1000); - assertEquals(codeCoverageEntity.getTotalLineCount(), 3500); - } - - @Test - public void getUrlSafeKeyTest() { - factory().register(CodeCoverageEntity.class); - - Key testParentKey = Key.create(TestEntity.class, "test1"); - Key testRunParentKey = Key.create(testParentKey, TestRunEntity.class, 1); - - CodeCoverageEntity codeCoverageEntity = new CodeCoverageEntity(testRunParentKey, 1000, 3500); - codeCoverageEntity.save(); - - String urlKey = - "kind%3A+%22Test%22%0A++name%3A+%22test1%22%0A%7D%0Apath+%7B%0A++kind%3A+%22TestRun%22%0A++id%3A+1%0A%7D%0Apath+%7B%0A++kind%3A+%22CodeCoverage%22%0A++id%3A+1%0A%7D%0A"; - assertTrue(codeCoverageEntity.getUrlSafeKey().endsWith(urlKey)); - } - -} diff --git a/src/test/java/com/android/vts/entity/CodeCoverageFileEntityTest.java b/src/test/java/com/android/vts/entity/CodeCoverageFileEntityTest.java deleted file mode 100644 index 5c944b2..0000000 --- a/src/test/java/com/android/vts/entity/CodeCoverageFileEntityTest.java +++ /dev/null @@ -1,58 +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.entity; - -import com.android.vts.util.ObjectifyTestBase; -import com.googlecode.objectify.Key; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; -import java.util.List; - -import static com.googlecode.objectify.ObjectifyService.factory; -import static com.googlecode.objectify.ObjectifyService.ofy; -import static org.junit.Assert.assertEquals; - -public class CodeCoverageFileEntityTest extends ObjectifyTestBase { - - @Test - public void saveTest() { - - factory().register(CodeCoverageFileEntity.class); - - Key testParentKey = Key.create(TestEntity.class, "test1"); - Key testRunParentKey = Key.create(testParentKey, TestRunEntity.class, 1); - - List<Long> lineCoverage = Arrays.asList(-1L, -1L, -1L, 4L, 2L, 0L); - CodeCoverageFileEntity codeCoverageFileEntity = new CodeCoverageFileEntity( - 10000, - testRunParentKey, - "audio/12.0/DevicesFile.h", - "", - lineCoverage, - 10020, - 40030, - "platform/hardware/interfaces", - "e8d6e9385a64b742ad1952c6d9"); - codeCoverageFileEntity.save(); - - CodeCoverageFileEntity loadCodeCoverageFileEntity = ofy().load().type(CodeCoverageFileEntity.class).first().now(); - - assertEquals(loadCodeCoverageFileEntity, codeCoverageFileEntity); - } - -} diff --git a/src/test/java/com/android/vts/entity/TestAcknowledgmentEntityTest.java b/src/test/java/com/android/vts/entity/TestAcknowledgmentEntityTest.java deleted file mode 100644 index 8ed68b6..0000000 --- a/src/test/java/com/android/vts/entity/TestAcknowledgmentEntityTest.java +++ /dev/null @@ -1,168 +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.entity; - -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.Key; -import com.google.appengine.api.datastore.KeyFactory; -import com.google.appengine.api.datastore.Text; -import com.google.appengine.api.users.User; -import com.google.appengine.api.users.UserServiceFactory; -import com.google.appengine.tools.development.testing.LocalServiceTestHelper; -import com.google.appengine.tools.development.testing.LocalUserServiceTestConfig; -import com.google.gson.JsonObject; -import java.util.ArrayList; -import java.util.List; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class TestAcknowledgmentEntityTest { - private final LocalServiceTestHelper helper = - new LocalServiceTestHelper(new LocalUserServiceTestConfig()) - .setEnvIsAdmin(true) - .setEnvIsLoggedIn(true) - .setEnvEmail("testemail@domain.com") - .setEnvAuthDomain("test"); - - @Before - public void setUp() { - helper.setUp(); - } - - @After - public void tearDown() { - helper.tearDown(); - } - - /** Test serialization to/from Entity objects. */ - @Test - public void testEntitySerialization() { - Key key = KeyFactory.createKey(TestEntity.KIND, "test"); - User user = UserServiceFactory.getUserService().getCurrentUser(); - List<String> branches = new ArrayList<>(); - branches.add("branch1"); - List<String> devices = new ArrayList<>(); - devices.add("device1"); - List<String> testCaseNames = new ArrayList<>(); - testCaseNames.add("testCase1"); - Text note = new Text("note"); - TestAcknowledgmentEntity ack = - new TestAcknowledgmentEntity(key, user, branches, devices, testCaseNames, note); - Entity e = ack.toEntity(); - - Assert.assertNotNull(e); - Assert.assertEquals(key, e.getProperty(TestAcknowledgmentEntity.TEST_KEY)); - Assert.assertEquals(user, e.getProperty(TestAcknowledgmentEntity.USER_OBJ)); - Assert.assertTrue( - ((List<String>) e.getProperty(TestAcknowledgmentEntity.BRANCHES)) - .containsAll(branches)); - Assert.assertTrue( - ((List<String>) e.getProperty(TestAcknowledgmentEntity.DEVICES)) - .containsAll(devices)); - Assert.assertTrue( - ((List<String>) e.getProperty(TestAcknowledgmentEntity.TEST_CASE_NAMES)) - .containsAll(testCaseNames)); - Assert.assertEquals(note, e.getProperty(TestAcknowledgmentEntity.NOTE)); - - TestAcknowledgmentEntity deserialized = TestAcknowledgmentEntity.fromEntity(e); - Assert.assertNotNull(deserialized); - Assert.assertEquals(key, deserialized.test); - Assert.assertEquals(user, deserialized.getUserObj()); - Assert.assertTrue(deserialized.getBranches().containsAll(branches)); - Assert.assertTrue(deserialized.getDevices().containsAll(devices)); - Assert.assertTrue(deserialized.getTestCaseNames().containsAll(testCaseNames)); - Assert.assertEquals(note.getValue(), deserialized.getNote()); - } - - /** Test serialization to/from Entity objects when optional parameters are null. */ - @Test - public void testEntitySerializationWithNulls() { - Key key = KeyFactory.createKey(TestEntity.KIND, "test"); - User user = UserServiceFactory.getUserService().getCurrentUser(); - TestAcknowledgmentEntity ack = - new TestAcknowledgmentEntity(key, user, null, null, null, null); - Entity e = ack.toEntity(); - - Assert.assertNotNull(e); - Assert.assertEquals(key, e.getProperty(TestAcknowledgmentEntity.TEST_KEY)); - Assert.assertEquals(user, e.getProperty(TestAcknowledgmentEntity.USER_OBJ)); - Assert.assertFalse(e.hasProperty(TestAcknowledgmentEntity.BRANCHES)); - Assert.assertFalse(e.hasProperty(TestAcknowledgmentEntity.DEVICES)); - Assert.assertFalse(e.hasProperty(TestAcknowledgmentEntity.TEST_CASE_NAMES)); - Assert.assertFalse(e.hasProperty(TestAcknowledgmentEntity.NOTE)); - - TestAcknowledgmentEntity deserialized = TestAcknowledgmentEntity.fromEntity(e); - Assert.assertNotNull(deserialized); - Assert.assertEquals(key, deserialized.test); - Assert.assertEquals(user, deserialized.getUserObj()); - Assert.assertEquals(0, deserialized.getBranches().size()); - Assert.assertEquals(0, deserialized.getDevices().size()); - Assert.assertEquals(0, deserialized.getTestCaseNames().size()); - Assert.assertNull(deserialized.getNote()); - } - - /** Test serialization to/from Json objects. */ - @Test - public void testJsonSerialization() { - Key key = KeyFactory.createKey(TestEntity.KIND, "test"); - User user = UserServiceFactory.getUserService().getCurrentUser(); - List<String> branches = new ArrayList<>(); - branches.add("branch1"); - List<String> devices = new ArrayList<>(); - devices.add("device1"); - List<String> testCaseNames = new ArrayList<>(); - testCaseNames.add("testCase1"); - Text note = new Text("note"); - TestAcknowledgmentEntity ack = - new TestAcknowledgmentEntity(key, user, branches, devices, testCaseNames, note); - Entity e = new Entity(KeyFactory.createKey(TestAcknowledgmentEntity.KIND, "fakekey")); - e.setPropertiesFrom(ack.toEntity()); - JsonObject json = TestAcknowledgmentEntity.fromEntity(e).toJson(); - - TestAcknowledgmentEntity deserialized = TestAcknowledgmentEntity.fromJson(user, json); - Assert.assertNotNull(deserialized); - Assert.assertEquals(key, deserialized.test); - Assert.assertEquals(user, deserialized.getUserObj()); - Assert.assertTrue(deserialized.getBranches().containsAll(branches)); - Assert.assertTrue(deserialized.getDevices().containsAll(devices)); - Assert.assertTrue(deserialized.getTestCaseNames().containsAll(testCaseNames)); - Assert.assertEquals(note.getValue(), deserialized.getNote()); - } - - /** Test serialization to/from Json objects when optional properties are null. */ - @Test - public void testJsonSerializationWithNulls() { - Key key = KeyFactory.createKey(TestEntity.KIND, "test"); - User user = UserServiceFactory.getUserService().getCurrentUser(); - TestAcknowledgmentEntity ack = - new TestAcknowledgmentEntity(key, user, null, null, null, null); - Entity e = new Entity(KeyFactory.createKey(TestAcknowledgmentEntity.KIND, "fakekey")); - e.setPropertiesFrom(ack.toEntity()); - JsonObject json = TestAcknowledgmentEntity.fromEntity(e).toJson(); - - TestAcknowledgmentEntity deserialized = TestAcknowledgmentEntity.fromJson(user, json); - Assert.assertNotNull(deserialized); - Assert.assertEquals(key, deserialized.test); - Assert.assertEquals(user, deserialized.getUserObj()); - Assert.assertEquals(0, deserialized.getBranches().size()); - Assert.assertEquals(0, deserialized.getDevices().size()); - Assert.assertEquals(0, deserialized.getTestCaseNames().size()); - Assert.assertEquals("", deserialized.getNote()); - } -} diff --git a/src/test/java/com/android/vts/entity/TestCaseRunEntityTest.java b/src/test/java/com/android/vts/entity/TestCaseRunEntityTest.java deleted file mode 100644 index d4abd38..0000000 --- a/src/test/java/com/android/vts/entity/TestCaseRunEntityTest.java +++ /dev/null @@ -1,59 +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.entity; - -import com.android.vts.util.ObjectifyTestBase; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; -import java.util.List; - -import static com.googlecode.objectify.ObjectifyService.factory; -import static org.junit.Assert.assertEquals; - -public class TestCaseRunEntityTest extends ObjectifyTestBase { - - @Test - public void saveTest() { - - factory().register(TestCaseRunEntity.class); - - List<Integer> results = Arrays.asList(1, 1, 1, 1, 1, 1, 1); - List<String> testCaseNames = - Arrays.asList( - "AudioEffectsFactoryTest.EnumerateEffects(default)_32bit", - "AudioEffectsFactoryTest.CreateEffect(default)_32bit", - "AudioEffectsFactoryTest.GetDescriptor(default)_32bit", - "AudioEffectsFactoryTest.DebugDumpArgument(default)_32bit", - "AudioEffectTest.Close(default)_32bit", - "AudioEffectTest.GetDescriptor(default)_32bit", - "AudioEffectTest.GetSetConfig(default)_32bit"); - - TestCaseRunEntity testCaseRunEntity = new TestCaseRunEntity(); - for (int index = 0; index < results.size(); index++) { - String testCaseName = testCaseNames.get(index); - int result = results.get(index); - testCaseRunEntity.addTestCase(testCaseName, result); - } - TestCaseRunEntity loadedTestCaseRunEntity = saveClearLoad(testCaseRunEntity); - - assertEquals(loadedTestCaseRunEntity.getTestCases().size(), results.size()); - assertEquals( - (Integer) loadedTestCaseRunEntity.getTestCases().get(0).result, results.get(0)); - assertEquals(loadedTestCaseRunEntity.getTestCases().get(0).name, testCaseNames.get(0)); - } -} diff --git a/src/test/java/com/android/vts/job/VtsAlertJobServletTest.java b/src/test/java/com/android/vts/job/VtsAlertJobServletTest.java deleted file mode 100644 index 9c24c65..0000000 --- a/src/test/java/com/android/vts/job/VtsAlertJobServletTest.java +++ /dev/null @@ -1,154 +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.job; - -import static com.googlecode.objectify.ObjectifyService.factory; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import com.android.vts.entity.DeviceInfoEntity; -import com.android.vts.entity.TestAcknowledgmentEntity; -import com.android.vts.util.ObjectifyTestBase; -import com.google.appengine.api.datastore.Key; -import com.google.appengine.api.datastore.KeyFactory; -import com.google.appengine.api.users.User; -import com.google.appengine.api.users.UserServiceFactory; -import com.google.appengine.tools.development.testing.LocalServiceTestHelper; -import com.google.appengine.tools.development.testing.LocalUserServiceTestConfig; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.BeforeEach; - -public class VtsAlertJobServletTest extends ObjectifyTestBase { - private final LocalServiceTestHelper userHelper = - new LocalServiceTestHelper(new LocalUserServiceTestConfig()) - .setEnvIsAdmin(true) - .setEnvIsLoggedIn(true) - .setEnvEmail("testemail@domain.com") - .setEnvAuthDomain("test"); - - User user; - private Key testKey; - private Set<String> allTestCases; - private List<DeviceInfoEntity> allDevices; - - @BeforeEach - void setUpExtra() { - factory().register(DeviceInfoEntity.class); - factory().register(TestAcknowledgmentEntity.class); - - userHelper.setUp(); - user = UserServiceFactory.getUserService().getCurrentUser(); - - testKey = KeyFactory.createKey(TestAcknowledgmentEntity.KIND, "test"); - - allTestCases = new HashSet<>(); - allTestCases.add("testCase1"); - allTestCases.add("testCase2"); - allTestCases.add("testCase3"); - - allDevices = new ArrayList<>(); - DeviceInfoEntity device1 = - new DeviceInfoEntity( - testKey, "branch1", "product1", "flavor1", "1234", "32", "abi"); - DeviceInfoEntity device2 = - new DeviceInfoEntity( - testKey, "branch2", "product2", "flavor2", "1235", "32", "abi"); - allDevices.add(device1); - allDevices.add(device2); - } - - @AfterEach - public void tearDown() { - userHelper.tearDown(); - } - - /** Test that acknowledge-all works correctly. */ - @Test - public void testSeparateAcknowledgedAll() { - - Set<String> testCases = new HashSet<>(allTestCases); - List<TestAcknowledgmentEntity> acks = new ArrayList<>(); - TestAcknowledgmentEntity ack = - new TestAcknowledgmentEntity(testKey, user, null, null, null, null); - acks.add(ack); - - Set<String> acknowledged = - VtsAlertJobServlet.separateAcknowledged(testCases, allDevices, acks); - assertEquals(allTestCases.size(), acknowledged.size()); - assertTrue(acknowledged.containsAll(allTestCases)); - assertEquals(0, testCases.size()); - } - - /** Test that specific branch/device/test case acknowledgement works correctly. */ - @Test - public void testSeparateAcknowledgedSpecific() { - - Set<String> testCases = new HashSet<>(allTestCases); - List<TestAcknowledgmentEntity> acks = new ArrayList<>(); - List<String> branches = new ArrayList<>(); - branches.add("branch1"); - - List<String> devices = new ArrayList<>(); - devices.add("flavor2"); - - List<String> testCaseNames = new ArrayList<>(); - testCaseNames.add("testCase1"); - - TestAcknowledgmentEntity ack = - new TestAcknowledgmentEntity( - testKey, user, branches, devices, testCaseNames, null); - acks.add(ack); - - Set<String> acknowledged = - VtsAlertJobServlet.separateAcknowledged(testCases, allDevices, acks); - assertEquals(0, acknowledged.size()); - assertEquals(allTestCases.size(), testCases.size()); - } - - /** Test that specific branch/device/test case acknowledgement skips device mismatches. */ - @Test - public void testSeparateAcknowledgedSpecificMismatch() { - - Set<String> testCases = new HashSet<>(allTestCases); - List<TestAcknowledgmentEntity> acks = new ArrayList<>(); - List<String> branches = new ArrayList<>(); - branches.add("branch1"); - - List<String> devices = new ArrayList<>(); - devices.add("flavor1"); - - List<String> testCaseNames = new ArrayList<>(); - testCaseNames.add("testCase1"); - - TestAcknowledgmentEntity ack = - new TestAcknowledgmentEntity( - testKey, user, branches, devices, testCaseNames, null); - acks.add(ack); - - Set<String> acknowledged = - VtsAlertJobServlet.separateAcknowledged(testCases, allDevices, acks); - assertEquals(1, acknowledged.size()); - assertTrue(acknowledged.contains("testCase1")); - assertTrue(!testCases.contains("testCase1")); - } -} diff --git a/src/test/java/com/android/vts/job/VtsPerformanceJobServletTest.java b/src/test/java/com/android/vts/job/VtsPerformanceJobServletTest.java deleted file mode 100644 index 814ab3a..0000000 --- a/src/test/java/com/android/vts/job/VtsPerformanceJobServletTest.java +++ /dev/null @@ -1,257 +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.job; - -import static org.junit.Assert.assertEquals; - -import com.android.vts.entity.ProfilingPointEntity; -import com.android.vts.entity.ProfilingPointSummaryEntity; -import com.android.vts.proto.VtsReportMessage.VtsProfilingRegressionMode; -import com.android.vts.util.ObjectifyTestBase; -import com.android.vts.util.PerformanceSummary; -import com.android.vts.util.ProfilingPointSummary; -import com.android.vts.util.StatSummary; -import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; -import com.google.appengine.tools.development.testing.LocalServiceTestHelper; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; - -public class VtsPerformanceJobServletTest extends ObjectifyTestBase { - private final LocalServiceTestHelper helper = - new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()); - - private static final String LABEL = "testLabel"; - private static final String ROOT = "src/test/resources/servlet"; - private static final String[] LABELS = new String[] {"label1", "label2", "label3"}; - private static final long[] HIGH_VALS = new long[] {10, 20, 30}; - private static final long[] LOW_VALS = new long[] {1, 2, 3}; - - List<PerformanceSummary> dailySummaries; - List<String> legendLabels; - - /** - * 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); - } - - /** Asserts whether text is the same as the contents in the baseline file specified. */ - private static void compareToBaseline(String text, String baselineFilename) - throws FileNotFoundException, IOException { - File f = new File(ROOT, baselineFilename); - String baseline = ""; - try (BufferedReader br = new BufferedReader(new FileReader(f))) { - StringBuilder sb = new StringBuilder(); - String line = br.readLine(); - - while (line != null) { - sb.append(line); - line = br.readLine(); - } - baseline = sb.toString(); - } - assertEquals(baseline, text); - } - - @BeforeEach - public void setUp() { - helper.setUp(); - } - - @AfterEach - public void tearDown() { - helper.tearDown(); - } - - public void setUp(boolean grouped) { - dailySummaries = new ArrayList<>(); - legendLabels = new ArrayList<>(); - legendLabels.add(""); - - // Add today's data - PerformanceSummary today = new PerformanceSummary(0, 1); - VtsProfilingRegressionMode mode = VtsProfilingRegressionMode.VTS_REGRESSION_MODE_INCREASING; - ProfilingPointSummary summary = new ProfilingPointSummary("", "", mode); - ProfilingPointSummaryEntity pt = createProfilingReport(LABELS, HIGH_VALS, mode); - if (grouped) { - summary.updateLabel(pt, LABEL); - summary.updateLabel(pt, LABEL); - } else { - summary.update(pt); - summary.update(pt); - } - today.insertProfilingPointSummary("p1", summary); - - mode = VtsProfilingRegressionMode.VTS_REGRESSION_MODE_DECREASING; - summary = new ProfilingPointSummary("", "", mode); - pt = createProfilingReport(LABELS, LOW_VALS, mode); - if (grouped) { - summary.updateLabel(pt, LABEL); - summary.updateLabel(pt, LABEL); - } else { - summary.update(pt); - summary.update(pt); - } - today.insertProfilingPointSummary("p2", summary); - dailySummaries.add(today); - legendLabels.add("today"); - - // Add yesterday data with regressions - PerformanceSummary yesterday = new PerformanceSummary(0, 1); - mode = VtsProfilingRegressionMode.VTS_REGRESSION_MODE_INCREASING; - summary = new ProfilingPointSummary("", "", mode); - pt = createProfilingReport(LABELS, LOW_VALS, mode); - if (grouped) { - summary.updateLabel(pt, LABEL); - summary.updateLabel(pt, LABEL); - } else { - summary.update(pt); - summary.update(pt); - } - yesterday.insertProfilingPointSummary("p1", summary); - - mode = VtsProfilingRegressionMode.VTS_REGRESSION_MODE_DECREASING; - summary = new ProfilingPointSummary("x", "y", mode); - pt = createProfilingReport(LABELS, HIGH_VALS, mode); - if (grouped) { - summary.updateLabel(pt, LABEL); - summary.updateLabel(pt, LABEL); - } else { - summary.update(pt); - summary.update(pt); - } - yesterday.insertProfilingPointSummary("p2", summary); - dailySummaries.add(yesterday); - legendLabels.add("yesterday"); - - // Add last week data without regressions - PerformanceSummary lastWeek = new PerformanceSummary(0, 1); - mode = VtsProfilingRegressionMode.VTS_REGRESSION_MODE_INCREASING; - summary = new ProfilingPointSummary("", "", mode); - pt = createProfilingReport(LABELS, HIGH_VALS, mode); - summary.update(pt); - summary.update(pt); - lastWeek.insertProfilingPointSummary("p1", summary); - - mode = VtsProfilingRegressionMode.VTS_REGRESSION_MODE_DECREASING; - summary = new ProfilingPointSummary("", "", mode); - pt = createProfilingReport(LABELS, LOW_VALS, mode); - summary.update(pt); - summary.update(pt); - lastWeek.insertProfilingPointSummary("p2", summary); - dailySummaries.add(lastWeek); - legendLabels.add("last week"); - } - - /** - * End-to-end test of performance report in the normal case. The normal case is when a profiling - * point is added or removed from the test. - */ - @Test - public void testPerformanceSummaryNormal() throws FileNotFoundException, IOException { - setUp(false); - String output = - VtsPerformanceJobServlet.getPerformanceSummary( - "test", dailySummaries, legendLabels); - compareToBaseline(output, "performanceSummary1.html"); - } - - /** - * End-to-end test of performance report when a profiling point was removed in the latest run. - */ - @Test - public void testPerformanceSummaryDroppedProfilingPoint() - throws FileNotFoundException, IOException { - setUp(false); - PerformanceSummary yesterday = dailySummaries.get(dailySummaries.size() - 1); - VtsProfilingRegressionMode mode = VtsProfilingRegressionMode.VTS_REGRESSION_MODE_INCREASING; - ProfilingPointSummary summary = new ProfilingPointSummary("x", "y", mode); - ProfilingPointSummaryEntity pt = createProfilingReport(LABELS, HIGH_VALS, mode); - summary.update(pt); - summary.update(pt); - yesterday.insertProfilingPointSummary("p3", summary); - String output = - VtsPerformanceJobServlet.getPerformanceSummary( - "test", dailySummaries, legendLabels); - compareToBaseline(output, "performanceSummary2.html"); - } - - /** End-to-end test of performance report when a profiling point was added in the latest run. */ - @Test - public void testPerformanceSummaryAddedProfilingPoint() - throws FileNotFoundException, IOException { - setUp(false); - PerformanceSummary today = dailySummaries.get(0); - VtsProfilingRegressionMode mode = VtsProfilingRegressionMode.VTS_REGRESSION_MODE_INCREASING; - ProfilingPointSummary summary = new ProfilingPointSummary("", "", mode); - ProfilingPointSummaryEntity pt = createProfilingReport(LABELS, HIGH_VALS, mode); - summary.update(pt); - summary.update(pt); - today.insertProfilingPointSummary("p3", summary); - String output = - VtsPerformanceJobServlet.getPerformanceSummary( - "test", dailySummaries, legendLabels); - compareToBaseline(output, "performanceSummary3.html"); - } - - /** - * End-to-end test of performance report labels are grouped (e.g. as if using unlabeled data) - */ - @Test - public void testPerformanceSummaryGroupedNormal() throws FileNotFoundException, IOException { - setUp(true); - String output = - VtsPerformanceJobServlet.getPerformanceSummary( - "test", dailySummaries, legendLabels); - compareToBaseline(output, "performanceSummary4.html"); - } -} diff --git a/src/test/java/com/android/vts/job/VtsProfilingStatsJobServletTest.java b/src/test/java/com/android/vts/job/VtsProfilingStatsJobServletTest.java deleted file mode 100644 index 36637a3..0000000 --- a/src/test/java/com/android/vts/job/VtsProfilingStatsJobServletTest.java +++ /dev/null @@ -1,381 +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.job; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.android.vts.entity.DeviceInfoEntity; -import com.android.vts.entity.ProfilingPointEntity; -import com.android.vts.entity.ProfilingPointRunEntity; -import com.android.vts.entity.ProfilingPointSummaryEntity; -import com.android.vts.entity.TestEntity; -import com.android.vts.entity.TestRunEntity; -import com.android.vts.proto.VtsReportMessage; -import com.android.vts.util.ObjectifyTestBase; -import com.android.vts.util.StatSummary; -import com.android.vts.util.TimeUtil; -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.EntityNotFoundException; -import com.google.appengine.api.datastore.Key; -import com.google.appengine.api.datastore.KeyFactory; -import com.google.appengine.api.datastore.Query; -import com.google.appengine.api.taskqueue.dev.LocalTaskQueue; -import com.google.appengine.api.taskqueue.dev.QueueStateInfo; -import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; -import com.google.appengine.tools.development.testing.LocalServiceTestHelper; -import com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig; -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.Month; -import java.time.ZonedDateTime; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import org.apache.commons.math3.stat.descriptive.moment.Mean; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; - -public class VtsProfilingStatsJobServletTest extends ObjectifyTestBase { - private final LocalServiceTestHelper helper = - new LocalServiceTestHelper( - new LocalDatastoreServiceTestConfig(), - new LocalTaskQueueTestConfig() - .setQueueXmlPath("src/main/webapp/WEB-INF/queue.xml")); - private static final double THRESHOLD = 1e-10; - - @BeforeEach - public void setUp() { - helper.setUp(); - } - - @AfterEach - public void tearDown() { - helper.tearDown(); - } - - private static void createProfilingRun() { - Date d = new Date(); - long time = TimeUnit.MILLISECONDS.toMicros(d.getTime()); - long canonicalTime = VtsProfilingStatsJobServlet.getCanonicalTime(time); - String test = "test"; - String profilingPointName = "profilingPoint"; - String xLabel = "xLabel"; - String yLabel = "yLabel"; - VtsReportMessage.VtsProfilingType type = - VtsReportMessage.VtsProfilingType.VTS_PROFILING_TYPE_UNLABELED_VECTOR; - VtsReportMessage.VtsProfilingRegressionMode mode = - VtsReportMessage.VtsProfilingRegressionMode.VTS_REGRESSION_MODE_INCREASING; - - Key testKey = KeyFactory.createKey(TestEntity.KIND, test); - Key testRunKey = KeyFactory.createKey(testKey, TestRunEntity.KIND, time); - Long[] valueArray = new Long[] {1l, 2l, 3l, 4l, 5l}; - StatSummary stats = - new StatSummary( - "expected", - VtsReportMessage.VtsProfilingRegressionMode.UNKNOWN_REGRESSION_MODE); - for (long value : valueArray) { - stats.updateStats(value); - } - Mean mean = new Mean(); - List<Long> values = Arrays.asList(valueArray); - ProfilingPointRunEntity profilingPointRunEntity = - new ProfilingPointRunEntity( - testRunKey, - profilingPointName, - type.getNumber(), - mode.getNumber(), - null, - values, - xLabel, - yLabel, - null); - - String branch = "master"; - String product = "product"; - String flavor = "flavor"; - String id = "12345"; - String bitness = "64"; - String abiName = "abi"; - DeviceInfoEntity device = - new DeviceInfoEntity(testRunKey, branch, product, flavor, id, bitness, abiName); - } - - /** - * Test that tasks are correctly scheduled on the queue. - * - * @throws InterruptedException - */ - @Test - public void testTasksScheduled() throws InterruptedException { - String[] testNames = new String[] {"test1", "test2", "test3"}; - List<Key> testKeys = new ArrayList(); - Set<Key> testKeySet = new HashSet<>(); - String kind = "TEST"; - for (String testName : testNames) { - Key key = KeyFactory.createKey(kind, testName); - testKeys.add(key); - testKeySet.add(key); - } - VtsProfilingStatsJobServlet.addTasks(testKeys); - Thread.sleep(1000); // wait one second (tasks are scheduled asychronously), must wait. - LocalTaskQueue taskQueue = LocalTaskQueueTestConfig.getLocalTaskQueue(); - QueueStateInfo qsi = taskQueue.getQueueStateInfo().get(VtsProfilingStatsJobServlet.QUEUE); - assertNotNull(qsi); - assertEquals(testNames.length, qsi.getTaskInfo().size()); - - int i = 0; - for (QueueStateInfo.TaskStateInfo taskStateInfo : qsi.getTaskInfo()) { - assertEquals( - VtsProfilingStatsJobServlet.PROFILING_STATS_JOB_URL, taskStateInfo.getUrl()); - assertEquals("POST", taskStateInfo.getMethod()); - String body = taskStateInfo.getBody(); - String[] parts = body.split("="); - assertEquals(2, parts.length); - assertEquals(VtsProfilingStatsJobServlet.PROFILING_POINT_KEY, parts[0]); - String keyString = parts[1]; - Key profilingPointRunKey; - try { - profilingPointRunKey = KeyFactory.stringToKey(keyString); - } catch (IllegalArgumentException e) { - fail(); - return; - } - assertTrue(testKeys.contains(profilingPointRunKey)); - } - } - - /** Test that canonical time is correctly derived from a timestamp in the middle of the day. */ - @Test - public void testCanonicalTimeMidday() { - int year = 2017; - Month month = Month.MAY; - int day = 28; - int hour = 14; - int minute = 30; - LocalDateTime now = LocalDateTime.of(year, month.getValue(), day, hour, minute); - ZonedDateTime zdt = ZonedDateTime.of(now, TimeUtil.PT_ZONE); - long time = TimeUnit.SECONDS.toMicros(zdt.toEpochSecond()); - long canonicalTime = VtsProfilingStatsJobServlet.getCanonicalTime(time); - long canonicalTimeSec = TimeUnit.MICROSECONDS.toSeconds(canonicalTime); - ZonedDateTime canonical = - ZonedDateTime.ofInstant(Instant.ofEpochSecond(canonicalTimeSec), TimeUtil.PT_ZONE); - assertEquals(month, canonical.getMonth()); - assertEquals(day, canonical.getDayOfMonth()); - assertEquals(0, canonical.getHour()); - assertEquals(0, canonical.getMinute()); - } - - /** Test that canonical time is correctly derived at the boundary of two days (midnight). */ - @Test - public void testCanonicalTimeMidnight() { - int year = 2017; - Month month = Month.MAY; - int day = 28; - int hour = 0; - int minute = 0; - LocalDateTime now = LocalDateTime.of(year, month.getValue(), day, hour, minute); - ZonedDateTime zdt = ZonedDateTime.of(now, TimeUtil.PT_ZONE); - long time = TimeUnit.SECONDS.toMicros(zdt.toEpochSecond()); - long canonicalTime = VtsProfilingStatsJobServlet.getCanonicalTime(time); - long canonicalTimeSec = TimeUnit.MICROSECONDS.toSeconds(canonicalTime); - ZonedDateTime canonical = - ZonedDateTime.ofInstant(Instant.ofEpochSecond(canonicalTimeSec), TimeUtil.PT_ZONE); - assertEquals(zdt, canonical); - } - - /** Test that new summaries are created with a clean database. */ - @Test - public void testNewSummary() { - Date d = new Date(); - long time = TimeUnit.MILLISECONDS.toMicros(d.getTime()); - String test = "test"; - - Key testKey = KeyFactory.createKey(TestEntity.KIND, test); - Key testRunKey = KeyFactory.createKey(testKey, TestRunEntity.KIND, time); - Long[] valueArray = new Long[] {1l, 2l, 3l, 4l, 5l}; - StatSummary expected = - new StatSummary( - "expected", - VtsReportMessage.VtsProfilingRegressionMode.UNKNOWN_REGRESSION_MODE); - for (long value : valueArray) { - expected.updateStats(value); - } - Mean mean = new Mean(); - List<Long> values = Arrays.asList(valueArray); - ProfilingPointRunEntity profilingPointRunEntity = - new ProfilingPointRunEntity( - testRunKey, - "profilingPoint", - VtsReportMessage.VtsProfilingType.VTS_PROFILING_TYPE_UNLABELED_VECTOR_VALUE, - VtsReportMessage.VtsProfilingRegressionMode - .VTS_REGRESSION_MODE_INCREASING_VALUE, - null, - values, - "xLabel", - "yLabel", - null); - - DeviceInfoEntity device = - new DeviceInfoEntity( - testRunKey, "master", "product", "flavor", "12345", "64", "abi"); - - List<DeviceInfoEntity> devices = new ArrayList<>(); - devices.add(device); - - boolean result = - VtsProfilingStatsJobServlet.updateSummaries( - testKey, profilingPointRunEntity, devices, time); - assertTrue(result); - - DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); - - // Check profiling point entity - Key profilingPointKey = ProfilingPointEntity.createKey(test, profilingPointRunEntity.getName()); - ProfilingPointEntity profilingPointEntity = null; - try { - Entity profilingPoint = datastore.get(profilingPointKey); - profilingPointEntity = ProfilingPointEntity.fromEntity(profilingPoint); - } catch (EntityNotFoundException exception) { - fail(); - } - assertNotNull(profilingPointEntity); - assertEquals(profilingPointRunEntity.getName(), profilingPointEntity.getProfilingPointName()); - assertEquals(profilingPointRunEntity.getXLabel(), profilingPointEntity.getXLabel()); - assertEquals(profilingPointRunEntity.getYLabel(), profilingPointEntity.getYLabel()); - assertEquals(profilingPointRunEntity.getType(), profilingPointEntity.getType()); - assertEquals(profilingPointRunEntity.getRegressionMode(), profilingPointEntity.getRegressionMode()); - - // Check all summary entities - Query q = new Query(ProfilingPointSummaryEntity.KIND).setAncestor(profilingPointKey); - for (Entity e : datastore.prepare(q).asIterable()) { - ProfilingPointSummaryEntity pps = ProfilingPointSummaryEntity.fromEntity(e); - assertNotNull(pps); - assertTrue( - pps.getBranch().equals(device.getBranch()) - || pps.getBranch().equals(ProfilingPointSummaryEntity.ALL)); - assertTrue( - pps.getBuildFlavor().equals(ProfilingPointSummaryEntity.ALL) - || pps.getBuildFlavor().equals(device.getBuildFlavor())); - assertEquals(expected.getCount(), pps.getGlobalStats().getCount()); - assertEquals(expected.getMax(), pps.getGlobalStats().getMax(), THRESHOLD); - assertEquals(expected.getMin(), pps.getGlobalStats().getMin(), THRESHOLD); - assertEquals(expected.getMean(), pps.getGlobalStats().getMean(), THRESHOLD); - assertEquals(expected.getSumSq(), pps.getGlobalStats().getSumSq(), THRESHOLD); - } - } - - /** Test that existing summaries are updated correctly when a job pushes new profiling data. */ - @Test - public void testUpdateSummary() { - Date d = new Date(); - long time = TimeUnit.MILLISECONDS.toMicros(d.getTime()); - String test = "test2"; - - Key testKey = KeyFactory.createKey(TestEntity.KIND, test); - Key testRunKey = KeyFactory.createKey(testKey, TestRunEntity.KIND, time); - Long[] valueArray = new Long[] {0l}; - List<Long> values = Arrays.asList(valueArray); - - // Create a new profiling point run - ProfilingPointRunEntity profilingPointRunEntity = - new ProfilingPointRunEntity( - testRunKey, - "profilingPoint2", - VtsReportMessage.VtsProfilingType.VTS_PROFILING_TYPE_UNLABELED_VECTOR_VALUE, - VtsReportMessage.VtsProfilingRegressionMode - .VTS_REGRESSION_MODE_INCREASING_VALUE, - null, - values, - "xLabel", - "yLabel", - null); - - // Create a device for the run - String series = ""; - DeviceInfoEntity device = - new DeviceInfoEntity( - testRunKey, "master", "product", "flavor", "12345", "64", "abi"); - - List<DeviceInfoEntity> devices = new ArrayList<>(); - devices.add(device); - - // Create the existing stats - Key profilingPointKey = ProfilingPointEntity.createKey(test, profilingPointRunEntity.getName()); - StatSummary expected = - new StatSummary( - "label", - 0, - 10, - 5, - 100, - 10, - VtsReportMessage.VtsProfilingRegressionMode.UNKNOWN_REGRESSION_MODE); - ProfilingPointSummaryEntity summary = - new ProfilingPointSummaryEntity( - profilingPointKey, - expected, - new ArrayList<>(), - new HashMap<>(), - device.getBranch(), - device.getBuildFlavor(), - series, - time); - - DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); - datastore.put(summary.toEntity()); - - // Update the summaries in the database - boolean result = - VtsProfilingStatsJobServlet.updateSummaries( - testKey, profilingPointRunEntity, devices, time); - assertTrue(result); - - // Calculate the expected stats with the values from the new run - for (long value : values) expected.updateStats(value); - - // Get the summary and check the values match what is expected - Key summaryKey = - ProfilingPointSummaryEntity.createKey( - profilingPointKey, device.getBranch(), device.getBuildFlavor(), series, time); - ProfilingPointSummaryEntity pps = null; - try { - Entity e = datastore.get(summaryKey); - pps = ProfilingPointSummaryEntity.fromEntity(e); - } catch (EntityNotFoundException e) { - fail(); - } - assertNotNull(pps); - assertTrue(pps.getBranch().equals(device.getBranch())); - assertTrue(pps.getBuildFlavor().equals(device.getBuildFlavor())); - assertEquals(expected.getCount(), pps.getGlobalStats().getCount()); - assertEquals(expected.getMax(), pps.getGlobalStats().getMax(), THRESHOLD); - assertEquals(expected.getMin(), pps.getGlobalStats().getMin(), THRESHOLD); - assertEquals(expected.getMean(), pps.getGlobalStats().getMean(), THRESHOLD); - assertEquals(expected.getSumSq(), pps.getGlobalStats().getSumSq(), THRESHOLD); - } -} 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); - } -} |