libtest: Fix use of flexible array member

Flexible array members must not appear in the middle of a structure.
This commit is contained in:
Sebastian Huber
2021-04-08 07:51:38 +02:00
parent 1eb6cdde60
commit 5b97821bc8
3 changed files with 37 additions and 35 deletions

View File

@@ -89,10 +89,8 @@ typedef struct T_fixture_node {
#if defined(__GNUC__) || __STDC_VERSION__ >= 199409L #if defined(__GNUC__) || __STDC_VERSION__ >= 199409L
#define T_ZERO_LENGTH_ARRAY #define T_ZERO_LENGTH_ARRAY
#define T_ZERO_LENGTH_ARRAY_EXTENSION(n) (n)
#else #else
#define T_ZERO_LENGTH_ARRAY 1 #define T_ZERO_LENGTH_ARRAY 1
#define T_ZERO_LENGTH_ARRAY_EXTENSION(n) ((n) - 1)
#endif #endif
/** @} */ /** @} */
@@ -2434,22 +2432,26 @@ typedef struct {
size_t recorded; size_t recorded;
size_t capacity; size_t capacity;
uint64_t switches; uint64_t switches;
} T_thread_switch_header;
typedef struct {
T_thread_switch_header header;
T_thread_switch_event events[T_ZERO_LENGTH_ARRAY]; T_thread_switch_event events[T_ZERO_LENGTH_ARRAY];
} T_thread_switch_log; } T_thread_switch_log;
typedef struct { typedef struct {
T_thread_switch_log log; T_thread_switch_header header;
T_thread_switch_event events[T_ZERO_LENGTH_ARRAY_EXTENSION(2)]; T_thread_switch_event events[2];
} T_thread_switch_log_2; } T_thread_switch_log_2;
typedef struct { typedef struct {
T_thread_switch_log log; T_thread_switch_header header;
T_thread_switch_event events[T_ZERO_LENGTH_ARRAY_EXTENSION(4)]; T_thread_switch_event events[4];
} T_thread_switch_log_4; } T_thread_switch_log_4;
typedef struct { typedef struct {
T_thread_switch_log log; T_thread_switch_header header;
T_thread_switch_event events[T_ZERO_LENGTH_ARRAY_EXTENSION(10)]; T_thread_switch_event events[10];
} T_thread_switch_log_10; } T_thread_switch_log_10;
T_thread_switch_log *T_thread_switch_record(T_thread_switch_log *); T_thread_switch_log *T_thread_switch_record(T_thread_switch_log *);

View File

