sim: Fix serialize_handlers.test.cc on Arm platforms
The C and C++ standards allows the character type char to be signed or
unsigned, depending on the platform and compiler. Most systems,
including x86 GNU/Linux and Microsoft Windows, use signed char, but
those based on PowerPC and ARM processors typically use unsigned char
This means testing for:
EXPECT_FALSE(parser.parse("255", value));
is not portable as Arm platforms are able to convert 255 into an unsigned
character. We are fixing this portability issue by performing
different checks depending on the platform.
Maybe a better solution would be to explicitly set the sign of the
char (signed char in this case)
Change-Id: I44dd84378ea62ae21a6b03e1f35119bf85f8c799
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/63539
Maintainer: Daniel Carvalho <odanrc@yahoo.com.br>
Maintainer: Bobby Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Reviewed-by: Bobby Bruce <bbruce@ucdavis.edu>
This commit is contained in:
@@ -224,9 +224,15 @@ TEST(SerializeTest, ParseParamChar)
|
||||
EXPECT_FALSE(parser.parse("false", value));
|
||||
|
||||
// 8-bit values
|
||||
EXPECT_FALSE(parser.parse("255", value));
|
||||
EXPECT_TRUE(parser.parse("-128", value));
|
||||
EXPECT_EQ(char(-128), value);
|
||||
if constexpr (std::is_signed_v<char>) {
|
||||
EXPECT_FALSE(parser.parse("255", value));
|
||||
EXPECT_TRUE(parser.parse("-128", value));
|
||||
EXPECT_EQ(char(-128), value);
|
||||
} else {
|
||||
EXPECT_FALSE(parser.parse("256", value));
|
||||
EXPECT_TRUE(parser.parse("255", value));
|
||||
EXPECT_EQ(char(255), value);
|
||||
}
|
||||
|
||||
// 16-bit values
|
||||
EXPECT_FALSE(parser.parse("1000", value));
|
||||
|
||||
Reference in New Issue
Block a user