From 253428ee49e901e3d86122478ba6842005b71fda Mon Sep 17 00:00:00 2001 From: Ilia Lin Date: Thu, 6 May 2021 11:38:16 +0300 Subject: [PATCH] ipa-kernel-tests: Pull latest changes Updating the kernel tests to the latest sha1 form the old project: 367590c22ab9d77f22290f0b11bd55b8c9e050cd Specifically porting the changes: 1. I93a09b45ac1e04107ddf0f5af0782251e45dfaaf 2. Ic816ed3da12cb82a23a745467d6ed818ce569492 Change-Id: I71fe69ba02f3134d3ab9d2a8d5cf6b95ef7694ef Signed-off-by: Ilia Lin --- .../ipa_test_module/ipa_test_module_impl.c | 10 ++--- ipanat/src/ipa_ipv6ct.c | 43 +++++++------------ ipanat/src/ipa_mem_descriptor.c | 2 +- ipanat/src/ipa_table.c | 10 ++++- kernel-tests/DataPathTests.cpp | 4 +- kernel-tests/main.cpp | 20 +++++++-- 6 files changed, 48 insertions(+), 41 deletions(-) diff --git a/drivers/platform/msm/ipa/ipa_test_module/ipa_test_module_impl.c b/drivers/platform/msm/ipa/ipa_test_module/ipa_test_module_impl.c index 1f236ac62b..eb087eb41b 100644 --- a/drivers/platform/msm/ipa/ipa_test_module/ipa_test_module_impl.c +++ b/drivers/platform/msm/ipa/ipa_test_module/ipa_test_module_impl.c @@ -532,14 +532,14 @@ int create_channel_device_by_type( /* Add a pointer from the channel device to the test context info */ channel_dev->test = ipa_test; - channel_dev->class = class_create(THIS_MODULE, name); + channel_dev->class = class_create(THIS_MODULE, channel_dev->name); if (IS_ERR(channel_dev->class)) { IPATEST_ERR(":class_create() err.\n"); ret = -ENOMEM; goto create_class_failure; } - ret = alloc_chrdev_region(&channel_dev->dev_num, 0, 1, name); + ret = alloc_chrdev_region(&channel_dev->dev_num, 0, 1, channel_dev->name); if (ret) { IPATEST_ERR("alloc_chrdev_region err.\n"); ret = -ENOMEM; @@ -547,7 +547,7 @@ int create_channel_device_by_type( } channel_dev->dev = device_create(channel_dev->class, NULL, - channel_dev->dev_num, channel_dev, name); + channel_dev->dev_num, channel_dev, channel_dev->name); if (IS_ERR(channel_dev->dev)) { IPATEST_ERR("device_create err.\n"); ret = -ENODEV; @@ -576,7 +576,7 @@ int create_channel_device_by_type( if (!ret) IPATEST_DBG("Channel device:%d, name:%s created, address:0x%px.\n", - index, name, channel_dev); + index, channel_dev->name, channel_dev); return 0; @@ -593,7 +593,7 @@ create_class_failure: create_channel_device_failure: kfree(channel_dev); IPATEST_ERR("Channel device %d, name %s creation FAILED.\n", - index, name); + index, channel_dev->name); return ret; } diff --git a/ipanat/src/ipa_ipv6ct.c b/ipanat/src/ipa_ipv6ct.c index 9420468b4c..cb7a6b05b2 100644 --- a/ipanat/src/ipa_ipv6ct.c +++ b/ipanat/src/ipa_ipv6ct.c @@ -38,6 +38,8 @@ #define IPA_IPV6CT_DEBUG_FILE_PATH "/sys/kernel/debug/ipa/ipv6ct" #define IPA_UC_ACT_DEBUG_FILE_PATH "/sys/kernel/debug/ipa/uc_act_table" #define IPA_IPV6CT_TABLE_NAME "IPA IPv6CT table" +#define IPA_MAX_DMA_ENTRIES_FOR_ADD 2 +#define IPA_MAX_DMA_ENTRIES_FOR_DEL 2 static int ipa_ipv6ct_create_table(ipa_ipv6ct_table* ipv6ct_table, uint16_t number_of_entries, uint8_t table_index); static int ipa_ipv6ct_destroy_table(ipa_ipv6ct_table* ipv6ct_table); @@ -213,6 +215,9 @@ int ipa_ipv6ct_add_rule(uint32_t table_handle, const ipa_ipv6ct_rule* user_rule, ipa_ipv6ct_table* ipv6ct_table; uint16_t new_entry_index; uint32_t new_entry_handle; + uint32_t cmd_sz = sizeof(struct ipa_ioc_nat_dma_cmd) + + (IPA_MAX_DMA_ENTRIES_FOR_ADD * sizeof(struct ipa_ioc_nat_dma_one)); + char cmd_buf[cmd_sz]; struct ipa_ioc_nat_dma_cmd* cmd; IPADBG("\n"); @@ -252,24 +257,16 @@ int ipa_ipv6ct_add_rule(uint32_t table_handle, const ipa_ipv6ct_rule* user_rule, goto unlock; } - cmd = (struct ipa_ioc_nat_dma_cmd *)calloc(1, - sizeof(struct ipa_ioc_nat_dma_cmd) + - (MAX_DMA_ENTRIES_FOR_ADD * sizeof(struct ipa_ioc_nat_dma_one))); - if (cmd == NULL) - { - IPAERR("unable to allocate memory for Talbe DMA command\n"); - ret = -ENOMEM; - goto unlock; - } + memset(cmd_buf, 0, sizeof(cmd_buf)); + cmd = (struct ipa_ioc_nat_dma_cmd*) cmd_buf; cmd->entries = 0; - new_entry_index = ipa_ipv6ct_hash(user_rule, ipv6ct_table->table.table_entries - 1); ret = ipa_table_add_entry(&ipv6ct_table->table, (void*)user_rule, &new_entry_index, &new_entry_handle, cmd); if (ret) { IPAERR("failed to add a new IPV6CT entry\n"); - goto fail_add_entry; + goto unlock; } ret = ipa_ipv6ct_post_dma_cmd(cmd); @@ -278,7 +275,6 @@ int ipa_ipv6ct_add_rule(uint32_t table_handle, const ipa_ipv6ct_rule* user_rule, IPAERR("unable to post dma command\n"); goto bail; } - free(cmd); if (pthread_mutex_unlock(&ipv6ct_mutex)) { @@ -293,8 +289,6 @@ int ipa_ipv6ct_add_rule(uint32_t table_handle, const ipa_ipv6ct_rule* user_rule, bail: ipa_table_erase_entry(&ipv6ct_table->table, new_entry_index); -fail_add_entry: - free(cmd); unlock: if (pthread_mutex_unlock(&ipv6ct_mutex)) IPAERR("unable to unlock the ipv6ct mutex\n"); @@ -304,9 +298,12 @@ unlock: int ipa_ipv6ct_del_rule(uint32_t table_handle, uint32_t rule_handle) { ipa_ipv6ct_table* ipv6ct_table; - struct ipa_ioc_nat_dma_cmd* cmd; ipa_table_iterator table_iterator; ipa_ipv6ct_hw_entry* entry; + uint32_t cmd_sz = sizeof(struct ipa_ioc_nat_dma_cmd) + + (IPA_MAX_DMA_ENTRIES_FOR_DEL * sizeof(struct ipa_ioc_nat_dma_one)); + char cmd_buf[cmd_sz]; + struct ipa_ioc_nat_dma_cmd* cmd; uint16_t index; int ret; @@ -356,15 +353,8 @@ int ipa_ipv6ct_del_rule(uint32_t table_handle, uint32_t rule_handle) goto unlock; } - cmd = (struct ipa_ioc_nat_dma_cmd *)calloc(1, - sizeof(struct ipa_ioc_nat_dma_cmd) + - (MAX_DMA_ENTRIES_FOR_DEL * sizeof(struct ipa_ioc_nat_dma_one))); - if (cmd == NULL) - { - IPAERR("unable to allocate memory for Talbe DMA command\n"); - ret = -ENOMEM; - goto unlock; - } + memset(cmd_buf, 0, sizeof(cmd_buf)); + cmd = (struct ipa_ioc_nat_dma_cmd*) cmd_buf; cmd->entries = 0; ipa_table_create_delete_command(&ipv6ct_table->table, cmd, &table_iterator); @@ -373,7 +363,7 @@ int ipa_ipv6ct_del_rule(uint32_t table_handle, uint32_t rule_handle) if (ret) { IPAERR("unable to post dma command\n"); - goto fail; + goto unlock; } if (!ipa_table_iterator_is_head_with_tail(&table_iterator)) @@ -384,9 +374,6 @@ int ipa_ipv6ct_del_rule(uint32_t table_handle, uint32_t rule_handle) ipa_table_delete_entry(&ipv6ct_table->table, &table_iterator, is_prev_empty); } -fail: - free(cmd); - unlock: if (pthread_mutex_unlock(&ipv6ct_mutex)) { diff --git a/ipanat/src/ipa_mem_descriptor.c b/ipanat/src/ipa_mem_descriptor.c index d7fdc82e0a..4ef5343464 100644 --- a/ipanat/src/ipa_mem_descriptor.c +++ b/ipanat/src/ipa_mem_descriptor.c @@ -145,7 +145,7 @@ static int MapMemory( if (ipa_dev_dir_path_len >= IPA_RESOURCE_NAME_MAX) { IPAERR("Unable to copy a string with size %d to buffer with size %d\n", - ipa_dev_dir_path_len, IPA_RESOURCE_NAME_MAX); + (int)ipa_dev_dir_path_len, IPA_RESOURCE_NAME_MAX); ret = -EINVAL; goto bail; } diff --git a/ipanat/src/ipa_table.c b/ipanat/src/ipa_table.c index 902fc8aa14..0d415b7d32 100644 --- a/ipanat/src/ipa_table.c +++ b/ipanat/src/ipa_table.c @@ -203,13 +203,19 @@ uint8_t* ipa_table_calculate_addresses( void ipa_table_reset( ipa_table* table) { + uint32_t i,tot; + IPADBG("In\n"); IPADBG("memset %s table to 0, %pK\n", table->name, table->table_addr); - memset(table->table_addr, 0, table->entry_size * table->table_entries); + tot = table->entry_size * table->table_entries; + for (i = 0; i < tot; i++) + table->table_addr[i] = '\0'; IPADBG("memset %s expn table to 0, %pK\n", table->name, table->expn_table_addr); - memset(table->expn_table_addr, 0, table->entry_size * table->expn_table_entries); + tot = table->entry_size * table->expn_table_entries; + for (i = 0; i < tot; i++) + table->expn_table_addr[i] = '\0'; IPADBG("Out\n"); } diff --git a/kernel-tests/DataPathTests.cpp b/kernel-tests/DataPathTests.cpp index e9a629d7af..8d3290c1a8 100644 --- a/kernel-tests/DataPathTests.cpp +++ b/kernel-tests/DataPathTests.cpp @@ -54,7 +54,7 @@ public: LOG_MSG_DEBUG("Entering %s\n", __func__); int ret; unsigned char *input, *output; - char pkt[PACKET_SIZE] = { + unsigned char pkt[PACKET_SIZE] = { 0x59, 0x61, 0x6e, 0x69, 0x76, 0x5f, 0x48 ,0x61, 0x73 ,0x62 ,0x61 ,0x6e, @@ -142,7 +142,7 @@ public: LOG_MSG_DEBUG("Entering %s\n", __func__); int ret; unsigned char *input, *output; - char pkt[PACKET_SIZE] = { + unsigned char pkt[PACKET_SIZE] = { 0x59, 0x61, 0x6e, 0x69, 0x76, 0x5f, 0x48 ,0x61, 0x73 ,0x62 ,0x61 ,0x6e, diff --git a/kernel-tests/main.cpp b/kernel-tests/main.cpp index ff57c097c1..7f83a9feb0 100644 --- a/kernel-tests/main.cpp +++ b/kernel-tests/main.cpp @@ -91,6 +91,7 @@ const char *ipa_hw_type_name[] = { "4.5", "4.9", "5.0", + "5.1", "MAX" }; @@ -199,10 +200,15 @@ int chooserMode() { const char* res; int result = 0; char input_str[4]; + char* temp; printf("Welcome to the ip_accelerator\nChoose an option:\n"); printf("1) Run tests\n2) Run suites\n3) Exit\nChoose an option: "); - res = fgets(input_str, sizeof(input_str), stdin); + temp = fgets(input_str, sizeof(input_str), stdin); + if (!temp) { + printf("Error: fgets returned nullptr !!"); + return -1; + } type = atoi(input_str); switch((enum ipa_test_type)type) { case TEST: @@ -210,7 +216,11 @@ int chooserMode() { showTests(); printf("Choose which test you wish to run: \n"); fflush(stdin); - res = fgets(input_str, sizeof(input_str), stdin); + temp = fgets(input_str, sizeof(input_str), stdin); + if (!temp) { + printf("Error: fgets returned nullptr !!"); + return -1; + } test_num = atoi(input_str); if ( test_num > testmanager->m_testList.size()) { printf("Invalid test number. Try again\n"); @@ -231,7 +241,11 @@ int chooserMode() { showSuits(); printf("Choose which suite you wish to run: \n"); fflush(stdin); - res = fgets(input_str, sizeof(input_str), stdin); + temp = fgets(input_str, sizeof(input_str), stdin); + if (!temp) { + printf("Error: fgets returned nullptr !!"); + return -1; + } suite_num = atoi(input_str); if (suite_num < 0 || suite_num > MAX_SUITES) { printf("Invalid test number. Try again\n");