Skip to content

Commit

Permalink
Testcase for OpenPower Gard Interfaces.
Browse files Browse the repository at this point in the history
This testcase just copies the fake.gard file from test_binaries
into the test machine and flashes into the Host PNOR.
Then it verifies this with opal-gard tool for list, show and clearing
gard records.

Signed-off-by: Pridhiviraj Paidipeddi <ppaidipe@linux.vnet.ibm.com>
[stewart: use unittest.assertEqual rather than just raise exception]
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
pridhiviraj authored and stewartsmith committed Nov 15, 2017
1 parent fe00973 commit b0d147d
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
24 changes: 24 additions & 0 deletions common/OpTestHost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 2 additions & 0 deletions op-test
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
Binary file added test_binaries/fake.gard
Binary file not shown.
100 changes: 100 additions & 0 deletions testcases/OpalGard.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit b0d147d

Please sign in to comment.