Files
templates/c/telemetry-logger/tests/test_telemetry_logger.c
T

54 lines
2.3 KiB
C

#include "telemetry_gas.h"
#include <assert.h>
int main(void)
{
slog_t log;
slog_gas_t gas;
slog_sample_t bank[2][4] = {0};
uint16_t words[18];
assert(!slog_init(&log, 2, bank[0], bank[1], 4, 4));
assert(slog_init(&log, 2, bank[0], bank[1], 4, 1));
assert(!slog_gas_init(&gas, &log, 0x6000, 0x6001, 0, 1));
assert(slog_gas_init(&gas, &log, 0x6000, 0x5000, 0x89abcdef, 1));
assert(slog_gas_write(&gas, 0x6012, GL_START) == GL_OK);
int32_t values[] = {2000, -302};
for (unsigned i = 0; i < 7; ++i) {
assert(slog_push(&log, i * 1250, i == 5 ? 2 : 3, i == 5 ? 9 : 0, values, i == 5));
}
uint64_t cursor = 0;
slog_sample_t row;
assert(slog_read(&log, &cursor, &row) && cursor == 4 && row.sequence == 3);
uint32_t generation;
size_t count, trigger;
assert(slog_archive_info(&log, &generation, &count, &trigger));
assert(count == 4 && trigger == 2);
assert(slog_gas_read(&gas, 0x6000, words, 18) == GL_OK);
assert(words[2] == 3 && words[7] == 4 && words[10] == 0xcdef && words[11] == 0x89ab);
assert(slog_gas_read(&gas, 0x610d, words, 9) == GL_OK);
assert(words[1] == 6 && words[2] == 0 && words[3] == 5 && words[5] == 9);
assert(words[6] == UINT16_MAX && words[7] == (uint16_t)-302 && words[8] == 7);
assert(slog_push(&log, 10000, 3, 8, values, true));
assert(log.missed_triggers == 1);
assert(slog_gas_write(&gas, 0x6012, GL_RELEASE) == GL_STALE);
assert(slog_gas_write(&gas, 0x6013, (uint16_t)generation) == GL_OK);
assert(slog_gas_write(&gas, 0x6012, GL_RELEASE) == GL_OK);
assert(slog_read(&log, &cursor, &row) && cursor == 8 && row.sequence == 7);
assert(!slog_push(&log, 1, 3, 0, values, false));
assert(slog_gas_read(&gas, 0x5000, words, 2) == GL_OK);
assert(words[0] == 2000 && words[1] == (uint16_t)-302);
assert(slog_gas_write(&gas, 0x6012, GL_SNAPSHOT) == GL_OK);
assert(slog_archive_info(&log, &generation, &count, &trigger));
assert(count == 1 && trigger == count);
slog_t other;
static slog_sample_t wide[1];
int32_t channels[40] = {0};
channels[39] = 42;
assert(slog_init(&other, 40, wide, NULL, 1, 0));
assert(slog_push(&other, 0, UINT64_C(1) << 39, 0, channels, false));
assert(slog_latest(&other, &row) && row.values[39] == 42);
return 0;
}