How to write a program for a testing machine?

I'm working in a company that produces measurement devices. They are testet and calibrated on a machine. There are several steps like power test, communication test, calibrating inputs and outputs and so on.

The test and calibration steps are stored in a database. Not each device has the same steps. Some steps might be skipped.

The current code is a horrible spaghetti code written in Delphi with lots of it's and else's. I want to write some demo code in Rust to reproduce the behavior, but I'm not sure which way I should go.

The code should run in a loop to check several in- and outputs. And it should step through the different test and calibration steps.

Should I use a state machine or how can I implement this? I just need a rough sketch to get an idea where to start.

This seems like general program design advice, not really Rust specific, but some pointers:

  • Lean towards table-driven testing, to mimic the old system. Define a struct with all the parameters you need for a particular test suite, and loop over a constant array of each case.

  • For the one-off tests that don't have slight variations, give them one function each.

  • Get something working as a binary first, then decide if you should try to make #[test] work. (Single shot only)

  • Is this a long running binary that needs to test many different copies of the same device, or a single shot binary that you download to the SUT? (System Under Test)

    A long running binary needs to catch panics, handle catastrophic communication protocol errors, and in general be resilient to any poor behavior from the SUT.

  • A single shot binary can be specialized for each device you have. A long running binary needs to handle any device.

It's a long running binary. Depending on the device, there are a handful to several 100 devices that need to be tested.

You put a device in an adapter, close the lid and the test starts automatically. So you have different general states like "enter the order number", get Database Infos about the order, wait for the test begin, run the test, finish the test, wait for the next device.

There is also some kind of PLC involved. Check inputs, drive some outputs like Relais or pressure valves and so on.

With "table-driven testing" you mean to build an array that contains some kind of struct with informations about each step like the functions that should be tested and the necessary parameters for the test and then simply step to the next?

I think I can use an enum to define each test step and attach a struct with the parameters for this test. I can store this in an array and use match to call each test. Could this work?

And can I use async/await to run the test in the background while continue the loop with other stuff? I'm not sure if async/await works this way