1 /* 2 * \file pkt_printer_t.h 3 * \brief OpenCSD : Test packet printer. 4 * 5 * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved. 6 */ 7 8 /* 9 * Redistribution and use in source and binary forms, with or without modification, 10 * are permitted provided that the following conditions are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright notice, 13 * this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 19 * 3. Neither the name of the copyright holder nor the names of its contributors 20 * may be used to endorse or promote products derived from this software without 21 * specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #ifndef ARM_PKT_PRINTER_T_H_INCLUDED 36 #define ARM_PKT_PRINTER_T_H_INCLUDED 37 38 #include "opencsd.h" 39 40 #include <string> 41 #include <sstream> 42 #include <iostream> 43 #include <iomanip> 44 45 template<class P> 46 class PacketPrinter : public IPktDataIn<P>, public IPktRawDataMon<P>, public ItemPrinter 47 { 48 public: 49 PacketPrinter(const uint8_t trcID); 50 PacketPrinter(const uint8_t trcID, ocsdMsgLogger *pMsgLogger); 51 virtual ~PacketPrinter(); 52 53 54 virtual ocsd_datapath_resp_t PacketDataIn( const ocsd_datapath_op_t op, 55 const ocsd_trc_index_t index_sop, 56 const P *p_packet_in); 57 58 virtual void RawPacketDataMon( const ocsd_datapath_op_t op, 59 const ocsd_trc_index_t index_sop, 60 const P *pkt, 61 const uint32_t size, 62 const uint8_t *p_data); 63 64 65 private: 66 void printIdx_ID(const ocsd_trc_index_t index_sop); 67 68 uint8_t m_trcID; 69 bool m_bRawPrint; 70 std::ostringstream m_oss; 71 ocsd_datapath_resp_t m_last_resp; 72 73 }; 74 75 template<class P> PacketPrinter<P>::PacketPrinter(uint8_t trcID) : 76 m_trcID(trcID), 77 m_bRawPrint(false), 78 m_last_resp(OCSD_RESP_CONT) 79 { 80 } 81 82 template<class P> PacketPrinter<P>::PacketPrinter(const uint8_t trcID, ocsdMsgLogger *pMsgLogger) : 83 m_trcID(trcID), 84 m_bRawPrint(false), 85 m_last_resp(OCSD_RESP_CONT) 86 { 87 setMessageLogger(pMsgLogger); 88 } 89 90 template<class P> PacketPrinter<P>::~PacketPrinter() 91 { 92 } 93 94 template<class P> ocsd_datapath_resp_t PacketPrinter<P>::PacketDataIn( const ocsd_datapath_op_t op, 95 const ocsd_trc_index_t index_sop, 96 const P *p_packet_in) 97 { 98 std::string pktstr; 99 ocsd_datapath_resp_t resp = OCSD_RESP_CONT; 100 101 // wait / flush test verification 102 if(!m_bRawPrint && (m_last_resp == OCSD_RESP_WAIT)) 103 { 104 // expect a flush or a complete reset after a wait. 105 if((op != OCSD_OP_FLUSH) || (op != OCSD_OP_RESET)) 106 { 107 m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tERROR: FLUSH operation expected after wait on trace decode path\n"; 108 itemPrintLine(m_oss.str()); 109 m_oss.str(""); 110 return OCSD_RESP_FATAL_INVALID_OP; 111 } 112 } 113 114 switch(op) 115 { 116 case OCSD_OP_DATA: 117 p_packet_in->toString(pktstr); 118 if(!m_bRawPrint) 119 printIdx_ID(index_sop); 120 m_oss << ";\t" << pktstr << std::endl; 121 122 // test the wait/flush response mechnism 123 if(getTestWaits() && !m_bRawPrint) 124 { 125 decTestWaits(); 126 resp = OCSD_RESP_WAIT; 127 } 128 break; 129 130 case OCSD_OP_EOT: 131 m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tEND OF TRACE DATA\n"; 132 break; 133 134 case OCSD_OP_FLUSH: 135 m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tFLUSH operation on trace decode path\n"; 136 break; 137 138 case OCSD_OP_RESET: 139 m_oss <<"ID:"<< std::hex << (uint32_t)m_trcID << "\tRESET operation on trace decode path\n"; 140 break; 141 } 142 143 m_last_resp = resp; 144 itemPrintLine(m_oss.str()); 145 m_oss.str(""); 146 return resp; 147 } 148 149 template<class P> void PacketPrinter<P>::RawPacketDataMon( const ocsd_datapath_op_t op, 150 const ocsd_trc_index_t index_sop, 151 const P *pkt, 152 const uint32_t size, 153 const uint8_t *p_data) 154 { 155 switch(op) 156 { 157 case OCSD_OP_DATA: 158 printIdx_ID(index_sop); 159 m_oss << "; ["; 160 if((size > 0) && (p_data != 0)) 161 { 162 uint32_t data = 0; 163 for(uint32_t i = 0; i < size; i++) 164 { 165 data = (uint32_t)(p_data[i] & 0xFF); 166 m_oss << "0x" << std::hex << std::setw(2) << std::setfill('0') << data << " "; 167 } 168 } 169 m_oss << "]"; 170 m_bRawPrint = true; 171 PacketDataIn(op,index_sop,pkt); 172 m_bRawPrint = false; 173 break; 174 175 default: 176 PacketDataIn(op,index_sop,pkt); 177 break; 178 } 179 180 } 181 182 template<class P> void PacketPrinter<P>::printIdx_ID(const ocsd_trc_index_t index_sop) 183 { 184 m_oss << "Idx:" << std::dec << index_sop << "; ID:"<< std::hex << (uint32_t)m_trcID; 185 } 186 187 #endif // ARM_PKT_PRINTER_T_H_INCLUDED 188 189 /* End of File pkt_printer_t.h */ 190