123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- /*
- * Copyright (c) 2017,2020 The Linux Foundation. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * * Neither the name of The Linux Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <stdint.h>
- #include "hton.h" /* for htonl*/
- #include "DataPathTestFixture.h"
- #include "Constants.h"
- #include "TestsUtils.h"
- #include "linux/msm_ipa.h"
- #define PACKET_SIZE ((10)*(4))
- class IpaTxDpTest:public DataPathTestFixture {
- public:
- IpaTxDpTest() {
- m_name = "IpaTxDpTest";
- m_description = "Sending one SKB via ipa_tx_dp() and checking"
- "if it was received";
- m_runInRegression = true;
- }
- bool TestLogic() {
- LOG_MSG_DEBUG("Entering %s\n", __func__);
- int ret;
- unsigned char *input, *output;
- unsigned char pkt[PACKET_SIZE] = {
- 0x59, 0x61, 0x6e, 0x69,
- 0x76, 0x5f, 0x48 ,0x61,
- 0x73 ,0x62 ,0x61 ,0x6e,
- 0x69 ,0x5f ,0x54 ,0x68,
- 0x65 ,0x5f ,0x47 ,0x72,
- 0x65 ,0x61 ,0x74 ,0x16,
- 0x32 ,0x49 ,0x0c ,0x3f,
- 0x37 ,0x23 ,0x6d ,0x15,
- 0x50 ,0x10 ,0x3f ,0xbd,
- 0xcc ,0xd8 ,0x00, 0x00
- };
- input = (unsigned char *)malloc(PACKET_SIZE);
- if(!input) {
- LOG_MSG_ERROR("Error in allocation\n");
- goto fail;
- }
- output = (unsigned char *)malloc(PACKET_SIZE);
- if(!output) {
- LOG_MSG_ERROR("Error in allocation\n");
- free(input);
- goto fail;
- }
- memcpy(input, pkt, PACKET_SIZE);
- LOG_MSG_DEBUG("Sending packet through ipa_tx_dp() in func %s\n", __func__);
- ret = m_IpaDriverPipe.Send(input, PACKET_SIZE);
- if (ret != PACKET_SIZE) {
- LOG_MSG_ERROR(
- "Amount of bits sent are: %d instead of %d\nExiting..\n"
- , ret
- , PACKET_SIZE);
- free(input);
- free(output);
- goto fail;
- }
- ret = m_FromIPAPipe.Receive(output, PACKET_SIZE);
- if (ret != PACKET_SIZE) {
- LOG_MSG_ERROR(
- "Amount of bits sent are: %d instead of %d\nExiting..\n",
- ret,
- PACKET_SIZE);
- free(input);
- free(output);
- goto fail;
- }
- LOG_MSG_INFO("Input buff:\n");
- print_buff(input, PACKET_SIZE);
- LOG_MSG_INFO("Output buff:\n");
- print_buff(output, PACKET_SIZE);
- if (memcmp(input,output, PACKET_SIZE)) {
- free(input);
- free(output);
- return false;
- }
- free(input);
- free(output);
- return true;
- fail:
- return false;
- }
- };
- class IpaTxDpMultipleTest:public DataPathTestFixture {
- public:
- IpaTxDpMultipleTest() {
- m_name = "IpaTxDpMultipleTest";
- m_description = "Sending multiple SKB via ipa_tx_dp() and checking"
- "if it was received";
- m_runInRegression = false;
- }
- bool TestLogic() {
- int packet_to_send = 10;
- int loop_size = 100;
- int i;
- int j;
- LOG_MSG_DEBUG("Entering %s\n", __func__);
- int ret;
- unsigned char *input, *output;
- unsigned char pkt[PACKET_SIZE] = {
- 0x59, 0x61, 0x6e, 0x69,
- 0x76, 0x5f, 0x48 ,0x61,
- 0x73 ,0x62 ,0x61 ,0x6e,
- 0x69 ,0x5f ,0x54 ,0x68,
- 0x65 ,0x5f ,0x47 ,0x72,
- 0x65 ,0x61 ,0x74 ,0x16,
- 0x32 ,0x49 ,0x0c ,0x3f,
- 0x37 ,0x23 ,0x6d ,0x15,
- 0x50 ,0x10 ,0x3f ,0xbd,
- 0xcc ,0xd8 ,0x00, 0x00
- };
- input = (unsigned char *)malloc(PACKET_SIZE);
- if(!input) {
- LOG_MSG_ERROR("Error in allocation\n");
- goto fail;
- }
- output = (unsigned char *)malloc(PACKET_SIZE);
- if(!output) {
- LOG_MSG_ERROR("Error in allocation\n");
- free(input);
- goto fail;
- }
- memcpy(input, pkt, PACKET_SIZE);
- for (i = 0; i < loop_size; i++) {
- for (j = 0; j < packet_to_send; j++) {
- input[0] = i;
- input[1] = j;
- LOG_MSG_DEBUG("Sending packet through ipa_tx_dp() in func %s\n", __func__);
- ret = m_IpaDriverPipe.Send(input, PACKET_SIZE);
- if (ret != PACKET_SIZE) {
- LOG_MSG_ERROR(
- "Amount of bits sent are: %d instead of %d\nExiting..\n"
- , ret
- , PACKET_SIZE);
- free(input);
- free(output);
- goto fail;
- }
- }
- for (j = 0; j < packet_to_send; j++) {
- ret = m_FromIPAPipe.Receive(output, PACKET_SIZE);
- if (ret != PACKET_SIZE) {
- LOG_MSG_ERROR(
- "Amount of bits sent are: %d instead of %d\nExiting..\n",
- ret,
- PACKET_SIZE);
- free(input);
- free(output);
- goto fail;
- }
- input[0] = i;
- input[1] = j;
- LOG_MSG_INFO("Input buff:\n");
- print_buff(input, PACKET_SIZE);
- LOG_MSG_INFO("Output buff:\n");
- print_buff(output, PACKET_SIZE);
- if (memcmp(input,output, PACKET_SIZE)) {
- free(input);
- free(output);
- LOG_MSG_ERROR("Failed in buffers comparison");
- return false;
- }
- }
- }
- free(input);
- free(output);
- return true;
- fail:
- return false;
- }
- };
- class IPAToAppsTest:public DataPathTestFixture {
- public:
- IPAToAppsTest() {
- m_name = "IPAToApps";
- m_description = "Sending one SKB via USB_PROD pipe and checking"
- "if it was received";
- m_runInRegression = true;
- }
- bool TestLogic() {
- int ret;
- unsigned char *input, *output;
- unsigned char pkt[PACKET_SIZE] = {
- 0x59, 0x61, 0x6e, 0x69,
- 0x76, 0x5f, 0x48 ,0x61,
- 0x73 ,0x62 ,0x61 ,0x6e,
- 0x69 ,0x5f ,0x54 ,0x68,
- 0x65 ,0x5f ,0x47 ,0x72,
- 0x65 ,0x61 ,0x74 ,0x16,
- 0x32 ,0x49 ,0x0c ,0x3f,
- 0x37 ,0x23 ,0x6d ,0x15,
- 0x50 ,0x10 ,0x3f ,0xbd,
- 0xcc ,0xd8 ,0x00, 0x00
- };
- input = (unsigned char *)malloc(PACKET_SIZE);
- if(!input) {
- LOG_MSG_ERROR("Error in allocation\n");
- goto fail;
- }
- output = (unsigned char *)malloc(PACKET_SIZE);
- if(!output) {
- LOG_MSG_ERROR("Error in allocation\n");
- free(input);
- goto fail;
- }
- memcpy(input, pkt, PACKET_SIZE);
- LOG_MSG_DEBUG("Sending packet through USB_PROD pipe in func %s\n", __func__);
- ret = m_ToIpaPipe.Send(input, PACKET_SIZE);
- if (ret != PACKET_SIZE) {
- LOG_MSG_ERROR(
- "Amount of bits sent are: %d instead of %d\nExiting..\n",
- ret,
- PACKET_SIZE);
- goto fail;
- }
- LOG_MSG_DEBUG("Reading packet through Dummy Endpoint pipe in func %s\n", __func__);
- ret = m_IpaDriverPipe.Receive(output, PACKET_SIZE);
- if (ret != 0) {
- LOG_MSG_ERROR("Failed in reading buffer. %d error", ret);
- free(input);
- free(output);
- goto fail;
- }
- LOG_MSG_DEBUG("SKB original packet:\n");
- print_buff(input, PACKET_SIZE);
- LOG_MSG_DEBUG("SKB received packet:\n");
- print_buff(output, PACKET_SIZE);
- if (memcmp(input,output, PACKET_SIZE)) {
- free(input);
- free(output);
- return false;
- }
- free(input);
- free(output);
- return true;
- fail:
- return false;
- }
- };
- class IPAToAppsMultipleTest:public DataPathTestFixture {
- public:
- IPAToAppsMultipleTest() {
- m_name = "IPAToAppsMultipleTest";
- m_description = "Sending multiple SKB via USB_PROD pipe and checking"
- "if they was received";
- m_runInRegression = false;
- }
- bool TestLogic() {
- int packet_to_send = 10;
- int loop_size = 100;
- int i;
- int j;
- int ret;
- unsigned char *input, *output;
- unsigned char pkt[PACKET_SIZE] = {
- 0x59, 0x61, 0x6e, 0x69,
- 0x76, 0x5f, 0x48 ,0x61,
- 0x73 ,0x62 ,0x61 ,0x6e,
- 0x69 ,0x5f ,0x54 ,0x68,
- 0x65 ,0x5f ,0x47 ,0x72,
- 0x65 ,0x61 ,0x74 ,0x16,
- 0x32 ,0x49 ,0x0c ,0x3f,
- 0x37 ,0x23 ,0x6d ,0x15,
- 0x50 ,0x10 ,0x3f ,0xbd,
- 0xcc ,0xd8 ,0x00, 0x00
- };
- input = (unsigned char *)malloc(PACKET_SIZE);
- if(!input) {
- LOG_MSG_ERROR("Error in allocation\n");
- goto fail;
- }
- output = (unsigned char *)malloc(PACKET_SIZE);
- if(!output) {
- LOG_MSG_ERROR("Error in allocation\n");
- free(input);
- goto fail;
- }
- memcpy(input, pkt, PACKET_SIZE);
- for (i = 0; i < loop_size; i++) {
- for (j = 0; j < packet_to_send; j++) {
- input[0] = i;
- input[1] = j;
- LOG_MSG_DEBUG("Sending packet through USB_PROD pipe in func %s\n", __func__);
- ret = m_ToIpaPipe.Send(input, PACKET_SIZE);
- if (ret != PACKET_SIZE) {
- LOG_MSG_ERROR(
- "Amount of bits sent are: %d instead of %d\nExiting..\n",
- ret,
- PACKET_SIZE);
- free(input);
- free(output);
- goto fail;
- }
- }
- for (j = 0; j < packet_to_send; j++) {
- input[0] = i;
- input[1] = j;
- LOG_MSG_DEBUG("Reading packet through Dummy Endpoint pipe in func %s\n", __func__);
- ret = m_IpaDriverPipe.Receive(output, PACKET_SIZE);
- if (ret != 0) {
- LOG_MSG_ERROR("Failed in reading buffer. %d error", ret);
- free(input);
- free(output);
- goto fail;
- }
- LOG_MSG_DEBUG("SKB original packet:\n");
- print_buff(input, PACKET_SIZE);
- LOG_MSG_DEBUG("SKB received packet:\n");
- print_buff(output, PACKET_SIZE);
- if (memcmp(input,output, PACKET_SIZE)) {
- free(input);
- free(output);
- LOG_MSG_ERROR("Failed in buffers comparison");
- return false;
- }
- }
- }
- free(input);
- free(output);
- return true;
- fail:
- return false;
- }
- };
- static IpaTxDpTest ipaTxDpTest;
- static IpaTxDpMultipleTest ipaTxDpMultipleTest;
- static IPAToAppsTest ipaToApps;
- static IPAToAppsMultipleTest iPAToAppsMultipleTestApps;
|