Remove android.security.cts.SeccompBpfTest.

This is obsolete now that the kernel-level unittests run as part of
android.os.cts (c.f. I607195da52df24c39366b34cb1f5caddf6217b8b).

Bug: 21396275
Change-Id: Iaa18f92709418c73bbd61edeae83bd9f7845f1bb
diff --git a/tests/tests/security/jni/Android.mk b/tests/tests/security/jni/Android.mk
index 7106385..6bef886 100644
--- a/tests/tests/security/jni/Android.mk
+++ b/tests/tests/security/jni/Android.mk
@@ -28,7 +28,6 @@
 		android_security_cts_LinuxRngTest.cpp \
 		android_security_cts_LoadEffectLibraryTest.cpp \
 		android_security_cts_NativeCodeTest.cpp \
-		android_security_cts_SeccompDeathTestService.cpp \
 		android_security_cts_SELinuxTest.cpp \
 		android_security_cts_MMapExecutableTest.cpp \
 		android_security_cts_AudioPolicyBinderTest.cpp
diff --git a/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp b/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp
index 424dbaf..1051a82 100644
--- a/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp
+++ b/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp
@@ -22,7 +22,6 @@
 extern int register_android_security_cts_LinuxRngTest(JNIEnv*);
 extern int register_android_security_cts_NativeCodeTest(JNIEnv*);
 extern int register_android_security_cts_LoadEffectLibraryTest(JNIEnv*);
-extern int register_android_security_cts_SeccompDeathTestService(JNIEnv*);
 extern int register_android_security_cts_SELinuxTest(JNIEnv*);
 extern int register_android_security_cts_MMapExecutableTest(JNIEnv* env);
 extern int register_android_security_cts_AudioPolicyBinderTest(JNIEnv* env);
@@ -50,10 +49,6 @@
         return JNI_ERR;
     }
 
-    if (register_android_security_cts_SeccompDeathTestService(env)) {
-        return JNI_ERR;
-    }
-
     if (register_android_security_cts_SELinuxTest(env)) {
         return JNI_ERR;
     }
