7. Test Bench Configuration Tutorial

Static configuration

The static configuration are the parameters statically configuring the execution of the test plan. They are used to modify the flow of the test without changing the test cases or test tools code itself. The following examples illustrate test parameters that should be defined in the static configuration.

Definition

In the context of a test bench implementation on spintop-openhtf, the static configuration is defined as classes of parameters accessible across the test bench sources.

Create a new file called static.py in the same folder as your test bench main. In the file, let’s define a class building the parameters of the sleep test. Add the following code to the file:

class SleepConfig():
    SLEEP_TIME = 5
    SLEEP_ITERATIONS = 2

Use of parameters

To access the configuration in the test bench code, simply import the class.

from static import SleepConfig

and access directly the instanciated parameters.

@plan.testcase('Sleep')
def sleep_test(test):
    """Waits five seconds"""

    for x in range(SleepConfig.SLEEP_ITERATIONS):
        print ("Sleep iteration {} - sleep time {}".format(x,
                                            SleepConfig.SLEEP_TIME))
        sleep(SleepConfig.SLEEP_TIME)

Add the use of the static configuration use to your latest test bench and run it.

The test will execute a 5 second sleep twice as determined

Sleep iteration 0 - sleep time 5
Sleep iteration 1 - sleep time 5

Use in Complex Test Benches

Multiple classes can be defined in the same configuration file. The pattern used for the definition is up to the developper. Each test case can have its own class of parameters, or they can be split according to product features across multiple test cases.

The static configuration as proposed is very useful in the definition of complex test benches, for example one managing the tests of different versions of the same products. In this case, the difference between the products can be parametrized using two classes with the same variables at different values.

class ProductVersionA():
    TRX_CNT = 2
    TEMP_SENSOR_I2C_ADDR = 0x49


class ProductVersionB():
    TRX_CNT = 1
    TEMP_SENSOR_I2C_ADDR = 0x48

Add the product version selection in the trigger phase and import dynamically the right class depending on the selected product. As illustrated below, using the custom trigger phase from the Custom Trigger Phase tutorial.

if test.state["product"] == "A":
    from static import ProductVersionA as ProductConfig
elif test.state["product"] == "B":
    from static import ProductVersionB as ProductConfig

print ("I2C Address: {}".format(ProductConfig.TEMP_SENSOR_I2C_ADDR))

Add the above code to the sleep test case and run it again. Enter “A” for the product when prompted and the right configuration for product A will be imported.

I2C Address: 0x49

Tutorial source

Configuration file

Test Station Configuration

The test station configuration is the list of all parameters configuring the test station itself, that is parameters changing from station to station and test jig to test jig, such as ip adresses, com port, etc.

Definition

In the context of a test bench implementation on spintop-openhtf, the test station configuration is defined as a yaml file. As an example, the following yaml snippet defines the configuration of the serial port and ip address of a test bench.

serial  :
 comport: "COM4"
 baudrate : "115200"
ip_address : "192.168.0.100"
test_constant: 4

Create a new .yml file, paste the above configurations in it and save it as config.yml in the same directory as your test bench main.py It will be imported in a test bench.

Load Configuration from File

To load the configurations in the test logic, the openhth conf module must be imported.

from openhtf.util import conf

The configuration parameters used must then be defined. A description of the configuration can be added to the declaration.

conf.declare("serial", 'A dict that contains two keys, "comport" and "baudrate"')
conf.declare("ip_address", 'The IP Address of the testbench')
conf.declare("test_constant", 'A test constant')

and the configuration file loaded.

conf.load_from_filename("config.yml")

Use Configuration

Once loaded and declared, the test station parameters can be accessed through the conf object. For example, to print soome of the configuration parameters, use the following in a test case:

print ("Serial port is {}".format(conf.serial["comport"]))
print ("IP address is {}".format(conf.ip_address))
print ("Test constant is {}".format(conf.test_constant))

Add the above code excerpts to your latest test bench and run it.

The test will print the information in the console window as

Serial port is COM4
IP address is 192.168.0.100
Test constant is 4

Built-in station id parameter

Spintop-openhtf uses a built-in parameter in the conf object that defines the test station id. The id used is the hostname of the PC on which the test bench runs. For example, printing the station ID of a PC whose hostname is “TutorialStation”

print ("Station ID is {}".format(conf.station_id))

will result in

Station ID is TutorialStation

Tutorial source

Configuration file