bc: run the tests in presubmit.

Test: ./run-bc-tests-on-android.sh
Test: atest bc-tests
Test: treehugger
Change-Id: Ic230b06ca5edad7e46fbd19c796bc236241cf29a
diff --git a/Android.bp b/Android.bp
index 36516e4..e7ae66d 100644
--- a/Android.bp
+++ b/Android.bp
@@ -61,3 +61,17 @@
   name: "gavinhoward-bc",
   defaults: ["bc-defaults"],
 }
+
+sh_test {
+  name: "bc-tests",
+  src: "run-bc-tests-on-android.sh",
+  filename: "run-bc-tests-on-android.sh",
+  test_suites: ["general-tests"],
+  host_supported: true,
+  device_supported: false,
+  test_config: "bc-tests.xml",
+  data: [
+    "functions.sh",
+    "tests/**/*",
+  ],
+}
diff --git a/TEST_MAPPING b/TEST_MAPPING
new file mode 100644
index 0000000..c05ac95
--- /dev/null
+++ b/TEST_MAPPING
@@ -0,0 +1,7 @@
+{
+  "presubmit": [
+    {
+      "name": "bc-tests"
+    }
+  ]
+}
diff --git a/bc-tests.xml b/bc-tests.xml
new file mode 100644
index 0000000..6d70d3c
--- /dev/null
+++ b/bc-tests.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2019 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.
+-->
+<configuration description="Config for running bc-tests through Atest or in Infra">
+    <option name="test-suite-tag" value="bc-tests" />
+    <!-- This test requires a device, so it's not annotated with a null-device. -->
+    <test class="com.android.tradefed.testtype.binary.ExecutableHostTest" >
+        <option name="binary" value="run-bc-tests-on-android.sh" />
+        <!-- Test script assumes a relative path with the tests/ folders. -->
+        <option name="relative-path-execution" value="true" />
+        <!-- Tests shouldn't be that long but set 15m to be safe. -->
+        <option name="per-binary-timeout" value="15m" />
+    </test>
+</configuration>
diff --git a/run-bc-tests-on-android.sh b/run-bc-tests-on-android.sh
new file mode 100755
index 0000000..d957a7e
--- /dev/null
+++ b/run-bc-tests-on-android.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+# Copy the tests across.
+adb shell rm -rf /data/local/tmp/bc-tests/
+adb shell mkdir /data/local/tmp/bc-tests/
+adb push tests/ /data/local/tmp/bc-tests/
+adb push functions.sh /data/local/tmp/bc-tests/
+
+if tty -s; then
+  dash_t="-t"
+else
+  dash_t=""
+fi
+
+exec adb shell $dash_t /data/local/tmp/bc-tests/tests/all.sh bc 0 1 0 1 bc