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