Skip to content

Commit

Permalink
Add hostmac,bmcutil,gpiopresence tests
Browse files Browse the repository at this point in the history
Summary:
This diff adds 3 tests :
1) checking hostmac using wedge_us_mac.sh availability
2) Running through non disruptive shell scripts and they do no return non-zero error exit status
3) GPIO presence test: Tests presence of GPIOs present and their values
- > Also adds a handy script to get this list of gpionames that have in /tmp

Test Plan:
[vineelak@devbig609 tools{cit_flitr}]$ python CLI.py wedge100.json rsw1dc.23.snc1 --verbose DEBUG
DEBUG - Executing host MAC command: /usr/local/bin/wedge_us_mac.sh
DEBUG - Received host MAC=00:90:fb:5c:97:f9:
Host Mac Test [PASSED]

GPIO test :
....
DEBUG - GPIO name=BMC_READY_N present
DEBUG - reading path=/tmp/gpionames/BMC_READY_N/active_low data=0
DEBUG - reading path=/tmp/gpionames/BMC_READY_N/direction data=in
DEBUG - reading path=/tmp/gpionames/BMC_READY_N/edge data=none
DEBUG - reading path=/tmp/gpionames/BMC_READY_N/value data=1
DEBUG - GPIO name=ISO_COM_PWROK present
DEBUG - reading path=/tmp/gpionames/ISO_COM_PWROK/active_low data=0
DEBUG - reading path=/tmp/gpionames/ISO_COM_PWROK/direction data=in
DEBUG - reading path=/tmp/gpionames/ISO_COM_PWROK/edge data=none
DEBUG - reading path=/tmp/gpionames/ISO_COM_PWROK/value data=1
DEBUG - GPIO name=SWITCH_MDIO present
DEBUG - reading path=/tmp/gpionames/SWITCH_MDIO/active_low data=0
DEBUG - reading path=/tmp/gpionames/SWITCH_MDIO/direction data=in
DEBUG - reading path=/tmp/gpionames/SWITCH_MDIO/edge data=none
DEBUG - reading path=/tmp/gpionames/SWITCH_MDIO/value data=1
GPIO test [PASSED]

D10858233: flitr runs for these

Reviewed By: tomrepo

fbshipit-source-id: d4cd37ed9
  • Loading branch information
vineelasmile authored and facebook-github-bot committed Oct 25, 2018
1 parent deb0da2 commit d46d765
Show file tree
Hide file tree
Showing 13 changed files with 734 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/common/bmcUtiltest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def bmc_util_check(data):
"""
Given a json of shell scripts, check that all of them run and have
exited properly
exited properly. Take care to have only non-disruptive scripts here
"""
for script in data:
print("executing command: {}".format(script))
Expand Down
66 changes: 66 additions & 0 deletions tests/common/gpioTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import sys
import unitTestUtil
import logging
import os
import time

def read_data(path):
handle = open(path, "r")
data = handle.readline().rstrip()
handle.close()
logger.debug("reading path={} data={}".format(path, data))
return data


def gpio_test(data):
"""
given a json of gpios and expected values, check that all of the gpios
exist and its values
"""
for gpioname, v in data['gpios'].items():
gpio_path = "/tmp/gpionames/" + str(gpioname)
if not os.path.exists(gpio_path):
print("GPIO test : Missing GPIO={} [FAILED]".format(gpioname))
sys.exit(1)
else:
logger.debug("GPIO name={} present".format(gpioname))
checker = [
"active_low",
"direction",
"edge",
"value"
]
for item in checker:
vpath = gpio_path + "/" + item
rdata = read_data(vpath)
jdata = v[item]
if rdata not in jdata:
print("GPIO test : Incorrect {} for GPIO={} [FAILED]".format(item, gpioname))
sys.exit(1)
print("GPIO test [PASSED]")
sys.exit(0)

if __name__ == "__main__":
"""
Input to this file should look like the following:
python gpioTest.py gpiolist.json
"""
util = unitTestUtil.UnitTestUtil()
logger = util.logger(logging.WARN)
try:
data = {}
args = util.Argparser(['json', '--verbose'], [str, None],
['json file',
'output all steps from test with mode options: DEBUG, INFO, WARNING, ERROR'])
if args.verbose is not None:
logger = util.logger(args.verbose)
data = util.JSONparser(args.json)
gpio_test(data)
except Exception as e:
print("GPIO test [FAILED]")
print("Error code returned: " + str(e))
sys.exit(1)
58 changes: 58 additions & 0 deletions tests/common/hostMacTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import subprocess
import sys
import unitTestUtil
import logging
import re


def mac_verify(read_mac):
if re.match("[0-9a-f]{2}([:]?)[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$",
read_mac.lower()):
return True
return False


def hostmacTest(util):
utilCMD = util.HostMacCmd
if utilCMD is None:
raise Exception("Host MAC command not implemented")

logger.debug("Executing host MAC command: " + str(utilCMD))
info = subprocess.check_output(utilCMD).decode()
logger.debug("Received host MAC={} ".format(info))
success = mac_verify(info)
if success:
print("Host Mac Test [PASSED]")
sys.exit(0)
else:
print("Host Mac Test received MAC={} [FAILED]".format(info))
sys.exit(1)