@@ -96,11 +96,11 @@ T_thread_switch_recorder(Thread_Control *executing, Thread_Control *heir)
if (log != NULL) { if (log != NULL) {
size_t recorded; size_t recorded;
++log->switches; ++log->header.switches;
recorded = log->recorded; recorded = log->header.recorded;
if (recorded < log->capacity) { if (recorded < log->header.capacity) {
log->recorded = recorded + 1; log->header.recorded = recorded + 1;
log->events[recorded].executing = executing->Object.id; log->events[recorded].executing = executing->Object.id;
log->events[recorded].heir = heir->Object.id; log->events[recorded].heir = heir->Object.id;
log->events[recorded].cpu = log->events[recorded].cpu =
@@ -127,8 +127,8 @@ T_thread_switch_record(T_thread_switch_log *log)
} }
if (log != NULL) { if (log != NULL) {
log->recorded = 0; log->header.recorded = 0;
log->switches = 0; log->header.switches = 0;
} }
rtems_interrupt_lock_acquire(&ctx->lock, &lock_context); rtems_interrupt_lock_acquire(&ctx->lock, &lock_context);
@@ -142,20 +142,20 @@ T_thread_switch_record(T_thread_switch_log *log)
T_thread_switch_log * T_thread_switch_log *
T_thread_switch_record_2(T_thread_switch_log_2 *log) T_thread_switch_record_2(T_thread_switch_log_2 *log)
{ {
log->log.capacity = 2; log->header.capacity = T_ARRAY_SIZE(log->events);
return T_thread_switch_record(&log->log); return T_thread_switch_record((T_thread_switch_log *)log);
} }
T_thread_switch_log * T_thread_switch_log *
T_thread_switch_record_4(T_thread_switch_log_4 *log) T_thread_switch_record_4(T_thread_switch_log_4 *log)
{ {
log->log.capacity = 4; log->header.capacity = T_ARRAY_SIZE(log->events);
return T_thread_switch_record(&log->log); return T_thread_switch_record((T_thread_switch_log *)log);
} }
T_thread_switch_log * T_thread_switch_log *
T_thread_switch_record_10(T_thread_switch_log_10 *log) T_thread_switch_record_10(T_thread_switch_log_10 *log)
{ {
log->log.capacity = 10; log->header.capacity = T_ARRAY_SIZE(log->events);
return T_thread_switch_record(&log->log); return T_thread_switch_record((T_thread_switch_log *)log);
} }

View File

@@ -222,23 +222,23 @@ T_TEST_CASE(TestThreadSwitch)
memset(&log_2, 0xff, sizeof(log_2)); memset(&log_2, 0xff, sizeof(log_2));
log = T_thread_switch_record_2(&log_2); log = T_thread_switch_record_2(&log_2);
T_null(log); T_null(log);
T_eq_sz(log_2.log.recorded, 0); T_eq_sz(log_2.header.recorded, 0);
T_eq_sz(log_2.log.capacity, 2); T_eq_sz(log_2.header.capacity, 2);
T_eq_u64(log_2.log.switches, 0); T_eq_u64(log_2.header.switches, 0);
memset(&log_4, 0xff, sizeof(log_4)); memset(&log_4, 0xff, sizeof(log_4));
log = T_thread_switch_record_4(&log_4); log = T_thread_switch_record_4(&log_4);
T_eq_ptr(log, &log_2.log); T_eq_ptr(&log->header, &log_2.header);
T_eq_sz(log_4.log.recorded, 0); T_eq_sz(log_4.header.recorded, 0);
T_eq_sz(log_4.log.capacity, 4); T_eq_sz(log_4.header.capacity, 4);
T_eq_u64(log_4.log.switches, 0); T_eq_u64(log_4.header.switches, 0);
memset(&log_10, 0xff, sizeof(log_10)); memset(&log_10, 0xff, sizeof(log_10));
log = T_thread_switch_record_10(&log_10); log = T_thread_switch_record_10(&log_10);
T_eq_ptr(log, &log_4.log); T_eq_ptr(&log->header, &log_4.header);
T_eq_sz(log_10.log.recorded, 0); T_eq_sz(log_10.header.recorded, 0);
T_eq_sz(log_10.log.capacity, 10); T_eq_sz(log_10.header.capacity, 10);
T_eq_u64(log_10.log.switches, 0); T_eq_u64(log_10.header.switches, 0);
for (i = 0; i < 6; ++i) { for (i = 0; i < 6; ++i) {
rtems_status_code sc; rtems_status_code sc;
@@ -248,10 +248,10 @@ T_TEST_CASE(TestThreadSwitch)
} }
log = T_thread_switch_record(NULL); log = T_thread_switch_record(NULL);
T_eq_ptr(log, &log_10.log); T_eq_ptr(&log->header, &log_10.header);
T_eq_sz(log->recorded, 10); T_eq_sz(log->header.recorded, 10);
T_eq_sz(log->capacity, 10); T_eq_sz(log->header.capacity, 10);
T_eq_u64(log->switches, 12); T_eq_u64(log->header.switches, 12);
executing = rtems_task_self(); executing = rtems_task_self();
T_eq_u32(log->events[0].executing, executing); T_eq_u32(log->events[0].executing, executing);
T_ne_u32(log->events[0].heir, 0); T_ne_u32(log->events[0].heir, 0);