diff options
author | Tej Singh <singhtejinder@google.com> | 2021-06-07 13:57:58 -0700 |
---|---|---|
committer | Tej Singh <singhtejinder@google.com> | 2021-07-01 00:37:51 -0700 |
commit | b0e4063bb917e9df6363decfac53480595e4e797 (patch) | |
tree | a524aee13806ba46f9e0b84078e1887fb02f8bf5 | |
parent | 42cc7d9f0071eea03fc47bd904a5de6849ba3d41 (diff) | |
download | StatsD-b0e4063bb917e9df6363decfac53480595e4e797.tar.gz |
CTS test to ensure statsd isn't in boostrap apexes
Reads boostrap-apex-info-list.xml and parses it.
Ensures that statsd is not present in the list.
Also, add a clang-format
Test: atest CtsStatsdHostTestCases#BootstrapApexTests
Bug: 186767843
Change-Id: I8299a7c274671b5310b1de75b743f3589287a120
-rw-r--r-- | tests/.clang-format | 13 | ||||
-rw-r--r-- | tests/src/android/cts/statsd/apex/BootstrapApexTests.java | 79 |
2 files changed, 92 insertions, 0 deletions
diff --git a/tests/.clang-format b/tests/.clang-format new file mode 100644 index 00000000..2b2c71ac --- /dev/null +++ b/tests/.clang-format @@ -0,0 +1,13 @@ +BasedOnStyle: Google + +AccessModifierOffset: -4 +AlignOperands: false +AllowShortFunctionsOnASingleLine: Inline +AlwaysBreakBeforeMultilineStrings: false +ColumnLimit: 100 +CommentPragmas: NOLINT:.* +ConstructorInitializerIndentWidth: 6 +ContinuationIndentWidth: 8 +IndentWidth: 4 +PenaltyBreakBeforeFirstCallParameter: 100000 +SpacesBeforeTrailingComments: 1
\ No newline at end of file diff --git a/tests/src/android/cts/statsd/apex/BootstrapApexTests.java b/tests/src/android/cts/statsd/apex/BootstrapApexTests.java new file mode 100644 index 00000000..647a9e32 --- /dev/null +++ b/tests/src/android/cts/statsd/apex/BootstrapApexTests.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.cts.statsd.apex; + +import static com.google.common.truth.Truth.assertThat; + +import android.cts.statsd.atom.BaseTestCase; +import com.android.compatibility.common.util.ApiLevelUtil; +import com.android.tradefed.log.LogUtil; +import java.io.StringReader; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import org.junit.Before; +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + +/** + * Verify statsd is not in the bootstrap apexes + */ +public class BootstrapApexTests extends BaseTestCase { + private static final String TAG = "Statsd.BootstrapApexTests"; + + // Constants + private static final String BOOTSTRAP_APEX_FILE = "/apex/.bootstrap-apex-info-list.xml"; + + private boolean sdkLevelAtLeast(int sdkLevel, String codename) throws Exception { + return ApiLevelUtil.isAtLeast(getDevice(), sdkLevel) + || ApiLevelUtil.codenameEquals(getDevice(), codename); + } + + public void testStatsdNotPresent() throws Exception { + if (!sdkLevelAtLeast(31, "S")) { + return; + } + String adbCommand = "cat " + BOOTSTRAP_APEX_FILE; + String fileContents = getDevice().executeShellCommand(adbCommand); + + LogUtil.CLog.d(TAG + " Received the following file: " + fileContents); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document xml = builder.parse(new InputSource(new StringReader(fileContents))); + + NodeList apexInfoList = xml.getElementsByTagName("apex-info-list"); + assertThat(apexInfoList.getLength()).isEqualTo(1); + NodeList apexInfoNodes = apexInfoList.item(0).getChildNodes(); + assertThat(apexInfoNodes.getLength()).isGreaterThan(0); + + int numApexes = 0; + for (int i = 0; i < apexInfoNodes.getLength(); i++) { + Node apexInfoNode = apexInfoNodes.item(i); + String name = apexInfoNode.getNodeName(); + if (name.equals("apex-info")) { + numApexes++; + NamedNodeMap attr = apexInfoNode.getAttributes(); + Node moduleName = attr.getNamedItem("moduleName"); + assertThat(moduleName).isNotNull(); + assertThat(moduleName.getNodeValue()).isNotEqualTo("com.android.os.statsd"); + } + } + assertThat(numApexes).isGreaterThan(0); + } +} |