Skip to content

Commit

Permalink
Fix test array sizes
Browse files Browse the repository at this point in the history
C++14 compiler compatibility

Updated test run scripts

Changed some ETL_ASSERT macros to ETL_ASSERT_OR_RETURN

Changed unit test macros for C++20 compaibility

Updated test run scripts

Updated CMake files to allow C++ standard selection

Replaced ETL_ASSERT_AND_RETURN with ETL_ASSERT_OR_RETURN

Updated C++14 & C++20 unit test compatibility

Changed native char8_t check

Added optional optimisation argument to bash script
  • Loading branch information
jwellbelove committed Mar 25, 2023
1 parent bb3faea commit 8eabe5f
Show file tree
Hide file tree
Showing 95 changed files with 2,461 additions and 1,221 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,6 @@ test/vs2022/Debug MSVC C++20
test/vs2022/Debug MSVC - Force C++03
test/vs2022/Debug MSVC - No STL - Built-ins
test/vs2022/Debug MSVC - No STL - Force Built-ins
test/temp
test/vs2022/Debug MSVC C++14
test/vs2022/Debug MSVC C++20 - No STL
8 changes: 4 additions & 4 deletions include/etl/bip_buffer_spsc_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,20 +267,20 @@ namespace etl
// Wrapped around already
if (write_index < read_index)
{
ETL_ASSERT_AND_RETURN((windex == write_index) && ((wsize + 1) <= read_index), ETL_ERROR(bip_buffer_reserve_invalid));
ETL_ASSERT_OR_RETURN((windex == write_index) && ((wsize + 1) <= read_index), ETL_ERROR(bip_buffer_reserve_invalid));
}
// No wraparound so far, also not wrapping around with this block
else if (windex == write_index)
{
ETL_ASSERT_AND_RETURN(wsize <= (capacity() - write_index), ETL_ERROR(bip_buffer_reserve_invalid));
ETL_ASSERT_OR_RETURN(wsize <= (capacity() - write_index), ETL_ERROR(bip_buffer_reserve_invalid));

// Move both indexes forward
last.store(windex + wsize, etl::memory_order_release);
}
// Wrapping around now
else
{
ETL_ASSERT_AND_RETURN((windex == 0) && ((wsize + 1) <= read_index), ETL_ERROR(bip_buffer_reserve_invalid));
ETL_ASSERT_OR_RETURN((windex == 0) && ((wsize + 1) <= read_index), ETL_ERROR(bip_buffer_reserve_invalid));
}

// Always update write index
Expand Down Expand Up @@ -330,7 +330,7 @@ namespace etl
if (rsize > 0)
{
size_type rsize_checker = rsize;
ETL_ASSERT_AND_RETURN((rindex == get_read_reserve(&rsize_checker)) && (rsize == rsize_checker), ETL_ERROR(bip_buffer_reserve_invalid));
ETL_ASSERT_OR_RETURN((rindex == get_read_reserve(&rsize_checker)) && (rsize == rsize_checker), ETL_ERROR(bip_buffer_reserve_invalid));

read.store(rindex + rsize, etl::memory_order_release);
}
Expand Down
63 changes: 6 additions & 57 deletions include/etl/bit_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,6 @@ SOFTWARE.

namespace etl
{
//***************************************************************************
/// Exception base for bit streams
//***************************************************************************
class bit_stream_exception : public etl::exception
{
public:

bit_stream_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
: exception(reason_, file_name_, line_number_)
{
}
};

//***************************************************************************
///\ingroup string
/// String empty exception.
//***************************************************************************
class bit_stream_overflow : public etl::bit_stream_exception
{
public:

bit_stream_overflow(string_type file_name_, numeric_type line_number_)
: bit_stream_exception(ETL_ERROR_TEXT("bit_stream:overflow", ETL_BIT_STREAM_FILE_ID"A"), file_name_, line_number_)
{
}
};

//***************************************************************************
/// Encodes and decodes bitstreams.
/// Data must be stored in the stream in network order.
Expand All @@ -89,8 +62,8 @@ namespace etl
/// Default constructor.
//***************************************************************************
bit_stream()
: pdata(ETL_NULLPTR),
length_chars(0U)
: pdata(ETL_NULLPTR)
, length_chars(0U)
{
restart();
}
Expand All @@ -99,8 +72,8 @@ namespace etl
/// Construct from range.
//***************************************************************************
bit_stream(void* begin_, void* end_)
: pdata(reinterpret_cast<unsigned char*>(begin_)),
length_chars(etl::distance(reinterpret_cast<unsigned char*>(begin_), reinterpret_cast<unsigned char*>(end_)))
: pdata(reinterpret_cast<unsigned char*>(begin_))
, length_chars(etl::distance(reinterpret_cast<unsigned char*>(begin_), reinterpret_cast<unsigned char*>(end_)))
{
restart();
}
Expand All @@ -109,8 +82,8 @@ namespace etl
/// Construct from begin and length.
//***************************************************************************
bit_stream(void* begin_, size_t length_)
: pdata(reinterpret_cast<unsigned char*>(begin_)),
length_chars(length_)
: pdata(reinterpret_cast<unsigned char*>(begin_))
, length_chars(length_)
{
restart();
}
Expand Down Expand Up @@ -667,10 +640,6 @@ namespace etl
{
write_unchecked(value);
}
else
{
ETL_ASSERT_FAIL(ETL_ERROR(etl::bit_stream_overflow));
}

return success;
}
Expand Down Expand Up @@ -700,10 +669,6 @@ namespace etl
{
write_unchecked(value, nbits);
}
else
{
ETL_ASSERT_FAIL(ETL_ERROR(etl::bit_stream_overflow));
}

