Cuica

Test Scripts
Test ScriptsCuica Module

Cuica Module

Definition and usage of the Cuica Module

Description

The cuica module is the method by which scripts return information back to the Cuica and provides hooks to the Cuica for controlling execution flow. It must be explicitly imported with import cuica.

Buffers

The standard output buffer, i.e. print() buffer, is written to during the execution of the test script and then retrieved and stored after execution by the Cuica.

The results buffer, used for storing raw data results from the test script is also retrieved and stored after execution by the Cuica, however it is treated as binary data and not echoed to the execution console like the standard output buffer.

Exceeding either buffer size will raise an exception.

Constants

The following constants are provided by the cuica module:

  • cuica.STDOUT_BUFFER_SIZE: int

    A constant containing the maximum number of bytes available for stdout.

  • cuica.RESULTS_BUFFER_SIZE: int

    A constant containing the maximum number of bytes available for results.

Methods

The following methods are provided by the cuica module:

  • cuica.get_fw_version() -> str

    Get the fixture firmware version.

  • cuica.get_fw_dev_version() -> str

    Get the fixture firmware development version.

  • cuica.get_fw_type() -> str

    Get the fixture firmware type.

  • cuica.record_results(data: Union[bytes, str], append: bool)

    If append is True, record results data starting at the current results pointer and advance the results pointer up to a maximum of cuica.RESULTS_BUFFER_SIZE total bytes; if append is False, record results data at the start of the results buffer, replacing any existing results.

  • cuica.set_max_checkpoint(iterations: int)

    Set the maximum number of checkpoints.

  • cuica.checkpoint(current_checkpoint: int)

    Set the current checkpoint. This method also serves as the point at which a script may exit gracefully via a SystemExit exception, which is treated as a Pass (Early Exit) test condition within a Test Suite. The progress is continuously calculated for display purposes only by the Cuica based on the formula: (current_checkpoint / max_checkpoint) * 100.0.

  • cuica.get_current_checkpoint() -> int

    Get the current checkpoint.

  • cuica.set_dut_reset(reset_high: int)

    Set the DUT reset line to 3.3V if reset_high is 1, 0V if reset_high is 0.

Basic Cuica Example

Example script exercising the informational methods and constants on the cuica module:

Test Script
import cuica
 
# List all the members of the cuica module
print('\n'.join(dir(cuica)))
 
# View constants
print(f'Stdout buffer is {cuica.STDOUT_BUFFER_SIZE}')
print(f'Results buffer is {cuica.RESULTS_BUFFER_SIZE}')
 
# View Cuica fixture firmware versions
print(f'Version is: {cuica.get_fw_version()}')
print(f'Development Version is: {cuica.get_fw_dev_version()}')
print(f'Type is: {cuica.get_fw_type()}')
Output
__class__
__name__
__dict__
RESULTS_BUFFER_SIZE
STDOUT_BUFFER_SIZE
checkpoint
get_current_checkpoint
get_fw_dev_version
get_fw_type
get_fw_version
record_results
set_max_checkpoint
Stdout buffer is 16384
Results buffer is 16384
Version is: 0.4.1
Development Version is: 36253f3
Type is: Micropython

Results Example

Test Script
import cuica
 
# Generate some data to store
data = [0xde, 0xad, 0xbe, 0xef]
 
# Record the results, replacing whatever was there up to max size 
# of cuica.RESULTS_BUFFER_SIZE. The data type must be an object with
# a buffer protocol such as a str or bytes
cuica.record_results('some string')
cuica.record_results(bytes(data))
 
# Record the results, appending onto whatever was there up to max 
# size of cuica.RESULTS_BUFFER_SIZE
cuica.record_results(bytes(data), append=True)
 
# Reset the results buffer
cuica.record_results(bytes([]))
 
# Store a dict as JSON for the results
import ujson
some_object = {
    'data': data,
    'double data': data + data,
}
cuica.record_results(ujson.dumps(some_object))
Results File Contents
{"double data": [222, 173, 190, 239, 222, 173, 190, 239],"data": [222, 173, 190, 239]}

Basic Checkpoint Example

This script echos the state of the Squeak Board debugging switch input and sets the debugging LED output correspondingly while also advancing the checkpoint:

Test Script
import cuica
import machine
import time
from machine import Pin
 
# Set debugging GPIO pin directions
gpio0 = Pin(0, Pin.IN)
gpio1 = Pin(1, Pin.IN)
gpio2 = Pin(2, Pin.OUT)
gpio3 = Pin(3, Pin.OUT)
 
# For 500 iterations, set the LED to the state
# of the corresponding pushbutton switch
ITERATIONS=500
cuica.set_max_checkpoint(ITERATIONS)
for i in range(ITERATIONS):
   cuica.checkpoint(i)
   time.sleep(0.1)
   gpio2.value(gpio0.value())
   gpio3.value(gpio1.value())

Note that when testing this the Squeak Board PCB jumpers on JP1, JP2, JP3, and JP4 must be set to PCB and SRC.

Copyright © Uatha LLC. All rights reserved.