blob: 98538eedfc9fa8c1a86985f4f103d0fb886d99f5 [file] [log] [blame]
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging, os, random
from autotest_lib.client.bin import utils, test
from autotest_lib.client.common_lib import error
class kernel_VbootContextEC(test.test):
'''Run the vboot context ec test.'''
version = 1
dts_node_path = ('/proc/device-tree/firmware'
sys_vbootcontext_path = '/sys/bus/platform/drivers/cros-ec-vbc/'
def run_once(self):
arch = utils.get_arch()
if not arch.startswith('arm'):'Skip test for non-ARM arch %s', arch)
media = utils.read_file(self.dts_node_path).strip('\n\x00')
if media != 'mkbp':'Skip test: Vboot Context storage media is "%s"',
sysfs_entry = None
for name in os.listdir(self.sys_vbootcontext_path):
if name.startswith('cros-ec-vbc'):
sysfs_entry = os.path.join(self.sys_vbootcontext_path, name,
raise error.TestFail('Could not find sysfs entry under %s',
# Retrieve Vboot Context
vboot_context = utils.system_output('mosys nvram vboot read').strip()
# Test read
vc_expect = vboot_context
vc_got = utils.read_file(sysfs_entry).strip('\n\x00')
if vc_got != vc_expect:
raise error.TestFail('Could not read Vboot Context: '
'Expect "%s" but got "%s"' %
(vc_expect, vc_got))
# Test write of a random hex string
vc_expect = ''.join(random.choice('0123456789abcdef')
for _ in xrange(32))
utils.open_write_close(sysfs_entry, vc_expect)
vc_got = utils.system_output('mosys nvram vboot read').strip()
if vc_got != vc_expect:
raise error.TestFail('Could not write Vboot Context: '
'Expect "%s" but got "%s"' %
(vc_expect, vc_got))
# Restore Vboot Context'mosys nvram vboot write "%s"' % vboot_context)