if __name__ == "__main__":
"""
Input to this file should look like the following:
python hostMac_test.py type=wedge
"""
util = unitTestUtil.UnitTestUtil()
logger = util.logger(logging.WARN)
try:
args = util.Argparser(['type', '--verbose'], [str, None],
['a platform type',
'output all steps from test with mode options: DEBUG, INFO, WARNING, ERROR'])
platformType = args.type
if args.verbose is not None:
logger = util.logger(args.verbose)
utilType = util.importUtil(platformType)
hostmacTest(utilType)
except Exception as e:
if type(e) == KeyError:
print("No support for platform type given or none given [FAILED]")
else:
print("Host Mac Test [FAILED]")
print("Error: " + str(e))
sys.exit(1)
9 changes: 9 additions & 0 deletions tests/common/tools/CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ def cmmComponentPresenceTest(ssh, data, testName):
if "eepromTest.py" in data:
if data["eepromTest.py"] == 'yes':
generalTypeTest(cmd_bmc, data, "eepromTest.py")
if "hostMacTest.py" in data:
if data["hostMacTest.py"] == 'yes':
generalTypeTest(cmd_bmc, data, "hostMacTest.py")
if "fansTest.py" in data:
if data["fansTest.py"] == 'yes':
generalTypeTest(cmd_bmc, data, "fansTest.py")
Expand Down Expand Up @@ -315,9 +318,15 @@ def cmmComponentPresenceTest(ssh, data, testName):
if "kernelModulesTest.py" in data:
if data["kernelModulesTest.py"][0] == 'yes':
generalJsonTest(cmd_bmc, data, "kernelModulesTest.py")
if "gpioTest.py" in data:
if data["gpioTest.py"][0] == 'yes':
generalJsonTest(cmd_bmc, data, "gpioTest.py")
if "processRunningTest.py" in data:
if data["processRunningTest.py"][0] == 'yes':
generalJsonTest(cmd_bmc, data, "processRunningTest.py")
if "bmcUtiltest.py" in data:
if data["bmcUtiltest.py"][0] == 'yes':
generalJsonTest(cmd_bmc, data, "bmcUtiltest.py")
if "solTest.py" in data:
if data["solTest.py"] == 'yes':
if HEADNODE:
Expand Down
4 changes: 3 additions & 1 deletion tests/common/tools/galaxy100.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
"restapiTest.py":["yes",
{
"json":"../../galaxy100/unittests/rest_endpoint.json"
}]
}],
"hostMacTest.py":"yes"

}
3 changes: 2 additions & 1 deletion tests/common/tools/wedge.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"processRunningTest.py":["yes",
{
"json":"../wedge/unittests/process.json"
}]
}],
"hostMacTest.py":"yes"
}
11 changes: 10 additions & 1 deletion tests/common/tools/wedge100.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@
"psumuxmon_test.py":["yes",
{
"testfile":"/wedge100/unittests/"
}]
}],
"bmcUtiltest.py":["yes",
{
"json":"../wedge100/unittests/bmcUtilTest.json"
}],
"hostMacTest.py":"yes",
"gpioTest.py":["yes",
{
"json":"../wedge100/unittests/gpiolist.json"
}]

}
38 changes: 38 additions & 0 deletions tests/experimental/generate_gpiolist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import json
import subprocess

# README: Copy this file over to target and run from /tmp/gpiosnames"

def gen_gpio_json():
'''
Following method will read every gpio for contents and publish a json file
at /tmp/gpiolist.json
'''
result = {}
presult = {}
cmd = "ls -1"
gpio_list = subprocess.check_output(cmd, shell=True).decode().splitlines()
for item in gpio_list:
cmd = "cat /tmp/gpionames/" + item + "/" + "direction"
result['direction'] = subprocess.check_output(cmd, shell=True).decode().strip('\n')
cmd = "cat /tmp/gpionames/" + item + "/" + "active_low"
result['active_low'] = subprocess.check_output(cmd, shell=True).decode().strip('\n')
cmd = "cat /tmp/gpionames/" + item + "/" + "edge"
result['edge'] = subprocess.check_output(cmd, shell=True).decode().strip('\n')
cmd = "cat /tmp/gpionames/" + item + "/" + "value"
result['value'] = subprocess.check_output(cmd, shell=True).decode().strip('\n')
presult[item] = result
result = {}
fresult = {
"gpios": presult
}
handle = open("/tmp/gpiolist.json", "a+")
handle.write(json.dumps(fresult))
handle.close()

if __name__ == "__main__":
gen_gpio_json()
3 changes: 3 additions & 0 deletions tests/galaxy100/unittests/Galaxy100Util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ def solConnectionClosed(self, info):
return True
else:
return False

# Host Mac
HostMacCmd = '/usr/local/bin/wedge_us_mac.sh'
3 changes: 3 additions & 0 deletions tests/wedge/unittests/WedgeUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class WedgeUtil(BaseUtil.BaseUtil):
watchdogDaemonKill = ['/usr/bin/killall fand']
watchdogDaemonRestore = ['/bin/sh /etc/init.d/setup-fan.sh']

# Host Mac
HostMacCmd = '/usr/local/bin/wedge_us_mac.sh'

def get_speed(self, info):
"""
Supports getting fan speed for wedge
Expand Down
3 changes: 3 additions & 0 deletions tests/wedge100/unittests/Wedge100Util.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class Wedge100Util(BaseUtil.BaseUtil):
watchdogDaemonKill = ['/usr/bin/sv stop fscd']
watchdogDaemonRestore = ['/usr/bin/sv start fscd']

# Host Mac
HostMacCmd = '/usr/local/bin/wedge_us_mac.sh'

def get_speed(self, info):
"""
Supports getting fan pwm for wedge100
Expand Down
6 changes: 6 additions & 0 deletions tests/wedge100/unittests/bmcUtilTest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"/usr/local/bin/cp2112_i2c_flush.sh",
"/usr/local/bin/cpld_rev.sh",
"/usr/local/bin/ec_version.sh",
"/usr/local/bin/wedge_us_mac.sh"
]
Loading

0 comments on commit d46d765

Please sign in to comment.