mirror of
https://git.k-space.ee/arti/vt1200.git
synced 2026-10-31 12:05:05 +02:00
61 lines
2.0 KiB
C++
61 lines
2.0 KiB
C++
// Standalone unit tests for the VT1200 board register model.
|
|
// g++ -std=c++17 -o /tmp/t vt1200_board.cpp test_vt1200_board.cpp && /tmp/t
|
|
#include "vt1200_board.h"
|
|
#include <cassert>
|
|
#include <cstdio>
|
|
|
|
static int failures = 0;
|
|
#define CHECK(cond) do { if (!(cond)) { \
|
|
std::printf("FAIL %s:%d %s\n", __FILE__, __LINE__, #cond); failures++; } } while (0)
|
|
|
|
static void test_default_read(void)
|
|
{
|
|
vt1200_board b;
|
|
b.set_default(0x0000);
|
|
CHECK(b.read(VT1200_WIN2 + VT1200_OFF_STATUS) == 0x0000);
|
|
}
|
|
|
|
static void test_override_read(void)
|
|
{
|
|
vt1200_board b;
|
|
b.set_override(VT1200_WIN2 + VT1200_OFF_STATUS, 0x00b7);
|
|
CHECK(b.read(VT1200_WIN2 + VT1200_OFF_STATUS) == 0x00b7);
|
|
}
|
|
|
|
static void test_monitor_switch_is_mixed_with_latches(void)
|
|
{
|
|
vt1200_board b;
|
|
b.set_monitor_switch(7); // position 7 -> bits 4-6 = 0x70
|
|
b.write(VT1200_WIN3 + VT1200_OFF_SWITCH, 0x0001); // output latch writes bit 0
|
|
const uint16_t v = b.read(VT1200_WIN3 + VT1200_OFF_SWITCH);
|
|
CHECK((v & 0x0070) == 0x0070); // switch bits read back as input
|
|
CHECK((v & 0x0001) == 0x0001); // output bits read back as latched
|
|
}
|
|
|
|
static void test_busy_bit_arms_on_write_and_clears(void)
|
|
{
|
|
vt1200_board b;
|
|
b.set_model_handshake(true);
|
|
b.set_busy_ticks(2);
|
|
const uint32_t status = VT1200_WIN2 + VT1200_OFF_STATUS;
|
|
const uint32_t cmd = VT1200_WIN2 + VT1200_OFF_CMD;
|
|
|
|
CHECK((b.read(status) & 0x0001) == 0x0000); // idle
|
|
b.write(cmd, 0x00ca); // command arms it
|
|
CHECK((b.read(status) & 0x0001) == 0x0001); // busy
|
|
b.tick();
|
|
CHECK((b.read(status) & 0x0001) == 0x0001); // still busy
|
|
b.tick();
|
|
CHECK((b.read(status) & 0x0001) == 0x0000); // done
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
test_default_read();
|
|
test_override_read();
|
|
test_monitor_switch_is_mixed_with_latches();
|
|
test_busy_bit_arms_on_write_and_clears();
|
|
std::printf(failures ? "%d FAILURE(S)\n" : "all board tests passed\n", failures);
|
|
return failures ? 1 : 0;
|
|
}
|