mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
Strict warnings in the unit tests. This commit needs to be carefully reviewed.
This commit is contained in:
parent
d9d6e80aea
commit
b09bfab117
@ -102,7 +102,7 @@ if (DEBUG_BUILD)
|
||||
|
||||
if (COMPILER_IS_GCC_COMPATIBLE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -Wfloat-equal -Wconversion -Wsign-conversion")
|
||||
set(exec_common_flags "-Wno-conversion -Wno-float-equal -Wno-sign-conversion")
|
||||
set(exec_common_flags "")
|
||||
set(cpp03_flags "-std=c++03 -Wno-variadic-macros -Wno-long-long")
|
||||
set(optim_flags "-O3 -DNDEBUG -g0")
|
||||
else ()
|
||||
|
||||
@ -385,7 +385,7 @@ class UAVCAN_EXPORT Array : public ArrayImpl<T, ArrayMode, MaxSize_>
|
||||
return -ErrLogic;
|
||||
}
|
||||
|
||||
template <typename InputIter>
|
||||
template <typename ScalarType, typename InputIter>
|
||||
void packSquareMatrixImpl(const InputIter src_row_major)
|
||||
{
|
||||
StaticAssert<IsDynamic>::check();
|
||||
@ -445,7 +445,7 @@ class UAVCAN_EXPORT Array : public ArrayImpl<T, ArrayMode, MaxSize_>
|
||||
}
|
||||
}
|
||||
|
||||
template <typename OutputIter>
|
||||
template <typename ScalarType, typename OutputIter>
|
||||
void unpackSquareMatrixImpl(OutputIter it) const
|
||||
{
|
||||
StaticAssert<IsDynamic>::check();
|
||||
@ -464,23 +464,26 @@ class UAVCAN_EXPORT Array : public ArrayImpl<T, ArrayMode, MaxSize_>
|
||||
const bool on_diagonal = (index / Width) == (index % Width);
|
||||
if (on_diagonal)
|
||||
{
|
||||
const SizeType source_index = (this->size() == 1) ? 0 : (index / Width);
|
||||
*it++ = this->at(source_index);
|
||||
const SizeType source_index = SizeType((this->size() == 1) ? 0 : (index / Width));
|
||||
*it++ = ScalarType(this->at(source_index));
|
||||
}
|
||||
else
|
||||
{
|
||||
*it++ = 0;
|
||||
*it++ = ScalarType(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this->size() == MaxSize)
|
||||
{
|
||||
(void)::uavcan::copy(this->begin(), this->end(), it);
|
||||
for (SizeType index = 0; index < MaxSize; index++)
|
||||
{
|
||||
*it++ = ScalarType(this->at(index));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// coverity[suspicious_sizeof : FALSE]
|
||||
::uavcan::fill_n(it, MaxSize, 0);
|
||||
::uavcan::fill_n(it, MaxSize, ScalarType(0));
|
||||
}
|
||||
}
|
||||
|
||||
@ -654,10 +657,8 @@ public:
|
||||
SelfType& operator+=(const Array<T, RhsArrayMode, RhsMaxSize>& rhs)
|
||||
{
|
||||
typedef Array<T, RhsArrayMode, RhsMaxSize> Rhs;
|
||||
typedef typename Select<(sizeof(SizeType) > sizeof(typename Rhs::SizeType)),
|
||||
SizeType, typename Rhs::SizeType>::Result CommonSizeType;
|
||||
StaticAssert<IsDynamic>::check();
|
||||
for (CommonSizeType i = 0; i < rhs.size(); i++)
|
||||
for (typename Rhs::SizeType i = 0; i < rhs.size(); i++)
|
||||
{
|
||||
push_back(rhs[i]);
|
||||
}
|
||||
@ -689,11 +690,11 @@ public:
|
||||
|
||||
ValueType* const ptr = Base::end();
|
||||
UAVCAN_ASSERT(capacity() >= size());
|
||||
const SizeType max_size = capacity() - size();
|
||||
const SizeType max_size = SizeType(capacity() - size());
|
||||
|
||||
// We have one extra byte for the null terminator, hence +1
|
||||
using namespace std; // For snprintf()
|
||||
const int ret = snprintf(reinterpret_cast<char*>(ptr), max_size + 1, format, value);
|
||||
const int ret = snprintf(reinterpret_cast<char*>(ptr), SizeType(max_size + 1U), format, value);
|
||||
|
||||
for (int i = 0; i < min(ret, int(max_size)); i++)
|
||||
{
|
||||
@ -714,7 +715,7 @@ public:
|
||||
template <typename ScalarType>
|
||||
void packSquareMatrix(const ScalarType (&src_row_major)[MaxSize])
|
||||
{
|
||||
packSquareMatrixImpl<const ScalarType*>(src_row_major);
|
||||
packSquareMatrixImpl<ScalarType, const ScalarType*>(src_row_major);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -727,7 +728,7 @@ public:
|
||||
if (this->size() == MaxSize)
|
||||
{
|
||||
ValueType matrix[MaxSize];
|
||||
for (unsigned i = 0; i < MaxSize; i++)
|
||||
for (SizeType i = 0; i < MaxSize; i++)
|
||||
{
|
||||
matrix[i] = this->at(i);
|
||||
}
|
||||
@ -750,7 +751,10 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills this array as a packed square matrix from any container that implements the methods begin() and size().
|
||||
* Fills this array as a packed square matrix from any container that has the following public entities:
|
||||
* - method begin()
|
||||
* - method size()
|
||||
* - only for C++03: type value_type
|
||||
* Please refer to the specification to learn more about matrix packing.
|
||||
* Note that matrix packing code uses @ref areClose() for comparison.
|
||||
*/
|
||||
@ -760,7 +764,12 @@ public:
|
||||
{
|
||||
if (src_row_major.size() == MaxSize)
|
||||
{
|
||||
packSquareMatrixImpl(src_row_major.begin());
|
||||
#if UAVCAN_CPP_VERSION > UAVCAN_CPP03
|
||||
typedef typename std::remove_reference<decltype(*src_row_major.begin())>::type RhsValueType;
|
||||
packSquareMatrixImpl<RhsValueType>(src_row_major.begin());
|
||||
#else
|
||||
packSquareMatrixImpl<typename R::value_type>(src_row_major.begin());
|
||||
#endif
|
||||
}
|
||||
else if (src_row_major.size() == 0)
|
||||
{
|
||||
@ -784,7 +793,7 @@ public:
|
||||
template <typename ScalarType>
|
||||
void unpackSquareMatrix(ScalarType (&dst_row_major)[MaxSize]) const
|
||||
{
|
||||
unpackSquareMatrixImpl<ScalarType*>(dst_row_major);
|
||||
unpackSquareMatrixImpl<ScalarType, ScalarType*>(dst_row_major);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -804,7 +813,10 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconstructs full matrix, result will be saved into container that implements begin() and size().
|
||||
* Reconstructs full matrix, result will be saved into container that has the following public entities:
|
||||
* - method begin()
|
||||
* - method size()
|
||||
* - only for C++03: type value_type
|
||||
* Please refer to the specification to learn more about matrix packing.
|
||||
*/
|
||||
template <typename R>
|
||||
@ -813,7 +825,12 @@ public:
|
||||
{
|
||||
if (dst_row_major.size() == MaxSize)
|
||||
{
|
||||
unpackSquareMatrixImpl(dst_row_major.begin());
|
||||
#if UAVCAN_CPP_VERSION > UAVCAN_CPP03
|
||||
typedef typename std::remove_reference<decltype(*dst_row_major.begin())>::type RhsValueType;
|
||||
unpackSquareMatrixImpl<RhsValueType>(dst_row_major.begin());
|
||||
#else
|
||||
unpackSquareMatrixImpl<typename R::value_type>(dst_row_major.begin());
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -875,9 +892,9 @@ class UAVCAN_EXPORT YamlStreamer<Array<T, ArrayMode, MaxSize> >
|
||||
static void streamPrimitives(Stream& s, const ArrayType& array)
|
||||
{
|
||||
s << '[';
|
||||
for (std::size_t i = 0; i < array.size(); i++)
|
||||
for (typename ArrayType::SizeType i = 0; i < array.size(); i++)
|
||||
{
|
||||
YamlStreamer<T>::stream(s, array.at(i), 0);
|
||||
YamlStreamer<T>::stream(s, array.at(typename ArrayType::SizeType(i)), 0);
|
||||
if ((i + 1) < array.size())
|
||||
{
|
||||
s << ", ";
|
||||
@ -890,7 +907,7 @@ class UAVCAN_EXPORT YamlStreamer<Array<T, ArrayMode, MaxSize> >
|
||||
static void streamCharacters(Stream& s, const ArrayType& array)
|
||||
{
|
||||
s << '"';
|
||||
for (std::size_t i = 0; i < array.size(); i++)
|
||||
for (typename ArrayType::SizeType i = 0; i < array.size(); i++)
|
||||
{
|
||||
const int c = array.at(i);
|
||||
if (c < 32 || c > 126)
|
||||
@ -898,10 +915,10 @@ class UAVCAN_EXPORT YamlStreamer<Array<T, ArrayMode, MaxSize> >
|
||||
char nibbles[2] = {char((c >> 4) & 0xF), char(c & 0xF)};
|
||||
for (int k = 0; k < 2; k++)
|
||||
{
|
||||
nibbles[k] += '0';
|
||||
nibbles[k] = char(nibbles[k] + '0');
|
||||
if (nibbles[k] > '9')
|
||||
{
|
||||
nibbles[k] += 'A' - '9' - 1;
|
||||
nibbles[k] = char(nibbles[k] + 'A' - '9' - 1);
|
||||
}
|
||||
}
|
||||
s << "\\x" << nibbles[0] << nibbles[1];
|
||||
@ -926,7 +943,7 @@ class UAVCAN_EXPORT YamlStreamer<Array<T, ArrayMode, MaxSize> >
|
||||
static void genericStreamImpl(Stream& s, const ArrayType& array, int, SelectorStringLike)
|
||||
{
|
||||
bool printable_only = true;
|
||||
for (int i = 0; i < array.size(); i++)
|
||||
for (typename ArrayType::SizeType i = 0; i < array.size(); i++)
|
||||
{
|
||||
if (!isNiceCharacter(array[i]))
|
||||
{
|
||||
@ -960,7 +977,7 @@ class UAVCAN_EXPORT YamlStreamer<Array<T, ArrayMode, MaxSize> >
|
||||
s << "[]";
|
||||
return;
|
||||
}
|
||||
for (std::size_t i = 0; i < array.size(); i++)
|
||||
for (typename ArrayType::SizeType i = 0; i < array.size(); i++)
|
||||
{
|
||||
s << '\n';
|
||||
for (int pos = 0; pos < level; pos++)
|
||||
|
||||
@ -40,7 +40,7 @@ class UAVCAN_EXPORT CharArrayFormatter
|
||||
{
|
||||
if (array_.size() != array_.capacity())
|
||||
{
|
||||
array_.push_back(value);
|
||||
array_.push_back(typename ArrayType_::ValueType(value));
|
||||
}
|
||||
}
|
||||
else if (std::is_signed<T>())
|
||||
|
||||
@ -55,7 +55,7 @@ class UAVCAN_EXPORT ScalarCodec
|
||||
StaticAssert<NumericTraits<T>::IsInteger>::check(); // Not applicable to floating point types
|
||||
if (value & (T(1) << (BitLen - 1))) // The most significant bit is set --> negative
|
||||
{
|
||||
value |= 0xFFFFFFFFFFFFFFFF & ~((T(1) << BitLen) - 1);
|
||||
value |= T(T(0xFFFFFFFFFFFFFFFFULL) & ~((T(1) << BitLen) - 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ public:
|
||||
LazyConstructor(const LazyConstructor<T>& rhs) // Implicit
|
||||
: ptr_(NULL)
|
||||
{
|
||||
fill(data_.pool, data_.pool + sizeof(T), 0);
|
||||
fill(data_.pool, data_.pool + sizeof(T), uint8_t(0));
|
||||
if (rhs)
|
||||
{
|
||||
construct<const T&>(*rhs); // Invoke copy constructor
|
||||
|
||||
@ -15,7 +15,7 @@ public:
|
||||
mutable uint64_t monotonic;
|
||||
mutable uint64_t utc;
|
||||
uavcan::UtcDuration last_adjustment;
|
||||
int64_t monotonic_auto_advance;
|
||||
uint64_t monotonic_auto_advance;
|
||||
bool preserve_utc;
|
||||
|
||||
SystemClockMock(uint64_t initial = 0)
|
||||
@ -52,7 +52,7 @@ public:
|
||||
{
|
||||
assert(this);
|
||||
const uint64_t prev_utc = utc;
|
||||
utc += adjustment.toUSec();
|
||||
utc = uint64_t(int64_t(utc) + adjustment.toUSec());
|
||||
last_adjustment = adjustment;
|
||||
std::cout << "Clock adjustment " << prev_utc << " --> " << utc << std::endl;
|
||||
}
|
||||
@ -73,7 +73,7 @@ public:
|
||||
assert(0);
|
||||
return uavcan::MonotonicTime();
|
||||
}
|
||||
return uavcan::MonotonicTime::fromUSec(uint64_t(ts.tv_sec) * 1000000UL + ts.tv_nsec / 1000UL);
|
||||
return uavcan::MonotonicTime::fromUSec(uint64_t(int64_t(ts.tv_sec) * 1000000L + int64_t(ts.tv_nsec / 1000L)));
|
||||
}
|
||||
|
||||
virtual uavcan::UtcTime getUtc() const
|
||||
@ -85,7 +85,7 @@ public:
|
||||
assert(0);
|
||||
return uavcan::UtcTime();
|
||||
}
|
||||
return uavcan::UtcTime::fromUSec(uint64_t(tv.tv_sec) * 1000000UL + tv.tv_usec) + utc_adjustment;
|
||||
return uavcan::UtcTime::fromUSec(uint64_t(int64_t(tv.tv_sec) * 1000000L + tv.tv_usec)) + utc_adjustment;
|
||||
}
|
||||
|
||||
virtual void adjustUtc(uavcan::UtcDuration adjustment)
|
||||
|
||||
@ -37,7 +37,12 @@ struct CustomType
|
||||
, c()
|
||||
{ }
|
||||
|
||||
bool operator==(const CustomType& rhs) const { return a == rhs.a && b == rhs.b && c == rhs.c; }
|
||||
bool operator==(const CustomType& rhs) const
|
||||
{
|
||||
return a == rhs.a &&
|
||||
uavcan::areFloatsExactlyEqual(b, rhs.b) &&
|
||||
c == rhs.c;
|
||||
}
|
||||
|
||||
static int encode(const CustomType& obj, uavcan::ScalarCodec& codec,
|
||||
uavcan::TailArrayOptimizationMode tao_mode = uavcan::TailArrayOptEnabled)
|
||||
@ -127,19 +132,19 @@ TEST(Array, Basic)
|
||||
/*
|
||||
* Modification with known values; array lengths are hard coded.
|
||||
*/
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
a1.at(i) = i;
|
||||
a1.at(i) = int8_t(i);
|
||||
}
|
||||
for (int i = 0; i < 2; i++)
|
||||
for (uint8_t i = 0; i < 2; i++)
|
||||
{
|
||||
a2.at(i) = i;
|
||||
}
|
||||
for (int i = 0; i < 2; i++)
|
||||
for (uint8_t i = 0; i < 2; i++)
|
||||
{
|
||||
a3[i].a = i;
|
||||
a3[i].a = int8_t(i);
|
||||
a3[i].b = i;
|
||||
for (int i2 = 0; i2 < 5; i2++)
|
||||
for (uint8_t i2 = 0; i2 < 5; i2++)
|
||||
{
|
||||
a3[i].c.push_back(i2 & 1);
|
||||
}
|
||||
@ -187,15 +192,15 @@ TEST(Array, Basic)
|
||||
ASSERT_EQ(a2_, a2);
|
||||
ASSERT_EQ(a3_, a3);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
ASSERT_EQ(a1[i], a1_[i]);
|
||||
}
|
||||
for (int i = 0; i < 2; i++)
|
||||
for (uint8_t i = 0; i < 2; i++)
|
||||
{
|
||||
ASSERT_EQ(a2[i], a2_[i]);
|
||||
}
|
||||
for (int i = 0; i < 2; i++)
|
||||
for (uint8_t i = 0; i < 2; i++)
|
||||
{
|
||||
ASSERT_EQ(a3[i].a, a3_[i].a);
|
||||
ASSERT_EQ(a3[i].b, a3_[i].b);
|
||||
@ -355,11 +360,11 @@ TEST(Array, Dynamic)
|
||||
ASSERT_EQ(5, a.size());
|
||||
ASSERT_EQ(255, b.size());
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
for (uint8_t i = 0; i < 5; i++)
|
||||
{
|
||||
ASSERT_TRUE(a[i]);
|
||||
}
|
||||
for (int i = 0; i < 255; i++)
|
||||
for (uint8_t i = 0; i < 255; i++)
|
||||
{
|
||||
ASSERT_EQ(72, b[i]);
|
||||
}
|
||||
@ -382,7 +387,11 @@ struct CustomType2
|
||||
, b()
|
||||
{ }
|
||||
|
||||
bool operator==(const CustomType2& rhs) const { return a == rhs.a && b == rhs.b; }
|
||||
bool operator==(const CustomType2& rhs) const
|
||||
{
|
||||
return uavcan::areFloatsExactlyEqual(a, rhs.a) &&
|
||||
b == rhs.b;
|
||||
}
|
||||
|
||||
static int encode(const CustomType2& obj, uavcan::ScalarCodec& codec,
|
||||
uavcan::TailArrayOptimizationMode tao_mode = uavcan::TailArrayOptEnabled)
|
||||
@ -699,7 +708,7 @@ TEST(Array, Appending)
|
||||
ASSERT_EQ(2, a[1]);
|
||||
|
||||
b += a;
|
||||
ASSERT_TRUE(a == b);
|
||||
ASSERT_TRUE(b == a);
|
||||
b += a;
|
||||
ASSERT_EQ(4, b.size());
|
||||
ASSERT_EQ(1, b[0]);
|
||||
@ -793,8 +802,8 @@ TEST(Array, FlatStreaming)
|
||||
std::cout << std::endl;
|
||||
|
||||
AF16D af16d1;
|
||||
af16d1.push_back(1.23);
|
||||
af16d1.push_back(4.56);
|
||||
af16d1.push_back(1.23F);
|
||||
af16d1.push_back(4.56F);
|
||||
uavcan::YamlStreamer<AF16D>::stream(std::cout, af16d1, 0);
|
||||
std::cout << std::endl;
|
||||
|
||||
@ -816,15 +825,15 @@ TEST(Array, MultidimensionalStreaming)
|
||||
|
||||
ThreeDimensional threedee;
|
||||
threedee.resize(3);
|
||||
for (int x = 0; x < threedee.size(); x++)
|
||||
for (uint8_t x = 0; x < threedee.size(); x++)
|
||||
{
|
||||
threedee[x].resize(3);
|
||||
for (int y = 0; y < threedee[x].size(); y++)
|
||||
for (uint8_t y = 0; y < threedee[x].size(); y++)
|
||||
{
|
||||
threedee[x][y].resize(3);
|
||||
for (int z = 0; z < threedee[x][y].size(); z++)
|
||||
for (uint8_t z = 0; z < threedee[x][y].size(); z++)
|
||||
{
|
||||
threedee[x][y][z] = 1.0 / (x + y + z + 1.0);
|
||||
threedee[x][y][z] = 1.0F / (float(x + y + z) + 1.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -854,9 +863,9 @@ TEST(Array, SquareMatrixPacking)
|
||||
// Empty array will be decoded as zero matrix
|
||||
double nans3x3_out[9];
|
||||
m3x3s.unpackSquareMatrix(nans3x3_out);
|
||||
for (int i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
ASSERT_FLOAT_EQ(0, nans3x3_out[i]);
|
||||
ASSERT_DOUBLE_EQ(0, nans3x3_out[i]);
|
||||
}
|
||||
}
|
||||
{
|
||||
@ -866,25 +875,25 @@ TEST(Array, SquareMatrixPacking)
|
||||
|
||||
empty.resize(9);
|
||||
m3x3s.unpackSquareMatrix(empty);
|
||||
for (int i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
ASSERT_FLOAT_EQ(0, empty.at(i));
|
||||
ASSERT_DOUBLE_EQ(0, empty.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Scalar matrix will be reduced to a single value
|
||||
{
|
||||
std::vector<float> scalar2x2(4);
|
||||
scalar2x2[0] = scalar2x2[3] = 3.14;
|
||||
scalar2x2[0] = scalar2x2[3] = 3.14F;
|
||||
m2x2f.packSquareMatrix(scalar2x2);
|
||||
ASSERT_EQ(1, m2x2f.size());
|
||||
ASSERT_FLOAT_EQ(3.14, m2x2f[0]);
|
||||
ASSERT_FLOAT_EQ(3.14F, m2x2f[0]);
|
||||
|
||||
m2x2f.unpackSquareMatrix(scalar2x2);
|
||||
const float reference[] =
|
||||
{
|
||||
3.14, 0,
|
||||
0, 3.14
|
||||
3.14F, 0.0F,
|
||||
0.0F, 3.14F
|
||||
};
|
||||
ASSERT_TRUE(std::equal(scalar2x2.begin(), scalar2x2.end(), reference));
|
||||
}
|
||||
@ -900,7 +909,7 @@ TEST(Array, SquareMatrixPacking)
|
||||
};
|
||||
m6x6d.packSquareMatrix(scalar6x6);
|
||||
ASSERT_EQ(1, m6x6d.size());
|
||||
ASSERT_FLOAT_EQ(-18, m6x6d[0]);
|
||||
ASSERT_DOUBLE_EQ(-18, m6x6d[0]);
|
||||
|
||||
std::vector<long double> output(36);
|
||||
m6x6d.unpackSquareMatrix(output);
|
||||
@ -920,12 +929,12 @@ TEST(Array, SquareMatrixPacking)
|
||||
};
|
||||
m6x6d.packSquareMatrix(diagonal6x6);
|
||||
ASSERT_EQ(6, m6x6d.size());
|
||||
ASSERT_FLOAT_EQ(1, m6x6d[0]);
|
||||
ASSERT_FLOAT_EQ(-2, m6x6d[1]);
|
||||
ASSERT_FLOAT_EQ(3, m6x6d[2]);
|
||||
ASSERT_FLOAT_EQ(-4, m6x6d[3]);
|
||||
ASSERT_FLOAT_EQ(5, m6x6d[4]);
|
||||
ASSERT_FLOAT_EQ(-6, m6x6d[5]);
|
||||
ASSERT_DOUBLE_EQ(1, m6x6d[0]);
|
||||
ASSERT_DOUBLE_EQ(-2, m6x6d[1]);
|
||||
ASSERT_DOUBLE_EQ(3, m6x6d[2]);
|
||||
ASSERT_DOUBLE_EQ(-4, m6x6d[3]);
|
||||
ASSERT_DOUBLE_EQ(5, m6x6d[4]);
|
||||
ASSERT_DOUBLE_EQ(-6, m6x6d[5]);
|
||||
|
||||
std::vector<long double> output(36);
|
||||
m6x6d.unpackSquareMatrix(output);
|
||||
@ -935,15 +944,15 @@ TEST(Array, SquareMatrixPacking)
|
||||
// A matrix filled with random values will not be compressed
|
||||
{
|
||||
std::vector<float> full3x3(9);
|
||||
for (int i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
full3x3[i] = i;
|
||||
full3x3[i] = float(i);
|
||||
}
|
||||
m3x3s.packSquareMatrix(full3x3);
|
||||
ASSERT_EQ(9, m3x3s.size());
|
||||
for (int i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
ASSERT_FLOAT_EQ(i, m3x3s[i]);
|
||||
ASSERT_FLOAT_EQ(float(i), m3x3s[i]);
|
||||
}
|
||||
|
||||
long output[9];
|
||||
@ -961,21 +970,21 @@ TEST(Array, SquareMatrixPacking)
|
||||
};
|
||||
m3x3s.packSquareMatrix(scalarnan3x3);
|
||||
ASSERT_EQ(3, m3x3s.size());
|
||||
ASSERT_FALSE(m3x3s[0] == m3x3s[0]); // NAN
|
||||
ASSERT_FALSE(m3x3s[1] == m3x3s[1]); // NAN
|
||||
ASSERT_FALSE(m3x3s[2] == m3x3s[2]); // NAN
|
||||
ASSERT_FALSE(m3x3s[0] <= m3x3s[0]); // NAN
|
||||
ASSERT_FALSE(m3x3s[1] <= m3x3s[1]); // NAN
|
||||
ASSERT_FALSE(m3x3s[2] <= m3x3s[2]); // NAN
|
||||
|
||||
float output[9];
|
||||
m3x3s.unpackSquareMatrix(output);
|
||||
ASSERT_FALSE(output[0] == output[0]); // NAN
|
||||
ASSERT_FALSE(output[0] <= output[0]); // NAN
|
||||
ASSERT_EQ(0, output[1]);
|
||||
ASSERT_EQ(0, output[2]);
|
||||
ASSERT_EQ(0, output[3]);
|
||||
ASSERT_FALSE(output[4] == output[4]); // NAN
|
||||
ASSERT_FALSE(output[4] <= output[4]); // NAN
|
||||
ASSERT_EQ(0, output[5]);
|
||||
ASSERT_EQ(0, output[6]);
|
||||
ASSERT_EQ(0, output[7]);
|
||||
ASSERT_FALSE(output[8] == output[8]); // NAN
|
||||
ASSERT_FALSE(output[8] <= output[8]); // NAN
|
||||
}
|
||||
|
||||
// This is a full matrix too (notice the NAN)
|
||||
@ -988,14 +997,14 @@ TEST(Array, SquareMatrixPacking)
|
||||
m2x2f.packSquareMatrix(full2x2);
|
||||
ASSERT_EQ(4, m2x2f.size());
|
||||
ASSERT_FLOAT_EQ(1, m2x2f[0]);
|
||||
ASSERT_FALSE(m2x2f[1] == m2x2f[1]); // NAN
|
||||
ASSERT_FALSE(m2x2f[1] <= m2x2f[1]); // NAN
|
||||
ASSERT_FLOAT_EQ(0, m2x2f[2]);
|
||||
ASSERT_FLOAT_EQ(-2, m2x2f[3]);
|
||||
|
||||
float output[4];
|
||||
m2x2f.unpackSquareMatrix(output);
|
||||
ASSERT_EQ(1, output[0]);
|
||||
ASSERT_FALSE(output[1] == output[1]); // NAN
|
||||
ASSERT_FALSE(output[1] <= output[1]); // NAN
|
||||
ASSERT_EQ(0, output[2]);
|
||||
ASSERT_EQ(-2, output[3]);
|
||||
}
|
||||
@ -1037,12 +1046,12 @@ TEST(Array, FuzzySquareMatrixPacking)
|
||||
|
||||
m6x6d.packSquareMatrix(diagonal6x6);
|
||||
ASSERT_EQ(6, m6x6d.size());
|
||||
ASSERT_FLOAT_EQ(1, m6x6d[0]);
|
||||
ASSERT_FLOAT_EQ(-2, m6x6d[1]);
|
||||
ASSERT_FLOAT_EQ(3, m6x6d[2]);
|
||||
ASSERT_FLOAT_EQ(-4, m6x6d[3]);
|
||||
ASSERT_FLOAT_EQ(5, m6x6d[4]);
|
||||
ASSERT_FLOAT_EQ(-6, m6x6d[5]);
|
||||
ASSERT_DOUBLE_EQ(1, m6x6d[0]);
|
||||
ASSERT_DOUBLE_EQ(-2, m6x6d[1]);
|
||||
ASSERT_DOUBLE_EQ(3, m6x6d[2]);
|
||||
ASSERT_DOUBLE_EQ(-4, m6x6d[3]);
|
||||
ASSERT_DOUBLE_EQ(5, m6x6d[4]);
|
||||
ASSERT_DOUBLE_EQ(-6, m6x6d[5]);
|
||||
|
||||
std::vector<long double> output(36);
|
||||
m6x6d.unpackSquareMatrix(output);
|
||||
@ -1087,13 +1096,13 @@ TEST(Array, SquareMatrixPackingIntegers)
|
||||
}
|
||||
{
|
||||
std::vector<long double> full(9);
|
||||
for (int i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
full[i] = i;
|
||||
}
|
||||
m3x3int.packSquareMatrix(full);
|
||||
ASSERT_EQ(9, m3x3int.size());
|
||||
for (int i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
ASSERT_EQ(i, m3x3int[i]);
|
||||
}
|
||||
@ -1123,7 +1132,7 @@ TEST(Array, SquareMatrixPackingInPlace)
|
||||
// Will fill with zeros - matrix is empty
|
||||
m3x3s.unpackSquareMatrix();
|
||||
ASSERT_EQ(9, m3x3s.size());
|
||||
for (unsigned i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
ASSERT_EQ(0, m3x3s[i]);
|
||||
}
|
||||
@ -1177,7 +1186,7 @@ TEST(Array, SquareMatrixPackingInPlace)
|
||||
m3x3s.unpackSquareMatrix();
|
||||
ASSERT_EQ(9, m3x3s.size());
|
||||
|
||||
for (unsigned i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
const bool diagonal = (i == 0) || (i == 4) || (i == 8);
|
||||
ASSERT_EQ((diagonal ? 123 : 0), m3x3s[i]);
|
||||
|
||||
@ -27,16 +27,16 @@ TEST(FloatSpec, Limits)
|
||||
typedef FloatSpec<64, CastModeSaturate> F64S;
|
||||
|
||||
ASSERT_FALSE(F16S::IsExactRepresentation);
|
||||
ASSERT_FLOAT_EQ(65504.0, F16S::max());
|
||||
ASSERT_FLOAT_EQ(9.77e-04, F16S::epsilon());
|
||||
ASSERT_FLOAT_EQ(65504.0F, F16S::max());
|
||||
ASSERT_FLOAT_EQ(9.77e-04F, F16S::epsilon());
|
||||
|
||||
ASSERT_TRUE(F32T::IsExactRepresentation);
|
||||
ASSERT_FLOAT_EQ(std::numeric_limits<float>::max(), F32T::max());
|
||||
ASSERT_FLOAT_EQ(std::numeric_limits<float>::epsilon(), F32T::epsilon());
|
||||
|
||||
ASSERT_TRUE(F64S::IsExactRepresentation);
|
||||
ASSERT_FLOAT_EQ(std::numeric_limits<double>::max(), F64S::max());
|
||||
ASSERT_FLOAT_EQ(std::numeric_limits<double>::epsilon(), F64S::epsilon());
|
||||
ASSERT_DOUBLE_EQ(std::numeric_limits<double>::max(), F64S::max());
|
||||
ASSERT_DOUBLE_EQ(std::numeric_limits<double>::epsilon(), F64S::epsilon());
|
||||
}
|
||||
|
||||
TEST(FloatSpec, Basic)
|
||||
@ -110,12 +110,12 @@ TEST(FloatSpec, Basic)
|
||||
|
||||
for (int i = 0; i < NumValues; i++)
|
||||
{
|
||||
ASSERT_EQ(1, F16S::encode(Values[i], sc_wr, uavcan::TailArrayOptDisabled));
|
||||
ASSERT_EQ(1, F16T::encode(Values[i], sc_wr, uavcan::TailArrayOptDisabled));
|
||||
ASSERT_EQ(1, F32S::encode(Values[i], sc_wr, uavcan::TailArrayOptDisabled));
|
||||
ASSERT_EQ(1, F32T::encode(Values[i], sc_wr, uavcan::TailArrayOptDisabled));
|
||||
ASSERT_EQ(1, F64S::encode(Values[i], sc_wr, uavcan::TailArrayOptDisabled));
|
||||
ASSERT_EQ(1, F64T::encode(Values[i], sc_wr, uavcan::TailArrayOptDisabled));
|
||||
ASSERT_EQ(1, F16S::encode(float(Values[i]), sc_wr, uavcan::TailArrayOptDisabled));
|
||||
ASSERT_EQ(1, F16T::encode(float(Values[i]), sc_wr, uavcan::TailArrayOptDisabled));
|
||||
ASSERT_EQ(1, F32S::encode(float(Values[i]), sc_wr, uavcan::TailArrayOptDisabled));
|
||||
ASSERT_EQ(1, F32T::encode(float(Values[i]), sc_wr, uavcan::TailArrayOptDisabled));
|
||||
ASSERT_EQ(1, F64S::encode(double(Values[i]), sc_wr, uavcan::TailArrayOptDisabled));
|
||||
ASSERT_EQ(1, F64T::encode(double(Values[i]), sc_wr, uavcan::TailArrayOptDisabled));
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, F16S::encode(0, sc_wr, uavcan::TailArrayOptDisabled)); // Out of buffer space now
|
||||
@ -130,20 +130,20 @@ TEST(FloatSpec, Basic)
|
||||
do { \
|
||||
StorageType<FloatType>::Type var = StorageType<FloatType>::Type(); \
|
||||
ASSERT_EQ(1, FloatType::decode(var, sc_rd, uavcan::TailArrayOptDisabled)); \
|
||||
if (!isnan(expected_value)) { \
|
||||
ASSERT_FLOAT_EQ(expected_value, var); } \
|
||||
if (!std::isnan(expected_value)) { \
|
||||
ASSERT_DOUBLE_EQ(expected_value, var); } \
|
||||
else { \
|
||||
ASSERT_EQ(!!isnan(expected_value), !!isnan(var)); } \
|
||||
ASSERT_EQ(!!std::isnan(expected_value), !!std::isnan(var)); } \
|
||||
} while (0)
|
||||
|
||||
for (int i = 0; i < NumValues; i++)
|
||||
{
|
||||
CHECK(F16S, ValuesF16S[i]);
|
||||
CHECK(F16T, ValuesF16T[i]);
|
||||
CHECK(F32S, Values[i]);
|
||||
CHECK(F32T, Values[i]);
|
||||
CHECK(F64S, Values[i]);
|
||||
CHECK(F64T, Values[i]);
|
||||
CHECK(F16S, float(ValuesF16S[i]));
|
||||
CHECK(F16T, float(ValuesF16T[i]));
|
||||
CHECK(F32S, float(Values[i]));
|
||||
CHECK(F32T, float(Values[i]));
|
||||
CHECK(F64S, double(Values[i]));
|
||||
CHECK(F64T, double(Values[i]));
|
||||
}
|
||||
|
||||
#undef CHECK
|
||||
@ -165,9 +165,9 @@ TEST(FloatSpec, Float16Representation)
|
||||
ASSERT_EQ(1, F16S::encode(0.0, sc_wr, uavcan::TailArrayOptDisabled));
|
||||
ASSERT_EQ(1, F16S::encode(1.0, sc_wr, uavcan::TailArrayOptDisabled));
|
||||
ASSERT_EQ(1, F16S::encode(-2.0, sc_wr, uavcan::TailArrayOptDisabled));
|
||||
ASSERT_EQ(1, F16T::encode(999999, sc_wr, uavcan::TailArrayOptDisabled)); // +inf
|
||||
ASSERT_EQ(1, F16S::encode(-999999, sc_wr, uavcan::TailArrayOptDisabled)); // -max
|
||||
ASSERT_EQ(1, F16S::encode(nan(""), sc_wr, uavcan::TailArrayOptDisabled)); // nan
|
||||
ASSERT_EQ(1, F16T::encode(999999, sc_wr, uavcan::TailArrayOptDisabled)); // +inf
|
||||
ASSERT_EQ(1, F16S::encode(-999999, sc_wr, uavcan::TailArrayOptDisabled)); // -max
|
||||
ASSERT_EQ(1, F16S::encode(float(nan("")), sc_wr, uavcan::TailArrayOptDisabled)); // nan
|
||||
|
||||
ASSERT_EQ(0, F16S::encode(0, sc_wr, uavcan::TailArrayOptDisabled)); // Out of buffer space now
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ TEST(Publisher, Basic)
|
||||
msg.payload = "Msg";
|
||||
|
||||
const uint8_t expected_transfer_payload[] = {0x42, 0x72, 0x08, 0xa5, 'M', 's', 'g'};
|
||||
const uint64_t tx_timeout_usec = publisher.getDefaultTxTimeout().toUSec();
|
||||
const uint64_t tx_timeout_usec = uint64_t(publisher.getDefaultTxTimeout().toUSec());
|
||||
|
||||
/*
|
||||
* Broadcast
|
||||
|
||||
@ -57,12 +57,12 @@ TEST(ServiceServer, Basic)
|
||||
/*
|
||||
* Request frames
|
||||
*/
|
||||
for (int i = 0; i < 2; i++)
|
||||
for (uint8_t i = 0; i < 2; i++)
|
||||
{
|
||||
// uint_fast16_t data_type_id, TransferType transfer_type, NodeID src_node_id, NodeID dst_node_id,
|
||||
// uint_fast8_t frame_index, TransferID transfer_id, bool last_frame
|
||||
uavcan::Frame frame(root_ns_a::StringService::DefaultDataTypeID, uavcan::TransferTypeServiceRequest,
|
||||
uavcan::NodeID(i + 0x10), 1, 0, i, true);
|
||||
uavcan::NodeID(uint8_t(i + 0x10)), 1, 0, i, true);
|
||||
|
||||
const uint8_t req[] = {'r', 'e', 'q', uint8_t(i + '0')};
|
||||
frame.setPayload(req, sizeof(req));
|
||||
|
||||
@ -107,14 +107,15 @@ TEST(Subscriber, Basic)
|
||||
* RxFrame generation
|
||||
*/
|
||||
std::vector<uavcan::RxFrame> rx_frames;
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
uavcan::TransferType tt = (i & 1) ? uavcan::TransferTypeMessageUnicast : uavcan::TransferTypeMessageBroadcast;
|
||||
uavcan::NodeID dni = (tt == uavcan::TransferTypeMessageBroadcast) ?
|
||||
uavcan::NodeID::Broadcast : node.getDispatcher().getNodeID();
|
||||
// uint_fast16_t data_type_id, TransferType transfer_type, NodeID src_node_id, NodeID dst_node_id,
|
||||
// uint_fast8_t frame_index, TransferID transfer_id, bool last_frame
|
||||
uavcan::Frame frame(uavcan::mavlink::Message::DefaultDataTypeID, tt, uavcan::NodeID(i + 100), dni, 0, i, true);
|
||||
uavcan::Frame frame(uavcan::mavlink::Message::DefaultDataTypeID, tt, uavcan::NodeID(uint8_t(i + 100)),
|
||||
dni, 0, i, true);
|
||||
frame.setPayload(transfer_payload, 7);
|
||||
uavcan::RxFrame rx_frame(frame, clock_driver.getMonotonic(), clock_driver.getUtc(), 0);
|
||||
rx_frames.push_back(rx_frame);
|
||||
@ -207,12 +208,12 @@ TEST(Subscriber, FailureCount)
|
||||
|
||||
ASSERT_EQ(0, sub.getFailureCount());
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
// uint_fast16_t data_type_id, TransferType transfer_type, NodeID src_node_id, NodeID dst_node_id,
|
||||
// uint_fast8_t frame_index, TransferID transfer_id, bool last_frame
|
||||
uavcan::Frame frame(uavcan::mavlink::Message::DefaultDataTypeID, uavcan::TransferTypeMessageBroadcast,
|
||||
uavcan::NodeID(i + 100), uavcan::NodeID::Broadcast, 0, i, true);
|
||||
uavcan::NodeID(uint8_t(i + 100)), uavcan::NodeID::Broadcast, 0, i, true);
|
||||
// No payload - broken transfer
|
||||
uavcan::RxFrame rx_frame(frame, clock_driver.getMonotonic(), clock_driver.getUtc(), 0);
|
||||
can_driver.ifaces[0].pushRx(rx_frame);
|
||||
@ -251,12 +252,12 @@ TEST(Subscriber, SingleFrameTransfer)
|
||||
|
||||
sub.start(listener.bindSimple());
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
// uint_fast16_t data_type_id, TransferType transfer_type, NodeID src_node_id, NodeID dst_node_id,
|
||||
// uint_fast8_t frame_index, TransferID transfer_id, bool last_frame
|
||||
uavcan::Frame frame(root_ns_a::EmptyMessage::DefaultDataTypeID, uavcan::TransferTypeMessageBroadcast,
|
||||
uavcan::NodeID(i + 100), uavcan::NodeID::Broadcast, 0, i, true);
|
||||
uavcan::NodeID(uint8_t(i + 100)), uavcan::NodeID::Broadcast, 0, i, true);
|
||||
// No payload - message is empty
|
||||
uavcan::RxFrame rx_frame(frame, clock_driver.getMonotonic(), clock_driver.getUtc(), 0);
|
||||
can_driver.ifaces[0].pushRx(rx_frame);
|
||||
|
||||
@ -156,7 +156,7 @@ struct InterlinkedTestNodes
|
||||
int spinBoth(uavcan::MonotonicDuration duration)
|
||||
{
|
||||
assert(!duration.isNegative());
|
||||
unsigned nspins2 = duration.toMSec() / 2;
|
||||
unsigned nspins2 = unsigned(duration.toMSec() / 2);
|
||||
nspins2 = nspins2 ? nspins2 : 1;
|
||||
while (nspins2 --> 0)
|
||||
{
|
||||
|
||||
@ -38,7 +38,7 @@ struct GlobalTimeSyncTestNetwork
|
||||
void spinAll(uavcan::MonotonicDuration duration = uavcan::MonotonicDuration::fromMSec(9))
|
||||
{
|
||||
assert(!duration.isNegative());
|
||||
unsigned nspins3 = duration.toMSec() / 3;
|
||||
unsigned nspins3 = unsigned(duration.toMSec() / 3);
|
||||
nspins3 = nspins3 ? nspins3 : 2;
|
||||
while (nspins3 --> 0)
|
||||
{
|
||||
|
||||
@ -193,7 +193,7 @@ TEST(GlobalTimeSyncSlave, Validation)
|
||||
slave_clock.preserve_utc = true;
|
||||
|
||||
CanDriverMock slave_can(3, slave_clock);
|
||||
for (int i = 0; i < slave_can.getNumIfaces(); i++)
|
||||
for (uint8_t i = 0; i < slave_can.getNumIfaces(); i++)
|
||||
{
|
||||
slave_can.ifaces.at(i).enable_utc_timestamping = true;
|
||||
}
|
||||
@ -283,7 +283,7 @@ TEST(GlobalTimeSyncSlave, Suppression)
|
||||
slave_clock.preserve_utc = true;
|
||||
|
||||
CanDriverMock slave_can(3, slave_clock);
|
||||
for (int i = 0; i < slave_can.getNumIfaces(); i++)
|
||||
for (uint8_t i = 0; i < slave_can.getNumIfaces(); i++)
|
||||
{
|
||||
slave_can.ifaces.at(i).enable_utc_timestamping = true;
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ static void publishNodeStatus(CanDriverMock& can, uavcan::NodeID node_id, uavcan
|
||||
uavcan::CanFrame can_frame;
|
||||
ASSERT_TRUE(frame.compile(can_frame));
|
||||
|
||||
for (int i = 0; i < can.getNumIfaces(); i++)
|
||||
for (uint8_t i = 0; i < can.getNumIfaces(); i++)
|
||||
{
|
||||
can.ifaces.at(i).pushRx(can_frame);
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ struct ParamServerTestManager : public uavcan::IParamManager
|
||||
KeyValue::const_iterator it = kv.find(name.c_str());
|
||||
if (it != kv.end())
|
||||
{
|
||||
out_value.value_float.push_back(it->second);
|
||||
out_value.value_float.push_back(float(it->second));
|
||||
}
|
||||
std::cout << "READ [" << name.c_str() << "]\n" << out_value << "\n---" << std::endl;
|
||||
}
|
||||
@ -146,7 +146,7 @@ TEST(ParamServer, Basic)
|
||||
ASSERT_STREQ("foobar", get_set_cln.collector.result->response.name.c_str());
|
||||
ASSERT_TRUE(get_set_cln.collector.result->response.value.value_bool.empty());
|
||||
ASSERT_TRUE(get_set_cln.collector.result->response.value.value_int.empty());
|
||||
ASSERT_FLOAT_EQ(123.456, get_set_cln.collector.result->response.value.value_float[0]);
|
||||
ASSERT_FLOAT_EQ(123.456F, get_set_cln.collector.result->response.value.value_float[0]);
|
||||
|
||||
// Set by index
|
||||
get_set_rq = uavcan::protocol::param::GetSet::Request();
|
||||
|
||||
@ -163,7 +163,7 @@ public:
|
||||
uavcan::ISystemClock& iclock;
|
||||
bool select_failure;
|
||||
|
||||
CanDriverMock(int num_ifaces, uavcan::ISystemClock& iclock)
|
||||
CanDriverMock(unsigned num_ifaces, uavcan::ISystemClock& iclock)
|
||||
: ifaces(num_ifaces, CanIfaceMock(iclock))
|
||||
, iclock(iclock)
|
||||
, select_failure(false)
|
||||
@ -179,15 +179,15 @@ public:
|
||||
return -1;
|
||||
}
|
||||
|
||||
const uavcan::uint8_t valid_iface_mask = (1 << getNumIfaces()) - 1;
|
||||
const uavcan::uint8_t valid_iface_mask = uavcan::uint8_t((1 << getNumIfaces()) - 1);
|
||||
EXPECT_FALSE(inout_masks.write & ~valid_iface_mask);
|
||||
EXPECT_FALSE(inout_masks.read & ~valid_iface_mask);
|
||||
|
||||
uavcan::uint8_t out_write_mask = 0;
|
||||
uavcan::uint8_t out_read_mask = 0;
|
||||
for (int i = 0; i < getNumIfaces(); i++)
|
||||
for (unsigned i = 0; i < getNumIfaces(); i++)
|
||||
{
|
||||
const uavcan::uint8_t mask = 1 << i;
|
||||
const uavcan::uint8_t mask = uavcan::uint8_t(1 << i);
|
||||
if ((inout_masks.write & mask) && ifaces.at(i).writeable)
|
||||
{
|
||||
out_write_mask |= mask;
|
||||
@ -208,14 +208,14 @@ public:
|
||||
{
|
||||
if (diff.isPositive())
|
||||
{
|
||||
mock->advance(diff.toUSec()); // Emulating timeout
|
||||
mock->advance(uint64_t(diff.toUSec())); // Emulating timeout
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (diff.isPositive())
|
||||
{
|
||||
usleep(diff.toUSec());
|
||||
usleep(unsigned(diff.toUSec()));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -224,12 +224,12 @@ public:
|
||||
}
|
||||
|
||||
virtual uavcan::ICanIface* getIface(uavcan::uint8_t iface_index) { return &ifaces.at(iface_index); }
|
||||
virtual uavcan::uint8_t getNumIfaces() const { return ifaces.size(); }
|
||||
virtual uavcan::uint8_t getNumIfaces() const { return uavcan::uint8_t(ifaces.size()); }
|
||||
};
|
||||
|
||||
enum FrameType { STD, EXT };
|
||||
inline uavcan::CanFrame makeCanFrame(uint32_t id, const std::string& str_data, FrameType type)
|
||||
{
|
||||
id |= (type == EXT) ? uavcan::CanFrame::FlagEFF : 0;
|
||||
return uavcan::CanFrame(id, reinterpret_cast<const uint8_t*>(str_data.c_str()), str_data.length());
|
||||
return uavcan::CanFrame(id, reinterpret_cast<const uint8_t*>(str_data.c_str()), uavcan::uint8_t(str_data.length()));
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ TEST(CanDriverMock, Basic)
|
||||
EXPECT_EQ(7, masks.write);
|
||||
EXPECT_EQ(0, masks.read);
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (unsigned i = 0; i < 3; i++)
|
||||
{
|
||||
driver.ifaces.at(i).writeable = false;
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ TEST(Frame, FrameParsing)
|
||||
|
||||
for (unsigned i = 0; i < sizeof(CanFrame::data); i++)
|
||||
{
|
||||
can.data[i] = i | (i << 4);
|
||||
can.data[i] = uint8_t(i | (i << 4));
|
||||
}
|
||||
|
||||
// CAN ID field order: Transfer ID, Last Frame, Frame Index, Source Node ID, Transfer Type, Data Type ID
|
||||
@ -227,7 +227,7 @@ TEST(Frame, FrameToString)
|
||||
uint8_t data[8];
|
||||
for (unsigned i = 0; i < sizeof(data); i++)
|
||||
{
|
||||
data[i] = i;
|
||||
data[i] = uint8_t(i);
|
||||
}
|
||||
rx_frame.setPayload(data, sizeof(data));
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ static uavcan::RxFrame makeFrame()
|
||||
uavcan::Frame(123, uavcan::TransferTypeMessageBroadcast, 1, uavcan::NodeID::Broadcast, 0, 1, true),
|
||||
tsMono(123), tsUtc(456), 0);
|
||||
uint8_t data[8];
|
||||
for (unsigned i = 0; i < sizeof(data); i++)
|
||||
for (uint8_t i = 0; i < sizeof(data); i++)
|
||||
{
|
||||
data[i] = i;
|
||||
}
|
||||
@ -93,12 +93,12 @@ TEST(MultiFrameIncomingTransfer, Basic)
|
||||
const uint8_t* const data_ptr = reinterpret_cast<const uint8_t*>(data.c_str());
|
||||
ASSERT_FALSE(bufmgr.access(bufmgr_key));
|
||||
ASSERT_TRUE(bufmgr.create(bufmgr_key));
|
||||
ASSERT_EQ(data.length(), bufmgr.access(bufmgr_key)->write(0, data_ptr, data.length()));
|
||||
ASSERT_EQ(data.length(), bufmgr.access(bufmgr_key)->write(0, data_ptr, unsigned(data.length())));
|
||||
|
||||
/*
|
||||
* Check
|
||||
*/
|
||||
ASSERT_TRUE(match(it, frame, data_ptr, data.length()));
|
||||
ASSERT_TRUE(match(it, frame, data_ptr, unsigned(data.length())));
|
||||
|
||||
/*
|
||||
* Buffer release
|
||||
|
||||
@ -22,12 +22,12 @@ static bool allEqual(const T (&a)[Size])
|
||||
return n == 0;
|
||||
}
|
||||
|
||||
template <typename T, unsigned Size>
|
||||
static void fill(T (&a)[Size], int value)
|
||||
template <typename T, unsigned Size, typename R>
|
||||
static void fill(T (&a)[Size], R value)
|
||||
{
|
||||
for (unsigned i = 0; i < Size; i++)
|
||||
{
|
||||
a[i] = value;
|
||||
a[i] = T(value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ static bool matchAgainst(const std::string& data, const uavcan::ITransferBuffer&
|
||||
}
|
||||
else
|
||||
{
|
||||
const int res = tbb.read(offset, local_buffer, len);
|
||||
const int res = tbb.read(offset, local_buffer, unsigned(len));
|
||||
if (res != len)
|
||||
{
|
||||
std::cout << "matchAgainst(): res " << res << " expected " << len << std::endl;
|
||||
@ -97,7 +97,7 @@ TEST(StaticTransferBuffer, Basic)
|
||||
ASSERT_TRUE(allEqual(local_buffer));
|
||||
|
||||
// Bulk write
|
||||
ASSERT_EQ(TEST_BUFFER_SIZE, buf.write(0, test_data_ptr, TEST_DATA.length()));
|
||||
ASSERT_EQ(TEST_BUFFER_SIZE, buf.write(0, test_data_ptr, unsigned(TEST_DATA.length())));
|
||||
ASSERT_TRUE(matchAgainstTestData(buf, 0));
|
||||
ASSERT_TRUE(matchAgainstTestData(buf, TEST_BUFFER_SIZE));
|
||||
ASSERT_TRUE(matchAgainstTestData(buf, TEST_BUFFER_SIZE / 2));
|
||||
@ -149,7 +149,7 @@ TEST(DynamicTransferBufferManagerEntry, Basic)
|
||||
ASSERT_TRUE(allEqual(local_buffer));
|
||||
|
||||
// Bulk write
|
||||
ASSERT_EQ(MAX_SIZE, buf.write(0, test_data_ptr, TEST_DATA.length()));
|
||||
ASSERT_EQ(MAX_SIZE, buf.write(0, test_data_ptr, unsigned(TEST_DATA.length())));
|
||||
|
||||
ASSERT_LT(0, pool.getNumUsedBlocks()); // Making sure some memory was used
|
||||
|
||||
@ -222,7 +222,7 @@ TEST(TransferBufferManager, TestDataValidation)
|
||||
|
||||
static int fillTestData(const std::string& data, uavcan::ITransferBuffer* tbb)
|
||||
{
|
||||
return tbb->write(0, reinterpret_cast<const uint8_t*>(data.c_str()), data.length());
|
||||
return tbb->write(0, reinterpret_cast<const uint8_t*>(data.c_str()), unsigned(data.length()));
|
||||
}
|
||||
|
||||
TEST(TransferBufferManager, Basic)
|
||||
|
||||
@ -106,9 +106,8 @@ TEST(TransferListener, CrcFailure)
|
||||
ASSERT_TRUE(ser_mft.size() > 1);
|
||||
ASSERT_TRUE(ser_sft.size() == 1);
|
||||
|
||||
// Fuck my brain.
|
||||
const_cast<uint8_t*>(ser_mft[1].getPayloadPtr())[1] = ~ser_mft[1].getPayloadPtr()[1]; // CRC is no longer valid
|
||||
const_cast<uint8_t*>(ser_sft[0].getPayloadPtr())[2] = ~ser_sft[0].getPayloadPtr()[2]; // no CRC - will be undetected
|
||||
const_cast<uint8_t*>(ser_mft[1].getPayloadPtr())[1] = uint8_t(~ser_mft[1].getPayloadPtr()[1]); // CRC invalid now
|
||||
const_cast<uint8_t*>(ser_sft[0].getPayloadPtr())[2] = uint8_t(~ser_sft[0].getPayloadPtr()[2]); // no CRC here
|
||||
|
||||
/*
|
||||
* Sending and making sure that MFT was not received, but SFT was.
|
||||
@ -122,7 +121,7 @@ TEST(TransferListener, CrcFailure)
|
||||
emulator.send(sers);
|
||||
|
||||
Transfer tr_sft_damaged = tr_sft;
|
||||
tr_sft_damaged.payload[2] = ~tr_sft.payload[2]; // Damaging the data similarly, so that it can be matched
|
||||
tr_sft_damaged.payload[2] = char(~tr_sft.payload[2]); // Damaging the data similarly, so that it can be matched
|
||||
|
||||
ASSERT_TRUE(subscriber.matchAndPop(tr_sft_damaged));
|
||||
ASSERT_TRUE(subscriber.isEmpty());
|
||||
|
||||
@ -25,7 +25,7 @@ struct RxFrameGenerator
|
||||
, bufmgr_key(bufmgr_key)
|
||||
{ }
|
||||
|
||||
uavcan::RxFrame operator()(int iface_index, const std::string& data, uint8_t frame_index, bool last,
|
||||
uavcan::RxFrame operator()(uint8_t iface_index, const std::string& data, uint8_t frame_index, bool last,
|
||||
uint8_t transfer_id, uint64_t ts_monotonic, uint64_t ts_utc = 0)
|
||||
{
|
||||
const uavcan::NodeID dst_nid =
|
||||
@ -35,7 +35,8 @@ struct RxFrameGenerator
|
||||
uavcan::Frame frame(data_type_id, bufmgr_key.getTransferType(), bufmgr_key.getNodeID(),
|
||||
dst_nid, frame_index, transfer_id, last);
|
||||
|
||||
EXPECT_EQ(data.length(), frame.setPayload(reinterpret_cast<const uint8_t*>(data.c_str()), data.length()));
|
||||
EXPECT_EQ(data.length(),
|
||||
frame.setPayload(reinterpret_cast<const uint8_t*>(data.c_str()), unsigned(data.length())));
|
||||
|
||||
return uavcan::RxFrame(frame, uavcan::MonotonicTime::fromUSec(ts_monotonic),
|
||||
uavcan::UtcTime::fromUSec(ts_utc), iface_index);
|
||||
@ -75,7 +76,7 @@ static bool matchBufferContent(const uavcan::ITransferBuffer* tbb, const std::st
|
||||
std::cerr << "matchBufferContent(): Content is too long" << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
tbb->read(0, data, content.length());
|
||||
tbb->read(0, data, unsigned(content.length()));
|
||||
if (std::equal(content.begin(), content.end(), data))
|
||||
{
|
||||
return true;
|
||||
@ -260,9 +261,9 @@ TEST(TransferReceiver, UnterminatedTransfer)
|
||||
uavcan::TransferBufferAccessor bk(context.bufmgr, RxFrameGenerator::DEFAULT_KEY);
|
||||
|
||||
std::string content;
|
||||
for (int i = 0; i <= uavcan::Frame::MaxIndex; i++)
|
||||
for (uint8_t i = 0; i <= uavcan::Frame::MaxIndex; i++)
|
||||
{
|
||||
CHECK_NOT_COMPLETE(rcv.addFrame(gen(1, "12345678", i, false, 0, 1000 + i), bk)); // Last one will be dropped
|
||||
CHECK_NOT_COMPLETE(rcv.addFrame(gen(1, "12345678", i, false, 0, 1000U + i), bk)); // Last one will be dropped
|
||||
content += "12345678";
|
||||
}
|
||||
CHECK_COMPLETE(rcv.addFrame(gen(1, "12345678", uavcan::Frame::MaxIndex, true, 0, 1100), bk));
|
||||
@ -461,7 +462,7 @@ TEST(TransferReceiver, HeaderParsing)
|
||||
/*
|
||||
* MFT, message unicast, service request/response
|
||||
*/
|
||||
for (int i = 0; i < int(sizeof(ADDRESSED_TRANSFER_TYPES) / sizeof(ADDRESSED_TRANSFER_TYPES[0])); i++)
|
||||
for (unsigned i = 0; i < (sizeof(ADDRESSED_TRANSFER_TYPES) / sizeof(ADDRESSED_TRANSFER_TYPES[0])); i++)
|
||||
{
|
||||
gen.bufmgr_key =
|
||||
uavcan::TransferBufferManagerKey(gen.bufmgr_key.getNodeID(), ADDRESSED_TRANSFER_TYPES[i]);
|
||||
@ -504,13 +505,13 @@ TEST(TransferReceiver, HeaderParsing)
|
||||
/*
|
||||
* SFT, message unicast, service request/response
|
||||
*/
|
||||
for (int i = 0; i < int(sizeof(ADDRESSED_TRANSFER_TYPES) / sizeof(ADDRESSED_TRANSFER_TYPES[0])); i++)
|
||||
for (unsigned i = 0; i < int(sizeof(ADDRESSED_TRANSFER_TYPES) / sizeof(ADDRESSED_TRANSFER_TYPES[0])); i++)
|
||||
{
|
||||
gen.bufmgr_key =
|
||||
uavcan::TransferBufferManagerKey(gen.bufmgr_key.getNodeID(), ADDRESSED_TRANSFER_TYPES[i]);
|
||||
uavcan::TransferBufferAccessor bk(context.bufmgr, gen.bufmgr_key);
|
||||
|
||||
const uavcan::RxFrame frame = gen(0, SFT_PAYLOAD_UNICAST, 0, true, tid.get(), i + 10000);
|
||||
const uavcan::RxFrame frame = gen(0, SFT_PAYLOAD_UNICAST, 0, true, tid.get(), i + 10000U);
|
||||
|
||||
CHECK_SINGLE_FRAME(rcv.addFrame(frame, bk));
|
||||
ASSERT_EQ(0x0000, rcv.getLastTransferCrc()); // Default value - zero
|
||||
|
||||
@ -13,7 +13,7 @@ static int sendOne(uavcan::TransferSender& sender, const std::string& data,
|
||||
uint64_t monotonic_tx_deadline, uint64_t monotonic_blocking_deadline,
|
||||
uavcan::TransferType transfer_type, uavcan::NodeID dst_node_id)
|
||||
{
|
||||
return sender.send(reinterpret_cast<const uint8_t*>(data.c_str()), data.length(),
|
||||
return sender.send(reinterpret_cast<const uint8_t*>(data.c_str()), unsigned(data.length()),
|
||||
uavcan::MonotonicTime::fromUSec(monotonic_tx_deadline),
|
||||
uavcan::MonotonicTime::fromUSec(monotonic_blocking_deadline), transfer_type, dst_node_id);
|
||||
}
|
||||
@ -22,7 +22,7 @@ static int sendOne(uavcan::TransferSender& sender, const std::string& data,
|
||||
uint64_t monotonic_tx_deadline, uint64_t monotonic_blocking_deadline,
|
||||
uavcan::TransferType transfer_type, uavcan::NodeID dst_node_id, uavcan::TransferID tid)
|
||||
{
|
||||
return sender.send(reinterpret_cast<const uint8_t*>(data.c_str()), data.length(),
|
||||
return sender.send(reinterpret_cast<const uint8_t*>(data.c_str()), unsigned(data.length()),
|
||||
uavcan::MonotonicTime::fromUSec(monotonic_tx_deadline),
|
||||
uavcan::MonotonicTime::fromUSec(monotonic_blocking_deadline), transfer_type, dst_node_id, tid);
|
||||
}
|
||||
@ -101,7 +101,7 @@ TEST(TransferSender, Basic)
|
||||
/*
|
||||
* Receiving on the other side.
|
||||
*/
|
||||
for (int i = 0; i < driver.getNumIfaces(); i++) // Moving the frames from TX to RX side
|
||||
for (uint8_t i = 0; i < driver.getNumIfaces(); i++) // Moving the frames from TX to RX side
|
||||
{
|
||||
CanIfaceMock& iface = driver.ifaces.at(i);
|
||||
std::cout << "Num frames: " << iface.tx.size() << std::endl;
|
||||
|
||||
@ -23,8 +23,8 @@ TEST(TransferTestHelpers, Transfer)
|
||||
// Filling the buffer with data
|
||||
static const std::string TEST_DATA = "Kaneda! What do you see? Kaneda! What do you see? Kaneda! Kaneda!!!";
|
||||
ASSERT_TRUE(tba.create());
|
||||
ASSERT_EQ(TEST_DATA.length(),
|
||||
tba.access()->write(0, reinterpret_cast<const uint8_t*>(TEST_DATA.c_str()), TEST_DATA.length()));
|
||||
ASSERT_EQ(TEST_DATA.length(), tba.access()->write(0, reinterpret_cast<const uint8_t*>(TEST_DATA.c_str()),
|
||||
unsigned(TEST_DATA.length())));
|
||||
|
||||
// Reading back
|
||||
const Transfer transfer(mfit, uavcan::DataTypeDescriptor());
|
||||
|
||||
@ -47,8 +47,8 @@ struct Transfer
|
||||
{
|
||||
break;
|
||||
}
|
||||
payload += std::string(reinterpret_cast<const char*>(buf), res);
|
||||
offset += res;
|
||||
payload += std::string(reinterpret_cast<const char*>(buf), unsigned(res));
|
||||
offset += unsigned(res);
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,27 +186,27 @@ std::vector<uavcan::RxFrame> serializeTransfer(const Transfer& transfer)
|
||||
if (need_crc)
|
||||
{
|
||||
uavcan::TransferCRC payload_crc = transfer.data_type.getSignature().toTransferCRC();
|
||||
payload_crc.add(reinterpret_cast<const uint8_t*>(transfer.payload.c_str()), transfer.payload.length());
|
||||
payload_crc.add(reinterpret_cast<const uint8_t*>(transfer.payload.c_str()), uint16_t(transfer.payload.length()));
|
||||
// Little endian
|
||||
raw_payload.push_back(payload_crc.get() & 0xFF);
|
||||
raw_payload.push_back((payload_crc.get() >> 8) & 0xFF);
|
||||
raw_payload.push_back(uint8_t(payload_crc.get() & 0xFF));
|
||||
raw_payload.push_back(uint8_t((payload_crc.get() >> 8) & 0xFF));
|
||||
}
|
||||
raw_payload.insert(raw_payload.end(), transfer.payload.begin(), transfer.payload.end());
|
||||
|
||||
std::vector<uavcan::RxFrame> output;
|
||||
unsigned frame_index = 0;
|
||||
uint8_t frame_index = 0;
|
||||
unsigned offset = 0;
|
||||
uavcan::MonotonicTime ts_monotonic = transfer.ts_monotonic;
|
||||
uavcan::UtcTime ts_utc = transfer.ts_utc;
|
||||
|
||||
while (true)
|
||||
{
|
||||
const int bytes_left = raw_payload.size() - offset;
|
||||
const int bytes_left = int(raw_payload.size()) - int(offset);
|
||||
EXPECT_TRUE(bytes_left >= 0);
|
||||
|
||||
uavcan::Frame frm(transfer.data_type.getID(), transfer.transfer_type, transfer.src_node_id,
|
||||
transfer.dst_node_id, frame_index, transfer.transfer_id);
|
||||
const int spres = frm.setPayload(&*(raw_payload.begin() + offset), bytes_left);
|
||||
const int spres = frm.setPayload(&*(raw_payload.begin() + offset), unsigned(bytes_left));
|
||||
if (spres < 0)
|
||||
{
|
||||
std::cerr << ">_<" << std::endl;
|
||||
@ -217,7 +217,7 @@ std::vector<uavcan::RxFrame> serializeTransfer(const Transfer& transfer)
|
||||
frm.makeLast();
|
||||
}
|
||||
|
||||
offset += spres;
|
||||
offset += unsigned(spres);
|
||||
EXPECT_GE(uavcan::Frame::MaxIndex, frame_index);
|
||||
frame_index++;
|
||||
|
||||
@ -236,7 +236,7 @@ std::vector<uavcan::RxFrame> serializeTransfer(const Transfer& transfer)
|
||||
|
||||
inline uavcan::DataTypeDescriptor makeDataType(uavcan::DataTypeKind kind, uint16_t id, const char* name = "")
|
||||
{
|
||||
const uavcan::DataTypeSignature signature((uint64_t(kind) << 16) | (id << 8) | (id & 0xFF));
|
||||
const uavcan::DataTypeSignature signature((uint64_t(kind) << 16) | uint16_t(id << 8) | uint16_t(id & 0xFF));
|
||||
return uavcan::DataTypeDescriptor(kind, id, signature, name);
|
||||
}
|
||||
|
||||
|
||||
@ -142,7 +142,7 @@ TEST(Map, Basic)
|
||||
{
|
||||
ASSERT_EQ(value, *res);
|
||||
}
|
||||
max_key_integer = i;
|
||||
max_key_integer = unsigned(i);
|
||||
}
|
||||
std::cout << "Max key/value: " << max_key_integer << std::endl;
|
||||
ASSERT_LT(4, max_key_integer);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user