Skip to content

Commit b0d147d

Browse files
pridhivirajstewartsmith
authored andcommittedNov 15, 2017
Testcase for OpenPower Gard Interfaces.
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 <[email protected]> [stewart: use unittest.assertEqual rather than just raise exception] Signed-off-by: Stewart Smith <[email protected]>
1 parent fe00973 commit b0d147d

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed
 

‎common/OpTestHost.py

+24
Original file line numberDiff line numberDiff line change
@@ -977,3 +977,27 @@ def host_get_core_count(self):
977977
def host_gather_debug_logs(self):
978978
self.ssh.run_command_ignore_fail("grep ',[0-4]\]' /sys/firmware/opal/msglog")
979979
self.ssh.run_command_ignore_fail("dmesg -T --level=alert,crit,err,warn")
980+
981+
def host_copy_fake_gard(self):
982+
path = os.path.abspath(os.path.join("common", os.pardir))
983+
i_image = path + "/test_binaries/fake.gard"
984+
# Copy the fake.gard file to the tmp folder in the host
985+
try:
986+
self.util.copyFilesToDest(i_image, self.user,
987+
self.ip, "/tmp/", self.passwd)
988+
except:
989+
l_msg = "Copying fake.gard file to host failed"
990+
print l_msg
991+
raise OpTestError(l_msg)
992+
993+
def host_pflash_get_partition(self, partition):
994+
d = self.host_run_command("pflash --info")
995+
for line in d:
996+
s = re.search(partition, line)
997+
if s:
998+
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)
999+
offset = int(m.group(1), 16)
1000+
length = int(m.group(4), 16)
1001+
ret = {'offset': offset, 'length': length}
1002+
return ret
1003+

‎op-test

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ from testcases import fspTODCorruption
8080
from testcases import Console
8181
from testcases import testRestAPI
8282
from testcases import OpTestPNOR
83+
from testcases import OpalGard
8384
import testcases
8485

8586
args, remaining_args = OpTestConfiguration.conf.parse_args(sys.argv)
@@ -178,6 +179,7 @@ class FullSuite():
178179
self.s.addTest(testRestAPI.RestAPI())
179180
self.s.addTest(BasicIPLSuite().suite())
180181
self.s.addTest(DefaultSuite().suite())
182+
self.s.addTest(OpalGard.OpalGard())
181183
self.s.addTest(OpalUtils.OpalUtils())
182184
self.s.addTest(OpTestRTCdriver.HostRTC())
183185
self.s.addTest(OpTestInbandIPMI.full_suite())

‎test_binaries/fake.gard

63 Bytes
Binary file not shown.

‎testcases/OpalGard.py

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/python
2+
# IBM_PROLOG_BEGIN_TAG
3+
# This is an automatically generated prolog.
4+
#
5+
# $Source: op-test-framework/testcases/OpalGard.py $
6+
#
7+
# OpenPOWER Automated Test Project
8+
#
9+
# Contributors Listed Below - COPYRIGHT 2015
10+
# [+] International Business Machines Corp.
11+
#
12+
#
13+
# Licensed under the Apache License, Version 2.0 (the "License");
14+
# you may not use this file except in compliance with the License.
15+
# You may obtain a copy of the License at
16+
#
17+
# http://www.apache.org/licenses/LICENSE-2.0
18+
#
19+
# Unless required by applicable law or agreed to in writing, software
20+
# distributed under the License is distributed on an "AS IS" BASIS,
21+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
22+
# implied. See the License for the specific language governing
23+
# permissions and limitations under the License.
24+
#
25+
# IBM_PROLOG_END_TAG
26+
27+
# @package opal-gard
28+
# Test different OPAL GARD Related functionality
29+
#
30+
31+
import re
32+
import random
33+
34+
35+
from common.OpTestConstants import OpTestConstants as BMC_CONST
36+
import unittest
37+
38+
import OpTestConfiguration
39+
from common.OpTestSystem import OpSystemState
40+
from common.Exceptions import CommandFailed
41+
42+
class OpalGard(unittest.TestCase):
43+
def setUp(self):
44+
conf = OpTestConfiguration.conf
45+
self.cv_IPMI = conf.ipmi()
46+
self.cv_SYSTEM = conf.system()
47+
self.cv_HOST = conf.host()
48+
self.bmc_type = conf.args.bmc_type
49+
self.cv_SYSTEM.goto_state(OpSystemState.OS)
50+
51+
52+
def list_gard_records(self):
53+
cmd = "PATH=/usr/local/sbin:$PATH opal-gard list all"
54+
try:
55+
res = self.c.run_command(cmd,timeout=120)
56+
except CommandFailed as cf:
57+
self.assertEqual(cf.exitcode, 0, "List gard records operation failed: %s" % str(cf))
58+
59+
def clear_gard_records(self):
60+
cmd = "PATH=/usr/local/sbin:$PATH opal-gard clear all"
61+
try:
62+
res = self.c.run_command(cmd,timeout=120)
63+
except CommandFailed as cf:
64+
self.assertEqual(cf.exitcode, 0, "Clear gard records operation failed: %s" % str(cf))
65+
66+
def show_gard_record(self, id):
67+
cmd = "PATH=/usr/local/sbin:$PATH opal-gard show %s" % id
68+
try:
69+
res = self.c.run_command(cmd,timeout=120)
70+
except CommandFailed as cf:
71+
self.assertEqual(cf.exitcode, 0, "show gard records operation failed: %s" % str(cf))
72+
73+
def tearDown(self):
74+
cmd = "dmesg -T --level=alert,crit,err,warn"
75+
res = self.c.run_command_ignore_fail(cmd, timeout=120)
76+
self.c.run_command_ignore_fail("grep ',[0-4]\]' /sys/firmware/opal/msglog")
77+
78+
def runTest(self):
79+
# opal-gard from host is not supported in FSP systems
80+
if "FSP" in self.bmc_type:
81+
self.skipTest("OpenPOWER BMC specific")
82+
83+
self.c = self.cv_SYSTEM.sys_get_ipmi_console()
84+
self.cv_SYSTEM.host_console_login()
85+
self.cv_SYSTEM.host_console_unique_prompt()
86+
self.cv_HOST.host_check_command("pflash")
87+
self.cv_HOST.host_copy_fake_gard()
88+
self.c.run_command("dmesg -D")
89+
self.cpu = ''.join(self.c.run_command("grep '^cpu' /proc/cpuinfo |uniq|sed -e 's/^.*: //;s/ .*//;'"))
90+
91+
if self.cpu not in ["POWER8", "POWER8E", "POWER9"]:
92+
self.skipTest("Unknown CPU type %s" % self.cpu)
93+
data = self.cv_HOST.host_pflash_get_partition("GUARD")
94+
offset = hex(int(data["offset"])/16)
95+
for i in range(0, 11):
96+
self.list_gard_records()
97+
self.c.run_command("dd if=/tmp/fake.gard of=/dev/mtd0 bs=$((0x10)) seek=$((%s)) conv=notrunc" % offset)
98+
self.list_gard_records()
99+
self.show_gard_record("00000001")
100+
self.clear_gard_records()

0 commit comments

Comments
 (0)
Please sign in to comment.