stest — Utilities for testing simics.
import stest
class stest.TestFailure
Exception class used to signal failures in Simics tests.
Use the fail function instead of raising this exception yourself.
stest.fail(msg)
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()
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()
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(logtype, obj=None)
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:
stest.untrap_log(logtype, obj=None)
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:
stest.trapped_log_types()
Returns the log types currently trapped.
stest.expect_true(cond, msg='expectation failed')
Check if a condition is true and cause a test failure if it is not.
Arguments:
stest.expect_false(cond, msg='expectation failed')
Check if a condition is false and cause a test failure if it is not.
Arguments:
stest.expect_equal(got, expected, msg='expectation failed')
Checks if a value is equal to an expectation and cause a test failure if it is not.
Arguments:
stest.expect_different(got, unexpected, msg='expectation failed')
Checks if a value is different to an expectation.
Cause a test failure if it is not.
Arguments:
stest.expect_log(
fun,
args=[],
obj=None,
log_type='error',
msg=None,
regex='',
with_log_level=None
)
Call a function and verify that a particular log message is emitted.
Returns the called function’s return value.
Arguments:
funAll other arguments are identical to expect_log_mgr.
stest.expect_log_mgr(
obj=None,
log_type='error',
msg=None,
regex='',
with_log_level=None
)
Context manager, verifying that, on exit from the with-statement, a particular log message has been emitted.
Arguments:
re.search(), which the emitted log must matchwith 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(fun, args, exc, regex='')
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(exc, regex='')
Context manager verifying that the body of with-statement throws an exception of the specified type.
Arguments:
re.search(), which the string representation of raised exception must matchwith stest.expect_exception_mgr(simics.SimExc_AttrNotWritable):
dev.read_only_attribute = False
stest.deprecation_level(level)
Allow to temporarily set deprecation level to ‘level’.
Context manager for temporarily setting a deprecation level and restore it when exiting the context.
Arguments:
with stest.deprecation_level(2)
stest.expect_equal(conf.sim.deprecation_level, 2)