• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.cts.statsdatom.tls;
18 
19 import com.android.tradefed.util.RunUtil;
20 import static com.google.common.truth.Truth.assertThat;
21 
22 import android.cts.statsdatom.lib.AtomTestUtils;
23 import android.cts.statsdatom.lib.ConfigUtils;
24 import android.cts.statsdatom.lib.DeviceUtils;
25 import android.cts.statsdatom.lib.ReportUtils;
26 
27 import com.android.os.AtomsProto;
28 import com.android.os.StatsLog;
29 import com.android.tradefed.build.IBuildInfo;
30 import com.android.tradefed.testtype.DeviceTestCase;
31 import com.android.tradefed.testtype.IBuildReceiver;
32 
33 import java.util.List;
34 
35 public class TlsHandshakeStatsTests extends DeviceTestCase implements IBuildReceiver {
36 
37     private IBuildInfo mCtsBuild;
38 
39     @Override
setUp()40     protected void setUp() throws Exception {
41         super.setUp();
42         assertThat(mCtsBuild).isNotNull();
43         ConfigUtils.removeConfig(getDevice());
44         ReportUtils.clearReports(getDevice());
45         DeviceUtils.installStatsdTestApp(getDevice(), mCtsBuild);
46         RunUtil.getDefault().sleep(AtomTestUtils.WAIT_TIME_LONG);
47     }
48 
49     @Override
tearDown()50     protected void tearDown() throws Exception {
51         ConfigUtils.removeConfig(getDevice());
52         ReportUtils.clearReports(getDevice());
53         DeviceUtils.uninstallStatsdTestApp(getDevice());
54         super.tearDown();
55     }
56 
57     @Override
setBuild(IBuildInfo buildInfo)58     public void setBuild(IBuildInfo buildInfo) {
59         mCtsBuild = buildInfo;
60     }
61 
testTlsHandshake()62     public void testTlsHandshake()
63             throws Exception {
64         final int atomTag = AtomsProto.Atom.TLS_HANDSHAKE_REPORTED_FIELD_NUMBER;
65         ConfigUtils.uploadConfigForPushedAtom(getDevice(), DeviceUtils.STATSD_ATOM_TEST_PKG,
66                 atomTag);
67 
68         DeviceUtils.runDeviceTestsOnStatsdApp(getDevice(), ".AtomTests", "testTlsHandshake");
69 
70         // Sorted list of events in order in which they occurred.
71         List<StatsLog.EventMetricData> data = ReportUtils.getEventMetricDataList(getDevice());
72 
73         assertThat(data.size()).isAtLeast(2);
74         AtomsProto.TlsHandshakeReported atom = data.get(0).getAtom().getTlsHandshakeReported();
75         AtomsProto.TlsHandshakeReported atom2 = data.get(1).getAtom().getTlsHandshakeReported();
76         assertThat(atom.getProtocol().toString()).contains("TLS_V1_3");
77         assertThat(atom2.getProtocol().toString()).contains("TLS_V1_3");
78     }
79 }