@@ -160,18 +160,10 @@ TEST(Descriptor, FixedStride) {
160160 EXPECT_EQ (descriptor.FixedStride ().value_or (-666 ), 0 );
161161}
162162
163- static std::string getAddrFilteredContent (FILE *fin) {
164- rewind (fin);
165- std::ostringstream content;
166- char buffer[1024 ];
167- size_t bytes_read;
168- while ((bytes_read = fread (buffer, 1 , sizeof (buffer), fin)) > 0 ) {
169- content.write (buffer, bytes_read);
170- }
171- return std::regex_replace (
172- content.str (), std::regex (" (0x[0-9a-fA-F]*)" ), " [address]" );
173- }
174-
163+ // The test below uses file operations that have nuances across multiple
164+ // platforms. Hence limit coverage by linux only unless wider coverage
165+ // should be required.
166+ #if defined(__linux__) && !defined(__ANDROID__)
175167TEST (Descriptor, Dump) {
176168 StaticDescriptor<4 > staticDesc[2 ];
177169 Descriptor &descriptor{staticDesc[0 ].descriptor ()};
@@ -181,20 +173,37 @@ TEST(Descriptor, Dump) {
181173 TypeCode integer{TypeCategory::Integer, four};
182174 // Scalar
183175 descriptor.Establish (integer, four, data, 0 );
184- FILE *tmpf = tmpfile ();
176+ FILE *tmpf = nullptr ;
177+ tmpf = tmpfile ();
185178 ASSERT_TRUE (tmpf) << " tmpfile returned NULL" ;
186179 auto resetTmpFile = [tmpf]() {
180+ fflush (tmpf);
187181 rewind (tmpf);
188182 ftruncate (fileno (tmpf), 0 );
189183 };
190184
185+ auto getAddrFilteredContent = [tmpf]() -> std::string {
186+ rewind (tmpf);
187+ std::ostringstream content;
188+ char buffer[1024 ];
189+ size_t bytes_read;
190+ while ((bytes_read = fread (buffer, 1 , sizeof (buffer), tmpf)) > 0 ) {
191+ content.write (buffer, bytes_read);
192+ }
193+
194+ return std::regex_replace (
195+ std::regex_replace (content.str (), std::regex (" Descriptor @.*:" ),
196+ " Descriptor @ [addr]:" ),
197+ std::regex (" base_addr .*" ), " base_addr [addr]" );
198+ };
199+
191200 descriptor.Dump (tmpf, /* dumpRawType=*/ false );
192201 // also dump as CFI type
193202 descriptor.Dump (tmpf, /* dumpRawType=*/ true );
194- std::string output = getAddrFilteredContent (tmpf );
203+ std::string output = getAddrFilteredContent ();
195204 ASSERT_STREQ (output.c_str (),
196- " Descriptor @ [address ]:\n "
197- " base_addr [address ]\n "
205+ " Descriptor @ [addr ]:\n "
206+ " base_addr [addr ]\n "
198207 " elem_len 4\n "
199208 " version 20240719\n "
200209 " scalar\n "
@@ -203,8 +212,8 @@ TEST(Descriptor, Dump) {
203212 " extra 0\n "
204213 " addendum 0\n "
205214 " alloc_idx 0\n "
206- " Descriptor @ [address ]:\n "
207- " base_addr [address ]\n "
215+ " Descriptor @ [addr ]:\n "
216+ " base_addr [addr ]\n "
208217 " elem_len 4\n "
209218 " version 20240719\n "
210219 " scalar\n "
@@ -219,10 +228,10 @@ TEST(Descriptor, Dump) {
219228 descriptor.Establish (integer, four, data, 2 , extent);
220229 resetTmpFile ();
221230 descriptor.Dump (tmpf, /* dumpRawType=*/ false );
222- output = getAddrFilteredContent (tmpf );
231+ output = getAddrFilteredContent ();
223232 ASSERT_STREQ (output.c_str (),
224- " Descriptor @ [address ]:\n "
225- " base_addr [address ]\n "
233+ " Descriptor @ [addr ]:\n "
234+ " base_addr [addr ]\n "
226235 " elem_len 4\n "
227236 " version 20240719\n "
228237 " rank 2\n "
@@ -248,10 +257,10 @@ TEST(Descriptor, Dump) {
248257
249258 resetTmpFile ();
250259 descriptor.Dump (tmpf, /* dumpRawType=*/ false );
251- output = getAddrFilteredContent (tmpf );
260+ output = getAddrFilteredContent ();
252261 ASSERT_STREQ (output.c_str (),
253- " Descriptor @ [address ]:\n "
254- " base_addr [address ]\n "
262+ " Descriptor @ [addr ]:\n "
263+ " base_addr [addr ]\n "
255264 " elem_len 4\n "
256265 " version 20240719\n "
257266 " rank 3\n "
@@ -271,3 +280,4 @@ TEST(Descriptor, Dump) {
271280 " sm 512\n " );
272281 fclose (tmpf);
273282}
283+ #endif // defined(__linux__) && !defined(__ANDROID__)
0 commit comments