Home | History | Annotate | Download | only in security
      1 /*
      2  * Copyright (C) 2016 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.security.cts;
     17 
     18 import com.android.tradefed.device.ITestDevice;
     19 import com.android.tradefed.device.DeviceNotAvailableException;
     20 import com.android.tradefed.testtype.DeviceTestCase;
     21 
     22 public class PerfEventParanoidTest extends DeviceTestCase {
     23 
     24    /**
     25     * a reference to the device under test.
     26     */
     27     private ITestDevice mDevice;
     28 
     29     private static final String PERF_EVENT_PARANOID_PATH = "/proc/sys/kernel/perf_event_paranoid";
     30 
     31     @Override
     32     protected void setUp() throws Exception {
     33         super.setUp();
     34         mDevice = getDevice();
     35     }
     36 
     37     public void testPerfEventRestricted() throws DeviceNotAvailableException {
     38         String cmd = "cat " + PERF_EVENT_PARANOID_PATH;
     39         String output = mDevice.executeShellCommand(cmd);
     40         assertTrue("\n/proc/sys/kernel/perf_event_paranoid=3 is required.\n"
     41                    + "Please add CONFIG_SECURITY_PERF_EVENTS_RESTRICT=y\n"
     42                    + "to your device kernel's defconfig and apply the\n"
     43                    + "appropriate patches for your kernel located here:\n"
     44                    + "https://android-review.googlesource.com/#/q/topic:CONFIG_SECURITY_PERF_EVENTS_RESTRICT",
     45                    output.equals("3\n"));
     46     }
     47 }
     48