instrumentation dev_util
API Reference Manual  /  Python API  / 

stest

Name

stest — Utilities for testing simics.

Synopsis

Python

import stest

class stest.TestFailure

Synopsis

class stest.TestFailure

Description

Exception class used to signal failures in Simics tests.

Use the fail function instead of raising this exception yourself.

stest.fail

Synopsis

stest.fail(msg)

Description

Signal a failure in a test.

Takes a string describing the failure as its single argument. If called in collect failures mode this will collect the failure for later checking with check_failures. If called outside collect failures mode it will immediately raise a TestFailure exception instead.

stest.collect_failures

Synopsis

stest.collect_failures()

Description

Change the behavior of stest to collect failures instead of terminating on the first failure detected.

If you use this you have to call check_failures at the end of your test script to check if it signaled any failures.

stest.check_failures

Synopsis

stest.check_failures()

Description

Check if any failures have occurred and leave collect failures mode.

If any failures have occurred this function will report the failures and raise a TestFailure exception. If called outside collect failures mode this function will fail.

stest.trap_log

Synopsis

stest.trap_log(logtype, obj=None)

Description

Configure Simics to trap a type of log messages, and cause Simics to quit with a test failure on any such log message.

By default the stest trap ‘error’ and ‘spec-viol’ log messages.

trap_log without an object sets the default handling for the given log type. Object specific settings always take precedence over the default handling.

Arguments:

logtype
the type of log messages to trap, one of ‘info’, ‘error’, ‘undef’, ‘spec-viol’, and ‘unimpl’
obj
the configuration object whose log messages to trap, defaults to None, which means that all log messages of the right type are trapped

stest.untrap_log

Synopsis

stest.untrap_log(logtype, obj=None)

Description

Explicitly allow messages of a given log type.

Can be used to undo a previous trap_log or to filter objects from a default trap.

untrap_log without an object sets the default behavior for the given log type. Object specific settings always take precedence over the default handling.

Arguments:

logtype
the type of log messages to untrap, one of ‘info’, ‘error’, ‘undef’, ‘spec-viol’, and ‘unimpl’
obj
the configuration object whose log messages to untrap, defaults to None, which means that all log messages of the right type are untrapped

stest.trapped_log_types

Synopsis

stest.trapped_log_types()

Description

Returns the log types currently trapped.

stest.expect_true

Synopsis

stest.expect_true(cond, msg='expectation failed')

Description

Check if a condition is true and cause a test failure if it is not.

Arguments:

cond
the condition to test
msg
a message explaining the failure

stest.expect_false

Synopsis

stest.expect_false(cond, msg='expectation failed')

Description

Check if a condition is false and cause a test failure if it is not.

Arguments:

cond
the condition to test
msg
a message explaining the failure

stest.expect_equal

Synopsis

stest.expect_equal(got, expected, msg='expectation failed')

Description

Checks if a value is equal to an expectation and cause a test failure if it is not.

Arguments:

got
the value to check
expected
what to compare the value with
msg
a message explaining the failure

stest.expect_different

Synopsis

stest.expect_different(got, unexpected, msg='expectation failed')

Description

Checks if a value is different to an expectation.

Cause a test failure if it is not.

Arguments:

got
the value to check
unexpected
what to compare the value with
msg
a message explaining the failure

stest.expect_log

Synopsis

stest.expect_log(
    fun,
    args=[],
    obj=None,
    log_type='error',
    msg=None,
    regex='',
    with_log_level=None
)

Description

Call a function and verify that a particular log message is emitted.

Returns the called function’s return value.

Arguments:

fun
the function to be called
args
the arguments with which to call fun

All other arguments are identical to expect_log_mgr.

stest.expect_log_mgr

Synopsis

stest.expect_log_mgr(
    obj=None,
    log_type='error',
    msg=None,
    regex='',
    with_log_level=None
)

Description

Context manager, verifying that, on exit from the with-statement, a particular log message has been emitted.

Arguments:

obj
optional object from which a log is expected, default is None which accepts any object
log_type
optional log type which the emitted log must belong to, one of “error” (default), “unimpl”, “info”, “spec-viol” or “undefined”
msg
optional message emitted on failure
regex
optional regular expression object or a string containing a regular expression suitable for use by re.search(), which the emitted log must match
with_log_level
optional log level to apply inside the context

Example

with stest.expect_log_mgr(log_type="spec-viol",
                        msg="Check warning on read-only fields"):
reg_compute_units.write(0xffff_ffff_ffff_ffff)

stest.expect_exception

Synopsis

stest.expect_exception(fun, args, exc, regex='')

Description

Call function fun with arguments args, and verify that it raises an exception of type exc. If fun does not raise exc, cause a failure.

stest.expect_exception_mgr

Synopsis

stest.expect_exception_mgr(exc, regex='')

Description

Context manager verifying that the body of with-statement throws an exception of the specified type.

Arguments:

exc
exception type
regex
optional regular expression object or a string containing a regular expression suitable for use by re.search(), which the string representation of raised exception must match

Example

with stest.expect_exception_mgr(simics.SimExc_AttrNotWritable):
dev.read_only_attribute = False

stest.deprecation_level

Synopsis

stest.deprecation_level(level)

Description

Allow to temporarily set deprecation level to ‘level’.

Context manager for temporarily setting a deprecation level and restore it when exiting the context.

Arguments:

level
deprecation level in context

Example

with stest.deprecation_level(2)
stest.expect_equal(conf.sim.deprecation_level, 2)
instrumentation dev_util