diff --git a/tests/common/bmcUtiltest.py b/tests/common/bmcUtiltest.py index 068d246b9c48..753544b08933 100644 --- a/tests/common/bmcUtiltest.py +++ b/tests/common/bmcUtiltest.py @@ -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)) diff --git a/tests/common/gpioTest.py b/tests/common/gpioTest.py new file mode 100644 index 000000000000..e4b135d64d34 --- /dev/null +++ b/tests/common/gpioTest.py @@ -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) diff --git a/tests/common/hostMacTest.py b/tests/common/hostMacTest.py new file mode 100644 index 000000000000..365f5b40c928 --- /dev/null +++ b/tests/common/hostMacTest.py @@ -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) diff --git a/tests/common/tools/CLI.py b/tests/common/tools/CLI.py index b53117ea0de1..7520e2b83b59 100644 --- a/tests/common/tools/CLI.py +++ b/tests/common/tools/CLI.py @@ -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") @@ -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: diff --git a/tests/common/tools/galaxy100.json b/tests/common/tools/galaxy100.json index 7c21f825ca2e..461a7fb522d2 100644 --- a/tests/common/tools/galaxy100.json +++ b/tests/common/tools/galaxy100.json @@ -41,5 +41,7 @@ "restapiTest.py":["yes", { "json":"../../galaxy100/unittests/rest_endpoint.json" - }] + }], + "hostMacTest.py":"yes" + } diff --git a/tests/common/tools/wedge.json b/tests/common/tools/wedge.json index a3d5fa7192ed..f023d7896d29 100644 --- a/tests/common/tools/wedge.json +++ b/tests/common/tools/wedge.json @@ -43,5 +43,6 @@ "processRunningTest.py":["yes", { "json":"../wedge/unittests/process.json" - }] + }], + "hostMacTest.py":"yes" } diff --git a/tests/common/tools/wedge100.json b/tests/common/tools/wedge100.json index 567835341546..b746507c4a32 100644 --- a/tests/common/tools/wedge100.json +++ b/tests/common/tools/wedge100.json @@ -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" + }] } diff --git a/tests/experimental/generate_gpiolist.py b/tests/experimental/generate_gpiolist.py new file mode 100644 index 000000000000..4b51be431249 --- /dev/null +++ b/tests/experimental/generate_gpiolist.py @@ -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() diff --git a/tests/galaxy100/unittests/Galaxy100Util.py b/tests/galaxy100/unittests/Galaxy100Util.py index 9548d49b5320..28d533990f3a 100644 --- a/tests/galaxy100/unittests/Galaxy100Util.py +++ b/tests/galaxy100/unittests/Galaxy100Util.py @@ -42,3 +42,6 @@ def solConnectionClosed(self, info): return True else: return False + + # Host Mac + HostMacCmd = '/usr/local/bin/wedge_us_mac.sh' diff --git a/tests/wedge/unittests/WedgeUtil.py b/tests/wedge/unittests/WedgeUtil.py index 932e73e68396..96e0d48d49b8 100644 --- a/tests/wedge/unittests/WedgeUtil.py +++ b/tests/wedge/unittests/WedgeUtil.py @@ -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 diff --git a/tests/wedge100/unittests/Wedge100Util.py b/tests/wedge100/unittests/Wedge100Util.py index 3d0405f72cbf..d7d16a3479d2 100644 --- a/tests/wedge100/unittests/Wedge100Util.py +++ b/tests/wedge100/unittests/Wedge100Util.py @@ -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 diff --git a/tests/wedge100/unittests/bmcUtilTest.json b/tests/wedge100/unittests/bmcUtilTest.json new file mode 100644 index 000000000000..92b4263a147a --- /dev/null +++ b/tests/wedge100/unittests/bmcUtilTest.json @@ -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" +] diff --git a/tests/wedge100/unittests/gpiolist.json b/tests/wedge100/unittests/gpiolist.json new file mode 100644 index 000000000000..b4b20116afdb --- /dev/null +++ b/tests/wedge100/unittests/gpiolist.json @@ -0,0 +1,532 @@ +{ + "gpios": { + "BMC_COM_NIC_ISOBUF_EN": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_COM_PANTHER_ISOBUF_EN": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_CPLD_POWER_INT": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_CPLD_QSFP_INT": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_CPLD_RESET1": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "BMC_CPLD_RESET2": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "BMC_CPLD_RESET3": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "BMC_CPLD_RESET4": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "BMC_CPLD_SPARE7": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "BMC_CPLD_TCK": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_CPLD_TDI": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_CPLD_TDO": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_CPLD_TMS": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_EEPROM1_SPI_MISO": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_EEPROM1_SPI_MOSI": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_EEPROM1_SPI_SCK": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_EEPROM1_SPI_SS": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_HEARTBEAT_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "BMC_MAIN_RESET_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_PWR_BTN_IN_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "BMC_PWR_BTN_OUT_N": { + "active_low": "0", + "direction": "out", + "edge": "none", + "value": "1" + }, + "BMC_READY_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "BMC_SPI_WP_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_UART_1_RTS": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_WDTRST1": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BMC_WDTRST2": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BOARD_REV_ID0": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BOARD_REV_ID1": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "BOARD_REV_ID2": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "BRG_COM_BIOS_DIS0_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "BRG_COM_BIOS_DIS1_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "COM6_BUF_EN": { + "active_low": "0", + "direction": "out", + "edge": "none", + "value": "0" + }, + "COM_SPI_SEL": { + "active_low": "0", + "direction": "out", + "edge": "none", + "value": "0" + }, + "CPLD_JTAG_SEL": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "CPLD_UPD_EN": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "DEBUG_PORT_UART_SEL_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "DEBUG_UART_SEL_0": { + "active_low": "0", + "direction": "out", + "edge": "none", + "value": "1" + }, + "FANCARD_CPLD_TCK": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "FANCARD_CPLD_TDI": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "FANCARD_CPLD_TDO": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "FANCARD_CPLD_TMS": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "FANCARD_I2C_ALARM": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "ISO_BRG_THRMTRIP_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "ISO_BRG_THRM_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "ISO_BUF_EN": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "ISO_COM_BRG_WDT": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "ISO_COM_PWROK": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "ISO_COM_SUS_S3_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "ISO_COM_SUS_S4_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "ISO_COM_SUS_S5_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "ISO_COM_SUS_STAT_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "ISO_MICROSRV_PRSNT_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "LED_POSTCODE_0": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "LED_POSTCODE_1": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "LED_POSTCODE_2": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "LED_POSTCODE_3": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "LED_POSTCODE_4": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "LED_POSTCODE_5": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "LED_POSTCODE_6": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "LED_POSTCODE_7": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "LED_PWR_BLUE": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "MSERVE_ISOBUF_EN": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "MSERV_NIC_SMBUS_ALERT_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "MSERV_POWERUP": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "PANTHER_I2C_ALERT_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "PM_SM_ALERT_N": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "QSFP_LED_POSITION": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "RCKMON_SPARE0": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "RCKMON_SPARE1": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "RCKMON_SPARE2": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "RCKMON_SPARE3": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "RCKMON_SPARE4": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "RCKMON_SPARE5": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "RMON1_PF": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "RMON1_RF": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "RMON2_PF": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "RMON2_RF": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "RMON3_PF": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "RMON3_RF": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "SMB_ALERT": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "SPI_IBMC_BT_CS1_N_R": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "SWITCH_EEPROM1_WRT": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "SWITCH_MDC": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "SWITCH_MDIO": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + }, + "TH_POWERUP": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "TPM_SPI_BUF_EN": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "TPM_SPI_SEL": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "0" + }, + "USB_OCS_N1": { + "active_low": "0", + "direction": "in", + "edge": "none", + "value": "1" + } + } +}