From 275a3f1ca9bb9835b5b20b53d21f055438cc3148 Mon Sep 17 00:00:00 2001 From: snadampal <87143774+snadampal@users.noreply.github.com> Date: Sat, 30 Nov 2024 15:16:46 -0600 Subject: [PATCH] fix build and test failures on arm64 linux platform (#978) There are few build and test failures on arm64 platform with "narrowing conversion" errors. This is due to the char datatype implementation differences between different platforms and gcc versions. This commit replaces the char datatype with the explicit datatype that works across all the platforms. --- test/test_bit_stream.cpp | 8 ++++---- test/test_bit_stream_reader_big_endian.cpp | 8 ++++---- test/test_bresenham_line.cpp | 2 +- test/test_correlation.cpp | 18 +++++++++--------- test/test_covariance.cpp | 18 +++++++++--------- test/test_rms.cpp | 4 ++-- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/test/test_bit_stream.cpp b/test/test_bit_stream.cpp index c0cbd2512..7ed5979dd 100644 --- a/test/test_bit_stream.cpp +++ b/test/test_bit_stream.cpp @@ -930,8 +930,8 @@ namespace //************************************************************************* TEST(put_get_multiple_variable_size) { - char c1 = 26; // 6 bits - char c2 = -10; // 7 bits + int8_t c1 = 26; // 6 bits + int8_t c2 = -10; // 7 bits unsigned short s1 = 6742; // 13 bits unsigned short s2 = 1878; // 11 bits int32_t i1 = 2448037L; // 23 bits @@ -983,8 +983,8 @@ namespace bit_stream.restart(); - char rc1 = 0; - char rc2 = 0; + int8_t rc1 = 0; + int8_t rc2 = 0; unsigned short rs1 = 0; unsigned short rs2 = 0; int32_t ri1 = 0; diff --git a/test/test_bit_stream_reader_big_endian.cpp b/test/test_bit_stream_reader_big_endian.cpp index 4cdf3d299..9c099085c 100644 --- a/test/test_bit_stream_reader_big_endian.cpp +++ b/test/test_bit_stream_reader_big_endian.cpp @@ -210,7 +210,7 @@ namespace TEST(test_read_int8_t) { std::array storage = { char(0x01), char(0x5A), char(0xA5), char(0xFF) }; - std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; + std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big); @@ -246,7 +246,7 @@ namespace TEST(test_read_checked_int8_t_using_non_member_function) { std::array storage = { char(0x01), char(0x5A), char(0xA5), char(0xFF) }; - std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; + std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big); @@ -282,7 +282,7 @@ namespace TEST(test_read_unchecked_int8_t_using_non_member_function) { std::array storage = { char(0x01), char(0x5A), char(0xA5), char(0xFF) }; - std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; + std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big); @@ -307,7 +307,7 @@ namespace TEST(test_read_int8_t_5bits) { std::array storage = { char(0x0E), char(0x8B), char(0xF0) }; - std::array expected = { int8_t(0x01), int8_t(0xFA), int8_t(0x05), int8_t(0xFF) }; + std::array expected = { int8_t(0x01), int8_t(0xFA), int8_t(0x05), int8_t(0xFF) }; etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big); diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index 96f5e231c..e350e894f 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -44,7 +44,7 @@ namespace etl namespace { - using Value = char; + using Value = int8_t; using Point = etl::coordinate_2d; diff --git a/test/test_correlation.cpp b/test/test_correlation.cpp index 82f2d0327..aeed9f759 100644 --- a/test/test_correlation.cpp +++ b/test/test_correlation.cpp @@ -34,17 +34,17 @@ SOFTWARE. namespace { - std::array input_c + std::array input_c { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - std::array input_c_flat + std::array input_c_flat { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - std::array input_c_inv + std::array input_c_inv { 0, -1, -2, -3, -4, -5, -6, -7, -8, -9 }; @@ -120,21 +120,21 @@ namespace double covariance_result; // Negative correlation. - etl::correlation correlation1(input_c.begin(), input_c.end(), input_c_inv.begin()); + etl::correlation correlation1(input_c.begin(), input_c.end(), input_c_inv.begin()); correlation_result = correlation1; CHECK_CLOSE(-1.0, correlation_result, 0.1); covariance_result = correlation1.get_covariance(); CHECK_CLOSE(-8.25, covariance_result, 0.1); // Zero correlation - etl::correlation correlation2(input_c.begin(), input_c.end(), input_c_flat.begin()); + etl::correlation correlation2(input_c.begin(), input_c.end(), input_c_flat.begin()); correlation_result = correlation2; CHECK_CLOSE(0.0, correlation_result, 0.1); covariance_result = correlation2.get_covariance(); CHECK_CLOSE(0.0, covariance_result, 0.1); // Positive correlation. - etl::correlation correlation3(input_c.begin(), input_c.end(), input_c.begin()); + etl::correlation correlation3(input_c.begin(), input_c.end(), input_c.begin()); correlation_result = correlation3; CHECK_CLOSE(1.0, correlation_result, 0.1); covariance_result = correlation3.get_covariance(); @@ -148,21 +148,21 @@ namespace double covariance_result; // Negative correlation. - etl::correlation correlation1(input_c.begin(), input_c.end(), input_c_inv.begin()); + etl::correlation correlation1(input_c.begin(), input_c.end(), input_c_inv.begin()); correlation_result = correlation1; CHECK_CLOSE(-1.0, correlation_result, 0.1); covariance_result = correlation1.get_covariance(); CHECK_CLOSE(-9.17, covariance_result, 0.1); // Zero correlation - etl::correlation correlation2(input_c.begin(), input_c.end(), input_c_flat.begin()); + etl::correlation correlation2(input_c.begin(), input_c.end(), input_c_flat.begin()); correlation_result = correlation2; CHECK_CLOSE(0.0, correlation_result, 0.1); covariance_result = correlation2.get_covariance(); CHECK_CLOSE(0.0, covariance_result, 0.1); // Positive correlation. - etl::correlation correlation3(input_c.begin(), input_c.end(), input_c.begin()); + etl::correlation correlation3(input_c.begin(), input_c.end(), input_c.begin()); correlation_result = correlation3; CHECK_CLOSE(1.0, correlation_result, 0.1); covariance_result = correlation3.get_covariance(); diff --git a/test/test_covariance.cpp b/test/test_covariance.cpp index a127616c8..6ce84d726 100644 --- a/test/test_covariance.cpp +++ b/test/test_covariance.cpp @@ -34,17 +34,17 @@ SOFTWARE. namespace { - std::array input_c + std::array input_c { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - std::array input_c_flat + std::array input_c_flat { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - std::array input_c_inv + std::array input_c_inv { 0, -1, -2, -3, -4, -5, -6, -7, -8, -9 }; @@ -119,17 +119,17 @@ namespace double covariance_result; // Negative covariance. - etl::covariance covariance1(input_c.begin(), input_c.end(), input_c_inv.begin()); + etl::covariance covariance1(input_c.begin(), input_c.end(), input_c_inv.begin()); covariance_result = covariance1.get_covariance(); CHECK_CLOSE(-8.25, covariance_result, 0.1); // Zero covariance - etl::covariance covariance2(input_c.begin(), input_c.end(), input_c_flat.begin()); + etl::covariance covariance2(input_c.begin(), input_c.end(), input_c_flat.begin()); covariance_result = covariance2.get_covariance(); CHECK_CLOSE(0.0, covariance_result, 0.1); // Positive covariance. - etl::covariance covariance3(input_c.begin(), input_c.end(), input_c.begin()); + etl::covariance covariance3(input_c.begin(), input_c.end(), input_c.begin()); covariance_result = covariance3.get_covariance(); CHECK_CLOSE(8.25, covariance_result, 0.1); } @@ -140,17 +140,17 @@ namespace double covariance_result; // Negative covariance. - etl::covariance covariance1(input_c.begin(), input_c.end(), input_c_inv.begin()); + etl::covariance covariance1(input_c.begin(), input_c.end(), input_c_inv.begin()); covariance_result = covariance1.get_covariance(); CHECK_CLOSE(-9.17, covariance_result, 0.1); // Zero covariance - etl::covariance covariance2(input_c.begin(), input_c.end(), input_c_flat.begin()); + etl::covariance covariance2(input_c.begin(), input_c.end(), input_c_flat.begin()); covariance_result = covariance2.get_covariance(); CHECK_CLOSE(0.0, covariance_result, 0.1); // Positive covariance. - etl::covariance covariance3(input_c.begin(), input_c.end(), input_c.begin()); + etl::covariance covariance3(input_c.begin(), input_c.end(), input_c.begin()); covariance_result = covariance3.get_covariance(); CHECK_CLOSE(9.17, covariance_result, 0.1); } diff --git a/test/test_rms.cpp b/test/test_rms.cpp index cbc198841..39ae6753e 100644 --- a/test/test_rms.cpp +++ b/test/test_rms.cpp @@ -34,7 +34,7 @@ SOFTWARE. namespace { - std::array input_c + std::array input_c { // Sawtooth wave 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -8, -7, -6, -5, -4, -3, -2, -1 @@ -52,7 +52,7 @@ namespace //************************************************************************* TEST(test_char_rms) { - etl::rms rms(input_c.begin(), input_c.end()); + etl::rms rms(input_c.begin(), input_c.end()); double result = rms.get_rms(); CHECK_CLOSE(5.21, result, 0.05);