return success;
}
Expand All @@ -730,10 +695,6 @@ namespace etl
step(static_cast<unsigned char>(nbits));
}
}
else
{
ETL_ASSERT_FAIL(ETL_ERROR(etl::bit_stream_overflow));
}

return success;
}
Expand Down Expand Up @@ -1144,10 +1105,6 @@ namespace etl
{
result = read_unchecked<bool>();
}
else
{
ETL_ASSERT_FAIL(ETL_ERROR(etl::bit_stream_overflow));
}

return result;
}
Expand Down Expand Up @@ -1180,10 +1137,6 @@ namespace etl
{
result = read_unchecked<T>(nbits);
}
else
{
ETL_ASSERT_FAIL(ETL_ERROR(etl::bit_stream_overflow));
}

return result;
}
Expand Down Expand Up @@ -1266,10 +1219,6 @@ namespace etl
step(static_cast<unsigned char>(nbits));
}
}
else
{
ETL_ASSERT_FAIL_AND_RETURN_VALUE(ETL_ERROR(etl::bit_stream_overflow), false);
}

return success;
}
Expand Down
4 changes: 2 additions & 2 deletions include/etl/callback_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,9 @@ namespace etl
#endif
#endif

volatile etl::timer_semaphore_t process_semaphore;
etl::timer_semaphore_t process_semaphore;
#endif
volatile uint_least8_t registered_timers;
uint_least8_t registered_timers;

public:

Expand Down
6 changes: 3 additions & 3 deletions include/etl/callback_timer_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,9 @@ namespace etl
// The list of active timers.
timer_list active_list;

volatile bool enabled;
volatile TSemaphore process_semaphore;
volatile uint_least8_t number_of_registered_timers;
bool enabled;
TSemaphore process_semaphore;
uint_least8_t number_of_registered_timers;

public:

Expand Down
4 changes: 2 additions & 2 deletions include/etl/callback_timer_interrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,8 @@ namespace etl
// The list of active timers.
timer_list active_list;

volatile bool enabled;
volatile uint_least8_t number_of_registered_timers;
bool enabled;
uint_least8_t number_of_registered_timers;

public:

Expand Down
4 changes: 2 additions & 2 deletions include/etl/callback_timer_locked.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ namespace etl
// The list of active timers.
timer_list active_list;

volatile bool enabled;
volatile uint_least8_t number_of_registered_timers;
bool enabled;
uint_least8_t number_of_registered_timers;

try_lock_type try_lock; ///< The callback that tries to lock.
lock_type lock; ///< The callback that locks.
Expand Down
10 changes: 5 additions & 5 deletions include/etl/char_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ namespace etl

template<> struct char_traits_types<wchar_t>
{
typedef wchar_t char_type;
typedef wchar_t int_type;
typedef long long off_type;
typedef size_t pos_type;
typedef char state_type;
typedef wchar_t char_type;
typedef uint_least16_t int_type;
typedef long long off_type;
typedef size_t pos_type;
typedef char state_type;
};

#if ETL_USING_CPP20
Expand Down
32 changes: 16 additions & 16 deletions include/etl/error_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,53 +269,53 @@ namespace etl
//***************************************************************************
#if defined(ETL_NO_CHECKS)
#define ETL_ASSERT(b, e) // Does nothing.
#define ETL_ASSERT_AND_RETURN(b, e) // Does nothing.
#define ETL_ASSERT_AND_RETURN_VALUE(b, e, v) // Does nothing.
#define ETL_ASSERT_OR_RETURN(b, e) // Does nothing.
#define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) // Does nothing.

#define ETL_ASSERT_FAIL(e) // Does nothing.
#define ETL_ASSERT_FAIL_AND_RETURN(e) // Does nothing.
#define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) // Does nothing.
#elif ETL_USING_EXCEPTIONS
#if defined(ETL_LOG_ERRORS)
#define ETL_ASSERT(b, e) {if (!(b)) {etl::error_handler::error((e)); throw((e));}} // If the condition fails, calls the error handler then throws an exception.
#define ETL_ASSERT_AND_RETURN(b, e) {if (!(b)) {etl::error_handler::error((e)); throw((e)); return;}} // If the condition fails, calls the error handler then throws an exception.
#define ETL_ASSERT_AND_RETURN_VALUE(b, e, v) {if (!(b)) {etl::error_handler::error((e)); throw((e)); return(v);}} // If the condition fails, calls the error handler then throws an exception.
#define ETL_ASSERT_OR_RETURN(b, e) {if (!(b)) {etl::error_handler::error((e)); throw((e)); return;}} // If the condition fails, calls the error handler then throws an exception.
#define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) {etl::error_handler::error((e)); throw((e)); return(v);}} // If the condition fails, calls the error handler then throws an exception.

