|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# IBM_PROLOG_BEGIN_TAG |
| 3 | +# This is an automatically generated prolog. |
| 4 | +# |
| 5 | +# $Source: op-test-framework/testcases/OpTestInterrupt.py $ |
| 6 | +# |
| 7 | +# OpenPOWER Automated Test Project |
| 8 | +# |
| 9 | +# Contributors Listed Below - COPYRIGHT 2020 |
| 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 | +''' |
| 28 | +OpTestInterrupt |
| 29 | +--------------- |
| 30 | +This module contain testcases related to XIVE. |
| 31 | +1.Enable kernel logging,basically generate console traffic |
| 32 | +by printing the processes/tasks to the console |
| 33 | +2.check Xive is configured properly or not |
| 34 | +3.check system reboot with xive=on and xive=off |
| 35 | +4.validate interrupts handled by CPU's |
| 36 | +''' |
| 37 | +import os |
| 38 | +import re |
| 39 | +import sys |
| 40 | +import time |
| 41 | +import pexpect |
| 42 | +import unittest |
| 43 | +import subprocess |
| 44 | + |
| 45 | +import OpTestConfiguration |
| 46 | +from common import OpTestHMC, OpTestFSP |
| 47 | +from common.OpTestError import OpTestError |
| 48 | +from common.OpTestSystem import OpSystemState |
| 49 | +from common.OpTestSSH import ConsoleState as SSHConnectionState |
| 50 | +from common.OpTestConstants import OpTestConstants as BMC_CONST |
| 51 | + |
| 52 | +import logging |
| 53 | +import OpTestLogger |
| 54 | +log = OpTestLogger.optest_logger_glob.get_logger(__name__) |
| 55 | + |
| 56 | + |
| 57 | +class OpTestInterrupt(unittest.TestCase): |
| 58 | + def setUp(self): |
| 59 | + conf = OpTestConfiguration.conf |
| 60 | + self.cv_SYSTEM = conf.system() |
| 61 | + self.c = self.cv_SYSTEM.console |
| 62 | + self.con = self.cv_SYSTEM.cv_HOST.get_ssh_connection() |
| 63 | + |
| 64 | + def enable_consoletraffic(self): |
| 65 | + ''' |
| 66 | + Enable kernel logging, basically generate console traffic by printing the |
| 67 | + processes/tasks to the console |
| 68 | + ''' |
| 69 | + self.c.run_command("echo 10 > /proc/sys/kernel/printk") |
| 70 | + try: |
| 71 | + i = 1 |
| 72 | + while i <= 10: |
| 73 | + self.c.run_command("echo t > /proc/sysrq-trigger", timeout=600) |
| 74 | + i = i+1 |
| 75 | + except(KernelOOPS, KernelKdump): |
| 76 | + self.cv_SYSTEM.goto_state(OpSystemState.OS) |
| 77 | + self.c.run_command("echo $?") |
| 78 | + |
| 79 | +class XiveTest(OpTestInterrupt): |
| 80 | + ''' |
| 81 | + 1.This function will check xive is configured properly or not |
| 82 | + 2.check for system reboot with Xive=off and on |
| 83 | + ''' |
| 84 | + def setup_test(self): |
| 85 | + self.cv_SYSTEM.goto_state(OpSystemState.OS) |
| 86 | + self.con.run_command("uname -a") |
| 87 | + result = self.con.run_command("grep -i --color=never xive /boot/config-`uname -r`") |
| 88 | + for line in result: |
| 89 | + temp = ''.join(self.con.run_command("echo %s | cut -d '=' -f 2" % line)) |
| 90 | + if temp != 'y': |
| 91 | + self.fail("xive is not configured properly") |
| 92 | + res = self.con.run_command("cat /etc/os-release | grep NAME | head -1") |
| 93 | + if 'SLES' in res[0].strip(): |
| 94 | + self.con.run_command_ignore_fail("sed -i -e 's/xive=.* / /' -e 's/xive=.*/\"/' /etc/default/grub") |
| 95 | + self.con.run_command("sed -i '/GRUB_CMDLINE_LINUX_DEFAULT/s/\"$/ xive=off\"/' /etc/default/grub") |
| 96 | + self.sles_grub_update() |
| 97 | + self.con.run_command("sed -i 's/xive=.*/xive=on\"/' /etc/default/grub") |
| 98 | + self.sles_grub_update() |
| 99 | + elif 'Red Hat' in res[0].strip(): |
| 100 | + self.rhel_grub_update('off') |
| 101 | + self.rhel_grub_update('on') |
| 102 | + |
| 103 | + def sles_grub_update(self): |
| 104 | + self.con.run_command("grub2-mkconfig -o /boot/grub2/grub.cfg") |
| 105 | + self.con.run_command("sync;sleep 10") |
| 106 | + self.cv_SYSTEM.goto_state(OpSystemState.OFF) |
| 107 | + self.cv_SYSTEM.goto_state(OpSystemState.OS) |
| 108 | + self.con.run_command("cat /proc/cmdline") |
| 109 | + |
| 110 | + def rhel_grub_update(self, param): |
| 111 | + ''' |
| 112 | + This function will pass xive=on and off parameters to command line |
| 113 | + ''' |
| 114 | + self.con.run_command("grubby --info=/boot/vmlinuz-`uname -r`") |
| 115 | + self.con.run_command_ignore_fail("grubby --remove-args=xive* --update-kernel=/boot/vmlinuz-`uname -r`") |
| 116 | + self.con.run_command("grubby --args=xive=%s --update-kernel=/boot/vmlinuz-`uname -r`" % param) |
| 117 | + self.con.run_command("sync; sync; sleep 5") |
| 118 | + self.cv_SYSTEM.goto_state(OpSystemState.OFF) |
| 119 | + self.cv_SYSTEM.goto_state(OpSystemState.OS) |
| 120 | + self.con.run_command("grubby --info=/boot/vmlinuz-`uname -r`") |
| 121 | + |
| 122 | + def interrupt_cpu_check(self): |
| 123 | + ''' |
| 124 | + This function will validate interrupts handled by CPU's. |
| 125 | + ''' |
| 126 | + self.con = self.cv_SYSTEM.cv_HOST.get_ssh_connection() |
| 127 | + res = self.con.run_command("ip route list | grep default | awk '{print $5}'") |
| 128 | + interrupt = "cat /proc/interrupts | grep %s | head -1" % res[0] |
| 129 | + self.con.run_command(interrupt) |
| 130 | + self.con.run_command("ppc64_cpu --cores-on") |
| 131 | + self.con.run_command("ppc64_cpu --cores-on=1") |
| 132 | + self.con.run_command(interrupt) |
| 133 | + temp = "%s | awk '{print $2}'" % interrupt |
| 134 | + self.con.run_command("ppc64_cpu --smt=off") |
| 135 | + tmp1 = self.con.run_command(temp) |
| 136 | + time.sleep(10) |
| 137 | + tmp2 = self.con.run_command(temp) |
| 138 | + if (tmp1[0] < tmp2[0]): |
| 139 | + log.info("Interrupts are handled by CPU0") |
| 140 | + self.con.run_command("ppc64_cpu --cores-on=all") |
| 141 | + self.con.run_command("ppc64_cpu --smt=on") |
| 142 | + output = self.con.run_command(interrupt) |
| 143 | + cmd = "%s | awk '{print $4}'" % interrupt |
| 144 | + tmp3 = self.con.run_command(cmd) |
| 145 | + smp = "%s | awk '{print $1}'" % interrupt |
| 146 | + result = self.con.run_command(smp) |
| 147 | + log.info("setting smp_affinity_list to CPU2") |
| 148 | + self.con.run_command("echo 2 > /proc/irq/%s/smp_affinity_list" % result[0].lstrip().split(':')[0]) |
| 149 | + self.con.run_command(interrupt) |
| 150 | + time.sleep(10) |
| 151 | + tmp4 = self.con.run_command(cmd) |
| 152 | + if (tmp3[0] < tmp4[0]): |
| 153 | + log.info("Interrupts are handled by CPU2") |
| 154 | + else: |
| 155 | + self.fail("Interrupts are not handled by CPU2") |
| 156 | + else: |
| 157 | + self.fail("Interrupts are not handled by CPU") |
| 158 | + |
| 159 | + def runTest(self): |
| 160 | + self.setup_test() |
| 161 | + self.enable_consoletraffic() |
| 162 | + self.interrupt_cpu_check() |
| 163 | + |
0 commit comments