UlsoTestFixture.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (c) 2021 The Linux Foundation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above
  10. * copyright notice, this list of conditions and the following
  11. * disclaimer in the documentation and/or other materials provided
  12. * with the distribution.
  13. * * Neither the name of The Linux Foundation nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  21. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  26. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  27. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef ULSOTESTFIXTURE_H_
  30. #define ULSOTESTFIXTURE_H_
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <unistd.h>
  34. #include <string.h>
  35. #include <stdint.h>
  36. #include <linux/if_ether.h>
  37. #include "Constants.h"
  38. #include "Logger.h"
  39. #include "linux/msm_ipa.h"
  40. #include "TestsUtils.h"
  41. #include "TestBase.h"
  42. #include "network_traffic/UlsoPacket.h"
  43. using std::cout;
  44. using std::endl;
  45. using std::string;
  46. class UlsoTestFixture: public TestBase {
  47. public:
  48. UlsoTestFixture(){
  49. m_testSuiteName.push_back("ULSO");
  50. memset(m_sendBuf, 0, sizeof(m_sendBuf));
  51. memset(m_receiveBuf, 0, sizeof(m_receiveBuf));
  52. memset(m_segmentBuf, 0, sizeof(m_segmentBuf));
  53. }
  54. virtual bool Setup() {
  55. if(!setupKernelModule()){
  56. return false;
  57. }
  58. m_producer.Open(INTERFACE0_TO_IPA_DATA_PATH, INTERFACE0_FROM_IPA_DATA_PATH);
  59. m_consumer.Open(INTERFACE1_TO_IPA_DATA_PATH, INTERFACE1_FROM_IPA_DATA_PATH);
  60. return true;
  61. }
  62. virtual bool Teardown(){
  63. m_producer.Close();
  64. m_consumer.Close();
  65. return true;
  66. }
  67. virtual bool Run() = 0;
  68. protected:
  69. virtual void configFromEp(struct test_ipa_ep_cfg *ep_cfg){
  70. return;
  71. }
  72. size_t clearPipe(){
  73. cout << "In clearPipe" << endl;
  74. if(m_consumer.setReadNoBlock() == -1){
  75. cout << "Error: setReadNoBlock returned -1" << endl;
  76. return 0;
  77. }
  78. size_t recievedBytes = m_consumer.ReceiveSingleDataChunk(m_receiveBuf, UlsoPacket<>::maxSize);
  79. size_t totalReceivedBytes = recievedBytes;
  80. if(recievedBytes > 0){
  81. unsigned count = 1;
  82. while(recievedBytes){
  83. cout << "Receive #" << count << endl;
  84. printBuf(m_receiveBuf, recievedBytes, string("Rceived ")
  85. + std::to_string(recievedBytes) + string(" Bytes:"));
  86. recievedBytes = m_consumer.ReceiveSingleDataChunk(m_receiveBuf, UlsoPacket<>::maxSize);
  87. totalReceivedBytes += recievedBytes;
  88. count ++;
  89. }
  90. } else {
  91. cout << "There were no bytes left in the pipe" << endl;
  92. }
  93. m_consumer.clearReadNoBlock();
  94. return totalReceivedBytes;
  95. }
  96. bool fail(size_t sendSize=0, size_t totalSegmentsSize=0, size_t recievedBytes=0){
  97. printBuf(m_sendBuf, sendSize, "Sent:");
  98. printBuf(m_receiveBuf, recievedBytes, string("Rceived ") + std::to_string(recievedBytes) + string(" Bytes:"));
  99. printBuf(m_segmentBuf, totalSegmentsSize, string("Expected to receive ") + std::to_string(totalSegmentsSize) + string(" Bytes:"));
  100. clearPipe();
  101. return false;
  102. }
  103. virtual int setupKernelModule(bool en_status = 0){
  104. struct ipa_channel_config from_ipa_channels[1];
  105. struct test_ipa_ep_cfg from_ipa_cfg[1];
  106. struct ipa_channel_config to_ipa_channels[1];
  107. struct test_ipa_ep_cfg to_ipa_cfg[1];
  108. struct ipa_test_config_header header = {0};
  109. struct ipa_channel_config *to_ipa_array[1];
  110. struct ipa_channel_config *from_ipa_array[1];
  111. /* From ipa configurations - 1 pipe */
  112. memset(&from_ipa_cfg[0], 0, sizeof(from_ipa_cfg[0]));
  113. from_ipa_cfg[0].ulso.is_ulso_pipe = true;
  114. configFromEp(&from_ipa_cfg[0]);
  115. prepare_channel_struct(&from_ipa_channels[0],
  116. header.from_ipa_channels_num++,
  117. IPA_CLIENT_TEST_CONS,
  118. (void *)&from_ipa_cfg[0],
  119. sizeof(from_ipa_cfg[0]),
  120. en_status);
  121. from_ipa_array[0] = &from_ipa_channels[0];
  122. /* To ipa configurations - 1 pipe */
  123. memset(&to_ipa_cfg[0], 0, sizeof(to_ipa_cfg[0]));
  124. to_ipa_cfg[0].ulso.ipid_min_max_idx = 0;
  125. to_ipa_cfg[0].ulso.is_ulso_pipe = true;
  126. prepare_channel_struct(&to_ipa_channels[0],
  127. header.to_ipa_channels_num++,
  128. IPA_CLIENT_TEST_PROD,
  129. (void *)&to_ipa_cfg[0],
  130. sizeof(to_ipa_cfg[0]));
  131. to_ipa_array[0] = &to_ipa_channels[0];
  132. prepare_header_struct(&header, from_ipa_array, to_ipa_array);
  133. return GenericConfigureScenario(&header, true);
  134. }
  135. protected:
  136. static void printBuf(uint8_t* buf, size_t bufSize, string title=""){
  137. if(bufSize == 0){
  138. return;
  139. }
  140. cout << title << endl << std::hex;
  141. for (size_t i = 0; i < bufSize-1; i++)
  142. cout << std::setfill('0') << std::setw(2) << static_cast<int>(buf[i]) << " ";
  143. cout << std::setfill('0') << std::setw(2) << static_cast<int>(buf[bufSize-1]) << std::dec << endl;
  144. }
  145. public:
  146. InterfaceAbstraction m_producer;
  147. InterfaceAbstraction m_consumer;
  148. uint8_t m_sendBuf[UlsoPacket<>::maxSize];
  149. uint8_t m_receiveBuf[UlsoPacket<>::maxSize];
  150. uint8_t m_segmentBuf[UlsoPacket<>::maxSize];
  151. };
  152. #endif /* ULSOTESTFIXTURE_H_ */