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_TIMESTAMP) &&\
44 defined(MIPI_SYST_PCFG_ENABLE_BUILD_API)
45
46 class MipiSysTFixtureBuild : public MipiSysTFixtureOutput
47 {
48 public:
SetUp()49 void SetUp() {
50 MipiSysTFixtureOutput::SetUp();
51 }
52
TearDown()53 void TearDown(){
54 MipiSysTFixtureOutput::TearDown();
55 }
56
mipi_syst_write_build_message(struct mipi_syst_handle * svh,struct mipi_syst_msglocation * loc,enum mipi_syst_severity severity,mipi_syst_u64 subtype,const char * data,mipi_syst_u16 length)57 const char * mipi_syst_write_build_message(
58 struct mipi_syst_handle* svh,
59 struct mipi_syst_msglocation* loc,
60 enum mipi_syst_severity severity,
61 mipi_syst_u64 subtype,
62 const char * data,
63 mipi_syst_u16 length)
64 {
65 sstr.str("");
66
67 ::mipi_syst_write_build_message(svh, loc, severity, subtype, data, length);
68 result = sstr.str();
69
70 return result.c_str();
71 }
72
73 static std::string result;
74 };
75
76 std::string MipiSysTFixtureBuild::result;
77
78
79 #if defined(MIPI_SYST_PCFG_ENABLE_BUILD_API)
TEST_F(MipiSysTFixtureBuild,syst_build_long)80 TEST_F(MipiSysTFixtureBuild, syst_build_long)
81 {
82 EXPECT_STREQ(
83 xform(""),
84 MIPI_SYST_BUILD(NULL, MIPI_SYST_SEVERITY_MAX, 0x1122334455667788ull, "some text", 10)
85 );
86
87 EXPECT_STREQ(
88 xform("<D32TS>02012200[typ=0:2 mu=1:2 sev=0 len]<D16>0012<D64>1122334455667788<D64>78657420656d6f73<D16>0074<FLAG>"),
89 MIPI_SYST_BUILD(ph, MIPI_SYST_SEVERITY_MAX, 0x1122334455667788ull, "some text", 10)
90 );
91 EXPECT_STREQ(
92 xform("<D32TS>02012200[typ=0:2 mu=1:2 sev=0 len]<D16>0008<D64>1122334455667788<FLAG>"),
93 MIPI_SYST_BUILD(ph, MIPI_SYST_SEVERITY_MAX, 0x1122334455667788ull, NULL, 0)
94 );
95
96 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD)
97 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS)
98 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR)
99 EXPECT_STREQ(
100 xform("<D32TS>02012300[typ=0:2 mu=1:2 sev=0 loc len]<D8>03<D64>12345678aabbccdd<D16>0012<D64>1122334455667788<D64>78657420656d6f73<D16>0074<FLAG>"),
101 MIPI_SYST_BUILD_LOCADDR(ph, MIPI_SYST_SEVERITY_MAX, 0x1122334455667788ull, "some text", 10)
102 );
103 #else
104 EXPECT_STREQ(
105 xform("<D32TS>02012300[typ=0:2 mu=1:2 sev=0 loc len]<D8>02<D32>12345678<D16>0012<D64>1122334455667788<D64>78657420656d6f73<D16>0074<FLAG>"),
106 MIPI_SYST_BUILD_LOCADDR(ph, MIPI_SYST_SEVERITY_MAX, 0x1122334455667788ull, "some text", 10)
107 );
108
109 #endif
110 #endif
111
112 EXPECT_STREQ(
113 xform("<D32TS>02012300[typ=0:2 mu=1:2 sev=0 loc len]<D8>00<D32>5678abcd<D16>0012<D64>1122334455667788<D64>78657420656d6f73<D16>0074<FLAG>"),
114 MIPI_SYST_BUILD_LOC16(ph, MIPI_SYST_SEVERITY_MAX, 0xabcd, 0x1122334455667788ull, "some text", 10)
115 );
116
117 EXPECT_STREQ(
118 xform("<D32TS>02012300[typ=0:2 mu=1:2 sev=0 loc len]<D8>01<D64>12345678aabbccdd<D16>0012<D64>1122334455667788<D64>78657420656d6f73<D16>0074<FLAG>"),
119 MIPI_SYST_BUILD_LOC32(ph, MIPI_SYST_SEVERITY_MAX, 0xaabbccdd, 0x1122334455667788ull, "some text", 10)
120 );
121 #endif
122 }
123
124 #endif /* defined(MIPI_SYST_PCFG_ENABLE_BUILD_API)*/
125
126 #endif
127
TEST_F(MipiSysTFixtureOutput,syst_build_compact_null)128 TEST_F(MipiSysTFixtureOutput, syst_build_compact_null)
129 {
130 std::string str;
131
132 MIPI_SYST_BUILD_COMPACT64(0, 0x0000000000000000ull);
133 str = sstr.str();
134
135 EXPECT_STREQ(
136 xform(""),
137 str.c_str()
138 );
139
140 MIPI_SYST_BUILD_COMPACT32(0, 0);
141 str = sstr.str();
142
143 EXPECT_STREQ(
144 xform(""),
145 str.c_str()
146 );
147 }
148
TEST_F(MipiSysTFixtureOutput,syst_build_compact64)149 TEST_F(MipiSysTFixtureOutput, syst_build_compact64)
150 {
151 std::string str;
152
153 MIPI_SYST_BUILD_COMPACT64(ph, 0x0000000000000000ull);
154 str = sstr.str();
155
156 EXPECT_STREQ(
157 xform("<D64MTS>0000000001000000"),
158 str.c_str()
159 );
160 sstr.str("");
161
162 MIPI_SYST_BUILD_COMPACT64(ph, 0x3FFFFFFFFFFFFFull);
163 str = sstr.str();
164
165 EXPECT_STREQ(
166 xform("<D64MTS>ffffffffc1fffff0"),
167 str.c_str()
168 );
169 sstr.str("");
170 }
171
TEST_F(MipiSysTFixtureOutput,syst_build_compact32)172 TEST_F(MipiSysTFixtureOutput, syst_build_compact32)
173 {
174 std::string str;
175
176 MIPI_SYST_BUILD_COMPACT32(ph, 0x00000000ull);
177 str = sstr.str();
178
179 EXPECT_STREQ(
180 xform("<D32MTS>00000000"),
181 str.c_str()
182 );
183 sstr.str("");
184
185 MIPI_SYST_BUILD_COMPACT32(ph, 0x3FFFFF);
186 str = sstr.str();
187
188 EXPECT_STREQ(
189 xform("<D32MTS>c0fffff0"),
190 str.c_str()
191 );
192 sstr.str("");
193 }