diff --git a/common/OpTestHost.py b/common/OpTestHost.py index 884f88584..f31937d97 100644 --- a/common/OpTestHost.py +++ b/common/OpTestHost.py @@ -977,3 +977,27 @@ def host_get_core_count(self): def host_gather_debug_logs(self): self.ssh.run_command_ignore_fail("grep ',[0-4]\]' /sys/firmware/opal/msglog") self.ssh.run_command_ignore_fail("dmesg -T --level=alert,crit,err,warn") + + def host_copy_fake_gard(self): + path = os.path.abspath(os.path.join("common", os.pardir)) + i_image = path + "/test_binaries/fake.gard" + # Copy the fake.gard file to the tmp folder in the host + try: + self.util.copyFilesToDest(i_image, self.user, + self.ip, "/tmp/", self.passwd) + except: + l_msg = "Copying fake.gard file to host failed" + print l_msg + raise OpTestError(l_msg) + + def host_pflash_get_partition(self, partition): + d = self.host_run_command("pflash --info") + for line in d: + s = re.search(partition, line) + if s: + m = re.match(r'ID=\d+\s+\S+\s+((0[xX])?[0-9a-fA-F]+)..(0[xX])?[0-9a-fA-F]+\s+\(actual=((0[xX])?[0-9a-fA-F]+)\).*', line) + offset = int(m.group(1), 16) + length = int(m.group(4), 16) + ret = {'offset': offset, 'length': length} + return ret + diff --git a/op-test b/op-test index e2ec46ae7..e4847a584 100755 --- a/op-test +++ b/op-test @@ -80,6 +80,7 @@ from testcases import fspTODCorruption from testcases import Console from testcases import testRestAPI from testcases import OpTestPNOR +from testcases import OpalGard import testcases args, remaining_args = OpTestConfiguration.conf.parse_args(sys.argv) @@ -178,6 +179,7 @@ class FullSuite(): self.s.addTest(testRestAPI.RestAPI()) self.s.addTest(BasicIPLSuite().suite()) self.s.addTest(DefaultSuite().suite()) + self.s.addTest(OpalGard.OpalGard()) self.s.addTest(OpalUtils.OpalUtils()) self.s.addTest(OpTestRTCdriver.HostRTC()) self.s.addTest(OpTestInbandIPMI.full_suite()) diff --git a/test_binaries/fake.gard b/test_binaries/fake.gard new file mode 100644 index 000000000..e1f634cc2 Binary files /dev/null and b/test_binaries/fake.gard differ diff --git a/testcases/OpalGard.py b/testcases/OpalGard.py new file mode 100644 index 000000000..f9c68d853 --- /dev/null +++ b/testcases/OpalGard.py @@ -0,0 +1,100 @@ +#!/usr/bin/python +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. +# +# $Source: op-test-framework/testcases/OpalGard.py $ +# +# OpenPOWER Automated Test Project +# +# Contributors Listed Below - COPYRIGHT 2015 +# [+] International Business Machines Corp. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. See the License for the specific language governing +# permissions and limitations under the License. +# +# IBM_PROLOG_END_TAG + +# @package opal-gard +# Test different OPAL GARD Related functionality +# + +import re +import random + + +from common.OpTestConstants import OpTestConstants as BMC_CONST +import unittest + +import OpTestConfiguration +from common.OpTestSystem import OpSystemState +from common.Exceptions import CommandFailed + +class OpalGard(unittest.TestCase): + def setUp(self): + conf = OpTestConfiguration.conf + self.cv_IPMI = conf.ipmi() + self.cv_SYSTEM = conf.system() + self.cv_HOST = conf.host() + self.bmc_type = conf.args.bmc_type + self.cv_SYSTEM.goto_state(OpSystemState.OS) + + + def list_gard_records(self): + cmd = "PATH=/usr/local/sbin:$PATH opal-gard list all" + try: + res = self.c.run_command(cmd,timeout=120) + except CommandFailed as cf: + self.assertEqual(cf.exitcode, 0, "List gard records operation failed: %s" % str(cf)) + + def clear_gard_records(self): + cmd = "PATH=/usr/local/sbin:$PATH opal-gard clear all" + try: + res = self.c.run_command(cmd,timeout=120) + except CommandFailed as cf: + self.assertEqual(cf.exitcode, 0, "Clear gard records operation failed: %s" % str(cf)) + + def show_gard_record(self, id): + cmd = "PATH=/usr/local/sbin:$PATH opal-gard show %s" % id + try: + res = self.c.run_command(cmd,timeout=120) + except CommandFailed as cf: + self.assertEqual(cf.exitcode, 0, "show gard records operation failed: %s" % str(cf)) + + def tearDown(self): + cmd = "dmesg -T --level=alert,crit,err,warn" + res = self.c.run_command_ignore_fail(cmd, timeout=120) + self.c.run_command_ignore_fail("grep ',[0-4]\]' /sys/firmware/opal/msglog") + + def runTest(self): + # opal-gard from host is not supported in FSP systems + if "FSP" in self.bmc_type: + self.skipTest("OpenPOWER BMC specific") + + self.c = self.cv_SYSTEM.sys_get_ipmi_console() + self.cv_SYSTEM.host_console_login() + self.cv_SYSTEM.host_console_unique_prompt() + self.cv_HOST.host_check_command("pflash") + self.cv_HOST.host_copy_fake_gard() + self.c.run_command("dmesg -D") + self.cpu = ''.join(self.c.run_command("grep '^cpu' /proc/cpuinfo |uniq|sed -e 's/^.*: //;s/ .*//;'")) + + if self.cpu not in ["POWER8", "POWER8E", "POWER9"]: + self.skipTest("Unknown CPU type %s" % self.cpu) + data = self.cv_HOST.host_pflash_get_partition("GUARD") + offset = hex(int(data["offset"])/16) + for i in range(0, 11): + self.list_gard_records() + self.c.run_command("dd if=/tmp/fake.gard of=/dev/mtd0 bs=$((0x10)) seek=$((%s)) conv=notrunc" % offset) + self.list_gard_records() + self.show_gard_record("00000001") + self.clear_gard_records()