Fix HIDL output errata. am: 23cc5fa023
am: 2ff5d88a57
Change-Id: Ib819290201ea0ae570d1100d9672ea5e818aca71
diff --git a/CompoundType.cpp b/CompoundType.cpp
index 64ec2c2..fc3c27d 100644
--- a/CompoundType.cpp
+++ b/CompoundType.cpp
@@ -460,19 +460,6 @@
void CompoundType::emitPackageTypeDeclarations(Formatter& out) const {
Scope::emitPackageTypeDeclarations(out);
- // TODO(b/65200821): remove these ifdefs
- out << "#ifdef REALLY_IS_HIDL_INTERNAL_LIB" << gCurrentCompileName << "\n";
- out << "std::string toString("
- << getCppArgumentType()
- << ");\n\n";
- if (canCheckEquality()) {
- out << "bool operator==("
- << getCppArgumentType() << ", " << getCppArgumentType() << ");\n\n";
-
- out << "bool operator!=("
- << getCppArgumentType() << ", " << getCppArgumentType() << ");\n\n";
- }
- out << "#else\n";
out << "static inline std::string toString("
<< getCppArgumentType()
<< (mFields->empty() ? "" : " o")
@@ -517,7 +504,6 @@
} else {
out << "// operator== and operator!= are not generated for " << localName() << "\n\n";
}
- out << "#endif // REALLY_IS_HIDL_INTERNAL_LIB\n";
}
void CompoundType::emitPackageHwDeclarations(Formatter& out) const {
@@ -574,53 +560,6 @@
emitResolveReferenceDef(out, prefix, true /* isReader */);
emitResolveReferenceDef(out, prefix, false /* isReader */);
}
-
- // TODO(b/65200821): remove toString + operator== from .cpp once all prebuilts are rebuilt
-
- out << "std::string toString("
- << getCppArgumentType()
- << (mFields->empty() ? "" : " o")
- << ") ";
-
- out.block([&] {
- // include toString for scalar types
- out << "using ::android::hardware::toString;\n"
- << "std::string os;\n";
- out << "os += \"{\";\n";
-
- for (const NamedReference<Type>* field : *mFields) {
- out << "os += \"";
- if (field != *(mFields->begin())) {
- out << ", ";
- }
- out << "." << field->name() << " = \";\n";
- field->type().emitDump(out, "os", "o." + field->name());
- }
-
- out << "os += \"}\"; return os;\n";
- }).endl().endl();
-
- if (canCheckEquality()) {
- out << "bool operator==("
- << getCppArgumentType() << " " << (mFields->empty() ? "/* lhs */" : "lhs") << ", "
- << getCppArgumentType() << " " << (mFields->empty() ? "/* rhs */" : "rhs") << ") ";
- out.block([&] {
- for (const auto &field : *mFields) {
- out.sIf("lhs." + field->name() + " != rhs." + field->name(), [&] {
- out << "return false;\n";
- }).endl();
- }
- out << "return true;\n";
- }).endl().endl();
-
- out << "bool operator!=("
- << getCppArgumentType() << " lhs," << getCppArgumentType() << " rhs)";
- out.block([&] {
- out << "return !(lhs == rhs);\n";
- }).endl().endl();
- } else {
- out << "// operator== and operator!= are not generated for " << localName() << "\n";
- }
}
void CompoundType::emitJavaTypeDeclarations(Formatter& out, bool atTopLevel) const {
diff --git a/EnumType.cpp b/EnumType.cpp
index f3528e4..46dfabf 100644
--- a/EnumType.cpp
+++ b/EnumType.cpp
@@ -397,23 +397,6 @@
emitBitFieldBitwiseAssignmentOperator(out, "|");
emitBitFieldBitwiseAssignmentOperator(out, "&");
- // TODO(b/65200821): remove these ifndefs
- out << "#ifdef REALLY_IS_HIDL_INTERNAL_LIB" << gCurrentCompileName << "\n";
- // toString for bitfields, equivalent to dumpBitfield in Java
- out << "template<typename>\n"
- << "std::string toString("
- << resolveToScalarType()->getCppArgumentType()
- << " o);\n";
- out << "template<>\n"
- << "std::string toString<" << getCppStackType() << ">("
- << resolveToScalarType()->getCppArgumentType()
- << " o);\n\n";
-
- // toString for enum itself
- out << "std::string toString("
- << getCppArgumentType()
- << " o);\n\n";
- out << "#else\n";
const ScalarType *scalarType = mStorageType->resolveToScalarType();
CHECK(scalarType != NULL);
@@ -466,67 +449,6 @@
"static_cast<" + scalarType->getCppStackType() + ">(o)");
out << "return os;\n";
}).endl().endl();
- out << "#endif // REALLY_IS_HIDL_INTERNAL_LIB\n";
-}
-
-void EnumType::emitTypeDefinitions(Formatter& out, const std::string& /* prefix */) const {
- // TODO(b/65200821): remove toString from .cpp once all prebuilts are rebuilt
-
- const ScalarType *scalarType = mStorageType->resolveToScalarType();
- CHECK(scalarType != NULL);
-
- out << "template<>\n"
- << "std::string toString<" << getCppStackType() << ">("
- << scalarType->getCppArgumentType()
- << " o) ";
- out.block([&] {
- // include toHexString for scalar types
- out << "using ::android::hardware::details::toHexString;\n"
- << "std::string os;\n"
- << getBitfieldCppType(StorageMode_Stack) << " flipped = 0;\n"
- << "bool first = true;\n";
-
- forEachValueFromRoot([&](EnumValue* value) {
- std::string valueName = fullName() + "::" + value->name();
- out.sIf("(o & " + valueName + ")" +
- " == static_cast<" + scalarType->getCppStackType() +
- ">(" + valueName + ")", [&] {
- out << "os += (first ? \"\" : \" | \");\n"
- << "os += \"" << value->name() << "\";\n"
- << "first = false;\n"
- << "flipped |= " << valueName << ";\n";
- }).endl();
- });
- // put remaining bits
- out.sIf("o != flipped", [&] {
- out << "os += (first ? \"\" : \" | \");\n";
- scalarType->emitHexDump(out, "os", "o & (~flipped)");
- });
- out << "os += \" (\";\n";
- scalarType->emitHexDump(out, "os", "o");
- out << "os += \")\";\n";
-
- out << "return os;\n";
- }).endl().endl();
-
- out << "std::string toString("
- << getCppArgumentType()
- << " o) ";
-
- out.block([&] {
- out << "using ::android::hardware::details::toHexString;\n";
-
- forEachValueFromRoot([&](EnumValue* value) {
- out.sIf("o == " + fullName() + "::" + value->name(), [&] {
- out << "return \"" << value->name() << "\";\n";
- }).endl();
- });
-
- out << "std::string os;\n";
- scalarType->emitHexDump(out, "os",
- "static_cast<" + scalarType->getCppStackType() + ">(o)");
- out << "return os;\n";
- }).endl().endl();
}
void EnumType::emitJavaTypeDeclarations(Formatter& out, bool atTopLevel) const {
diff --git a/EnumType.h b/EnumType.h
index ca0374e..d219506 100644
--- a/EnumType.h
+++ b/EnumType.h
@@ -94,7 +94,6 @@
void emitTypeForwardDeclaration(Formatter& out) const override;
void emitGlobalTypeDeclarations(Formatter& out) const override;
void emitPackageTypeDeclarations(Formatter& out) const override;
- void emitTypeDefinitions(Formatter& out, const std::string& prefix) const override;
void emitJavaTypeDeclarations(Formatter& out, bool atTopLevel) const override;
diff --git a/Interface.cpp b/Interface.cpp
index 9e53e1f..aceea30 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -848,12 +848,6 @@
void Interface::emitPackageTypeDeclarations(Formatter& out) const {
Scope::emitPackageTypeDeclarations(out);
- // TODO(b/65200821): remove these ifndefs
- out << "#ifdef REALLY_IS_HIDL_INTERNAL_LIB" << gCurrentCompileName << "\n";
- out << "std::string toString("
- << getCppArgumentType()
- << ");\n";
- out << "#else\n";
out << "static inline std::string toString(" << getCppArgumentType() << " o) ";
out.block([&] {
@@ -863,25 +857,12 @@
<< "os += o->isRemote() ? \"@remote\" : \"@local\";\n"
<< "return os;\n";
}).endl().endl();
- out << "#endif // REALLY_IS_HIDL_INTERNAL_LIB\n";
}
void Interface::emitTypeDefinitions(Formatter& out, const std::string& prefix) const {
std::string space = prefix.empty() ? "" : (prefix + "::");
+
Scope::emitTypeDefinitions(out, space + localName());
-
- // TODO(b/65200821): remove toString from .cpp once all prebuilts are rebuilt
- out << "std::string toString("
- << getCppArgumentType()
- << " o) ";
-
- out.block([&] {
- out << "std::string os = \"[class or subclass of \";\n"
- << "os += " << fullName() << "::descriptor;\n"
- << "os += \"]\";\n"
- << "os += o->isRemote() ? \"@remote\" : \"@local\";\n"
- << "return os;\n";
- }).endl().endl();
}
void Interface::emitJavaReaderWriter(
diff --git a/Type.cpp b/Type.cpp
index 23bc745..84be36f 100644
--- a/Type.cpp
+++ b/Type.cpp
@@ -28,9 +28,6 @@
namespace android {
-// TODO(b/65200821): remove
-std::string gCurrentCompileName;
-
Type::Type(Scope* parent) : mParent(parent) {}
Type::~Type() {}
diff --git a/Type.h b/Type.h
index db278d2..b1b97f4 100644
--- a/Type.h
+++ b/Type.h
@@ -30,10 +30,6 @@
namespace android {
-// TODO(b/65200821): remove
-// HACK because no no type can depend or see AST
-extern std::string gCurrentCompileName;
-
struct ConstantExpression;
struct Formatter;
struct FQName;
diff --git a/generateCpp.cpp b/generateCpp.cpp
index 6d9c4b7..bdf3861 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -776,9 +776,6 @@
<< mPackage.string() << "::" << baseName
<< "\"\n\n";
- // TODO(b/65200821): remove define
- out << "#define REALLY_IS_HIDL_INTERNAL_LIB" << gCurrentCompileName << "\n";
-
out << "#include <android/log.h>\n";
out << "#include <cutils/trace.h>\n";
out << "#include <hidl/HidlTransportSupport.h>\n\n";
@@ -1322,6 +1319,11 @@
out.indent();
+ out << "bool _hidl_is_oneway = _hidl_flags & " << Interface::FLAG_ONEWAY
+ << " /* oneway */;\n";
+ out << "if (_hidl_is_oneway != " << (method->isOneway() ? "true" : "false") << ") ";
+ out.block([&] { out << "return ::android::UNKNOWN_ERROR;\n"; }).endl().endl();
+
generateStubSourceForMethod(out, method, superInterface);
out.unindent();
diff --git a/generateJava.cpp b/generateJava.cpp
index 973af72..531211d 100644
--- a/generateJava.cpp
+++ b/generateJava.cpp
@@ -533,6 +533,15 @@
out.indent();
+ out << "boolean _hidl_is_oneway = (_hidl_flags & " << Interface::FLAG_ONEWAY
+ << " /* oneway */) != 0\n;";
+ out << "if (_hidl_is_oneway != " << (method->isOneway() ? "true" : "false") << ") ";
+ out.block([&] {
+ out << "_hidl_reply.writeStatus(" << UNKNOWN_ERROR << ");\n";
+ out << "_hidl_reply.send();\n";
+ out << "break;\n";
+ });
+
if (method->isHidlReserved() && method->overridesJavaImpl(IMPL_STUB)) {
method->javaImpl(IMPL_STUB, out);
out.unindent();
diff --git a/main.cpp b/main.cpp
index 3364bf4..384d391 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1374,9 +1374,6 @@
exit(1);
}
- // TODO(b/65200821): remove
- gCurrentCompileName = "_" + StringHelper::Uppercase(fqName.tokenName());
-
// Dump extra verbose output
if (coordinator.isVerbose()) {
status_t err =
diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh
new file mode 100755
index 0000000..bb6f7d7
--- /dev/null
+++ b/scripts/run-tests.sh
@@ -0,0 +1,114 @@
+#!/bin/bash
+
+# See hal_hidl_gtest.py
+
+THREADS=
+CHECKER=vts_testability_checker
+CHECKER_DEVICE_PATH="/data/local/tmp/${CHECKER}"
+PRINT_COMMANDS=
+
+function run() {
+ if [ "${PRINT_COMMANDS}" = true ] ; then
+ >&2 echo "*** $@"
+ fi
+ $@
+}
+
+function make_modules() {
+ if [ "${THREADS}" != "0" ] ; then
+ run make -j${THREADS} -C ${ANDROID_BUILD_TOP} -f build/core/main.mk $@
+ fi
+}
+
+function push_checker() {
+ run adb push ${OUT}/system/bin/${CHECKER} ${CHECKER_DEVICE_PATH}
+}
+
+function push_test() {
+ local module=$1
+ for test_dir in nativetest nativetest64 ; do
+ local test_file=/data/${test_dir}/${module}/${module}
+ run adb push ${OUT}${test_file} ${test_file}
+ done
+}
+
+function read_checker_output() {
+ python -c 'import json,sys;obj=json.load(sys.stdin);sys.stdout.write("%s\n"%obj["Testable"]);map(lambda i:sys.stdout.write("%s\n"%i),obj["instances"])'
+}
+
+function run_test() {
+ local module=$1
+ local status=0
+
+ for test_dir in nativetest nativetest64 ; do
+ local test_file=/data/${test_dir}/${module}/${module}
+ local interfaces=$(run adb shell ${test_file} --list_registered_services \
+ | sed -n 's/^hal_service: \(.*\)$/\1/p')
+ if [ -z "$interfaces" ]; then
+ run adb shell ${test_file} || status=$?
+ else
+ for interface in ${interfaces} ; do
+ local output=$(run adb shell ${CHECKER_DEVICE_PATH} -c ${interface} | read_checker_output)
+ local testable=$(echo "${output}" | head -n1)
+ local instances=$(echo "${output}" | tail -n+2)
+
+ if [ "${testable}" == "True" ] ; then
+ for instance in ${instances} ; do
+ run adb shell ${test_file} --hal_service_instance="${interface}/${instance}" || status=$?
+ done
+ fi
+ done
+ fi
+ done
+ return ${status}
+}
+
+function usage() {
+ echo "usage: $0 -m <module_name> [-m <module_name>[...]] [-j <jobs>] [-p]"
+ echo " -m <module_name>: name of test (e.g. VtsHalHealthV2_0TargetTest)"
+ echo " -p: print commands"
+ echo " -j <jobs>: # jobs in make. "
+ echo " -j0 skips making any modules."
+ echo " If not present, use infinite number of jobs."
+
+ exit 1
+}
+
+function main() {
+ local modules=
+
+ while getopts "m:j:p" option ; do
+ case "${option}" in
+ m)
+ [ ! -z ${OPTARG} ] || usage
+ modules="${modules} ${OPTARG}"
+ ;;
+ j)
+ THREADS=${OPTARG}
+ ;;
+ p)
+ PRINT_COMMANDS=true
+ ;;
+ *)
+ usage
+ ;;
+ esac
+ done
+
+ set -e
+ make_modules ${CHECKER} ${modules}
+ run adb root
+ push_checker
+ for module in ${modules} ; do
+ push_test ${module}
+ done
+
+ set +e
+ local status=0
+ for module in ${modules} ; do
+ run_test ${module} || status=$?
+ done
+ return ${status}
+}
+
+main $@