TIM-011 gets a unit test library

2023/12/24

TIM-011 was an 8-bit teaching computer that was ostensibly developed by IMP in what is now Serbia.

It is hard to develop for any machine without a way to test quickly whether your work results in something usable. Since it takes quite a while to spin up a TIM-011 emulator and run things on it, it was not going to be practical to wait for all the slow machinery to get spun up.

Furthermore, for some reason the TIM-011 emulator still thinks that the floppy image is read only, which is not quite as expected.

But that is an aside.

Instead, I used the CPM Emulator to build TIM011 binaries and quickly test them under the pure CPM code. This does not test any graphical elements, but is enough to test any pure computational in-out routines.

The test library is trivial, and based on Jera Design LLC’s minunit, which is just a few lines of C code.

#include <stdio.h>
#include <stdlib.h>

#include "lib/testing/minunit.h"

int foo = 7;
int bar = 4;

static char* test_foo() {
    mu_assert("error, foo != 7", foo == 7);
    return 0;
}

static char* test_bar() {
    mu_assert("error, bar != 4", bar == 4);
    return 0;
}

char* all_tests() {
    mu_run_test(test_foo);
    mu_run_test(test_bar);
    return 0;
}

and its BUILD.bazel file:

load(
    "//build:sdcc.bzl",
    "sdcc_z180_c_binary",
    "sdcc_z180_cpm_test",
)

sdcc_z180_c_binary(
    name = "bin",
    srcs = ["test.c"],
    deps = [
        "//lib/testing:minunit",
    ],
)

sdcc_z180_cpm_test(
    name = "test",
    binary = ":bin",
)

It’s as simple as it gets.

But all of that machinery is hidden behind bazel’s test infrastructure, so the only think you need to do is to type the following in the command line:

bazel test //...

Here it is in a video. Note that this shows the process starting from scratch. Subsequent runs are much faster as bazel reuses any unchanged artifacts without rebuilding them.