Home | History | Annotate | Download | only in recorder
      1 /*
      2  * Copyright (C) 2017 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 com.android.tradefed.profiler.recorder;
     18 
     19 import org.junit.Assert;
     20 import org.junit.Test;
     21 import org.junit.runner.RunWith;
     22 import org.junit.runners.JUnit4;
     23 
     24 /** Unit Tests for {@link TraceMetric}. */
     25 @RunWith(JUnit4.class)
     26 public class TraceMetricTest {
     27 
     28     @Test
     29     public void testParse_noExpectedVal() {
     30         String line = "mmc:mmc_cmd_rw_start:response:COUNT";
     31         TraceMetric m = TraceMetric.parse(line);
     32         Assert.assertEquals("mmc", m.getPrefix());
     33         Assert.assertEquals("mmc_cmd_rw_start", m.getFuncName());
     34         Assert.assertEquals("response", m.getParam());
     35         Assert.assertEquals(MetricType.COUNT, m.getMetricType());
     36     }
     37 
     38     @Test
     39     public void testParse_expectedValHex() {
     40         String line = "mmc:mmc_cmd_rw_start:response=0x00000090:COUNT";
     41         TraceMetric m = TraceMetric.parse(line);
     42         Assert.assertEquals("mmc", m.getPrefix());
     43         Assert.assertEquals("mmc_cmd_rw_start", m.getFuncName());
     44         Assert.assertEquals("response", m.getParam());
     45         Assert.assertEquals(Double.valueOf(144), m.getExpectedVal());
     46         Assert.assertEquals(MetricType.COUNT, m.getMetricType());
     47     }
     48 
     49     @Test
     50     public void testParse_expectedValDec() {
     51         String line = "mmc:mmc_cmd_rw_start:response=90:COUNT";
     52         TraceMetric m = TraceMetric.parse(line);
     53         Assert.assertEquals("mmc", m.getPrefix());
     54         Assert.assertEquals("mmc_cmd_rw_start", m.getFuncName());
     55         Assert.assertEquals("response", m.getParam());
     56         Assert.assertEquals(Double.valueOf(90), m.getExpectedVal());
     57         Assert.assertEquals(MetricType.COUNT, m.getMetricType());
     58     }
     59 
     60     @Test(expected = IllegalArgumentException.class)
     61     public void testParse_badFmt() {
     62         String line = "mmc:mmcfoobar:zz;fjdkls";
     63         TraceMetric.parse(line);
     64     }
     65 }
     66