In [1]:
import logging
reload(logging)
logging.basicConfig(
format='%(asctime)-9s %(levelname)-8s: %(message)s',
datefmt='%I:%M:%S')
# Enable logging at INFO level
logging.getLogger().setLevel(logging.INFO)
# Uncomment the follwing line to enabled devlib debugging statements
logging.getLogger('ssh').setLevel(logging.DEBUG)
In [2]:
import json
import time
import os
In [3]:
# Setup a target configuration
conf = {
# Platform and board to target
"platform" : "linux",
"board" : "juno",
# Login credentials
"host" : "192.168.0.1",
"username" : "root",
"password" : "",
# Local installation path
"tftp" : {
"folder" : "/var/lib/tftpboot",
"kernel" : "kern.bin",
"dtb" : "dtb.bin",
},
# Tools to deploy
"tools" : [ "rt-app", "taskset" ],
# RTApp calibration values (comment to let LISA do a calibration run)
"rtapp-calib" : {
"0": 358, "1": 138, "2": 138, "3": 357, "4": 359, "5": 355
},
# FTrace configuration
"ftrace" : {
"events" : [
"cpu_idle",
"sched_switch",
],
"buffsize" : 10240,
},
# Where results are collected
"results_dir" : "TestEnvExample",
# Tune which devlib module are required
#"exclude_modules" : [ "hwmon" ],
}
In [4]:
from env import TestEnv
# Initialize a test environment using the provided configuration
te = TestEnv(conf)
The initialization of the test environment pre-initialize some useful
environment variables which are available to write test cases.
These are some of the information available via the TestEnv object.
In [5]:
# The complete configuration of the target we have configured
print json.dumps(te.conf, indent=4)
In [6]:
# Last configured kernel and DTB image
print te.kernel
print te.dtb
In [7]:
# The IP and MAC address of the target
print te.ip
print te.mac
In [8]:
# A full platform descriptor
print json.dumps(te.platform, indent=4)
In [9]:
# A pre-created folder to host the tests results generated using this
# test environment, notice that the suite could add additional information
# in this folder, like for example a copy of the target configuration
# and other target specific collected information
te.res_dir
Out[9]:
In [10]:
# The working directory on the target
te.workdir
Out[10]:
In [11]:
# The target topology, which can be used to build BART assertions
te.topology
Out[11]:
Some methods are also exposed to test developers which could be used to easy the creation of tests.
These are some of the methods available:
In [12]:
# Calibrate RT-App (if required) and get the most updated calibration value
te.calibration()
Out[12]:
In [13]:
# Generate a JSON file with the complete platform description
te.platform_dump(dest_dir='/tmp')
Out[13]:
In [14]:
# Force a reboot of the target (and wait specified [s] before reconnect)
te.reboot(reboot_time=60, ping_time=15)
In [15]:
# Resolve a MAC address into an IP address
te.resolv_host(host='00:02:F7:00:5A:5B')
Out[15]:
In [16]:
# Copy the specified file into the TFTP server folder defined by configuration
te.tftp_deploy('/etc/group')
A special TestEnv attribute is target, which represent a devlib instance.
Using the target attribute we can access to the full set of devlib provided
functionalities. Which are summarized in the following sections.
In [17]:
# Run a command on the target
te.target.execute("echo -n 'Hello Test Environment'", as_root=False)
Out[17]:
In [18]:
# Spawn a command in background on the target
te.target.kick_off("sleep 10", as_root=True)
Out[18]:
In [19]:
# Acces to many target specific information
print "ABI : ", te.target.abi
print "big Core Family : ", te.target.big_core
print "LITTLE Core Family : ", te.target.little_core
print "CPU's Clusters IDs : ", te.target.core_clusters
print "CPUs type : ", te.target.core_names
In [20]:
# Access to big.LITTLE specific information
print "big CPUs IDs : ", te.target.bl.bigs
print "LITTLE CPUs IDs : ", te.target.bl.littles
print "big CPUs freqs : {}".format(te.target.bl.get_bigs_frequency())
print "big CPUs governor : {}".format(te.target.bl.get_bigs_governor())
In [21]:
# Reset and sample energy counters
te.emeter.reset()
nrg = te.emeter.sample()
nrg = json.dumps(te.emeter.sample(), indent=4)
print "First read: ", nrg
time.sleep(2)
nrg = te.emeter.sample()
nrg = json.dumps(te.emeter.sample(), indent=4)
print "Second read: ", nrg
In [22]:
# Configure a specific set of events to trace
te.ftrace_conf(
{
"events" : [
"cpu_idle",
"cpu_capacity",
"cpu_frequency",
"sched_switch",
],
"buffsize" : 10240
}
)
In [23]:
# Start/Stop a FTrace session
te.ftrace.start()
te.target.execute("uname -a")
te.ftrace.stop()
In [24]:
# Collect and visualize the trace
trace_file = os.path.join(te.res_dir, 'trace.dat')
te.ftrace.get_trace(trace_file)
output = os.popen("DISPLAY=:0.0 kernelshark {}".format(trace_file))