• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 package com.android.server.cts.device.expresslog;
17 
18 import com.android.modules.expresslog.Counter;
19 import com.android.modules.expresslog.Histogram;
20 
21 import org.junit.Test;
22 
23 public class AtomTests {
24 
25     private static final int TEST_UID = 123;
26 
27     @Test
testCounterMetric()28     public void testCounterMetric() throws Exception {
29         Counter.logIncrement("tex_test.value_telemetry_express_test_counter");
30         Thread.sleep(10);
31         Counter.logIncrement("tex_test.value_telemetry_express_test_counter", 10);
32     }
33 
34     @Test
testCounterWithUidMetric()35     public void testCounterWithUidMetric() throws Exception {
36         Counter.logIncrementWithUid(
37                 "tex_test.value_telemetry_express_test_counter_with_uid", TEST_UID);
38         Thread.sleep(10);
39         Counter.logIncrementWithUid(
40                 "tex_test.value_telemetry_express_test_counter_with_uid", TEST_UID, 10);
41     }
42 
43     @Test
testHistogramUniformMetric()44     public void testHistogramUniformMetric() throws Exception {
45         final Histogram histogram =
46                 new Histogram(
47                         "tex_test.value_telemetry_express_fixed_range_histogram",
48                         new Histogram.UniformOptions(
49                                 /* binCount= */ 50,
50                                 /* minValue= */ 1,
51                                 /* exclusiveMaxValue= */ 1000000));
52         histogram.logSample(0.f);
53         Thread.sleep(10);
54         histogram.logSample(1.f);
55         Thread.sleep(10);
56         histogram.logSample(100.f);
57         Thread.sleep(10);
58         histogram.logSample(2000000.f);
59     }
60 
61     @Test
testHistogramScaledMetric()62     public void testHistogramScaledMetric() throws Exception {
63         final Histogram histogram =
64                 new Histogram(
65                         "tex_test.value_telemetry_express_scaled_factor_histogram",
66                         new Histogram.ScaledRangeOptions(
67                                 /* binCount= */ 20,
68                                 /* minValue= */ 1,
69                                 /* firstBinWidth= */ 10,
70                                 /* scaleFactor= */ 1.6f));
71         histogram.logSample(0.f);
72         Thread.sleep(10);
73         histogram.logSample(1.f);
74         Thread.sleep(10);
75         histogram.logSample(100.f);
76         Thread.sleep(10);
77         histogram.logSample(2000000.f);
78     }
79 
80     @Test
testHistogramUniformWithUidMetric()81     public void testHistogramUniformWithUidMetric() throws Exception {
82         final Histogram histogram =
83                 new Histogram(
84                         "tex_test.value_telemetry_express_fixed_range_histogram_with_uid",
85                         new Histogram.UniformOptions(
86                                 /* binCount= */ 50,
87                                 /* minValue= */ 1,
88                                 /* exclusiveMaxValue= */ 1000000));
89         histogram.logSampleWithUid(TEST_UID, 0.f);
90         Thread.sleep(10);
91         histogram.logSampleWithUid(TEST_UID, 1.f);
92         Thread.sleep(10);
93         histogram.logSampleWithUid(TEST_UID, 100.f);
94         Thread.sleep(10);
95         histogram.logSampleWithUid(TEST_UID, 2000000.f);
96     }
97 
98     @Test
testHistogramScaledWithUidMetric()99     public void testHistogramScaledWithUidMetric() throws Exception {
100         final Histogram histogram =
101                 new Histogram(
102                         "tex_test.value_telemetry_express_scaled_range_histogram_with_uid",
103                         new Histogram.ScaledRangeOptions(
104                                 /* binCount= */ 20,
105                                 /* minValue= */ 1,
106                                 /* firstBinWidth= */ 10,
107                                 /* scaleFactor= */ 1.6f));
108         histogram.logSampleWithUid(TEST_UID, 0.f);
109         Thread.sleep(10);
110         histogram.logSampleWithUid(TEST_UID, 1.f);
111         Thread.sleep(10);
112         histogram.logSampleWithUid(TEST_UID, 100.f);
113         Thread.sleep(10);
114         histogram.logSampleWithUid(TEST_UID, 2000000.f);
115     }
116 }
117