#define ETL_ASSERT_FAIL(e) {etl::error_handler::error((e)); throw((e));} // Calls the error handler then throws an exception.
#define ETL_ASSERT_FAIL_AND_RETURN(e) {etl::error_handler::error((e)); throw((e)); return;} // Calls the error handler then throws an exception.
#define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {etl::error_handler::error((e)); throw((e)); return(v);} // Calls the error handler then throws an exception.
#else
#define ETL_ASSERT(b, e) {if (!(b)) {throw((e));}} // If the condition fails, throws an exception.
#define ETL_ASSERT_AND_RETURN(b, e) {if (!(b)) {throw((e)); return;}} // If the condition fails, throws an exception.
#define ETL_ASSERT_AND_RETURN_VALUE(b, e, v) {if (!(b)) {throw((e)); return(v);}} // If the condition fails, throws an exception.
#define ETL_ASSERT(b, e) {if (!(b)) {throw((e));}} // If the condition fails, throws an exception.
#define ETL_ASSERT_OR_RETURN(b, e) {if (!(b)) {throw((e));}} // If the condition fails, throws an exception.
#define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) {throw((e));}} // If the condition fails, throws an exception.

#define ETL_ASSERT_FAIL(e) {throw((e));} // Throws an exception.
#define ETL_ASSERT_FAIL_AND_RETURN(e) {throw((e)); return;} // Throws an exception.
#define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {throw((e)); return(v);} // Throws an exception.
#define ETL_ASSERT_FAIL(e) {throw((e));} // Throws an exception.
#define ETL_ASSERT_FAIL_AND_RETURN(e) {throw((e));} // Throws an exception.
#define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {throw((e));} // Throws an exception.

#endif
#else
#if defined(ETL_LOG_ERRORS)
#define ETL_ASSERT(b, e) {if(!(b)) {etl::error_handler::error((e));}} // If the condition fails, calls the error handler
#define ETL_ASSERT_AND_RETURN(b, e) {if(!(b)) {etl::error_handler::error((e)); return;}} // If the condition fails, calls the error handler and return
#define ETL_ASSERT_AND_RETURN_VALUE(b, e, v) {if(!(b)) {etl::error_handler::error((e)); return (v);}} // If the condition fails, calls the error handler and return a value
#define ETL_ASSERT_OR_RETURN(b, e) {if(!(b)) {etl::error_handler::error((e)); return;}} // If the condition fails, calls the error handler and return
#define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if(!(b)) {etl::error_handler::error((e)); return (v);}} // If the condition fails, calls the error handler and return a value

#define ETL_ASSERT_FAIL(e) {etl::error_handler::error((e));} // Calls the error handler
#define ETL_ASSERT_FAIL_AND_RETURN(e) {etl::error_handler::error((e)); return;} // Calls the error handler and return
#define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {etl::error_handler::error((e)); return (v);} // Calls the error handler and return a value
#else
#if ETL_IS_DEBUG_BUILD
#define ETL_ASSERT(b, e) assert((b)) // If the condition fails, asserts.
#define ETL_ASSERT_AND_RETURN(b, e) {if (!(b)) {assert(false); return;}} // If the condition fails, asserts and return.
#define ETL_ASSERT_AND_RETURN_VALUE(b, e, v) {if (!(b)) {assert(false); return(v);}} // If the condition fails, asserts and return a value.
#define ETL_ASSERT_OR_RETURN(b, e) {if (!(b)) {assert(false); return;}} // If the condition fails, asserts and return.
#define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) {assert(false); return(v);}} // If the condition fails, asserts and return a value.

#define ETL_ASSERT_FAIL(e) assert(false) // Asserts.
#define ETL_ASSERT_FAIL_AND_RETURN(e) {assert(false); return;} // Asserts.
#define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {assert(false); return(v);} // Asserts.
#else
#define ETL_ASSERT(b, e) // Does nothing.
#define ETL_ASSERT_AND_RETURN(b, e) {if (!(b)) return;} // Returns.
#define ETL_ASSERT_AND_RETURN_VALUE(b, e, v) {if (!(b)) return(v);} // Returns a value.
#define ETL_ASSERT_OR_RETURN(b, e) {if (!(b)) return;} // Returns.
#define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) return(v);} // Returns a value.

#define ETL_ASSERT_FAIL(e) // Does nothing.
#define ETL_ASSERT_FAIL_AND_RETURN(e) {return;} // Returns.
Expand Down
Loading

0 comments on commit 8eabe5f

Please sign in to comment.