diff --git a/tests/tests/security/jni/android_security_cts_SeccompDeathTestService.cpp b/tests/tests/security/jni/android_security_cts_SeccompDeathTestService.cpp
deleted file mode 100644
index eb32521..0000000
--- a/tests/tests/security/jni/android_security_cts_SeccompDeathTestService.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-#include <jni.h>
-#include <signal.h>
-#include <unistd.h>
-
-void android_security_cts_SeccompDeathTestService_testSigSysSelf(JNIEnv* env, jobject thiz)
-{
-    kill(getpid(), SIGSYS);
-}
-
-static JNINativeMethod methods[] = {
-    { "testSigSysSelf", "()V",
-        (void *)android_security_cts_SeccompDeathTestService_testSigSysSelf }
-};
-
-int register_android_security_cts_SeccompDeathTestService(JNIEnv* env) {
-    jclass clazz = env->FindClass("android/security/cts/SeccompDeathTestService");
-    return env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(JNINativeMethod));
-}
diff --git a/tests/tests/security/src/android/security/cts/SeccompBpfTest.java b/tests/tests/security/src/android/security/cts/SeccompBpfTest.java
deleted file mode 100644
index b7d8f2e..0000000
--- a/tests/tests/security/src/android/security/cts/SeccompBpfTest.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Copyright (C) 2014 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.security.cts;
-
-import android.test.AndroidTestCase;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
-import android.os.ConditionVariable;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.IBinder;
-import android.os.Message;
-import android.os.Messenger;
-import android.os.RemoteException;
-import android.util.Log;
-
-/**
- * Test for seccomp-bpf sandboxing technology. This makes use of the
- * SeccompDeathTestService to run sandboxing death tests out-of-process.
- */
-public class SeccompBpfTest extends AndroidTestCase implements ServiceConnection,
-       IBinder.DeathRecipient {
-    static final String TAG = "SeccompBpfTest";
-
-    /**
-     * Message sent from the SeccompDeathTestService before it runs a test.
-     */
-    static final int MSG_TEST_STARTED = 1;
-    /**
-     * Message sent from the SeccompDeathTestService after a test exits cleanly.
-     */
-    static final int MSG_TEST_ENDED_CLEAN = 2;
-
-    /**
-     * Dedicated thread used to receive messages from the SeccompDeathTestService.
-     */
-    final private HandlerThread mHandlerThread = new HandlerThread("SeccompBpfTest handler");
-    /**
-     * Messenger that runs on mHandlerThread.
-     */
-    private Messenger mMessenger;
-
-    /**
-     * Condition that blocks the test/instrumentation thread that runs the
-     * test cases, while the SeccompDeathTestService runs the test out-of-process.
-     */
-    final private ConditionVariable mCondition = new ConditionVariable();
-
-    /**
-     * The SeccompDeathTestService number to run.
-     */
-    private int mTestNumber = -1;
-
-    /**
-     * If the test has started.
-     */
-    private boolean mTestStarted = false;
-    /**
-     * If the test ended (either cleanly or with death).
-     */
-    private boolean mTestEnded = false;
-    /**
-     * If the test ended cleanly or died.
-     */
-    private boolean mTestDied = false;
-
-    public void testDeathTest() {
-        runDeathTest(SeccompDeathTestService.TEST_DEATH_TEST);
-        assertTrue(mTestDied);
-    }
-
-    public void testCleanTest() {
-        runDeathTest(SeccompDeathTestService.TEST_CLEAN_TEST);
-        assertFalse(mTestDied);
-    }
-
-    public void testSigSysSelf() {
-        runDeathTest(SeccompDeathTestService.TEST_SIGSYS_SELF);
-        assertTrue(mTestDied);
-    }
-
-    /**
-     * Runs a death test by its test number, which needs to match a value in
-     * SeccompDeathTestService.
-     *
-     * This blocks until the completion of the test, after which the test body
-     * can use mTestEnded/mTestDied to see if the test died.
-     */
-    public void runDeathTest(final int testNumber) {
-        mTestStarted = false;
-        mTestEnded = false;
-        mTestDied = false;
-
-        mTestNumber = testNumber;
-
-        Log.d(TAG, "Starting runDeathTest");
-        launchDeathTestService();
-        mCondition.block();
-
-        assertTrue(mTestStarted);
-        assertTrue(mTestEnded);
-    }
-
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-        mHandlerThread.start();
-        mMessenger = new Messenger(new Handler(mHandlerThread.getLooper()) {
-            @Override
-            public void handleMessage(Message msg) {
-                switch (msg.what) {
-                    case MSG_TEST_STARTED:
-                        onTestStarted();
-                        break;
-                    case MSG_TEST_ENDED_CLEAN:
-                        onTestEnded(false);
-                        break;
-                    default:
-                        super.handleMessage(msg);
-                }
-            }
-        });
-    }
-
-    @Override
-    public void tearDown() throws Exception {
-        try {
-            mHandlerThread.quitSafely();
-        } finally {
-            super.tearDown();
-        }
-    }
-
-    private void launchDeathTestService() {
-        Log.d(TAG, "launchDeathTestService");
-        mCondition.close();
-
-        Intent intent = new Intent();
-        intent.setComponent(new ComponentName("com.android.cts.security", "android.security.cts.SeccompDeathTestService"));
-
-        if (!getContext().bindService(intent, this, Context.BIND_AUTO_CREATE)) {
-            mCondition.open();
-            fail("Failed to start DeathTestService");
-        }
-    }
-
-    @Override
-    public void onServiceConnected(ComponentName name, IBinder service) {
-        Log.d(TAG, "onServiceConnected");
-
-        Messenger remoteMessenger = new Messenger(service);
-        Message msg = Message.obtain(null, SeccompDeathTestService.MSG_RUN_TEST);
-        msg.getData().putBinder(SeccompDeathTestService.REPLY_BINDER_NAME, mMessenger.getBinder());
-        msg.getData().putInt(SeccompDeathTestService.RUN_TEST_IDENTIFIER, mTestNumber);
-
-        try {
-            service.linkToDeath(this, 0);
-            remoteMessenger.send(msg);
-        } catch (RemoteException e) {
-            Log.e(TAG, "Error setting up SeccompDeathTestService: " + e.getMessage());
-        }
-        Log.d(TAG, "Send MSG_TEST_START");
-    }
-
-    private void onTestStarted() {
-        Log.d(TAG, "onTestStarted");
-        mTestStarted = true;
-    }
-
-    @Override
-    public void onServiceDisconnected(ComponentName name) {
-        Log.d(TAG, "onServiceDisconnected");
-    }
-
-    @Override
-    public void binderDied() {
-        Log.d(TAG, "binderDied");
-        if (mTestEnded)
-            return;
-        onTestEnded(true);
-    }
-
-    private void onTestEnded(boolean died) {
-        Log.d(TAG, "onTestEnded, died=" + died);
-        mTestEnded = true;
-        mTestDied = died;
-        getContext().unbindService(this);
-        mCondition.open();
-    }
-}
diff --git a/tests/tests/security/src/android/security/cts/SeccompDeathTestService.java b/tests/tests/security/src/android/security/cts/SeccompDeathTestService.java
deleted file mode 100644
index c78ea35..0000000
--- a/tests/tests/security/src/android/security/cts/SeccompDeathTestService.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 2014 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.security.cts;
-
-import android.app.Service;
-import android.content.Intent;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Message;
-import android.os.Messenger;
-import android.os.RemoteException;
-import android.util.Log;
-
-/**
- * Service used to run tests for seccomp-bpf sandboxing. Since sandbox violations
- * result in process termination, they cannot be run from within the test case
- * itself. The SeccompBpfTest starts this service to run code out-of-process and
- * then observes when the Binder channel dies. If the test does not die, the
- * service reports back to the test that it exited cleanly.
- */
-public class SeccompDeathTestService extends Service {
-    static final String TAG = SeccompBpfTest.TAG;
-
-    static {
-        System.loadLibrary("ctssecurity_jni");
-    }
-
-    /**
-     * Message sent from SeccompBpfTest to run a test.
-     */
-    final static int MSG_RUN_TEST = 100;
-    /**
-     * In MSG_RUN_TEST, the test number to run.
-     */
-    final static String RUN_TEST_IDENTIFIER = "android.security.cts.SeccompDeathTestService.testID";
-    /**
-     * In MSG_RUN_TEST, the Binder on which to report clean death.
-     */
-    static final String REPLY_BINDER_NAME = "android.security.cts.SeccompBpfTest";
-
-    // Test numbers that map to test methods in this service.
-    final static int TEST_DEATH_TEST = 1;
-    final static int TEST_CLEAN_TEST = 2;
-    final static int TEST_SIGSYS_SELF = 3;
-
-    final private Messenger mMessenger = new Messenger(new Handler() {
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case MSG_RUN_TEST:
-                    runTest(msg);
-                    break;
-                default:
-                    super.handleMessage(msg);
-            }
-        }
-    });
-
-    @Override
-    public IBinder onBind(Intent intent) {
-        Log.d(TAG, "onBind");
-        return mMessenger.getBinder();
-    }
-
-    private void runTest(Message msg) {
-        Log.d(TAG, "runTest");
-        IBinder harnessBinder = msg.getData().getBinder(REPLY_BINDER_NAME);
-        Messenger harness = new Messenger(harnessBinder);
-
-        try {
-            Log.d(TAG, "Send MSG_TEST_STARTED");
-            harness.send(Message.obtain(null, SeccompBpfTest.MSG_TEST_STARTED));
-        } catch (RemoteException e) {
-            Log.e(TAG, "Failed to MSG_TEST_STARTED: " + e.getMessage());
-        }
-
-        demuxTest(msg.getData().getInt(RUN_TEST_IDENTIFIER));
-
-        try {
-            Log.d(TAG, "Send MSG_TEST_ENDED_CLEAN");
-            harness.send(Message.obtain(null, SeccompBpfTest.MSG_TEST_ENDED_CLEAN));
-        } catch (RemoteException e) {
-            Log.e(TAG, "Failed to MSG_TEST_ENDED_CLEAN: " + e.getMessage());
-        }
-    }
-
-    private void demuxTest(int testNumber) {
-        switch (testNumber) {
-            case TEST_DEATH_TEST:
-                testDeath();
-                break;
-            case TEST_CLEAN_TEST:
-                break;
-            case TEST_SIGSYS_SELF:
-                testSigSysSelf();
-                break;
-            default:
-                throw new RuntimeException("Unknown test number " + testNumber);
-        }
-    }
-
-    public void testDeath() {
-        String s = null;
-        s.hashCode();
-    }
-
-    public native void testSigSysSelf();
-}