diff options
author | Zhuoyao Zhang <zhuoyao@google.com> | 2016-10-06 15:05:39 -0700 |
---|---|---|
committer | Zhuoyao Zhang <zhuoyao@google.com> | 2016-10-06 17:39:01 -0700 |
commit | c5ea9f589cc7cce0b5e97bd4ac6a8561eb313a02 (patch) | |
tree | 1cfa5088716ed2fc1d183f7083bbdeed26ec63b1 | |
parent | 8efccec25e4010829fff42d5d953dfb83549d807 (diff) | |
download | hidl-c5ea9f589cc7cce0b5e97bd4ac6a8561eb313a02.tar.gz |
Update hidl-gen support for vts.
* Support the new Enum type (based on scalar_data)
* Support sub_struct/sub_union defined within compound type.
* Code cleanup: use getVtsType() instead of hard code ones.
Test: make hidl-gen, locally run make hidl_gen_test.
Bug: 30762234
Change-Id: I9a21b5757e0a9fc6cd1bf829ab123565a7990ad5
-rw-r--r-- | ArrayType.cpp | 11 | ||||
-rw-r--r-- | ArrayType.h | 2 | ||||
-rw-r--r-- | CompoundType.cpp | 51 | ||||
-rw-r--r-- | CompoundType.h | 2 | ||||
-rw-r--r-- | EnumType.cpp | 29 | ||||
-rw-r--r-- | EnumType.h | 2 | ||||
-rw-r--r-- | Interface.cpp | 4 | ||||
-rw-r--r-- | ScalarType.cpp | 38 | ||||
-rw-r--r-- | ScalarType.h | 3 | ||||
-rw-r--r-- | StringType.cpp | 4 | ||||
-rw-r--r-- | StringType.h | 2 | ||||
-rw-r--r-- | Type.cpp | 5 | ||||
-rw-r--r-- | Type.h | 2 | ||||
-rw-r--r-- | VectorType.cpp | 7 | ||||
-rw-r--r-- | VectorType.h | 2 | ||||
-rw-r--r-- | test/data/android/hardware/nfc/1.0/Nfc.vts | 116 | ||||
-rw-r--r-- | test/data/android/hardware/nfc/1.0/NfcClientCallback.vts | 32 | ||||
-rw-r--r-- | test/data/android/hardware/nfc/1.0/types.vts | 110 |
18 files changed, 246 insertions, 176 deletions
diff --git a/ArrayType.cpp b/ArrayType.cpp index 82948060..ec91531e 100644 --- a/ArrayType.cpp +++ b/ArrayType.cpp @@ -120,6 +120,10 @@ std::string ArrayType::getJavaWrapperType() const { return mElementType->getJavaWrapperType(); } +std::string ArrayType::getVtsType() const { + return "TYPE_ARRAY"; +} + void ArrayType::emitReaderWriter( Formatter &out, const std::string &name, @@ -478,13 +482,14 @@ void ArrayType::emitJavaFieldReaderWriter( status_t ArrayType::emitVtsTypeDeclarations(Formatter &out) const { if (mSizes.size() > 1) { - // Multi-dimensional arrays are yet to be supported in VTS. + CHECK(!"Multi-dimensional arrays are yet to be supported in VTS."); return UNKNOWN_ERROR; } - out << "type: TYPE_ARRAY\n" << "vector_value: {\n"; + out << "type: " << getVtsType() << "\n"; + out << "vector_value: {\n"; out.indent(); - out << "size: " << mSizes[0] << "\n"; + out << "vector_size: " << mSizes[0] << "\n"; status_t err = mElementType->emitVtsTypeDeclarations(out); if (err != OK) { return err; diff --git a/ArrayType.h b/ArrayType.h index 878dc51b..e8f143a1 100644 --- a/ArrayType.h +++ b/ArrayType.h @@ -52,6 +52,8 @@ struct ArrayType : public Type { std::string getJavaWrapperType() const override; + std::string getVtsType() const override; + void emitReaderWriter( Formatter &out, const std::string &name, diff --git a/CompoundType.cpp b/CompoundType.cpp index 400cc194..7c8e04ac 100644 --- a/CompoundType.cpp +++ b/CompoundType.cpp @@ -88,6 +88,19 @@ std::string CompoundType::getJavaType( return fullJavaName(); } +std::string CompoundType::getVtsType() const { + switch (mStyle) { + case STYLE_STRUCT: + { + return "TYPE_STRUCT"; + } + case STYLE_UNION: + { + return "TYPE_UNION"; + } + } +} + void CompoundType::emitReaderWriter( Formatter &out, const std::string &name, @@ -763,36 +776,21 @@ bool CompoundType::resultNeedsDeref() const { status_t CompoundType::emitVtsTypeDeclarations(Formatter &out) const { out << "name: \"" << localName() << "\"\n"; - switch (mStyle) { - case STYLE_STRUCT: - { - out << "type: TYPE_STRUCT\n"; - break; - } - case STYLE_UNION: - { - out << "type: TYPE_UNION\n"; - break; - } - default: - break; - } + out << "type: " << getVtsType() << "\n"; // Emit declaration for each subtype. for (const auto &type : getSubTypes()) { switch (mStyle) { case STYLE_STRUCT: { - out << "struct_value: {\n"; + out << "sub_struct: {\n"; break; } case STYLE_UNION: { - out << "union_value: {\n"; + out << "sub_union: {\n"; break; } - default: - break; } out.indent(); status_t status(type->emitVtsTypeDeclarations(out)); @@ -816,8 +814,6 @@ status_t CompoundType::emitVtsTypeDeclarations(Formatter &out) const { out << "union_value: {\n"; break; } - default: - break; } out.indent(); out << "name: \"" << field->name() << "\"\n"; @@ -833,20 +829,7 @@ status_t CompoundType::emitVtsTypeDeclarations(Formatter &out) const { } status_t CompoundType::emitVtsAttributeType(Formatter &out) const { - switch (mStyle) { - case STYLE_STRUCT: - { - out << "type: TYPE_STRUCT\n"; - break; - } - case STYLE_UNION: - { - out << "type: TYPE_UNION\n"; - break; - } - default: - break; - } + out << "type: " << getVtsType() << "\n"; out << "predefined_type: \"" << localName() << "\"\n"; return OK; } diff --git a/CompoundType.h b/CompoundType.h index 5cd6efa1..3bc3d13c 100644 --- a/CompoundType.h +++ b/CompoundType.h @@ -45,6 +45,8 @@ struct CompoundType : public Scope { std::string getJavaType( std::string *extra, bool forInitializer) const override; + std::string getVtsType() const override; + void emitReaderWriter( Formatter &out, const std::string &name, diff --git a/EnumType.cpp b/EnumType.cpp index 5a8706ba..d5abf6dd 100644 --- a/EnumType.cpp +++ b/EnumType.cpp @@ -92,6 +92,10 @@ std::string EnumType::getJavaWrapperType() const { return mStorageType->resolveToScalarType()->getJavaWrapperType(); } +std::string EnumType::getVtsType() const { + return "TYPE_ENUM"; +} + LocalIdentifier *EnumType::lookupIdentifier(const std::string &name) const { std::vector<const EnumType *> chain; getTypeChain(&chain); @@ -232,11 +236,14 @@ status_t EnumType::emitJavaTypeDeclarations(Formatter &out, bool) const { } status_t EnumType::emitVtsTypeDeclarations(Formatter &out) const { - out << "name: \"" << localName() << "\"\n" - << "type: TYPE_ENUM\n" - << "enum_value: {\n"; + out << "name: \"" << localName() << "\"\n"; + out << "type: " << getVtsType() << "\n"; + out << "enum_value: {\n"; out.indent(); + out << "scalar_type: \"" + << mStorageType->resolveToScalarType()->getVtsScalarType() + << "\"\n\n"; std::vector<const EnumType *> chain; getTypeChain(&chain); @@ -245,13 +252,19 @@ status_t EnumType::emitVtsTypeDeclarations(Formatter &out) const { for (const auto &entry : type->values()) { out << "enumerator: \"" << entry->name() << "\"\n"; - + out << "scalar_value: {\n"; + out.indent(); if (!entry->isAutoFill()) { // don't autofill values for vts. std::string value = entry->value(); CHECK(!value.empty()); - out << "value: " << value << "\n"; + out << mStorageType->resolveToScalarType()->getVtsScalarType() + << ": " + << value + << "\n"; } + out.unindent(); + out << "}\n"; } } @@ -261,10 +274,8 @@ status_t EnumType::emitVtsTypeDeclarations(Formatter &out) const { } status_t EnumType::emitVtsAttributeType(Formatter &out) const { - out << "type: TYPE_ENUM\n" - << "predefined_type: \"" - << localName() - << "\"\n"; + out << "type: " << getVtsType() << "\n"; + out << "predefined_type: \"" << localName() << "\"\n"; return OK; } @@ -52,6 +52,8 @@ struct EnumType : public Scope { std::string getJavaWrapperType() const override; + std::string getVtsType() const override; + void emitReaderWriter( Formatter &out, const std::string &name, diff --git a/Interface.cpp b/Interface.cpp index ba5ea8c6..cd9dcd3c 100644 --- a/Interface.cpp +++ b/Interface.cpp @@ -172,6 +172,10 @@ void Interface::emitJavaReaderWriter( status_t Interface::emitVtsAttributeDeclaration(Formatter &out) const { for (const auto &type : getSubTypes()) { + // Skip for TypeDef as it is just an alias of a defined type. + if (type->isTypeDef()) { + continue; + } out << "attribute: {\n"; out.indent(); status_t status = type->emitVtsTypeDeclarations(out); diff --git a/ScalarType.cpp b/ScalarType.cpp index 9065e139..b89001f9 100644 --- a/ScalarType.cpp +++ b/ScalarType.cpp @@ -113,6 +113,28 @@ std::string ScalarType::getJavaSuffix() const { return kSuffix[mKind]; } +std::string ScalarType::getVtsType() const { + return "TYPE_SCALAR"; +} + +std::string ScalarType::getVtsScalarType() const { + static const char * const kName[] = { + "bool_t", + "int8_t", + "uint8_t", + "int16_t", + "uint16_t", + "int32_t", + "uint32_t", + "int64_t", + "uint64_t", + "float_t", + "double_t" + }; + + return kName[mKind]; +} + void ScalarType::emitReaderWriter( Formatter &out, const std::string &name, @@ -211,20 +233,8 @@ void ScalarType::emitJavaFieldReaderWriter( } status_t ScalarType::emitVtsTypeDeclarations(Formatter &out) const { - static const char *const kName[] = { - "bool_t", - "int8_t", - "uint8_t", - "int16_t", - "uint16_t", - "int32_t", - "uint32_t", - "int64_t", - "uint64_t", - "float_t", - "double_t" - }; - out << "type: TYPE_SCALAR\n"<< "scalar_type: \""<< kName[mKind]<< "\"\n"; + out << "type: " << getVtsType() << "\n"; + out << "scalar_type: \"" << getVtsScalarType() << "\"\n"; return OK; } diff --git a/ScalarType.h b/ScalarType.h index 3dcdae77..135f6fb2 100644 --- a/ScalarType.h +++ b/ScalarType.h @@ -56,6 +56,9 @@ struct ScalarType : public Type { std::string getJavaWrapperType() const override; std::string getJavaSuffix() const override; + std::string getVtsType() const override; + std::string getVtsScalarType() const; + void emitReaderWriter( Formatter &out, const std::string &name, diff --git a/StringType.cpp b/StringType.cpp index 35caa8b1..62fed1c2 100644 --- a/StringType.cpp +++ b/StringType.cpp @@ -57,6 +57,10 @@ std::string StringType::getJavaSuffix() const { return "String"; } +std::string StringType::getVtsType() const { + return "TYPE_STRING"; +} + void StringType::emitReaderWriter( Formatter &out, const std::string &name, diff --git a/StringType.h b/StringType.h index 2fb585f7..73225544 100644 --- a/StringType.h +++ b/StringType.h @@ -37,6 +37,8 @@ struct StringType : public Type { std::string getJavaSuffix() const override; + std::string getVtsType() const override; + void emitReaderWriter( Formatter &out, const std::string &name, @@ -110,6 +110,11 @@ std::string Type::getJavaSuffix() const { return std::string(); } +std::string Type::getVtsType() const { + CHECK(!"Should not be here"); + return std::string(); +} + void Type::emitReaderWriter( Formatter &, const std::string &, @@ -92,6 +92,8 @@ struct Type { virtual std::string getJavaWrapperType() const; virtual std::string getJavaSuffix() const; + virtual std::string getVtsType() const; + enum ErrorMode { ErrorMode_Ignore, ErrorMode_Goto, diff --git a/VectorType.cpp b/VectorType.cpp index 2e7d9322..f656281d 100644 --- a/VectorType.cpp +++ b/VectorType.cpp @@ -65,6 +65,10 @@ std::string VectorType::getJavaType( return mElementType->getJavaType(&elementExtra) + elementExtra; } +std::string VectorType::getVtsType() const { + return "TYPE_VECTOR"; +} + void VectorType::emitReaderWriter( Formatter &out, const std::string &name, @@ -540,7 +544,8 @@ bool VectorType::resultNeedsDeref() const { } status_t VectorType::emitVtsTypeDeclarations(Formatter &out) const { - out << "type: TYPE_VECTOR\n" << "vector_value: {\n"; + out << "type: " << getVtsType() << "\n"; + out << "vector_value: {\n"; out.indent(); status_t err = mElementType->emitVtsTypeDeclarations(out); if (err != OK) { diff --git a/VectorType.h b/VectorType.h index 0e0a07c4..e093777e 100644 --- a/VectorType.h +++ b/VectorType.h @@ -35,6 +35,8 @@ struct VectorType : public TemplatedType { std::string getJavaType( std::string *extra, bool forInitializer) const override; + std::string getVtsType() const override; + void emitReaderWriter( Formatter &out, const std::string &name, diff --git a/test/data/android/hardware/nfc/1.0/Nfc.vts b/test/data/android/hardware/nfc/1.0/Nfc.vts index 4dd78f63..03a5464e 100644 --- a/test/data/android/hardware/nfc/1.0/Nfc.vts +++ b/test/data/android/hardware/nfc/1.0/Nfc.vts @@ -8,76 +8,76 @@ import: "android.hardware.nfc@1.0::INfcClientCallback" import: "android.hardware.nfc@1.0::types" interface: { - api: { - name: "open" - return_type_hidl: { - type: TYPE_SCALAR - scalar_type: "int32_t" + api: { + name: "open" + return_type_hidl: { + type: TYPE_SCALAR + scalar_type: "int32_t" + } + arg: { + type: TYPE_HIDL_CALLBACK + predefined_type: "INfcClientCallback" + is_callback: true + } } - arg: { - type: TYPE_HIDL_CALLBACK - predefined_type: "INfcClientCallback" - is_callback: true - } - } - api: { - name: "write" - return_type_hidl: { - type: TYPE_SCALAR - scalar_type: "int32_t" - } - arg: { - type: TYPE_STRUCT - predefined_type: "nfc_data_t" + api: { + name: "write" + return_type_hidl: { + type: TYPE_SCALAR + scalar_type: "int32_t" + } + arg: { + type: TYPE_STRUCT + predefined_type: "nfc_data_t" + } } - } - api: { - name: "core_initialized" - return_type_hidl: { - type: TYPE_SCALAR - scalar_type: "int32_t" - } - arg: { - type: TYPE_VECTOR - vector_value: { - type: TYPE_SCALAR - scalar_type: "uint8_t" - } + api: { + name: "core_initialized" + return_type_hidl: { + type: TYPE_SCALAR + scalar_type: "int32_t" + } + arg: { + type: TYPE_VECTOR + vector_value: { + type: TYPE_SCALAR + scalar_type: "uint8_t" + } + } } - } - api: { - name: "pre_discover" - return_type_hidl: { - type: TYPE_SCALAR - scalar_type: "int32_t" + api: { + name: "pre_discover" + return_type_hidl: { + type: TYPE_SCALAR + scalar_type: "int32_t" + } } - } - api: { - name: "close" - return_type_hidl: { - type: TYPE_SCALAR - scalar_type: "int32_t" + api: { + name: "close" + return_type_hidl: { + type: TYPE_SCALAR + scalar_type: "int32_t" + } } - } - api: { - name: "control_granted" - return_type_hidl: { - type: TYPE_SCALAR - scalar_type: "int32_t" + api: { + name: "control_granted" + return_type_hidl: { + type: TYPE_SCALAR + scalar_type: "int32_t" + } } - } - api: { - name: "power_cycle" - return_type_hidl: { - type: TYPE_SCALAR - scalar_type: "int32_t" + api: { + name: "power_cycle" + return_type_hidl: { + type: TYPE_SCALAR + scalar_type: "int32_t" + } } - } } diff --git a/test/data/android/hardware/nfc/1.0/NfcClientCallback.vts b/test/data/android/hardware/nfc/1.0/NfcClientCallback.vts index 39d1ef85..d69f26de 100644 --- a/test/data/android/hardware/nfc/1.0/NfcClientCallback.vts +++ b/test/data/android/hardware/nfc/1.0/NfcClientCallback.vts @@ -7,24 +7,24 @@ package: "android.hardware.nfc" import: "android.hardware.nfc@1.0::types" interface: { - api: { - name: "sendEvent" - arg: { - type: TYPE_ENUM - predefined_type: "nfc_event_t" + api: { + name: "sendEvent" + arg: { + type: TYPE_ENUM + predefined_type: "nfc_event_t" + } + arg: { + type: TYPE_ENUM + predefined_type: "nfc_status_t" + } } - arg: { - type: TYPE_ENUM - predefined_type: "nfc_status_t" - } - } - api: { - name: "sendData" - arg: { - type: TYPE_STRUCT - predefined_type: "nfc_data_t" + api: { + name: "sendData" + arg: { + type: TYPE_STRUCT + predefined_type: "nfc_data_t" + } } - } } diff --git a/test/data/android/hardware/nfc/1.0/types.vts b/test/data/android/hardware/nfc/1.0/types.vts index b8cbb597..3ea29af4 100644 --- a/test/data/android/hardware/nfc/1.0/types.vts +++ b/test/data/android/hardware/nfc/1.0/types.vts @@ -6,53 +6,81 @@ package: "android.hardware.nfc" attribute: { - name: "nfc_event_t" - type: TYPE_ENUM - enum_value: { - enumerator: "HAL_NFC_OPEN_CPLT_EVT" - value: 0 - enumerator: "HAL_NFC_CLOSE_CPLT_EVT" - value: 1 - enumerator: "HAL_NFC_POST_INIT_CPLT_EVT" - value: 2 - enumerator: "HAL_NFC_PRE_DISCOVER_CPLT_EVT" - value: 3 - enumerator: "HAL_NFC_REQUEST_CONTROL_EVT" - value: 4 - enumerator: "HAL_NFC_RELEASE_CONTROL_EVT" - value: 5 - enumerator: "HAL_NFC_ERROR_EVT" - value: 6 - } + name: "nfc_event_t" + type: TYPE_ENUM + enum_value: { + scalar_type: "uint32_t" + + enumerator: "HAL_NFC_OPEN_CPLT_EVT" + scalar_value: { + uint32_t: 0 + } + enumerator: "HAL_NFC_CLOSE_CPLT_EVT" + scalar_value: { + uint32_t: 1 + } + enumerator: "HAL_NFC_POST_INIT_CPLT_EVT" + scalar_value: { + uint32_t: 2 + } + enumerator: "HAL_NFC_PRE_DISCOVER_CPLT_EVT" + scalar_value: { + uint32_t: 3 + } + enumerator: "HAL_NFC_REQUEST_CONTROL_EVT" + scalar_value: { + uint32_t: 4 + } + enumerator: "HAL_NFC_RELEASE_CONTROL_EVT" + scalar_value: { + uint32_t: 5 + } + enumerator: "HAL_NFC_ERROR_EVT" + scalar_value: { + uint32_t: 6 + } + } } attribute: { - name: "nfc_status_t" - type: TYPE_ENUM - enum_value: { - enumerator: "HAL_NFC_STATUS_OK" - value: 0 - enumerator: "HAL_NFC_STATUS_FAILED" - value: 1 - enumerator: "HAL_NFC_STATUS_ERR_TRANSPORT" - value: 2 - enumerator: "HAL_NFC_STATUS_ERR_CMD_TIMEOUT" - value: 3 - enumerator: "HAL_NFC_STATUS_REFUSED" - value: 4 - } + name: "nfc_status_t" + type: TYPE_ENUM + enum_value: { + scalar_type: "uint32_t" + + enumerator: "HAL_NFC_STATUS_OK" + scalar_value: { + uint32_t: 0 + } + enumerator: "HAL_NFC_STATUS_FAILED" + scalar_value: { + uint32_t: 1 + } + enumerator: "HAL_NFC_STATUS_ERR_TRANSPORT" + scalar_value: { + uint32_t: 2 + } + enumerator: "HAL_NFC_STATUS_ERR_CMD_TIMEOUT" + scalar_value: { + uint32_t: 3 + } + enumerator: "HAL_NFC_STATUS_REFUSED" + scalar_value: { + uint32_t: 4 + } + } } attribute: { - name: "nfc_data_t" - type: TYPE_STRUCT - struct_value: { - name: "data" - type: TYPE_VECTOR - vector_value: { - type: TYPE_SCALAR - scalar_type: "uint8_t" + name: "nfc_data_t" + type: TYPE_STRUCT + struct_value: { + name: "data" + type: TYPE_VECTOR + vector_value: { + type: TYPE_SCALAR + scalar_type: "uint8_t" + } } - } } |