mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-05 22:41:44 +00:00
This test checks we cannot overwrite current running system image. BUG=chrome-os-partner:10262 TEST=Test passed Change-Id: I72be277c9de2114e72000a102d8b885e842ef15a Reviewed-on: https://gerrit.chromium.org/gerrit/27006 Commit-Ready: Vic Yang <victoryang@chromium.org> Reviewed-by: Vic Yang <victoryang@chromium.org> Tested-by: Vic Yang <victoryang@chromium.org>
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
# Copyright (c) 2012 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.
|
|
#
|
|
# Utility functions for flash related test
|
|
#
|
|
|
|
import random
|
|
|
|
# Fixed random seed.
|
|
random.seed(1234)
|
|
|
|
def get_flash_size(helper):
|
|
helper.ec_command("hcflashinfo")
|
|
return int(helper.wait_output("flash_size = (?P<f>\d+)", use_re=True)["f"])
|
|
|
|
def get_ro_size(helper):
|
|
helper.ec_command("rosize")
|
|
return int(helper.wait_output(
|
|
"RO image size = (?P<ro>0x[0-9a-f]+)", use_re=True)["ro"], 16)
|
|
|
|
def xor_sum(size, seed, mult, add):
|
|
ret = 0
|
|
for i in xrange(size):
|
|
ret ^= (seed & 0xff)
|
|
seed = seed * mult + add
|
|
return ret
|
|
|
|
def test_write(helper, offset, size, expect_fail=False):
|
|
seed = random.randint(2, 10000)
|
|
mult = random.randint(2, 10000)
|
|
add = random.randint(2, 10000)
|
|
helper.ec_command("hcflashwrite %d %d %d %d %d" %
|
|
(offset, size, seed, mult, add))
|
|
if expect_fail:
|
|
helper.wait_output("Command returned error")
|
|
else:
|
|
expected_sum = xor_sum(size, seed, mult, add)
|
|
helper.wait_output("Flash write at %x size %x XOR %x" %
|
|
(offset, size, expected_sum))
|