Commit e51a409e authored by Javier Martinez Canillas's avatar Javier Martinez Canillas Committed by Enric Balletbo i Serra

Add test for ChromeOS Embedded Controller

Chromebooks have one or more Embedded Controllers (EC) that managed some
peripherals. Add a test case to check that the EC are working correctly.
Signed-off-by: 's avatarJavier Martinez Canillas <javier.martinez@collabora.co.uk>
parent 684f0446
Test for ChromeOS Embedded Controllers
This test checks if the ChromeOS EC in the system is working correctly by
sending IOCTL commands to the EC chardev driver and reading a file from
the sysfs interface.
{
"actions": [
{
"command": "deploy_kernel",
"parameters": {
"target_type": "ubuntu",
"dtb": "{{kernbase}}/{{fdtfile}}.dtb",
"kernel": "{{kernbase}}/zImage",
"nfsrootfs": "{{nfsrootfs}}",
"login_commands": [
"sudo su"
],
"login_prompt": "login:",
"password": "collabora",
"password_prompt": "Password:",
"username": "collabora"
}
},
{
"command": "boot_image",
"parameters": {
"test_image_prompt": "root@singularity"
}
},
{
"command": "lava_test_shell",
"parameters": {
"testdef_repos": [
{
"git-repo": "{{repobase}}/test-definitions.git",
"testdef": "kernel/cros_ec/cros-ec-test.yaml"
}
],
"timeout": 360
}
},
{
"command": "submit_results",
"parameters": {
"server": "https://lava.collabora.co.uk/RPC2/",
"stream": "{{bundle-stream}}"
}
}
],
"device_type": "{{device-type}}",
"job_name": "cros-ec-test-{{device-type}}",
"timeout": 480
}
metadata:
name: cros-ec-test
format: "Lava-Test-Shell Test Definition 1.0"
description: "Test for ChromeOS Embedded Controller."
maintainer:
- javier.martinez@collabora.co.uk
scope:
- functional
devices:
- peach-pi
- snow
environment:
- lava-test-shell
install:
deps:
- python2.7
run:
steps:
- lava-test-case run-cros-ec-tests --shell ./kernel/cros_ec/scripts/cros-ec-test.py
parse:
pattern: '(?P<test_case_id>\S*):\s+(?P<result>(pass|fail))'
profiles:
- name: snow
variables:
device-type: snow
fdtfile: exynos5250-snow
- name: peach-pi
variables:
device-type: peach-pi
fdtfile: exynos5800-peach-pi
#!/usr/bin/python2.7
#
# cros-ec-test - Basic test for the ChromeOS Embedded Controller
#
from ctypes import *
import errno
import fcntl
import sys
import os
EC_DEV_PATH = "/dev/cros_ec"
EC_SYSFS_PATH = "/sys/devices/virtual/chromeos/cros_ec/"
EC_DEV_IOC = 0xec
EC_DEV_IOCXCMD = 0xc20cec00 # _IOWR(EC_DEV_IOC, 0, struct cros_ec_command)
EC_DEV_IOCRDMEM = 0xc108ec01 # _IOWR(EC_DEV_IOC, 1, struct cros_ec_readmem)
EC_CMD_MAX = 0xfc
EC_MEMMAP_SIZE = 0xff
EC_CMD_HELLO = 0x01
EC_RES_SUCCESS = 0
EC_IN_DATA = 0xa0b0c0d0 # magic number that the EC expects on HELLO
EC_OUT_DATA = 0xa1b2c3d4 # magic number that the EC answers on HELLO
exit_status = os.EX_OK
fd = None
class cros_ec_command(Structure):
_fields_ = [
('version', c_uint),
('command', c_uint),
('outsize', c_uint),
('insize', c_uint),
('result', c_uint),
('outdata', c_ubyte * EC_CMD_MAX),
('indata', c_ubyte * EC_CMD_MAX)
]
class cros_ec_readmem(Structure):
_fields_ = [
('offset', c_uint),
('length', c_uint),
('buffer', c_ubyte * EC_MEMMAP_SIZE)
]
class ec_params_hello(Structure):
_fields_ = [
('in_data', c_uint)
]
class ec_params_response(Structure):
_fields_ = [
('out_data', c_uint)
]
print "Testing opening {0}".format(EC_DEV_PATH)
try:
fd = open(EC_DEV_PATH, 'r')
print "open-ec-dev: pass"
except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
print "open-ec-dev: fail"
exit_status = os.EX_IOERR
print "Testing EC_DEV_IOCXCMD cmd"
if exit_status == os.EX_OK:
param = ec_params_hello()
param.in_data = EC_IN_DATA
response = ec_params_response()
cmd = cros_ec_command()
cmd.version = 0x0
cmd.command = EC_CMD_HELLO
cmd.insize = sizeof(param)
cmd.outsize = sizeof(response)
memmove(addressof(cmd.outdata), addressof(param), cmd.outsize)
try:
fcntl.ioctl(fd, EC_DEV_IOCXCMD, cmd)
memmove(addressof(response), addressof(cmd.indata), cmd.insize)
if cmd.result == EC_RES_SUCCESS and response.out_data == EC_OUT_DATA:
print "ec-xcmd-ioctl: pass"
else:
print "ec-xcmd-ioctl: fail"
exit_status = os.EX_IOERR
except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
print "ec-xcmd-ioctl: fail"
exit_status = os.EX_IOERR
else:
print "ec-xcmd-ioctl: unknown"
print "Testing EC_DEV_IOCRDMEM cmd"
if exit_status == os.EX_OK:
mem = cros_ec_readmem()
mem.offset = 0x0
mem.length = EC_MEMMAP_SIZE
try:
fcntl.ioctl(fd, EC_DEV_IOCRDMEM, mem)
"ec-rdmem-ioctl: pass"
except IOError as e:
# Not all platforms supports direct reads, so -ENOTTY isn't an error
if e.errno == errno.ENOTTY:
print "ec-rdmem-ioctl: skip"
else:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
print "ec-rdmem-ioctl: fail"
exit_status = os.EX_IOERR
else:
print "ec-rdmem-ioctl: unknown"
if fd != None:
fd.close()
print "Testing EC sysfs interface"
try:
fd = open(EC_SYSFS_PATH + "version", 'r')
print "open-ec-sysfs: pass"
fd.close()
except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
print "open-ec-sysfs: fail"
exit_status = os.EX_IOERR
sys.exit(exit_status)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment