From 1856fee8f5af390769467e462c305d8d30e43d35 Mon Sep 17 00:00:00 2001 From: gonghui Date: Mon, 17 May 2021 16:07:59 +0800 Subject: [PATCH 1/2] sync L2 code to L1 --- ability/config/device_resource_if.c | 2 +- .../config/hcs_parser/include/hcs_blob_if.h | 4 +- .../hcs_parser/include/hcs_generate_tree.h | 6 +- .../config/hcs_parser/include/hcs_parser.h | 2 +- .../config/hcs_parser/include/hcs_tree_if.h | 2 +- ability/config/hcs_parser/src/hcs_blob_if.c | 6 +- .../config/hcs_parser/src/hcs_generate_tree.c | 10 +- ability/config/hcs_parser/src/hcs_parser.c | 6 +- ability/config/hcs_parser/src/hcs_tree_if.c | 30 +-- .../test/unittest/common/hdf_config_test.cpp | 176 +++++++++--------- 10 files changed, 120 insertions(+), 124 deletions(-) diff --git a/ability/config/device_resource_if.c b/ability/config/device_resource_if.c index 6bea6afd4..5f75a4092 100644 --- a/ability/config/device_resource_if.c +++ b/ability/config/device_resource_if.c @@ -41,7 +41,7 @@ static bool DeviceResourceIfaceConstruct(struct DeviceResourceIface *instance, D HcsIfaceConstruct(instance); break; default: - HDF_LOGE("%s: Currently, this configuration type is not supported. the type is %d", __func__, type); + HDF_LOGE("%s: Currently, this configuration type is not supported, the type is %d", __func__, type); return false; } return true; diff --git a/ability/config/hcs_parser/include/hcs_blob_if.h b/ability/config/hcs_parser/include/hcs_blob_if.h index b50c8f351..b2a73121c 100644 --- a/ability/config/hcs_parser/include/hcs_blob_if.h +++ b/ability/config/hcs_parser/include/hcs_blob_if.h @@ -71,7 +71,7 @@ static inline uint32_t HcsGetPrefix(const char *start) #define HCS_PREFIX_LENGTH (HcsIsByteAlign() ? HCS_DWORD_LENGTH : 1) #define HCS_BYTE_LENGTH (HcsIsByteAlign() ? HCS_DWORD_LENGTH : 1) #define HCS_WORD_LENGTH (HcsIsByteAlign() ? HCS_DWORD_LENGTH : 2) -#define HCS_STRING_LENGTH(str) (HcsIsByteAlign() ? HcsAlignSize(strlen(str) + 1) : (strlen(str) + 1)) // add the '\0'. +#define HCS_STRING_LENGTH(str) (HcsIsByteAlign() ? HcsAlignSize(strlen(str) + 1) : (strlen(str) + 1)) int32_t HcsGetDataTypeOffset(const char *start); int32_t HcsGetAttrLength(const char *start); int32_t HcsGetNodeOrAttrLength(const char *start); @@ -82,4 +82,4 @@ bool HcsSwapToUint16(uint16_t *value, const char *realValue, uint32_t type); bool HcsSwapToUint32(uint32_t *value, const char *realValue, uint32_t type); bool HcsSwapToUint64(uint64_t *value, const char *realValue, uint32_t type); -#endif // HCS_BLOB_IF_H \ No newline at end of file +#endif /* HCS_BLOB_IF_H */ \ No newline at end of file diff --git a/ability/config/hcs_parser/include/hcs_generate_tree.h b/ability/config/hcs_parser/include/hcs_generate_tree.h index 2aa2c63e9..d56bbcd7f 100644 --- a/ability/config/hcs_parser/include/hcs_generate_tree.h +++ b/ability/config/hcs_parser/include/hcs_generate_tree.h @@ -13,9 +13,9 @@ #define TREE_STACK_MAX 64 struct TreeStack { - uint32_t offset; // the offset of node in blob - struct DeviceResourceNode *node; // the node is the head node of every layer tree + uint32_t offset; // The offset of the node in the blob. + struct DeviceResourceNode *node; // The head node of a layer tree. }; int32_t GenerateCfgTree(const char *treeStart, int32_t length, char *treeMem, struct DeviceResourceNode **root); -#endif // HCS_GENERATE_TREE_H \ No newline at end of file +#endif /* HCS_GENERATE_TREE_H */ \ No newline at end of file diff --git a/ability/config/hcs_parser/include/hcs_parser.h b/ability/config/hcs_parser/include/hcs_parser.h index 216eecc38..a20e26ba4 100644 --- a/ability/config/hcs_parser/include/hcs_parser.h +++ b/ability/config/hcs_parser/include/hcs_parser.h @@ -13,4 +13,4 @@ bool HcsDecompile(const char *hcsBlob, uint32_t offset, struct DeviceResourceNode **root); -#endif // HCS_PARSER_H \ No newline at end of file +#endif /* HCS_PARSER_H */ \ No newline at end of file diff --git a/ability/config/hcs_parser/include/hcs_tree_if.h b/ability/config/hcs_parser/include/hcs_tree_if.h index b02bc332c..09875dec0 100644 --- a/ability/config/hcs_parser/include/hcs_tree_if.h +++ b/ability/config/hcs_parser/include/hcs_tree_if.h @@ -56,4 +56,4 @@ const struct DeviceResourceNode *HcsGetNodeByRefAttr(const struct DeviceResource #endif #endif /* __cplusplus */ -#endif // HCS_TREE_IF_H \ No newline at end of file +#endif /* HCS_TREE_IF_H */ \ No newline at end of file diff --git a/ability/config/hcs_parser/src/hcs_blob_if.c b/ability/config/hcs_parser/src/hcs_blob_if.c index 1f007c6f1..dfb023d8f 100644 --- a/ability/config/hcs_parser/src/hcs_blob_if.c +++ b/ability/config/hcs_parser/src/hcs_blob_if.c @@ -13,7 +13,7 @@ static bool g_byteAlign = false; -bool HcsIsByteAlign() +bool HcsIsByteAlign(void) { return g_byteAlign; } @@ -185,7 +185,7 @@ static bool CheckHcsBlobLength(uint32_t length, struct HbcHeader *header) HDF_LOGI("%s: the blobLength: %u, byteAlign: %d", __func__, blobLength, g_byteAlign); } if ((length != blobLength) || (blobLength < minLength)) { - HDF_LOGE("%s failed, Hcsblob file length is %u, But the length of calculation is %u", + HDF_LOGE("%s failed, Hcsblob file length is %u, but the calculated length is %u", __func__, length, blobLength); return false; } @@ -201,7 +201,7 @@ bool HcsCheckBlobFormat(const char *start, uint32_t length) } header = (struct HbcHeader *)start; if (header->magicNumber != HBC_MAGIC_NUMBER) { - HDF_LOGE("%s failed, the magic of HBC is %x", __func__, header->magicNumber); + HDF_LOGE("%s failed, the magic number of HBC is %x", __func__, header->magicNumber); return false; } if (!CheckHcsBlobLength(length, header)) { diff --git a/ability/config/hcs_parser/src/hcs_generate_tree.c b/ability/config/hcs_parser/src/hcs_generate_tree.c index cd638683a..c3306ed64 100644 --- a/ability/config/hcs_parser/src/hcs_generate_tree.c +++ b/ability/config/hcs_parser/src/hcs_generate_tree.c @@ -53,7 +53,7 @@ static bool UpdateTreeStack(struct TreeStack **treeStack, int32_t *treeLayer, st uint32_t offset) { if (*treeLayer >= (TREE_STACK_MAX - 1)) { - HDF_LOGE("%s failed, the treeLayer error. treeLayer: %d", __func__, *treeLayer); + HDF_LOGE("%s failed, the treeLayer error, treeLayer: %d", __func__, *treeLayer); return false; } (*treeLayer)++; @@ -83,7 +83,7 @@ static int32_t ParseByteCode(const char *treeStart, int32_t offset, char **treeM { int32_t termOffset = HcsGetNodeOrAttrLength(treeStart + offset); if (termOffset <= 0) { - HDF_LOGE("%s failed, HcsGetNodeOrAttrLength failed, errno: %d", __func__, termOffset); + HDF_LOGE("%s failed, HcsGetNodeOrAttrLength error, errno: %d", __func__, termOffset); return HDF_FAILURE; } @@ -111,7 +111,7 @@ static int32_t ParseByteCode(const char *treeStart, int32_t offset, char **treeM } parentOrCurNode = GetParentNode(offset, *treeStack, treeLayerOrMemLen, termOffset); if (!AddAttrInNode(treeStart + offset, parentOrCurNode, treeMem)) { - HDF_LOGE("%s failed, the AddAttrInNode error", __func__); + HDF_LOGE("%s failed, AddAttrInNode error", __func__); return HDF_FAILURE; } break; @@ -136,14 +136,14 @@ int32_t GenerateCfgTree(const char *treeStart, int32_t length, char *treeMem, st while ((offset < length) && (offset >= 0)) { int32_t eachOffset = ParseByteCode(treeStart, offset, &treeMem, &treeStack, &treeLayerOrMemLen); if (eachOffset <= 0) { - HDF_LOGE("%s failed, the ParseByteCode error", __func__); + HDF_LOGE("%s failed, ParseByteCode error", __func__); treeLayerOrMemLen = eachOffset; break; } offset += eachOffset; } if ((treeMem != NULL) && (root != NULL) && (treeLayerOrMemLen > 0)) { - // the treeStack[1] is root + // The treeStack[1] is root *root = treeStack[1].node; } OsalMemFree(treeStack); diff --git a/ability/config/hcs_parser/src/hcs_parser.c b/ability/config/hcs_parser/src/hcs_parser.c index 50ef76435..29596bd54 100644 --- a/ability/config/hcs_parser/src/hcs_parser.c +++ b/ability/config/hcs_parser/src/hcs_parser.c @@ -23,19 +23,19 @@ bool HcsDecompile(const char *hcsBlob, uint32_t offset, struct DeviceResourceNod { int32_t nodeLength = HcsGetNodeLength(hcsBlob + offset); if (nodeLength < 0) { - HDF_LOGE("%s failed, HcsGetNodeLength failed", __func__); + HDF_LOGE("%s failed, HcsGetNodeLength error", __func__); return false; } int32_t treeMemLength = GetHcsTreeSize(hcsBlob + offset, nodeLength); if (treeMemLength <= 0) { - HDF_LOGE("%s failed, GetHcsTreeSize failed", __func__); + HDF_LOGE("%s failed, GetHcsTreeSize error, treeMemLength = %d", __func__, treeMemLength); return false; } char *treeMem = (char *)OsalMemCalloc(treeMemLength); if (treeMem == NULL) { - HDF_LOGE("%s failed, OsalMemCalloc Device tree memory failed", __func__); + HDF_LOGE("%s failed, OsalMemCalloc error", __func__); return false; } int32_t treeLayer = GenerateCfgTree(hcsBlob + offset, nodeLength, treeMem, root); diff --git a/ability/config/hcs_parser/src/hcs_tree_if.c b/ability/config/hcs_parser/src/hcs_tree_if.c index d4aba7c68..2b760a492 100644 --- a/ability/config/hcs_parser/src/hcs_tree_if.c +++ b/ability/config/hcs_parser/src/hcs_tree_if.c @@ -36,7 +36,7 @@ bool HcsGetBool(const struct DeviceResourceNode *node, const char *attrName) } if (!HcsSwapToUint8(&value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) { - HDF_LOGE("%s failed, Incorrect prefix code", __func__); + HDF_LOGE("%s failed, incorrect prefix", __func__); return false; } return value ? true : false; @@ -44,7 +44,7 @@ bool HcsGetBool(const struct DeviceResourceNode *node, const char *attrName) #define RETURN_DEFAULT_VALUE(attr, attrName, value, def) do { \ if (((attr) == NULL) || ((attr)->value == NULL) || ((value) == NULL)) { \ - HDF_LOGE("%s failed, the attr of %s is NULL, or the value is NULL, return the default value", \ + HDF_LOGE("%s failed, the attr of %s is NULL, or the value is NULL, the value is default value", \ __func__, ((attrName) == NULL) ? "error attrName" : (attrName)); \ if ((value) != NULL) { \ *(value) = (def); \ @@ -60,7 +60,7 @@ int32_t HcsGetUint8(const struct DeviceResourceNode *node, const char *attrName, if (!HcsSwapToUint8(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) { *value = def; - HDF_LOGE("%s failed, Incorrect prefix code", __func__); + HDF_LOGE("%s failed, incorrect prefix", __func__); return HDF_FAILURE; } return HDF_SUCCESS; @@ -73,7 +73,7 @@ int32_t HcsGetUint16(const struct DeviceResourceNode *node, const char *attrName if (!HcsSwapToUint16(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) { *value = def; - HDF_LOGE("%s failed, Incorrect prefix code", __func__); + HDF_LOGE("%s failed, incorrect prefix", __func__); return HDF_FAILURE; } return HDF_SUCCESS; @@ -86,7 +86,7 @@ int32_t HcsGetUint32(const struct DeviceResourceNode *node, const char *attrName if (!HcsSwapToUint32(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) { *value = def; - HDF_LOGE("%s failed, Incorrect prefix code", __func__); + HDF_LOGE("%s failed, incorrect prefix", __func__); return HDF_FAILURE; } return HDF_SUCCESS; @@ -99,7 +99,7 @@ int32_t HcsGetUint64(const struct DeviceResourceNode *node, const char *attrName if (!HcsSwapToUint64(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) { *value = def; - HDF_LOGE("%s failed, Incorrect prefix code", __func__); + HDF_LOGE("%s failed, incorrect prefix", __func__); return HDF_FAILURE; } return HDF_SUCCESS; @@ -116,7 +116,7 @@ static const char *GetArrayElem(const struct DeviceResourceAttr *attr, uint32_t return NULL; } if (index >= count) { - HDF_LOGE("%s failed, the index: %u >= count: %u", __func__, index, count); + HDF_LOGE("%s failed, index: %u >= count: %u", __func__, index, count); return NULL; } for (i = 0; i < index; i++) { @@ -144,7 +144,7 @@ int32_t HcsGetUint8ArrayElem(const struct DeviceResourceNode *node, const char * } if (!HcsSwapToUint8(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) { *value = def; - HDF_LOGE("%s failed, Incorrect prefix code", __func__); + HDF_LOGE("%s failed, incorrect prefix", __func__); return HDF_ERR_INVALID_OBJECT; } return HDF_SUCCESS; @@ -165,7 +165,7 @@ int32_t HcsGetUint16ArrayElem(const struct DeviceResourceNode *node, const char } if (!HcsSwapToUint16(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) { *value = def; - HDF_LOGE("%s failed, Incorrect prefix code", __func__); + HDF_LOGE("%s failed, incorrect prefix", __func__); return HDF_ERR_INVALID_OBJECT; } return HDF_SUCCESS; @@ -186,7 +186,7 @@ int32_t HcsGetUint32ArrayElem(const struct DeviceResourceNode *node, const char } if (!HcsSwapToUint32(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) { *value = def; - HDF_LOGE("%s failed, Incorrect prefix code", __func__); + HDF_LOGE("%s failed, incorrect prefix", __func__); return HDF_ERR_INVALID_OBJECT; } return HDF_SUCCESS; @@ -202,7 +202,7 @@ int32_t HcsGetUint64ArrayElem(const struct DeviceResourceNode *node, const char realValue = GetArrayElem(attr, index); if ((realValue == NULL) || !HcsSwapToUint64(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) { *value = def; - HDF_LOGE("%s failed, the realValue is NULL or incorrect prefix code", __func__); + HDF_LOGE("%s failed, invalid realValue (NULL) or incorrect prefix", __func__); return HDF_FAILURE; } return HDF_SUCCESS; @@ -211,11 +211,11 @@ int32_t HcsGetUint64ArrayElem(const struct DeviceResourceNode *node, const char #define CONTINUE_RETURN_DIFFERENT_ERRNO(ret, result) do { \ if ((result) == HDF_ERR_INVALID_OBJECT) { \ (ret) = HDF_ERR_INVALID_OBJECT; \ - HDF_LOGE("%s failed, the ret is %d", __func__, (result)); \ + HDF_LOGE("%s failed, the result is %d", __func__, (result)); \ continue; \ } \ if ((result) != HDF_SUCCESS) { \ - HDF_LOGE("%s failed, the ret is %d", __func__, (result)); \ + HDF_LOGE("%s failed, the result is %d", __func__, (result)); \ return result; \ } \ } while (0) @@ -316,7 +316,7 @@ int32_t HcsGetString(const struct DeviceResourceNode *node, const char *attrName RETURN_DEFAULT_VALUE(attr, attrName, value, def); if (HcsGetPrefix(attr->value) != CONFIG_STRING) { *value = def; - HDF_LOGE("%s failed, Incorrect prefix code", __func__); + HDF_LOGE("%s failed, incorrect prefix", __func__); return HDF_FAILURE; } *value = attr->value + HCS_PREFIX_LENGTH; @@ -366,7 +366,7 @@ const struct DeviceResourceNode *HcsGetNodeByMatchAttr(const struct DeviceResour const struct DeviceResourceNode *curNode = NULL; struct DeviceResourceIface *instance = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); if ((attrValue == NULL) || (instance == NULL) || (instance->GetRootNode == NULL)) { - HDF_LOGE("%s failed, attrValue is NULL or DeviceResourceGetIfaceInstance error", __func__); + HDF_LOGE("%s failed, attrValue or instance error", __func__); return NULL; } curNode = (node != NULL) ? node : instance->GetRootNode(); diff --git a/ability/config/test/unittest/common/hdf_config_test.cpp b/ability/config/test/unittest/common/hdf_config_test.cpp index 69c1800f5..f8cd98cdb 100644 --- a/ability/config/test/unittest/common/hdf_config_test.cpp +++ b/ability/config/test/unittest/common/hdf_config_test.cpp @@ -19,7 +19,7 @@ using namespace testing::ext; namespace ConfigTest { -const int8_t HDF_MSG_RESUL_DEFALUT = 3; +const int8_t HDF_MSG_RESULT_DEFAULT = 3; // hcs config test case number enum HdfTestCaseCmd { @@ -84,23 +84,19 @@ void HdfConfigTest::TearDownTestCase() HdfTestCloseService(); } -void HdfConfigTest::SetUp() -{ -} +void HdfConfigTest::SetUp() {} -void HdfConfigTest::TearDown() -{ -} +void HdfConfigTest::TearDown() {} /** * @tc.name: HslTestCreateDMHslToTree001 - * @tc.desc: Create a config tree, enter config test + * @tc.desc: Create a configuration tree and start configuration test * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestCreateDMHslToTree001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestCreateDMHslToTree001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_CREATE_DM_HSL_TO_TREE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_CREATE_DM_HSL_TO_TREE_001, HDF_MSG_RESULT_DEFAULT}; printf("HdfConfigTest enter\n\r"); EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -111,9 +107,9 @@ HWTEST_F(HdfConfigTest, HslTestCreateDMHslToTree001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -123,9 +119,9 @@ HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -135,9 +131,9 @@ HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -147,9 +143,9 @@ HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -159,9 +155,9 @@ HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -171,9 +167,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -183,9 +179,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -195,9 +191,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -207,9 +203,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint8ArraySuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint8ArraySuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -219,9 +215,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArraySuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -231,9 +227,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -243,9 +239,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -255,9 +251,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -268,9 +264,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -280,9 +276,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint16ArraySuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint16ArraySuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -292,9 +288,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArraySuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -304,9 +300,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -316,9 +312,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -328,9 +324,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -341,9 +337,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -353,9 +349,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint32ArraySuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint32ArraySuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -365,9 +361,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArraySuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -377,9 +373,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -389,9 +385,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -401,9 +397,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -414,9 +410,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -426,9 +422,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint64ArraySuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint64ArraySuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -438,9 +434,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArraySuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -450,9 +446,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetElemNumSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetElemNumSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -462,9 +458,9 @@ HWTEST_F(HdfConfigTest, HslTestGetElemNumSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetElemNumFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetElemNumFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -474,9 +470,9 @@ HWTEST_F(HdfConfigTest, HslTestGetElemNumFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetChildNodeSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetChildNodeSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -486,9 +482,9 @@ HWTEST_F(HdfConfigTest, HslTestGetChildNodeSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetChildNodeFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetChildNodeFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -498,9 +494,9 @@ HWTEST_F(HdfConfigTest, HslTestGetChildNodeFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -510,9 +506,9 @@ HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -522,9 +518,9 @@ HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetStringSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetStringSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -534,9 +530,9 @@ HWTEST_F(HdfConfigTest, HslTestGetStringSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetStringFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetStringFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -546,9 +542,9 @@ HWTEST_F(HdfConfigTest, HslTestGetStringFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -559,9 +555,9 @@ HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -571,9 +567,9 @@ HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemFail001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefSuccess001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefSuccess001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_001, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_001, HDF_MSG_RESULT_DEFAULT}; EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } @@ -583,9 +579,9 @@ HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefSuccess001, TestSize.Level1) * @tc.type: FUNC * @tc.require: AR000DQ0TB */ -HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefFail001, TestSize.Level1) +HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefFail001, TestSize.Level0) { - struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_002, HDF_MSG_RESUL_DEFALUT}; + struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_002, HDF_MSG_RESULT_DEFAULT}; printf("HdfConfigTest last enter\n\r"); EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); } -- Gitee From 9bccf34cd63fc75b309b532d63ee9ebc76765e4f Mon Sep 17 00:00:00 2001 From: gonghui Date: Mon, 17 May 2021 16:35:06 +0800 Subject: [PATCH 2/2] sync L2 code to L1 code --- ability/sbuf/include/hdf_sbuf.h | 255 +++++++++++- ability/sbuf/include/hdf_sbuf_impl.h | 74 ++++ ability/sbuf/src/hdf_sbuf.c | 558 +++++++++++++-------------- ability/sbuf/src/hdf_sbuf_impl_raw.c | 553 ++++++++++++++++++++++++++ 4 files changed, 1138 insertions(+), 302 deletions(-) create mode 100644 ability/sbuf/include/hdf_sbuf_impl.h create mode 100644 ability/sbuf/src/hdf_sbuf_impl_raw.c diff --git a/ability/sbuf/include/hdf_sbuf.h b/ability/sbuf/include/hdf_sbuf.h index 6fd3bd6cd..1ec26e857 100644 --- a/ability/sbuf/include/hdf_sbuf.h +++ b/ability/sbuf/include/hdf_sbuf.h @@ -9,10 +9,11 @@ * @addtogroup Core * @{ * - * @brief Provides OpenHarmony Driver Foundation (HDF) APIs. + * @brief Provides functions to use the HarmonyOS Driver Foundation (HDF). * - * The HDF implements driver framework capabilities such as driver loading, service management, - * and driver message model. You can develop drivers based on the HDF. + * The HDF implements driver framework capabilities such as driver loading, service management, driver message model, + * and power management. + * You can develop drivers based on the HDF. * * @since 1.0 */ @@ -20,8 +21,8 @@ /** * @file hdf_sbuf.h * - * @brief Defines functions related to a HdfSBuf. The HDF provides data serialization and deserialization - * capabilities for data transmission between user-mode applications and kernel-mode drivers. + * @brief Declares functions related to the HDF SBUF. The HDF provides data serialization and deserialization + * capabilities for data transmission between user-space applications and kernel-space drivers. * * @since 1.0 */ @@ -33,19 +34,24 @@ #ifdef __cplusplus extern "C" { +#else +typedef uint16_t char16_t; #endif /* __cplusplus */ +struct HdfSBuf; +struct HdfSbufImpl; +struct HdfRemoteService; + /** - * @brief Defines a HdfSBuf. + * @brief Enumerates HDF SBUF types. * * @since 1.0 */ -struct HdfSBuf { - size_t writePos; /**< Current write position */ - size_t readPos; /**< Current read position */ - size_t capacity; /**< Storage capacity, at most 512 KB. */ - uint8_t *data; /**< Pointer to data storage */ - bool isBind; /**< Whether to bind the externally transferred pointer for data storage */ +enum HdfSbufType { + SBUF_RAW = 0, /* SBUF used for communication between the user space and the kernel space */ + SBUF_IPC, /* SBUF used for inter-process communication (IPC) */ + SBUF_IPC_HW, /* Reserved for extension */ + SBUF_TYPE_MAX, /* Maximum value of the SBUF type */ }; /** @@ -60,6 +66,18 @@ struct HdfSBuf { */ bool HdfSbufWriteBuffer(struct HdfSBuf *sbuf, const void *data, uint32_t writeSize); +/** + * @brief Writes unpadded data to a SBuf. You can call {@link HdfSbufReadUnpadBuffer} to read the unpadded data. + * + * @param sbuf Indicates the pointer to the target SBuf. + * @param data Indicates the pointer to the data to write. The value cannot be a null pointer. + * @param writeSize Indicates the size of the data to write. The value cannot be 0. + * @return Returns true if the operation is successful; returns false otherwise. + * + * @since 1.0 + */ +bool HdfSbufWriteUnpadBuffer(struct HdfSBuf *sbuf, const uint8_t *data, uint32_t writeSize); + /** * @brief Writes a 64-bit unsigned integer to a SBuf. * @@ -159,13 +177,133 @@ bool HdfSbufWriteInt8(struct HdfSBuf *sbuf, int8_t value); */ bool HdfSbufWriteString(struct HdfSBuf *sbuf, const char *value); +/** + * @brief Writes a wide character string to a SBuf. + * The SBUF of the SBUF_RAW type does not support this function. + * + * @param sbuf Indicates the pointer to the target SBuf. + * @param value Indicates the pointer to the wide character string to write. + * @param size Indicates the size of the wide character string to write. + * @return Returns true if the operation is successful; returns false otherwise. + * + * @since 1.0 + */ +bool HdfSbufWriteString16(struct HdfSBuf *sbuf, const char16_t *value, uint32_t size); + +/** + * @brief Writes a floating-point number to a SBuf. + * The SBUF of the SBUF_RAW type does not support this function. + * + * @param sbuf Indicates the pointer to the target SBuf. + * @param value Indicates the floating-point number to write. + * @return Returns true if the operation is successful; returns false otherwise. + * + * @since 1.0 + */ +bool HdfSbufWriteFloat(struct HdfSBuf *sbuf, float value); + +/** + * @brief Writes a double-precision floating-point number to a SBuf. + * The SBUF of the SBUF_RAW type does not support this function. + * + * @param sbuf Indicates the pointer to the target SBuf. + * @param value Indicates the double-precision floating-point number to write. + * @return Returns true if the operation is successful; returns false otherwise. + * + * @since 1.0 + */ +bool HdfSbufWriteDouble(struct HdfSBuf *sbuf, double value); + +/** + * @brief Writes a file descriptor to a SBuf. + * The SBUF of the SBUF_RAW type does not support this function. + * + * @param sbuf Indicates the pointer to the target SBuf. + * @param fd Indicates the file descriptor to write. + * @return Returns true if the operation is successful; returns false otherwise. + * + * @since 1.0 + */ +bool HdfSbufWriteFileDescriptor(struct HdfSBuf *sbuf, int fd); + +/** + * @brief Writes an IPC service to a SBuf. The SBUF of the SBUF_RAW type does not support this function. + * + * @param sbuf Indicates the pointer to the target SBuf. + * @param service Indicates the pointer to the IPC service to write. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + * + * @since 1.0 + */ +int32_t HdfSBufWriteRemoteService(struct HdfSBuf *sbuf, const struct HdfRemoteService *service); + +/** + * @brief Reads an IPC service from a SBuf. + * The SBUF of the SBUF_RAW type does not support this function. + * + * @param sbuf Indicates the pointer to the target SBuf. + * @return Returns the pointer to the IPC service object if the operation is successful; + * returns a null pointer otherwise. + * + * @since 1.0 + */ +struct HdfRemoteService *HdfSBufReadRemoteService(struct HdfSBuf *sbuf); + +/** + * @brief Reads a file descriptor from a SBuf. + * The SBUF of the SBUF_RAW type does not support this function. + * + * @param sbuf Indicates the pointer to the target SBuf. + * @return Returns a valid file descriptor if the operation is successful; returns a negative value otherwise. + * + * @since 1.0 + */ +int HdfSbufReadFileDescriptor(struct HdfSBuf *sbuf); + +/** + * @brief Reads a double-precision floating-point number from a SBuf. + * The SBUF of the SBUF_RAW type does not support this function. + * + * @param sbuf Indicates the pointer to the target SBuf. + * @param value Indicates the pointer to the double-precision floating-point number read, + * which is requested by the caller. + * @return Returns true if the operation is successful; returns false otherwise. + * + * @since 1.0 + */ +bool HdfSbufReadDouble(struct HdfSBuf *sbuf, double *value); + +/** + * @brief Reads a floating-point number from a SBuf. + * The SBUF of the SBUF_RAW type does not support this function. + * + * @param sbuf Indicates the pointer to the target SBuf. + * @param value Indicates the pointer to the floating-point number read, which is requested by the caller. + * @return Returns true if the operation is successful; returns false otherwise. + * + * @since 1.0 + */ +bool HdfSbufReadFloat(struct HdfSBuf *sbuf, float *value); + +/** + * @brief Reads a wide character string from a SBuf. + * The SBUF of the SBUF_RAW type does not support this function. + * + * @param sbuf Indicates the pointer to the target SBuf. + * @return Returns the pointer to the wide character string if the operation is successful; + * returns a null pointer otherwise. + * + * @since 1.0 + */ +const char16_t *HdfSBufReadString16(struct HdfSBuf *sbuf); + /** * @brief Reads a data segment from a SBuf. * * @param sbuf Indicates the pointer to the target SBuf. * @param data Indicates the double pointer to the data read. The data read is stored in *data, - * which is requested by the caller. The memory pointed to by *data is managed by the SBuf - * and they share the same lifecycle. + * which is requested by the caller. The memory pointed to by *data is managed by + * the SBuf and they share the same lifecycle. * @param readSize Indicates the pointer to the size of the data read. * @return Returns true if the operation is successful; returns false otherwise. * @@ -173,6 +311,17 @@ bool HdfSbufWriteString(struct HdfSBuf *sbuf, const char *value); */ bool HdfSbufReadBuffer(struct HdfSBuf *sbuf, const void **data, uint32_t *readSize); +/** + * @brief Reads unpadded data from a SBuf. + * + * @param sbuf Indicates the pointer to the target SBuf. + * @param length Indicates the length of the data to read. + * @return Returns the pointer to the unpadded data if the operation is successful; returns a null pointer otherwise. + * + * @since 1.0 + */ +const uint8_t *HdfSbufReadUnpadBuffer(struct HdfSBuf *sbuf, size_t length); + /** * @brief Reads a 64-bit unsigned integer from a SBuf. * @@ -273,10 +422,11 @@ bool HdfSbufReadInt8(struct HdfSBuf *sbuf, int8_t *value); const char *HdfSbufReadString(struct HdfSBuf *sbuf); /** - * @brief Obtains the pointer to the data stored in aSBuf. + * @brief Obtains the pointer to the data stored in a SBuf. * * @param sbuf Indicates the pointer to the target SBuf. - * @return Returns the pointer to the data stored in the target SBuf. + * @return Returns the pointer to the data stored in the target SBuf if the operation is successful; + * returns a null pointer otherwise. * * @since 1.0 */ @@ -296,6 +446,7 @@ void HdfSbufFlush(struct HdfSBuf *sbuf); * * @param sbuf Indicates the pointer to the target SBuf. * @return Returns the SBuf capacity. + * * @since 1.0 */ size_t HdfSbufGetCapacity(const struct HdfSBuf *sbuf); @@ -310,10 +461,20 @@ size_t HdfSbufGetCapacity(const struct HdfSBuf *sbuf); */ size_t HdfSbufGetDataSize(const struct HdfSBuf *sbuf); +/** + * @brief Sets the data size of a SBuf. + * + * @param sbuf Indicates the pointer to the target SBuf. + * @param size Indicates the data size to set, which cannot exceed the size obtained via {@link HdfSbufGetDataSize}. + * + * @since 1.0 + */ +void HdfSbufSetDataSize(struct HdfSBuf *sbuf, size_t size); + /** * @brief Obtains a SBuf instance. * - * @param capacity Indicates the initial capacity of theSBuf. + * @param capacity Indicates the initial capacity of the SBuf. * @return Returns the SBuf instance. * * @since 1.0 @@ -343,9 +504,9 @@ struct HdfSBuf *HdfSBufObtainDefaultSize(void); struct HdfSBuf *HdfSBufBind(uintptr_t base, size_t size); /** - * @brief Releases a SBuf . + * @brief Releases a SBuf. * - * @param sbuf Indicates the pointer to the SBuf to release. + * @param sbuf Indicates the pointer to the target SBuf. * * @since 1.0 */ @@ -383,6 +544,62 @@ struct HdfSBuf *HdfSBufCopy(const struct HdfSBuf *sbuf); */ void HdfSbufTransDataOwnership(struct HdfSBuf *sbuf); +/** + * @brief Obtains a SBuf instance of a specified type. + * + * @param type Indicates the SBUF type, which is defined in {@link HdfSbufType}. + * @return Returns the SBuf instance. + * + * @since 1.0 + */ +struct HdfSBuf *HdfSBufTypedObtain(uint32_t type); + +/** + * @brief Obtains a SBuf instance of a specified type based on the implementation of an existing SBuf. + * + * @param type Indicates the SBUF type, which is defined in {@link HdfSbufType}. + * @param impl Indicates the pointer to the implementation of an existing SBuf. + * @return Returns the new SBuf instance. + * + * @since 1.0 + */ +struct HdfSBuf *HdfSBufTypedObtainInplace(uint32_t type, struct HdfSbufImpl *impl); + +/** + * @brief Obtains a SBuf instance of a specified type with the given initial capacity. + * + * @param type Indicates the SBUF type, which is defined in {@link HdfSbufType}. + * @param capacity Indicates the initial capacity of the SBuf. + * @return Returns the new SBuf instance. + * + * @since 1.0 + */ +struct HdfSBuf *HdfSBufTypedObtainCapacity(uint32_t type, size_t capacity); + +/** + * @brief Creates a SBuf instance of a specified type with the specified data and size. + * The pointer to the data stored in the SBuf is released by the caller, + * and the written data size should not exceed the specified value of size. + * + * @param type Indicates the SBUF type, which is defined in {@link HdfSbufType}. + * @param base Indicates the base of the data to use. + * @param size Indicates the size of the data to use. + * @return Returns the SBuf instance. + * + * @since 1.0 + */ +struct HdfSBuf *HdfSBufTypedBind(uint32_t type, uintptr_t base, size_t size); + +/** + * @brief Obtains the implementation of a SBuf. + * + * @param sbuf Indicates the pointer to the target SBuf. + * @return Returns the pointer to the implementation of the SBuf. + * + * @since 1.0 + */ +struct HdfSbufImpl *HdfSbufGetImpl(struct HdfSBuf *sbuf); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/ability/sbuf/include/hdf_sbuf_impl.h b/ability/sbuf/include/hdf_sbuf_impl.h new file mode 100644 index 000000000..4b7906ad9 --- /dev/null +++ b/ability/sbuf/include/hdf_sbuf_impl.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef HDF_SBU_IMPL_H +#define HDF_SBU_IMPL_H + +#include "hdf_base.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +struct HdfSbufConstructor { + struct HdfSbufImpl *(*obtain)(size_t capacity); + struct HdfSbufImpl *(*bind)(uintptr_t base, size_t size); +}; + +struct HdfRemoteService; + +struct HdfSbufImpl { + bool (*writeBuffer)(struct HdfSbufImpl *sbuf, const uint8_t *data, uint32_t writeSize); + bool (*writeUnpadBuffer)(struct HdfSbufImpl *sbuf, const uint8_t *data, uint32_t writeSize); + bool (*writeUint64)(struct HdfSbufImpl *sbuf, uint64_t value); + bool (*writeUint32)(struct HdfSbufImpl *sbuf, uint32_t value); + bool (*writeUint16)(struct HdfSbufImpl *sbuf, uint16_t value); + bool (*writeUint8)(struct HdfSbufImpl *sbuf, uint8_t value); + bool (*writeInt64)(struct HdfSbufImpl *sbuf, int64_t value); + bool (*writeInt32)(struct HdfSbufImpl *sbuf, int32_t value); + bool (*writeInt16)(struct HdfSbufImpl *sbuf, int16_t value); + bool (*writeInt8)(struct HdfSbufImpl *sbuf, int8_t value); + bool (*writeString)(struct HdfSbufImpl *sbuf, const char *value); + bool (*writeFileDescriptor)(struct HdfSbufImpl *sbuf, int fd); + bool (*writeFloat)(struct HdfSbufImpl *sbuf, float value); + bool (*writeDouble)(struct HdfSbufImpl *sbuf, double value); + bool (*readDouble)(struct HdfSbufImpl *sbuf, double *value); + bool (*readFloat)(struct HdfSbufImpl *sbuf, float *value); + int (*readFileDescriptor)(struct HdfSbufImpl *sbuf); + bool (*writeString16)(struct HdfSbufImpl *sbuf, const char16_t *value, uint32_t size); + bool (*readBuffer)(struct HdfSbufImpl *sbuf, const uint8_t **data, uint32_t *readSize); + const uint8_t *(*readUnpadBuffer)(struct HdfSbufImpl *sbuf, size_t length); + bool (*readUint64)(struct HdfSbufImpl *sbuf, uint64_t *value); + bool (*readUint32)(struct HdfSbufImpl *sbuf, uint32_t *value); + bool (*readUint16)(struct HdfSbufImpl *sbuf, uint16_t *value); + bool (*readUint8)(struct HdfSbufImpl *sbuf, uint8_t *value); + bool (*readInt64)(struct HdfSbufImpl *sbuf, int64_t *value); + bool (*readInt32)(struct HdfSbufImpl *sbuf, int32_t *value); + bool (*readInt16)(struct HdfSbufImpl *sbuf, int16_t *value); + bool (*readInt8)(struct HdfSbufImpl *sbuf, int8_t *value); + const char *(*readString)(struct HdfSbufImpl *sbuf); + const char16_t *(*readString16)(struct HdfSbufImpl *sbuf); + int32_t (*writeRemoteService)(struct HdfSbufImpl *sbuf, const struct HdfRemoteService *service); + struct HdfRemoteService *(*readRemoteService)(struct HdfSbufImpl *sbuf); + const uint8_t *(*getData)(const struct HdfSbufImpl *sbuf); + void (*flush)(struct HdfSbufImpl *sbuf); + size_t (*getCapacity)(const struct HdfSbufImpl *sbuf); + size_t (*getDataSize)(const struct HdfSbufImpl *sbuf); + void (*setDataSize)(struct HdfSbufImpl *sbuf, size_t size); + void (*recycle)(struct HdfSbufImpl *sbuf); + struct HdfSbufImpl *(*move)(struct HdfSbufImpl *sbuf); + struct HdfSbufImpl *(*copy)(const struct HdfSbufImpl *sbuf); + void (*transDataOwnership)(struct HdfSbufImpl *sbuf); +}; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* HDF_SBUF_H */ +/** @} */ diff --git a/ability/sbuf/src/hdf_sbuf.c b/ability/sbuf/src/hdf_sbuf.c index 60341b0da..9aea25fcf 100644 --- a/ability/sbuf/src/hdf_sbuf.c +++ b/ability/sbuf/src/hdf_sbuf.c @@ -6,459 +6,451 @@ * See the LICENSE file in the root of this repository for complete details. */ -#include "securec.h" -#include "osal_mem.h" -#include "hdf_log.h" #include "hdf_sbuf.h" +#include "hdf_log.h" +#include "hdf_sbuf_impl.h" +#include "osal_mem.h" -#define HDF_SBUF_GROW_SIZE_DEFAULT 256 -#define HDF_SBUF_MAX_SIZE (512 * 1024) // 512kB -#define HDF_SBUF_ALIGN 4 - -#ifndef INT16_MAX -#ifdef S16_MAX -#define INT16_MAX S16_MAX -#else -#define INT16_MAX 32767 -#endif // !S16_MAX -#endif // INT16_MAX - -static inline size_t HdfSbufGetAlignSize(size_t size) -{ - return (size + HDF_SBUF_ALIGN - 1) & (~(HDF_SBUF_ALIGN - 1)); -} - -static size_t HdfSbufGetLeftWriteSize(struct HdfSBuf *sbuf) -{ - return (sbuf->capacity < sbuf->writePos) ? 0 : (sbuf->capacity - sbuf->writePos); -} - -static size_t HdfSbufGetLeftReadSize(struct HdfSBuf *sbuf) -{ - return (sbuf->writePos < sbuf->readPos) ? 0 : (sbuf->writePos - sbuf->readPos); -} - -static bool HdfSbufWriteRollback(struct HdfSBuf *sbuf, uint32_t size) -{ - size_t alignSize = HdfSbufGetAlignSize(size); - if (sbuf->writePos < alignSize) { - return false; - } - - sbuf->writePos -= alignSize; - return true; -} - -static bool HdfSbufReadRollback(struct HdfSBuf *sbuf, uint32_t size) -{ - size_t alignSize = HdfSbufGetAlignSize(size); - if (sbuf->readPos < alignSize) { - return false; +#define HDF_SBUF_DEFAULT_SIZE 256 +#define HDF_SBUF_IMPL_CHECK_RETURN(sbuf, api, retCode) \ + do { \ + if (sbuf == NULL || sbuf->impl == NULL) { \ + HDF_LOGE("%s: invalid sbuf object", __func__); \ + return retCode; \ + } \ + if (sbuf->impl->api == NULL) { \ + HDF_LOGE(#api " is not support on %d sbuf", sbuf->type); \ + return retCode; \ + } \ + } while (0) + +#define HDF_SBUF_IMPL_CHECK_RETURN_VOID(sbuf, api) \ + do { \ + if (sbuf == NULL || sbuf->impl == NULL) { \ + HDF_LOGE("%s: invalid sbuf object", __func__); \ + return; \ + } \ + if (sbuf->impl->api == NULL) { \ + HDF_LOGE(#api " is not support on %d sbuf", sbuf->type); \ + return; \ + } \ + } while (0) + +struct HdfSBuf { + struct HdfSbufImpl *impl; + uint32_t type; +}; + +struct HdfSbufImpl *SbufObtainRaw(size_t capacity); +struct HdfSbufImpl *SbufBindRaw(uintptr_t base, size_t size); +struct HdfSbufImpl *SbufObtainIpc(size_t capacity) __attribute__((weak)); +struct HdfSbufImpl *SbufBindIpc(uintptr_t base, size_t size) __attribute__((weak)); +struct HdfSbufImpl *SbufObtainIpcHw(size_t capacity) __attribute__((weak)); +struct HdfSbufImpl *SbufBindRawIpcHw(uintptr_t base, size_t size) __attribute__((weak)); + +static const struct HdfSbufConstructor g_sbufConstructorMap[SBUF_TYPE_MAX] = { + [SBUF_RAW] = { + .obtain = SbufObtainRaw, + .bind = SbufBindRaw, + }, + [SBUF_IPC] = { + .obtain = SbufObtainIpc, + .bind = SbufBindIpc, + }, + [SBUF_IPC_HW] = { + .obtain = SbufObtainIpcHw, + .bind = SbufBindRawIpcHw, + }, +}; + +static const struct HdfSbufConstructor *HdfSbufConstructorGet(uint32_t type) +{ + if (type >= SBUF_TYPE_MAX) { + return NULL; } - sbuf->readPos -= alignSize; - return true; + return &g_sbufConstructorMap[type]; } uint8_t *HdfSbufGetData(const struct HdfSBuf *sbuf) { - if (sbuf == NULL) { - HDF_LOGE("Get data is null, input sbuf is null"); - return NULL; - } - return (uint8_t *)sbuf->data; + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, getData, NULL); + return (uint8_t *)sbuf->impl->getData(sbuf->impl); } void HdfSbufFlush(struct HdfSBuf *sbuf) { - if (sbuf != NULL) { - sbuf->readPos = 0; - sbuf->writePos = 0; - } + HDF_SBUF_IMPL_CHECK_RETURN_VOID(sbuf, getData); + sbuf->impl->flush(sbuf->impl); } size_t HdfSbufGetCapacity(const struct HdfSBuf *sbuf) { - return (sbuf != NULL) ? sbuf->capacity : 0; + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, getCapacity, HDF_FAILURE); + return (sbuf != NULL && sbuf->impl != NULL) ? sbuf->impl->getCapacity(sbuf->impl) : 0; } size_t HdfSbufGetDataSize(const struct HdfSBuf *sbuf) { - return (sbuf != NULL) ? sbuf->writePos : 0; + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, getDataSize, HDF_FAILURE); + return sbuf->impl->getDataSize(sbuf->impl); } -static bool HdfSbufGrow(struct HdfSBuf *sbuf, uint32_t growSize) +void HdfSbufSetDataSize(struct HdfSBuf *sbuf, size_t size) { - if (sbuf->isBind) { - HDF_LOGE("%s: binded sbuf oom", __func__); - return false; - } - - uint32_t newSize = HdfSbufGetAlignSize(sbuf->capacity + growSize); - if (newSize < sbuf->capacity) { - HDF_LOGE("%s: grow size overflow", __func__); - return false; - } - if (newSize > HDF_SBUF_MAX_SIZE) { - HDF_LOGE("%s: buf size over limit", __func__); - return false; - } - - uint8_t *newData = OsalMemCalloc(newSize); - if (newData == NULL) { - HDF_LOGE("%s: oom", __func__); - return false; - } - - if (sbuf->data != NULL) { - if (memcpy_s(newData, newSize, sbuf->data, sbuf->writePos) != EOK) { - OsalMemFree(newData); - return false; - } - OsalMemFree(sbuf->data); - } - - sbuf->data = newData; - sbuf->capacity = newSize; - - return true; + HDF_SBUF_IMPL_CHECK_RETURN_VOID(sbuf, setDataSize); + sbuf->impl->setDataSize(sbuf->impl, size); } -static bool HdfSbufWrite(struct HdfSBuf *sbuf, const uint8_t *data, uint32_t size) +bool HdfSbufWriteBuffer(struct HdfSBuf *sbuf, const void *data, uint32_t writeSize) { - if (sbuf == NULL || sbuf->data == NULL || data == NULL) { - return false; - } - - if (size == 0) { - return true; - } - - size_t alignSize = HdfSbufGetAlignSize(size); - // in case of desireCapacity overflow - if (alignSize < size) { - HDF_LOGE("desireCapacity is overflow"); - return false; - } - size_t writeableSize = HdfSbufGetLeftWriteSize(sbuf); - if (alignSize > writeableSize) { - size_t growSize = (alignSize > HDF_SBUF_GROW_SIZE_DEFAULT) ? (alignSize + HDF_SBUF_GROW_SIZE_DEFAULT) : - HDF_SBUF_GROW_SIZE_DEFAULT; - if (!HdfSbufGrow(sbuf, growSize)) { - return false; - } - writeableSize = HdfSbufGetLeftWriteSize(sbuf); - } - - uint8_t *dest = sbuf->data + sbuf->writePos; - if (memcpy_s(dest, writeableSize, data, size) != EOK) { - return false; /* never hits */ - } - - sbuf->writePos += alignSize; - return true; + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, getCapacity, false); + return sbuf->impl->writeBuffer(sbuf->impl, (const uint8_t *)data, writeSize); } -static bool HdfSbufRead(struct HdfSBuf *sbuf, uint8_t *data, uint32_t readSize) +bool HdfSbufWriteUnpadBuffer(struct HdfSBuf *sbuf, const uint8_t *data, uint32_t writeSize) { - if (sbuf == NULL || sbuf->data == NULL || data == NULL) { - return false; - } - - if (readSize == 0) { - return true; - } - - size_t alignSize = HdfSbufGetAlignSize(readSize); - if (alignSize > HdfSbufGetLeftReadSize(sbuf)) { - HDF_LOGE("Read out of buffer range"); + if (data == NULL) { return false; } - if (memcpy_s(data, readSize, sbuf->data + sbuf->readPos, readSize) != EOK) { - return false; // never hits - } - sbuf->readPos += alignSize; - return true; + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeUnpadBuffer, false); + return sbuf->impl->writeUnpadBuffer(sbuf->impl, data, writeSize); } -bool HdfSbufWriteBuffer(struct HdfSBuf *sbuf, const void *data, uint32_t writeSize) +const uint8_t *HdfSbufReadUnpadBuffer(struct HdfSBuf *sbuf, size_t length) { - if (sbuf == NULL) { - HDF_LOGE("Write buffer failed, input param is invalid"); - return false; - } - if (data == NULL) { - return HdfSbufWriteInt32(sbuf, 0); - } - - if (!HdfSbufWriteInt32(sbuf, writeSize)) { - return false; - } - if (!HdfSbufWrite(sbuf, data, writeSize)) { - (void)HdfSbufWriteRollback(sbuf, sizeof(int32_t)); - return false; - } - - return true; + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUnpadBuffer, false); + return sbuf->impl->readUnpadBuffer(sbuf->impl, length); } bool HdfSbufReadBuffer(struct HdfSBuf *sbuf, const void **data, uint32_t *readSize) { - if (sbuf == NULL || sbuf->data == NULL || data == NULL || readSize == NULL) { - HDF_LOGE("%s:input invalid", __func__); - return false; - } - - int buffSize = 0; - if (!HdfSbufReadInt32(sbuf, &buffSize)) { - return false; - } - - if (buffSize == 0) { - *data = NULL; - *readSize = 0; - return true; - } - size_t alignSize = HdfSbufGetAlignSize(buffSize); - if (alignSize > HdfSbufGetLeftReadSize(sbuf)) { - HDF_LOGE("%s:readBuff out of range", __func__); - (void)HdfSbufReadRollback(sbuf, sizeof(int32_t)); - return false; - } - - *data = sbuf->data + sbuf->readPos; - *readSize = buffSize; - sbuf->readPos += alignSize; - return true; + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readBuffer, false); + return sbuf->impl->readBuffer(sbuf->impl, (const uint8_t **)data, readSize); } bool HdfSbufWriteUint64(struct HdfSBuf *sbuf, uint64_t value) { - return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeUint64, false); + return sbuf->impl->writeUint64(sbuf->impl, value); } bool HdfSbufWriteUint32(struct HdfSBuf *sbuf, uint32_t value) { - return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeUint32, false); + return sbuf->impl->writeUint32(sbuf->impl, value); } bool HdfSbufWriteUint16(struct HdfSBuf *sbuf, uint16_t value) { - return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeUint16, false); + return sbuf->impl->writeUint16(sbuf->impl, value); } bool HdfSbufWriteUint8(struct HdfSBuf *sbuf, uint8_t value) { - return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeUint8, false); + return sbuf->impl->writeUint8(sbuf->impl, value); } bool HdfSbufWriteInt64(struct HdfSBuf *sbuf, int64_t value) { - return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeInt64, false); + return sbuf->impl->writeInt64(sbuf->impl, value); } bool HdfSbufWriteInt32(struct HdfSBuf *sbuf, int32_t value) { - return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeInt32, false); + return sbuf->impl->writeInt32(sbuf->impl, value); } bool HdfSbufWriteInt16(struct HdfSBuf *sbuf, int16_t value) { - return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeInt16, false); + return sbuf->impl->writeInt16(sbuf->impl, value); } bool HdfSbufWriteInt8(struct HdfSBuf *sbuf, int8_t value) { - return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeInt8, false); + return sbuf->impl->writeInt8(sbuf->impl, value); } bool HdfSbufWriteString(struct HdfSBuf *sbuf, const char *value) { - if (sbuf == NULL) { - HDF_LOGE("%s:input null", __func__); - return false; - } + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeString, false); + return sbuf->impl->writeString(sbuf->impl, value); +} - return HdfSbufWriteBuffer(sbuf, value, value ? (strlen(value) + 1) : 0); +bool HdfSbufWriteString16(struct HdfSBuf *sbuf, const char16_t *value, uint32_t size) +{ + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeString16, false); + return sbuf->impl->writeString16(sbuf->impl, value, size); } bool HdfSbufReadUint64(struct HdfSBuf *sbuf, uint64_t *value) { - return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUint64, false); + return sbuf->impl->readUint64(sbuf->impl, value); } bool HdfSbufReadUint32(struct HdfSBuf *sbuf, uint32_t *value) { - return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUint32, false); + return sbuf->impl->readUint32(sbuf->impl, value); } bool HdfSbufReadUint16(struct HdfSBuf *sbuf, uint16_t *value) { - return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUint16, false); + return sbuf->impl->readUint16(sbuf->impl, value); } bool HdfSbufReadUint8(struct HdfSBuf *sbuf, uint8_t *value) { - return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUint8, false); + return sbuf->impl->readUint8(sbuf->impl, value); } bool HdfSbufReadInt64(struct HdfSBuf *sbuf, int64_t *value) { - return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readInt64, false); + return sbuf->impl->readInt64(sbuf->impl, value); } bool HdfSbufReadInt32(struct HdfSBuf *sbuf, int32_t *value) { - return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readInt32, false); + return sbuf->impl->readInt32(sbuf->impl, value); } bool HdfSbufReadInt16(struct HdfSBuf *sbuf, int16_t *value) { - return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readInt16, false); + return sbuf->impl->readInt16(sbuf->impl, value); } bool HdfSbufReadInt8(struct HdfSBuf *sbuf, int8_t *value) { - return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value)); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readInt8, false); + return sbuf->impl->readInt8(sbuf->impl, value); } const char *HdfSbufReadString(struct HdfSBuf *sbuf) { - if (sbuf == NULL || sbuf->data == NULL) { - HDF_LOGE("%s:input null", __func__); - return NULL; - } - /* this length contains '\0' at the end. */ - int32_t strLen = 0; - if (!HdfSbufReadInt32(sbuf, &strLen) || strLen <= 0) { - return NULL; - } - size_t alignSize = HdfSbufGetAlignSize(strLen); - if (strLen > INT16_MAX || alignSize > HdfSbufGetLeftReadSize(sbuf)) { - (void)HdfSbufReadRollback(sbuf, sizeof(int32_t)); - return NULL; - } + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readString, false); + return sbuf->impl->readString(sbuf->impl); +} - char *str = (char *)(sbuf->data + sbuf->readPos); - sbuf->readPos += alignSize; - /* force set '\0' at end of the string */ - str[strLen - 1] = '\0'; - return str; +bool HdfSBufWriteString16(struct HdfSBuf *sbuf, const char16_t *value, uint32_t size) +{ + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeString16, false); + return sbuf->impl->writeString16(sbuf->impl, value, size); } -struct HdfSBuf *HdfSBufObtainDefaultSize() +const char16_t *HdfSBufReadString16(struct HdfSBuf *sbuf) { - return HdfSBufObtain(HDF_SBUF_GROW_SIZE_DEFAULT); + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readString16, false); + return sbuf->impl->readString16(sbuf->impl); } -struct HdfSBuf *HdfSBufObtain(size_t capacity) +int32_t HdfSBufWriteRemoteService(struct HdfSBuf *sbuf, const struct HdfRemoteService *service) +{ + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeRemoteService, false); + return sbuf->impl->writeRemoteService(sbuf->impl, service); +} + +struct HdfRemoteService *HdfSBufReadRemoteService(struct HdfSBuf *sbuf) +{ + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readRemoteService, false); + return sbuf->impl->readRemoteService(sbuf->impl); +} + +bool HdfSbufWriteFloat(struct HdfSBuf *sbuf, float data) +{ + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeFloat, false); + return sbuf->impl->writeFloat(sbuf->impl, data); +} + +bool HdfSbufWriteDouble(struct HdfSBuf *sbuf, double data) +{ + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeDouble, false); + return sbuf->impl->writeDouble(sbuf->impl, data); +} + +bool HdfSbufWriteFileDescriptor(struct HdfSBuf *sbuf, int fd) +{ + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeFileDescriptor, false); + return sbuf->impl->writeFileDescriptor(sbuf->impl, fd); +} + +int HdfSbufReadFileDescriptor(struct HdfSBuf *sbuf) +{ + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readFileDescriptor, false); + return sbuf->impl->readFileDescriptor(sbuf->impl); +} + +bool HdfSbufReadDouble(struct HdfSBuf *sbuf, double *data) +{ + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readDouble, false); + return sbuf->impl->readDouble(sbuf->impl, data); +} + +bool HdfSbufReadFloat(struct HdfSBuf *sbuf, float *data) +{ + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readFloat, false); + return sbuf->impl->readFloat(sbuf->impl, data); +} + +struct HdfSBuf *HdfSBufTypedObtainCapacity(uint32_t type, size_t capacity) { - if (capacity > HDF_SBUF_MAX_SIZE) { - HDF_LOGE("%s: buf size over limit", __func__); + const struct HdfSbufConstructor *constructor = HdfSbufConstructorGet(type); + if (constructor == NULL) { + HDF_LOGE("sbuf constructor %d not implement", type); return NULL; } + if (constructor->obtain == NULL) { + HDF_LOGE("sbuf constructor %d obtain method not implement", type); + return NULL; + } + struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf)); if (sbuf == NULL) { - HDF_LOGE("instance usbuf failure"); + HDF_LOGE("instance sbuf failure"); return NULL; } - sbuf->data = (uint8_t *)OsalMemCalloc(capacity); - if (sbuf->data == NULL) { + sbuf->impl = constructor->obtain(capacity); + if (sbuf->impl == NULL) { OsalMemFree(sbuf); - HDF_LOGE("sbuf obtain oom, size=%u", (uint32_t)capacity); + HDF_LOGE("sbuf obtain fail, size=%u", (uint32_t)capacity); return NULL; } - sbuf->capacity = capacity; - sbuf->writePos = 0; - sbuf->readPos = 0; - sbuf->isBind = false; + sbuf->type = type; return sbuf; } -struct HdfSBuf *HdfSBufBind(uintptr_t base, size_t size) +struct HdfSBuf *HdfSBufTypedObtainInplace(uint32_t type, struct HdfSbufImpl *impl) { - if (base == 0 || size == 0) { - return NULL; - } - /* require 4 byte alignment for base */ - if ((base & 0x3) != 0) { - HDF_LOGE("Base is not align for 4-byte"); + if (type >= SBUF_TYPE_MAX || impl == NULL) { return NULL; } + struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf)); if (sbuf == NULL) { - HDF_LOGE("%s: oom", __func__); + HDF_LOGE("obtain in-place sbuf failure"); return NULL; } - sbuf->data = (uint8_t *)base; - sbuf->capacity = size; - sbuf->writePos = size; - sbuf->readPos = 0; - sbuf->isBind = true; + sbuf->impl = impl; + sbuf->type = type; return sbuf; } -struct HdfSBuf *HdfSBufCopy(const struct HdfSBuf *sbuf) +struct HdfSBuf *HdfSBufTypedObtain(uint32_t type) +{ + return HdfSBufTypedObtainCapacity(type, HDF_SBUF_DEFAULT_SIZE); +} + +struct HdfSBuf *HdfSBufTypedBind(uint32_t type, uintptr_t base, size_t size) { - if (sbuf == NULL || sbuf->data == NULL) { + const struct HdfSbufConstructor *constructor = HdfSbufConstructorGet(type); + if (constructor == NULL) { + HDF_LOGE("sbuf constructor %d not implement", type); return NULL; } - struct HdfSBuf *new = HdfSBufObtain(sbuf->capacity); - if (new == NULL) { + if (constructor->bind == NULL) { + HDF_LOGE("sbuf constructor %d bind method not implement", type); return NULL; } - new->capacity = sbuf->capacity; - new->readPos = 0; - new->writePos = sbuf->writePos; - if (memcpy_s(new->data, new->capacity, sbuf->data, sbuf->writePos) != EOK) { - HdfSBufRecycle(new); + + struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf)); + if (sbuf == NULL) { + HDF_LOGE("instance sbuf failure"); + return NULL; + } + + sbuf->impl = constructor->bind(base, size); + if (sbuf->impl == NULL) { + OsalMemFree(sbuf); + HDF_LOGE("sbuf bind fail"); return NULL; } + sbuf->type = type; + return sbuf; +} - return new; +struct HdfSBuf *HdfSBufObtain(size_t capacity) +{ + return HdfSBufTypedObtainCapacity(SBUF_RAW, capacity); } -struct HdfSBuf *HdfSBufMove(struct HdfSBuf *sbuf) +struct HdfSBuf *HdfSBufObtainDefaultSize() +{ + return HdfSBufObtain(HDF_SBUF_DEFAULT_SIZE); +} + +struct HdfSBuf *HdfSBufBind(uintptr_t base, size_t size) { - if (sbuf == NULL || sbuf->isBind) { + return HdfSBufTypedBind(SBUF_RAW, base, size); +} + +struct HdfSBuf *HdfSBufCopy(const struct HdfSBuf *sbuf) +{ + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, copy, NULL); + struct HdfSBuf *newBuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf)); + if (newBuf == NULL) { return NULL; } - - struct HdfSBuf *new = OsalMemCalloc(sizeof(struct HdfSBuf)); - if (new == NULL) { + newBuf->impl = sbuf->impl->copy(sbuf->impl); + if (newBuf->impl == NULL) { + OsalMemFree(newBuf); return NULL; } - new->capacity = sbuf->capacity; - new->readPos = 0; - new->writePos = sbuf->writePos; - new->data = sbuf->data; - - sbuf->data = NULL; - sbuf->capacity = 0; - HdfSbufFlush(sbuf); - - return new; + newBuf->type = sbuf->type; + return newBuf; } -void HdfSbufTransDataOwnership(struct HdfSBuf *sbuf) +struct HdfSBuf *HdfSBufMove(struct HdfSBuf *sbuf) { - if (sbuf == NULL) { - return; + HDF_SBUF_IMPL_CHECK_RETURN(sbuf, move, NULL); + struct HdfSBuf *newBuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf)); + if (newBuf == NULL) { + return NULL; } + newBuf->impl = sbuf->impl->move(sbuf->impl); + if (newBuf->impl == NULL) { + OsalMemFree(newBuf); + return NULL; + } + return newBuf; +} - sbuf->isBind = false; +void HdfSbufTransDataOwnership(struct HdfSBuf *sbuf) +{ + HDF_SBUF_IMPL_CHECK_RETURN_VOID(sbuf, transDataOwnership); + sbuf->impl->transDataOwnership(sbuf->impl); } void HdfSBufRecycle(struct HdfSBuf *sbuf) { if (sbuf != NULL) { - if (sbuf->data != NULL && !sbuf->isBind) { - OsalMemFree(sbuf->data); + if (sbuf->impl != NULL && sbuf->impl->recycle != NULL) { + sbuf->impl->recycle(sbuf->impl); + sbuf->impl = NULL; } OsalMemFree(sbuf); } } + +struct HdfSbufImpl *HdfSbufGetImpl(struct HdfSBuf *sbuf) +{ + if (sbuf != NULL) { + return sbuf->impl; + } + + return NULL; +} \ No newline at end of file diff --git a/ability/sbuf/src/hdf_sbuf_impl_raw.c b/ability/sbuf/src/hdf_sbuf_impl_raw.c new file mode 100644 index 000000000..051eacb46 --- /dev/null +++ b/ability/sbuf/src/hdf_sbuf_impl_raw.c @@ -0,0 +1,553 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "hdf_log.h" +#include "hdf_sbuf.h" +#include "hdf_sbuf_impl.h" +#include "osal_mem.h" +#include "securec.h" + +#define HDF_SBUF_GROW_SIZE_DEFAULT 256 +#define HDF_SBUF_MAX_SIZE (512 * 1024) // 512KB +#define HDF_SBUF_ALIGN 4 + +#ifndef INT16_MAX +#ifdef S16_MAX +#define INT16_MAX S16_MAX +#else +#define INT16_MAX 32767 +#endif // !S16_MAX +#endif // INT16_MAX + +struct HdfSBufRaw { + struct HdfSbufImpl infImpl; + size_t writePos; /**< Current write position */ + size_t readPos; /**< Current read position */ + size_t capacity; /**< Storage capacity, 512 KB at most. */ + uint8_t *data; /**< Pointer to data storage */ + bool isBind; /**< Whether to bind the externally transferred pointer to data storage */ +}; + +#define SBUF_RAW_CAST(impl) (struct HdfSBufRaw *)(impl) + +static struct HdfSBufRaw *SbufRawImplNewInstance(size_t capacity); +static void SbufInterfaceAssign(struct HdfSbufImpl *inf); + +static size_t SbufRawImplGetAlignSize(size_t size) +{ + return (size + HDF_SBUF_ALIGN - 1) & (~(HDF_SBUF_ALIGN - 1)); +} + +static void SbufRawImplRecycle(struct HdfSbufImpl *impl) +{ + struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl); + if (sbuf != NULL) { + if (sbuf->data != NULL && !sbuf->isBind) { + OsalMemFree(sbuf->data); + } + OsalMemFree(sbuf); + } +} + +static size_t SbufRawImplGetLeftWriteSize(struct HdfSBufRaw *sbuf) +{ + return (sbuf->capacity < sbuf->writePos) ? 0 : (sbuf->capacity - sbuf->writePos); +} + +static size_t SbufRawImplGetLeftReadSize(struct HdfSBufRaw *sbuf) +{ + return (sbuf->writePos < sbuf->readPos) ? 0 : (sbuf->writePos - sbuf->readPos); +} + +static bool SbufRawImplWriteRollback(struct HdfSbufImpl *impl, uint32_t size) +{ + struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl); + if (sbuf == NULL) { + return false; + } + + size_t alignSize = SbufRawImplGetAlignSize(size); + if (sbuf->writePos < alignSize) { + return false; + } + + sbuf->writePos -= alignSize; + return true; +} + +static bool SbufRawImplReadRollback(struct HdfSbufImpl *impl, uint32_t size) +{ + struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl); + if (sbuf == NULL) { + return false; + } + + size_t alignSize = SbufRawImplGetAlignSize(size); + if (sbuf->readPos < alignSize) { + return false; + } + + sbuf->readPos -= alignSize; + return true; +} + +static const uint8_t *SbufRawImplGetData(const struct HdfSbufImpl *impl) +{ + struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl); + if (sbuf == NULL) { + HDF_LOGE("The obtained data is null, and the input Sbuf is null."); + return NULL; + } + return (uint8_t *)sbuf->data; +} + +static void SbufRawImplSetDataSize(struct HdfSbufImpl *impl, size_t size) +{ + struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl); + if (sbuf == NULL) { + return; + } + if (size <= sbuf->capacity) { + sbuf->readPos = 0; + sbuf->writePos = size; + } +} + +static void SbufRawImplFlush(struct HdfSbufImpl *impl) +{ + struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl); + if (sbuf != NULL) { + sbuf->readPos = 0; + sbuf->writePos = 0; + } +} + +static size_t SbufRawImplGetCapacity(const struct HdfSbufImpl *impl) +{ + struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl); + return (sbuf != NULL) ? sbuf->capacity : 0; +} + +static size_t SbufRawImplGetDataSize(const struct HdfSbufImpl *impl) +{ + struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl); + return (sbuf != NULL) ? sbuf->writePos : 0; +} + +static bool SbufRawImplGrow(struct HdfSBufRaw *sbuf, uint32_t growSize) +{ + if (sbuf->isBind) { + HDF_LOGE("%s: binded sbuf oom", __func__); + return false; + } + + uint32_t newSize = SbufRawImplGetAlignSize(sbuf->capacity + growSize); + if (newSize < sbuf->capacity) { + HDF_LOGE("%s: grow size overflow", __func__); + return false; + } + if (newSize > HDF_SBUF_MAX_SIZE) { + HDF_LOGE("%s: buf size over limit", __func__); + return false; + } + + uint8_t *newData = OsalMemCalloc(newSize); + if (newData == NULL) { + HDF_LOGE("%s: oom", __func__); + return false; + } + + if (sbuf->data != NULL) { + if (memcpy_s(newData, newSize, sbuf->data, sbuf->writePos) != EOK) { + OsalMemFree(newData); + return false; + } + OsalMemFree(sbuf->data); + } + + sbuf->data = newData; + sbuf->capacity = newSize; + + return true; +} + +static bool SbufRawImplWrite(struct HdfSbufImpl *impl, const uint8_t *data, uint32_t size) +{ + struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl); + if (sbuf == NULL || sbuf->data == NULL || data == NULL) { + return false; + } + + if (size == 0) { + return true; + } + + size_t alignSize = SbufRawImplGetAlignSize(size); + // in case of desireCapacity overflow + if (alignSize < size) { + HDF_LOGE("desireCapacity overflow"); + return false; + } + size_t writeableSize = SbufRawImplGetLeftWriteSize(sbuf); + if (alignSize > writeableSize) { + size_t growSize = (alignSize > HDF_SBUF_GROW_SIZE_DEFAULT) ? (alignSize + HDF_SBUF_GROW_SIZE_DEFAULT) + : HDF_SBUF_GROW_SIZE_DEFAULT; + if (!SbufRawImplGrow(sbuf, growSize)) { + return false; + } + writeableSize = SbufRawImplGetLeftWriteSize(sbuf); + } + + uint8_t *dest = sbuf->data + sbuf->writePos; + if (memcpy_s(dest, writeableSize, data, size) != EOK) { + return false; /* never hits */ + } + + sbuf->writePos += alignSize; + return true; +} + +static bool SbufRawImplRead(struct HdfSbufImpl *impl, uint8_t *data, uint32_t readSize) +{ + struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl); + if (sbuf == NULL || sbuf->data == NULL || data == NULL) { + return false; + } + + if (readSize == 0) { + return true; + } + + size_t alignSize = SbufRawImplGetAlignSize(readSize); + if (alignSize > SbufRawImplGetLeftReadSize(sbuf)) { + HDF_LOGE("Read out of buffer range"); + return false; + } + + if (memcpy_s(data, readSize, sbuf->data + sbuf->readPos, readSize) != EOK) { + return false; // never hit + } + sbuf->readPos += alignSize; + return true; +} + +static bool SbufRawImplWriteUint64(struct HdfSbufImpl *impl, uint64_t value) +{ + return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value)); +} + +static bool SbufRawImplWriteUint32(struct HdfSbufImpl *impl, uint32_t value) +{ + return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value)); +} + +static bool SbufRawImplWriteUint16(struct HdfSbufImpl *impl, uint16_t value) +{ + return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value)); +} + +static bool SbufRawImplWriteUint8(struct HdfSbufImpl *impl, uint8_t value) +{ + return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value)); +} + +static bool SbufRawImplWriteInt64(struct HdfSbufImpl *impl, int64_t value) +{ + return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value)); +} + +static bool SbufRawImplWriteInt32(struct HdfSbufImpl *impl, int32_t value) +{ + return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value)); +} + +static bool SbufRawImplWriteInt16(struct HdfSbufImpl *impl, int16_t value) +{ + return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value)); +} + +static bool SbufRawImplWriteInt8(struct HdfSbufImpl *impl, int8_t value) +{ + return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value)); +} + +static bool SbufRawImplWriteBuffer(struct HdfSbufImpl *impl, const uint8_t *data, uint32_t writeSize) +{ + if (impl == NULL) { + HDF_LOGE("Failed to write the Sbuf, invalid input params"); + return false; + } + if (data == NULL) { + return SbufRawImplWriteInt32(impl, 0); + } + + if (!SbufRawImplWriteInt32(impl, writeSize)) { + return false; + } + if (!SbufRawImplWrite(impl, data, writeSize)) { + (void)SbufRawImplWriteRollback(impl, sizeof(int32_t)); + return false; + } + + return true; +} + +static bool SbufRawImplWriteString(struct HdfSbufImpl *impl, const char *value) +{ + if (impl == NULL) { + HDF_LOGE("%s: input null", __func__); + return false; + } + + return SbufRawImplWriteBuffer(impl, (const uint8_t *)value, value ? (strlen(value) + 1) : 0); +} + +static bool SbufRawImplReadUint64(struct HdfSbufImpl *impl, uint64_t *value) +{ + return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value)); +} + +static bool SbufRawImplReadUint32(struct HdfSbufImpl *impl, uint32_t *value) +{ + return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value)); +} + +static bool SbufRawImplReadUint16(struct HdfSbufImpl *impl, uint16_t *value) +{ + return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value)); +} + +static bool SbufRawImplReadUint8(struct HdfSbufImpl *impl, uint8_t *value) +{ + return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value)); +} + +static bool SbufRawImplReadInt64(struct HdfSbufImpl *impl, int64_t *value) +{ + return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value)); +} + +static bool SbufRawImplReadInt32(struct HdfSbufImpl *impl, int32_t *value) +{ + return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value)); +} + +static bool SbufRawImplReadInt16(struct HdfSbufImpl *impl, int16_t *value) +{ + return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value)); +} + +static bool SbufRawImplReadInt8(struct HdfSbufImpl *impl, int8_t *value) +{ + return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value)); +} + +static bool SbufRawImplReadBuffer(struct HdfSbufImpl *impl, const uint8_t **data, uint32_t *readSize) +{ + struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl); + if (sbuf == NULL || sbuf->data == NULL || data == NULL || readSize == NULL) { + HDF_LOGE("%s: input invalid", __func__); + return false; + } + + int buffSize = 0; + if (!SbufRawImplReadInt32(impl, &buffSize)) { + return false; + } + + if (buffSize == 0) { + *data = NULL; + *readSize = 0; + return true; + } + size_t alignSize = SbufRawImplGetAlignSize(buffSize); + if (alignSize > SbufRawImplGetLeftReadSize(sbuf)) { + HDF_LOGE("%s:readBuff out of range", __func__); + (void)SbufRawImplReadRollback(impl, sizeof(int32_t)); + return false; + } + + *data = sbuf->data + sbuf->readPos; + *readSize = buffSize; + sbuf->readPos += alignSize; + return true; +} + +static const char *SbufRawImplReadString(struct HdfSbufImpl *impl) +{ + struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl); + if (sbuf == NULL || sbuf->data == NULL) { + HDF_LOGE("%s: input null", __func__); + return NULL; + } + /* This length contains the '\0' at the end of the string. */ + int32_t strLen = 0; + if (!SbufRawImplReadInt32(impl, &strLen) || strLen <= 0) { + return NULL; + } + size_t alignSize = SbufRawImplGetAlignSize(strLen); + if (strLen > INT16_MAX || alignSize > SbufRawImplGetLeftReadSize(sbuf)) { + (void)SbufRawImplReadRollback(impl, sizeof(int32_t)); + return NULL; + } + + char *str = (char *)(sbuf->data + sbuf->readPos); + sbuf->readPos += alignSize; + /* Set '\0' at end of the string forcibly. */ + str[strLen - 1] = '\0'; + return str; +} + +static struct HdfSbufImpl *SbufRawImplCopy(const struct HdfSbufImpl *impl) +{ + struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl); + if (sbuf == NULL || sbuf->data == NULL) { + return NULL; + } + + struct HdfSBufRaw *new = SbufRawImplNewInstance(sbuf->capacity); + if (new == NULL) { + return NULL; + } + new->capacity = sbuf->capacity; + new->readPos = 0; + new->writePos = sbuf->writePos; + if (memcpy_s(new->data, new->capacity, sbuf->data, sbuf->capacity) != EOK) { + SbufRawImplRecycle(&new->infImpl); + return NULL; + } + + return &new->infImpl; +} + +static struct HdfSbufImpl *SbufRawImplMove(struct HdfSbufImpl *impl) +{ + struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl); + if (sbuf == NULL || sbuf->isBind) { + return NULL; + } + + struct HdfSBufRaw *new = OsalMemCalloc(sizeof(struct HdfSBufRaw)); + if (new == NULL) { + return NULL; + } + new->capacity = sbuf->capacity; + new->readPos = 0; + new->writePos = sbuf->writePos; + new->data = sbuf->data; + + sbuf->data = NULL; + sbuf->capacity = 0; + SbufRawImplFlush(&sbuf->infImpl); + SbufInterfaceAssign(&new->infImpl); + + return &new->infImpl; +} + +static void SbufRawImplTransDataOwnership(struct HdfSbufImpl *impl) +{ + struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl); + if (sbuf == NULL) { + return; + } + + sbuf->isBind = false; +} + +static void SbufInterfaceAssign(struct HdfSbufImpl *inf) +{ + inf->writeBuffer = SbufRawImplWriteBuffer; + inf->writeUint64 = SbufRawImplWriteUint64; + inf->writeUint32 = SbufRawImplWriteUint32; + inf->writeUint16 = SbufRawImplWriteUint16; + inf->writeUint8 = SbufRawImplWriteUint8; + inf->writeInt64 = SbufRawImplWriteInt64; + inf->writeInt32 = SbufRawImplWriteInt32; + inf->writeInt16 = SbufRawImplWriteInt16; + inf->writeInt8 = SbufRawImplWriteInt8; + inf->writeString = SbufRawImplWriteString; + inf->readBuffer = SbufRawImplReadBuffer; + inf->readUint64 = SbufRawImplReadUint64; + inf->readUint32 = SbufRawImplReadUint32; + inf->readUint16 = SbufRawImplReadUint16; + inf->readUint8 = SbufRawImplReadUint8; + inf->readInt64 = SbufRawImplReadInt64; + inf->readInt32 = SbufRawImplReadInt32; + inf->readInt16 = SbufRawImplReadInt16; + inf->readInt8 = SbufRawImplReadInt8; + inf->readString = SbufRawImplReadString; + inf->getData = SbufRawImplGetData; + inf->flush = SbufRawImplFlush; + inf->getCapacity = SbufRawImplGetCapacity; + inf->getDataSize = SbufRawImplGetDataSize; + inf->setDataSize = SbufRawImplSetDataSize; + inf->recycle = SbufRawImplRecycle; + inf->move = SbufRawImplMove; + inf->copy = SbufRawImplCopy; + inf->transDataOwnership = SbufRawImplTransDataOwnership; +} + +static struct HdfSBufRaw *SbufRawImplNewInstance(size_t capacity) +{ + if (capacity > HDF_SBUF_MAX_SIZE) { + HDF_LOGE("%s: Sbuf size exceeding max limit", __func__); + return NULL; + } + struct HdfSBufRaw *sbuf = (struct HdfSBufRaw *)OsalMemCalloc(sizeof(struct HdfSBufRaw)); + if (sbuf == NULL) { + HDF_LOGE("Sbuf instance failure"); + return NULL; + } + + sbuf->data = (uint8_t *)OsalMemCalloc(capacity); + if (sbuf->data == NULL) { + OsalMemFree(sbuf); + HDF_LOGE("sbuf obtain memory oom, size=%u", (uint32_t)capacity); + return NULL; + } + sbuf->capacity = capacity; + sbuf->writePos = 0; + sbuf->readPos = 0; + sbuf->isBind = false; + SbufInterfaceAssign(&sbuf->infImpl); + return sbuf; +} + +struct HdfSbufImpl *SbufObtainRaw(size_t capacity) +{ + struct HdfSBufRaw *sbuf = SbufRawImplNewInstance(capacity); + if (sbuf == NULL) { + return NULL; + } + return &sbuf->infImpl; +} + +struct HdfSbufImpl *SbufBindRaw(uintptr_t base, size_t size) +{ + if (base == 0 || size == 0) { + return NULL; + } + /* 4-byte alignment is required for base. */ + if ((base & 0x3) != 0) { + HDF_LOGE("Base not in 4-byte alignment"); + return NULL; + } + struct HdfSBufRaw *sbuf = (struct HdfSBufRaw *)OsalMemAlloc(sizeof(struct HdfSBufRaw)); + if (sbuf == NULL) { + HDF_LOGE("%s: oom", __func__); + return NULL; + } + + sbuf->data = (uint8_t *)base; + sbuf->capacity = size; + sbuf->writePos = size; + sbuf->readPos = 0; + sbuf->isBind = true; + SbufInterfaceAssign(&sbuf->infImpl); + return &sbuf->infImpl; +} \ No newline at end of file -- Gitee