Add libnativebridge test to CTS for API coverage.

It so far only tests a subset of the API, due to problems with the test
setup in tradefed (b/189484095).

Also fix bitrot in runtests.sh so that the host tests find their DSO
dependencies.

Test: m cts cts-tradefed
      cts-tradefed run commandAndExit cts \
        --module art_libnativebridge_cts_tests
Test: atest art_libnativebridge_cts_tests
Test: art/libnativebridge/tests/runtests.sh
Bug: 208431683
Change-Id: I359b12bb79e104e0179e8cbf62f91b3e700d9d6c
diff --git a/libnativebridge/tests/Android.bp b/libnativebridge/tests/Android.bp
index b789a2e..dfacae8 100644
--- a/libnativebridge/tests/Android.bp
+++ b/libnativebridge/tests/Android.bp
@@ -146,6 +146,50 @@
     header_libs: ["libbase_headers"],
 }
 
+// Variant of libnativebridge-tests that is part of CTS to verify backed-by API
+// coverage.
+cc_test {
+    name: "art_libnativebridge_cts_tests",
+    defaults: [
+        "art_standalone_test_defaults",
+        "libnativebridge-tests-defaults",
+    ],
+
+    // TODO(b/189484095): Pick only a subset of the tests in
+    // libnativebridge-tests that don't require the native bridge lib to be
+    // loaded, to avoid the problems with test_per_src and pushing the extra
+    // libnativebridge*-test-case.so files to device through tradefed.
+    srcs: [
+        // ValidNameNativeBridge_test.cpp needs to be first due to global state
+        // had_error that isn't reset between tests.
+        "ValidNameNativeBridge_test.cpp",
+        "NeedsNativeBridge_test.cpp",
+        "UnavailableNativeBridge_test.cpp",
+    ],
+    shared_libs: [
+        "liblog",
+        "libnativebridge",
+    ],
+    header_libs: ["libbase_headers"],
+
+    // Support multilib variants (using different suffix per sub-architecture),
+    // which is needed on build targets with secondary architectures, as the CTS
+    // test suite packaging logic flattens all test artifacts into a single
+    // `testcases` directory.
+    compile_multilib: "both",
+    multilib: {
+        lib32: {
+            suffix: "32",
+        },
+        lib64: {
+            suffix: "64",
+        },
+    },
+
+    test_config_template: ":art-gtests-target-standalone-cts-template",
+    test_suites: ["cts"],
+}
+
 cc_test {
     name: "libnativebridge-lazy-tests",
     defaults: ["libnativebridge-tests-defaults"],
diff --git a/libnativebridge/tests/runtests.sh b/libnativebridge/tests/runtests.sh
index 1eb232d..74af9c5 100755
--- a/libnativebridge/tests/runtests.sh
+++ b/libnativebridge/tests/runtests.sh
@@ -40,8 +40,7 @@
       echo "Skipping missing $build_dir"
     else
       for test_path in $build_dir/*/* ; do
-        test_rel_path=${test_path#${build_dir}/}
-        echo_and_run \( cd $build_dir \; $test_rel_path $* \)
+        echo_and_run LD_LIBRARY_PATH=$build_dir $test_path $*
       done
     fi
   done