Testframework
Overview
This is the central main component for your tests. In the first line of each Testfile you should import this module. Its highly recommended to import always the whole module:
from testframework import *
The testframework
contains multiple functions:
Group |
Available functions |
---|---|
Inputs/Outputs |
|
Supply |
|
Flow Control |
|
Trace |
|
Uart |
|
Device Info |
|
Others |
|
Testreport
A very important object of the testframework
is the report
object, where you can do all your value checks for the passed/failed criterias of your test. Any call in the report
will create an entry in the testreport.
To see all functions of the testreport modul see
Extension Modules
Another important feature of the test platform is its modularity. The ext
object is used in the testframework
to address the extension modules.
For all details about extensions, see
General Functions
- testframework.abortTest(msg: str)
This function aborts the running test.
- Parameters:
msg (str) – This message is displayed as the reason for cancellation in the test report.
- testframework.abortTestOnFailure(abort: bool)
Setup the behavior of the test if a test failed. The default value is
False
.- Parameters:
abort (bool) – Set this to
True
to stop the test on failed result.False
means that the test will continue when a step failed.
Example usage:
from testframework import * report.abortTestOnFailure(True)
Note
You can change the behavior during test as often as you want. If you have a sequence in which an error should lead to the test being stopped immediately, you can activate this option at the start of the sequence and deactivate it at the end.
- testframework.keepConfigurationAfterTest(keepConfig: bool)
After each test run, the framework resets the test box to default configuration (I/O Supply disabled, External Supply Relais disabled, …). If you want to debug the firmware of the DUT, this can lead to problems. You can therefore manually activate/deactivate the reset to default values via this function call.
The setting is retained until the box is restarted.
- Parameters:
keepConfig (bool) – Set this to
True
and all configuration will be kept after Test.False
(default value) will reset configuration after Test.
Example usage:
from testframework import * keepConfigurationAfterTest(True)
- testframework.enableIOSupply(level)
Activates the power supply for the IO-Pins. You can choose which voltage level is used.
- Parameters:
level – LEVEL_3V3, or LEVEL_5V
Example usage:
from testframework import * enableIOSupply(LEVEL_3V3)
- testframework.disableIOSupply()
Disables the power supply for the IO-Pins.
Example usage:
from testframework import * disableIOSupply()
- testframework.enableExternalSupply()
- testframework.disableExternalSupply()
- testframework.enableRelais(output)
Sets the Relaisoutput.
- Parameters:
output (int) – Number of the relais which should be set. You can use the constants (REL1 or REL2) or integer numbers (1-2)
Example usage:
from testframework import * enableRelais(REL2)
- testframework.disableRelais(output)
Unset the Relaisoutput.
- Parameters:
output (int) – Number of the relais which should be unset. You can use the constants (REL1 or REL2) or integer numbers (1-2)
Example usage:
from testframework import * disableRelais(REL2)
- testframework.getInputVoltage(input)
Measures and returns the voltage at an analog input pin.
- Parameters:
input (int) – Number of the analog input pin. You can use the constants (AIN1, AIN2, …, AIN8) or integer numbers (1-8)
- Returns:
Measured voltage in unit Volt
- Return type:
float
Example usage:
from testframework import * voltage = getInputVoltage(AIN1) print(voltage)
- testframework.setOutputVoltage(output, voltage: float)
Sets the output voltage of an analog output pin.
- Parameters:
output (int) – Analog output pin. You can use the constants (AOUT1, AOUT2) or integer numbers (1-2)
voltage (float) – Voltage in Volt
Note
You have to enable the IO-Supply with function
enableIOSupply
first. Keep in mind, that the maximum output voltage for the analog output is limited by the voltage level you have choosen.Example usage:
Sets the AOUT1 pin to 2,8V:
from testframework import * enableIOSupply(LEVEL_3V3) setOutputVoltage(AOUT1, 2.8)
- testframework.getInputs()
Returns the state of all digital inputs.
- Returns:
array of 12 elements with following values: 0 if the corresponding input is low, 1 if the corresponding input is high
Example usage:
from testframework import * inputStates = getInputs() if inputStates[0] == HIGH and inputStates[7] == LOW: print("Pin 1 is high and pin 8 is low") else: print("wrong pin levels")
- testframework.isInputHigh(input)
Checks if the geiven input has a hihg-level.
- Parameters:
input (int) – Digital intput pin. You can use the constants (IN1, IN2, … , IN12) or integer numbers (1-12)
- Returns:
True
if the pin is high.False
if the pin is low.
Example usage:
from testframework import * if isInputHigh(IN9): print("Pin is high") else: print("Pin is low")
- testframework.isInputLow(input: int)
See
isInputHigh()
- testframework.getInput(input: int)
- async testframework.waitForLow(input: int, timeout: int)
Waits until a given digital input pin is low or the timeout is over.
- Parameters:
input (int) – Digital intput pin. You can use the constants (IN1, IN2, … , IN12) or integer numbers (1-12)
timeout (int) – Timeout in milliseconds
- Returns:
True
if the pin got low within given timeout.False
if the timeout has expired.
Warning
this is an async function. You have to call it with
await
.Example usage:
To wait for low level of digital input pin 5 with a timeout of 2 seconds:
from testframework import * result = await waitForLow(IN5, 2000) if result == True: print("Pin is now low") else: print("Timeout")
- async testframework.waitForHigh(input: int, timeout: int)
See
waitForLow()
- testframework.setOutputLow(output: int)
Sets the Output to Low level (0V)
- Parameters:
output – Digital output pin. You can use the constants (OUT1, OUT2, … , OUT12) or integer numbers (1-12)
Example usage:
from testframework import * enableIOSupply(LEVEL_5V) setOutputLow(OUT3)
- testframework.setOutputHigh(output)
Sets the Output to High level. The voltage of high level is defined by the
enableIOSupply
call.- Parameters:
output – Digital output pin. You can use the constants (OUT1, OUT2, … , OUT12) or integer numbers (1-12)
Example usage:
from testframework import * enableIOSupply(LEVEL_3V3) setOutputHigh(OUT3)
- testframework.setOutputPWM(output: int, dutyCycle: float, frequency: int = -1)
Outputs a PWM signal at the given Output Pin. The high-voltage level of the signal is defined by the
enableIOSupply
call.Warning
OUT1 and OUT2 uses the same Timer. So both PWM outputs always have the same frequency! Changing the frequency of one also changes frequency of the other.
The same behavior also applies to OUT4 and OUT5. They also use the same timer (but they are completely independent to OUT1/OUT2).
- Parameters:
output – Digital output pin which can generate a PWM signal. Allowed: OUT1, OUT2, OUT4, OUT5.
dutyCycle (float) – duty cycle of the PWM signal in percent (0-100)
frequency (int) – (optional) defines the frequency of the signal in Hz. If this parameter is omitted, the signal will keep the last set frequency. On first call the frequency will set to 1kHz.
Example usage:
Outputs a 5kHz PWM Signal with 25% duty cycle at Pin OUT1.
from testframework import * enableIOSupply(LEVEL_5V) setOutputPWM(OUT1, 25.0, 5000)
- testframework.getDeviceTemperature()
Returns the current internal temperature of the Checkbox.
- Returns:
Temperature in °C
- Return type:
float
Example usage:
from testframework import * devTemp = getDeviceTemperature() report.infoValue("Device temperature", "%.1f °C" %devTemp)
- async testframework.sleep_ms(x)
- async testframework.sleep(x)
- testframework.getSerialNumber()
- testframework.getHWVersion()
- testframework.getSWVersion()
- async testframework.getUserInputBool(message: str) bool
Shows an user input dialog where the user can answer a simple Yes/No question.
- Parameters:
message (string) – Message that will be displayed
- Returns:
user input
- Return type:
bool
Example usage:
from testframework import * answer = await getUserInputBool("Is the green LED on?") report.checkBool("Green LED on", answer)
- async testframework.getUserInputString(message: str) str
Shows an user input dialog where the user can enter Text.
- Parameters:
message (string) – Message that will be displayed
- Returns:
user input
- Return type:
string
Example usage:
from testframework import * answer = await getUserInputString("Enter Serial Number") if len(answer) == 8: serialNumber = answer else: report.checkValue("Entered Serialnumber has wrong length.", len(answer), 8)
- async testframework.getUserInputInt(message: str) str
Shows an user input dialog where the user can enter an Integer Number.
- Parameters:
message (string) – Message that will be displayed
- Returns:
user input
- Return type:
string
Example usage:
from testframework import * answer = await getUserInputInt("Enter your personal number") report.putInfoValue("Personal Number of tester", answer)
- async testframework.getUserInputFloat(message: str) str
Shows an user input dialog where the user can enter an Floatingpoint Number.
- Parameters:
message (string) – Message that will be displayed
- Returns:
user input
- Return type:
string
Example usage:
from testframework import * answer = await getUserInputFloat("Enter current exchange rate") report.putInfoValue("Exchange Rate", answer)
- testframework.showProgressBar(description: str)
Shows a progress bar on the PC. This can be used to show the user a progress if a step during the test needs some time.
- Parameters:
description (string) – Text which will be displayed
Example usage:
from testframework import * showProgressBar("Download Firmware") for i in range(10): updateProgressBar(i*10) await sleep_ms(300) hideProgressBar()
- testframework.updateProgressBar(progress: float)
Sets the progress bar to given value. The progress value is in percent and have to be between 0-100%.
- Parameters:
progress (float) – Progress which should be set.
Example usage:
from testframework import * showProgressBar("Download Firmware") for i in range(10): updateProgressBar(i*10) await sleep_ms(300) hideProgressBar()
- testframework.hideProgressBar()
Hides the progress bar on PC and display.
Example usage:
from testframework import * showProgressBar("Download Firmware") for i in range(10): updateProgressBar(i*10) await sleep_ms(300) hideProgressBar()
- async testframework.executeCommand(cmdNumber: int, argument: str = '') int
Executes a command defined in the project settings on the connected computer. This can be used, for example, to download firmware to the device or to execute specific programmes on the PC that are required for the test. See also chapter Flash Firmware.
- Parameters:
cmdNumber (int) – selects which command from project settings should be executed.
argument (str) – (optional) Sets the argument values for the command.
- Returns:
The code returned by the command after its execution.
- Return type:
int
Example usage:
from testframework import * abortTestOnFailure(True) enableExternalSupply() await sleep(1.5) res = await executeCommand(1) report.checkBool("Download Firmware to the Device", res==0)
Trace Functions
With the trace function you can record an oscillogram of a signal. You can analyze the data and you can append the trace as a picture to your testreport.
The Trace Data is always recorded with 16 Bit unsigned integer values. The values have always the unit millivolt.
- testframework.TraceData(input: int, bufferSize: int, name: str)
Constructor of the TraceData Class. This will allocate the needed storage size for the trace data. If there is not enough space, it will throw an error.
Each data point in the trace object is a 16 Bit unsigned integer value.
- Parameters:
input (int) Number of the analog input pin. Attention: Only AIN1, AIN3 and AIN5 have trace capabilities.
bufferSize (int) Number of words which should be recorded. (bufferSize=1000 need 2000 Bytes of RAM)
name (str) Individual name of the signal. (Its used for the Testreport)
Example usage:
from testframework import * supplyTrace = TraceData(AIN1, 2000, "3,3V Power Supply")
- TraceData.len() int
Returns the bufferSize of the trace.
Example usage:
from testframework import * supplyTrace = TraceData(AIN1, 2000, "3,3V Power Supply") traceLen = supplyTrace.len()
- TraceData.name() str
Returns the name of the trace (which was set in the constructor)
- TraceData.timestep() int
Returns the time step in microseconds with which the data was recorded. Attention: This function will only return a correct value after you have started a record. Otherwiss
Example usage:
from testframework import * supplyTrace = TraceData(AIN1, 2000, "3,3V Power Supply") traceLen = supplyTrace.len()
- TraceData.getData(startIndex: int=0, length: int) tuple
Returns the recorded data as a tuple. This can be used if you want to perform your own data analysis.
- Parameters:
startIndex (int) [optional] start index of the data.
length (int) [optional] Number of words you want to get. If this parameter is not given, it returns all data from start to the end.
Example usage:
from testframework import * supplyTrace = TraceData(AIN1, 2000, "3,3V Power Supply") trace.start(supplyTrace, 100) await sleep_ms(200) #wait until trace record is finished (100us * 2000) data = supplyTrace.getData(0, supplyTrace.len()) min = 5000 max = 0 for val in data: if val < min: min = val if val > max: max = val
- TraceData.getEdges(edge: int, threshold: int = -1, blankingCnt: int = 0) tuple
Returns a tuple with all edges that cross the given threshold.
If no threshold is given, the threshold is set to the middle between the min and max value.
To filter noise on the signal, blankingCnt can be used to specify how many values should be ignored after the threshold has been exceeded.
- Parameters:
edge (int)
RISING
orFALLING
threshold (int) [optional] Threashold to evaluate.
blankingCnt (int) [optional] Number of values to be ignored after crossing the threashold.
Example usage:
from testframework import * pwmTrace = TraceData(AIN1, 2000, "PWM Signal") trace.start(pwmTrace, 10) await sleep_ms(20) #wait until trace record is finished (10us * 2000) risingEdges = pwmTrace.getEdges(RISING, blankingCnt=20)
- TraceData.applyFactor(factor: float) None
Can be used to scale the data. Keep in mind, that all data is an 16 Bit unsigned integer. If a value exceed 65535, it will be cutted at 655535.
- Parameters:
factor (float) factor which will be applyed to all values in the buffer.
Example usage:
from testframework import * supplyTrace = TraceData(AIN1, 2000, "3,3V Power Supply") trace.start(supplyTrace, 100) await sleep_ms(200) #wait until trace record is finished supplyTrace.applyFactor(0.5)
- TraceData.applyOffset(offset: int) None
Can be used to apply an offset to the data. Keep in mind, that all data is a 16 Bit integer. If a value exceed 65535, it will be cutted at 655535.
- Parameters:
offset (int) offset which will be applyed to all values in the buffer.
Example usage:
from testframework import * supplyTrace = TraceData(AIN1, 2000, "3,3V Power Supply") trace.start(supplyTrace, 100) await sleep_ms(200) #wait until trace record is finished supplyTrace.applyOffset(-1000)
- trace.start(traceObj: mixed, timeInterval: int) None
This function is used to start a trace. The trace object can be a single object or a tuple of trace objects. So it is possible to start multiple traces at the exact same time. But all traces will run with the given time interval.
This function returns immediately. The trace record is done in hardware via DMA. So you can proceed with your test during the record.
Keep in mind that you have to wait until the trace is finished before you can use the data. Trace duration is timeInterval * bufferSize.
To put the trace data into your testreport see
appendTrace()
.- Parameters:
traceObj (TraceData or tuple[TraceData]) Trace which should be started.
timeInterval (int) Timeinterval for the record in unit microseconds.
Example usage:
from testframework import * supply3V3Trace = TraceData(AIN1, 2000, "3,3V Power Supply") supply2V8Trace = TraceData(AIN3, 2000, "2,8V Power Supply") trace.start((supply3V3Trace, supply2V8Trace), 100) await sleep_ms(200) #wait until trace record is finished report.appendTrace("Power supply", (supply3V3Trace, supply2V8Trace))
Uart Functions
The testframework
contains two UART-Objects you can use to send and receive Data via digital IN11/OUT11 pins (uart1
) and IN12/OUT12 pins (uart2
).
If you initialise the uart object with the init
function, the pins will no longer work as digital IOs.
The same applies for the UART pins as for all other IOs: The voltage level must be set via enableIOSupply
. So it is possible to communicate with 3,3V level as well as 5V.
- UART.init(baudrate: int = 9600, bits: int = 8, parity: int = None, stop: int = 1, timeout: int = 0) None
Initialise the UART bus with the given parameters:
- Parameters:
baudrate (int) is the clock rate.
bits (int) is the number of bits per character, 7, 8 or 9.
parity is the parity, None, 0 (even) or 1 (odd).
stop is the number of stop bits, 1 or 2.
timeout specifies the time to wait for the first character (in ms) for functions such as
read
.
Example usage:
from testframework import * enableIOSupply(LEVEL_3V3) uart1.init(115200, parity=0)
- UART.readchar() int
Receive a single character on the bus.
- Returns:
The character read, as an integer. Returns -1 on timeout.
Example usage:
from testframework import * enableIOSupply(LEVEL_3V3) uart1.init(115200, parity=0) c = uart1.readchar() if c == -1: abortTest("No data received")
- UART.read([nbytes: int])
Read characters. If
nbytes
is specified then read at most that many bytes, otherwise read as much data as possible. It may return sooner if a timeout is reached. The timeout is configurable in the constructor.- Returns:
a bytes object containing the bytes read in. Returns
None
on timeout.
Example usage:
from testframework import * enableIOSupply(LEVEL_3V3) uart1.init(115200, parity=0) data = uart1.read(5)
- UART.readinto(buf: bytearray[, nbytes: int])
Read bytes into the buf. If
nbytes
is specified then read at most that many bytes. Otherwise, read at mostlen(buf)
bytes. It may return sooner if a timeout is reached. The timeout is configurable in the constructor.- Parameters:
buf (bytearray) buffer for the read data.
- Returns:
number of bytes read and stored into
buf
orNone
on timeout.
Example usage:
from testframework import * enableIOSupply(LEVEL_3V3) uart1.init(115200, parity=0) data = bytearray(5) uart1.readinto(data, 5)
- UART.readline() str
Read a line, ending in a newline character. It may return sooner if a timeout is reached. The timeout is configurable in the constructor.
- Returns:
the line read or
None
on timeout.
Example usage:
from testframework import * enableIOSupply(LEVEL_3V3) uart1.init(9600, parity=0) uart1.write("AT\n") answer = uart1.readline() report.checkString("Correct answer received?", answer, "OK")
- UART.writechar()
Write a single character on the bus.
char
is an integer to write.- Returns:
None
Example usage:
from testframework import * enableIOSupply(LEVEL_3V3) uart1.init(115200, parity=0) uart1.writechar(85)
- UART.write(buf: bytearray) int
Write the buffer of bytes to the bus.
- Parameters:
buf (bytearray/str) data to be sent.
- Returns:
number of bytes written.
Example usage:
from testframework import * enableIOSupply(LEVEL_3V3) uart1.init(115200, parity=0) uart1.write("AT\n") #alternative with bytearray: data = bytearray(3) data[0] = 0x2A data[1] = ord("*") data[2] = 13 uart1.write(data)
- UART.any() int
Returns an integer counting the number of characters that can be read without blocking. It will return 0 if there are no characters available and a positive number if there are characters. The method may return 1 even if there is more than one character available for reading.
Example usage:
from testframework import * enableIOSupply(LEVEL_3V3) uart1.init(115200, parity=0) if uart1.any() > 0: print("data available")