A bit of header containment.
Encode the list of /bin/cheritest commands and test cases once in an array
rather than twice, once in usage and once in a big list of if/else checks.
Normalise several test names based on the expectation that they will (or
won't) generate a fault.
Define useful constants for accessing the exception code and register
portions of the CHERI capability cause register.
Time out libcheri simple sandbox tests after 10 seconds -- this is primarily
intended for the 'spin' test but might help with others if they get
unintentionally stuck.
Add a header-file TODO to add 32-bit versions of the 64-bit CP2 state length
and pointer in mcontext.  We won't need this, but if we upstream userspace
CP2 support, then it may get used on MIPS processors that do need it.
Add a comment about a device-driver race condition that could cause the BERI
pipeline to wedge awaiting JTAG in the event that both the low-level console
and the tty layer decide to write to the JTAG FIFO just before JTAG is
disconnected.  Resolving this race is a bit tricky as it looks like there
isn't a way to 'give the character back' to the tty layer when we discover
the race.  The easy fix is to drop the character, which we don't yet do, but
perhaps should as that is a better outcome than wedging the pipeline.
Produce less partial output for tests intended to trigger faults: print out
the register name that was retrieved only if it was in fact improperly
retrieved (e.g., the fault didn't occur as expected).
Improve the readability of the MIPS sendsig() by clearly indicating that
calls to sigexit(9) will never return, since the kernel thread will exit.
Rewrite cheri_bcopy() and cheri_memcpy() in assembly -- it turns out that
memory copy routines used by copyin() and copyout(), and hence by
implication also those used in copyincap() and copyoutcap(), are not
allowed to use the stack, as they may be preempted due to a fault without
following their normal function return path / unwind.  This could lead to
stack corruption in the event a copyin/copyout of capability data
experienced a fault (e.g., page fault, unaligned access, etc).  The result
is similarly constrained to Very Aligned Memory, but probably a bit faster.
It may be as correct.
Substantial further reworking of CheriBSD's /bin/cheritest to improve it as
a testing, rather than just exercise, tool:

- Flag each test with whether it is expected to terminate with a signal, and
  if so, what signal number, and optionally, what MIPS exception code and
  CHERI exception code to expect.  If these are specified, they are tested
  for to decide if the test passed.

- Specify expected signal/exception information for all tests.

- Fork a new process for each test run, and set up a shared memory page,
  cheritest_child_state, used to propagate signal/exception information back
  to the parent process.

- Install signal handlers for various signals in the child process and use
  that to fill out cheritest_child_state.

- Provide each test with a plaintext description to be printed as tests run
  to make the results more human-friendly.

- Clearly print TEST, and PASS/FAIL information when each test runs.

- A special 'all' command-line argument is supported, which will run all
  available tests in order.

- Resort tests in cheri_tests[] array by general function.

Most tests pass, with the exception of 'invoke_spin', which times out after
10 seconds with a timer signal, which can't be properly delivered to the
in-sandbox stack.  This requires some further diagnosis and fixing.

/bin/cheritest is now increasingly suitable to be run as part of a larger
test environment to ensure that a range of CHERI and CheriBSD functions are
working properly.  It could use a lot more tests, though.