1 /* 2 * Copyright (C) 2018 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 android.cts.statsd.validation; 17 18 import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper; 19 import com.android.internal.os.StatsdConfigProto.StatsdConfig; 20 import com.android.tradefed.build.IBuildInfo; 21 import com.android.tradefed.log.LogUtil; 22 import com.android.tradefed.util.FileUtil; 23 24 import com.google.protobuf.TextFormat; 25 import com.google.protobuf.TextFormat.ParseException; 26 27 import java.io.File; 28 import java.io.IOException; 29 30 public class ValidationTestUtil { 31 32 private static final String TAG = "Statsd.ValidationTestUtil"; 33 getConfig(String fileName, IBuildInfo ctsBuild)34 public static StatsdConfig getConfig(String fileName, IBuildInfo ctsBuild) throws IOException { 35 try { 36 // TODO: Ideally, we should use real metrics that are also pushed to the fleet. 37 File configFile = getBuildHelper(ctsBuild).getTestFile(fileName); 38 String configStr = FileUtil.readStringFromFile(configFile); 39 StatsdConfig.Builder builder = StatsdConfig.newBuilder(); 40 TextFormat.merge(configStr, builder); 41 return builder.build(); 42 } catch (ParseException e) { 43 LogUtil.CLog.e( 44 "Failed to parse the config! line: " + e.getLine() + " col: " + e.getColumn(), 45 e); 46 } 47 return null; 48 } 49 getBuildHelper(IBuildInfo ctsBuild)50 private static CompatibilityBuildHelper getBuildHelper(IBuildInfo ctsBuild) { 51 return new CompatibilityBuildHelper(ctsBuild); 52 } 53 } 54