base=/system
export CLASSPATH=$base/framework/hidl_test_java.jar:$base/framework/android.hardware.tests.baz-V1.0-java.jar:$base/framework/android.hidl.base-V1.0-java.jar
export TREBLE_TESTING_OVERRIDE=true

e=0
for SIZE in 64 32; do
    native=/data/nativetest${SIZE/32}/hidl_test_java_native/hidl_test_java_native

    if [ -f $native ]; then
        echo "Testing $SIZE bit native client/server"

        # Test native server with Java client
        $native -s &
        sleep 1
        NATIVE_PID=$!
        app_process $base/bin com.android.commands.hidl_test_java.HidlTestJava -c \
            && echo "Java client => native server PASSED" \
            || (echo "Java client => native server FAILED" && false) || e=1

        kill $NATIVE_PID 2>/dev/null

        # Test Java server with native client
        app_process $base/bin com.android.commands.hidl_test_java.HidlTestJava -s &
        NATIVE_PID=$!
        sleep 1
        $native -c \
            && echo "native client => Java server PASSED" \
            || (echo "native client => Java server FAILED" && false) || e=1

        kill $NATIVE_PID 2>/dev/null
    else
        echo "FAILED: Not running $native because it doesn't exist."
        e=1
    fi
done

echo
echo "Summary: $e"
[ $e -eq 0 ] && echo "All tests PASSED." || echo "Test(s) FAILED."

exit $e