1 /*
2 Copyright (c) 2018, MIPI Alliance, Inc.
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 
9 * Redistributions of source code must retain the above copyright
10   notice, this list of conditions and the following disclaimer.
11 
12 * Redistributions in binary form must reproduce the above copyright
13   notice, this list of conditions and the following disclaimer in
14   the documentation and/or other materials provided with the
15   distribution.
16 
17 * Neither the name of the copyright holder nor the names of its
18   contributors may be used to endorse or promote products derived
19   from this software without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
34 /*
35  * Contributors:
36  * Norbert Schulz (Intel Corporation) - Initial API and implementation
37  */
38 
39 #include "mipi_syst_gtest.h"
40 
41 #if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA) &&\
42 	defined(MIPI_SYST_PCFG_ENABLE_DEFAULT_SCATTER_WRITE) &&\
43 	defined(MIPI_SYST_PCFG_ENABLE_WRITE_API)
44 
45 class MipiSysTFixtureRaw : public MipiSysTFixtureOutput
46 {
47 public:
SetUp()48 	void SetUp() {
49 		MipiSysTFixtureOutput::SetUp();
50 	}
51 
TearDown()52 	void TearDown(){
53 		MipiSysTFixtureOutput::TearDown();
54 	}
55 
mipi_syst_write_raw_message(struct mipi_syst_handle * svh,struct mipi_syst_msglocation * loc,enum mipi_syst_severity severity,mipi_syst_u8 subtype,const void * data,mipi_syst_u16 length)56 	const char * mipi_syst_write_raw_message(
57 	struct mipi_syst_handle* svh,
58 	struct mipi_syst_msglocation* loc,
59 		enum mipi_syst_severity severity,
60 		mipi_syst_u8    subtype,
61 		const void * data,
62 		mipi_syst_u16 length)
63 	{
64 		sstr.str("");
65 
66 		::mipi_syst_write_raw_message(svh, loc, severity, subtype, data, length);
67 		result = sstr.str();
68 
69 		return result.c_str();
70 	}
71 
72 	static std::string result;
73 };
74 
75 std::string MipiSysTFixtureRaw::result;
76 
TEST_F(MipiSysTFixtureRaw,syst_raw_nullptr)77 TEST_F(MipiSysTFixtureRaw, syst_raw_nullptr)
78 {
79 	EXPECT_STREQ(
80 		"",
81 		MIPI_SYST_WRITE(NULL, MIPI_SYST_SEVERITY_INFO, 0x3f, NULL, 0)
82 		);
83 
84 	EXPECT_STREQ(
85 		xform("<D32TS>3f012246[typ=6:3f mu=1:2 sev=4 len]<D16>0000<FLAG>"),
86 		MIPI_SYST_WRITE(ph, MIPI_SYST_SEVERITY_INFO, 0x3f, NULL, 0)
87 		);
88 }
89 
TEST_F(MipiSysTFixtureRaw,syst_raw_output)90 TEST_F(MipiSysTFixtureRaw, syst_raw_output)
91 {
92 	mipi_syst_u8 byte = 0xab;
93 	mipi_syst_u16 word =MIPI_SYST_HTOLE16(0xabcd);
94 	mipi_syst_u32 dword =MIPI_SYST_HTOLE32(0xaabbccdd);
95 	mipi_syst_u64 qword =MIPI_SYST_HTOLE64(0x1122aabbccddeeffull);
96 
97 	EXPECT_STREQ(
98 		xform("<D32TS>3f012246[typ=6:3f mu=1:2 sev=4 len]<D16>0001<D8>ab<FLAG>"),
99 		MIPI_SYST_WRITE(ph, MIPI_SYST_SEVERITY_INFO, 0x3f, &byte, 1)
100 		);
101 	EXPECT_STREQ(
102 		xform("<D32TS>3f012246[typ=6:3f mu=1:2 sev=4 len]<D16>0002<D16>abcd<FLAG>"),
103 		MIPI_SYST_WRITE(ph, MIPI_SYST_SEVERITY_INFO, 0x3f, &word, 2)
104 		);
105 	EXPECT_STREQ(
106 		xform("<D32TS>3f012246[typ=6:3f mu=1:2 sev=4 len]<D16>0004<D32>aabbccdd<FLAG>"),
107 		MIPI_SYST_WRITE(ph, MIPI_SYST_SEVERITY_INFO, 0x3f, &dword, 4)
108 		);
109 	EXPECT_STREQ(
110 		xform("<D32TS>3f012246[typ=6:3f mu=1:2 sev=4 len]<D16>0008<D64>1122aabbccddeeff<FLAG>"),
111 		MIPI_SYST_WRITE(ph, MIPI_SYST_SEVERITY_INFO, 0x3f, &qword, 8)
112 		);
113 
114 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD)
115 	EXPECT_STREQ(
116 		xform("<D32TS>3f012346[typ=6:3f mu=1:2 sev=4 loc len]<D8>00<D32>5678abcd<D16>0001<D8>ab<FLAG>"),
117 		MIPI_SYST_WRITE_LOC16(ph, MIPI_SYST_SEVERITY_INFO, 0xabcd, 0x3f,  &byte, 1)
118 		);
119 
120 	EXPECT_STREQ(
121 		xform("<D32TS>3f012346[typ=6:3f mu=1:2 sev=4 loc len]<D8>01<D64>12345678aabbccdd<D16>0001<D8>ab<FLAG>"),
122 		MIPI_SYST_WRITE_LOC32(ph, MIPI_SYST_SEVERITY_INFO, 0x12345678aabbccddull, 0x3f, &byte, 1)
123 		);
124 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS)
125 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR)
126 	EXPECT_STREQ(
127 		xform("<D32TS>3f012346[typ=6:3f mu=1:2 sev=4 loc len]<D8>03<D64>12345678aabbccdd<D16>0001<D8>ab<FLAG>"),
128 		MIPI_SYST_WRITE_LOCADDR(ph, MIPI_SYST_SEVERITY_INFO, 0x3f, &byte, 1)
129 		);
130 #else
131 	EXPECT_STREQ(
132 		xform("<D32TS>3f012346[typ=6:3f mu=1:2 sev=4 loc len]<D8>02<D32>12345678<D16>0001<D8>ab<FLAG>"),
133 		MIPI_SYST_WRITE_LOCADDR(ph, MIPI_SYST_SEVERITY_INFO, 0x3f, &byte, 1)
134 		);
135 #endif //MIPI_SYST_PCFG_ENABLE_64BIT_ADDR
136 #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS
137 #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD
138 }
139 
140 #endif //MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA && MIPI_SYST_PCFG_ENABLE_DEFAULT_SCATTER_WRITE && MIPI_SYST_PCFG_ENABLE_WRITE_API
141 
TEST_F(MipiSysTFixtureOutput,syst_short)142 TEST_F(MipiSysTFixtureOutput, syst_short)
143 {
144 	std::string str;
145 
146 	MIPI_SYST_SHORT32(ph, 0x02345678);
147 	str = sstr.str();
148 
149 	EXPECT_STREQ(
150 		xform("<D32MTS>23456781"),
151 		str.c_str()
152 	);
153 
154 	sstr.str("");
155 	MIPI_SYST_SHORT64(ph, 0x0122334455667788);
156 	str = sstr.str();
157 
158 	EXPECT_STREQ(
159 		xform("<D64MTS>1223344556677887"),
160 		str.c_str()
161 	);
162 }