Commit 6c448913 authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

sw: Started working on scripts and folde structure make

parent 92e725dc
all:
mkdir -p pts-conv-ttl-rs485/boot
mkdir -p pts-conv-ttl-rs485/tests
mkdir -p pts-conv-ttl-rs485/lib
cp -r shell/ pts-conv-ttl-rs485/
wget -P pts-conv-ttl-rs485/boot http://www.ohwr.org/attachments/download/3639/pts.bit
cp pts.py pts-conv-ttl-rs485
cp jpts.py pts-conv-ttl-rs485
cp leds.py pts-conv-ttl-rs485/tests/test00.py
#! /usr/bin/python
# coding: utf8
##________________________________________________________________________________________________
##
## CONV-TTL-RS485 PTS
##
## CERN,BE/CO-HT
##________________________________________________________________________________________________
##
##------------------------------------------------------------------------------------------------
##
## CONV-TTL-RS485 test sequencer
##
##------------------------------------------------------------------------------------------------
##
## Description This module gets called by the main PTS module (pts.py) to run the tests defined
## via the make-links.bat script. The tests are listed within this script and symlinks
## are created to point to the actual Pyton programs running the tests.
##
## The task of this module is to run these Python programs in a sequence and print the
## test results to output files.
##
## Two types of output files exist for this purpose. The first is the log file (.log),
## which contains brief information, PASS/FAIL for each test. The second, the info
## file (.inf) contains more detailed information, listing the steps the test takes
## and the reasons for which the test failed (if it failed).
##
## Authors Julian Lewis (Julian.Lewis@cern.ch)
## Theodor Stana (t.stana@cern.ch)
## Website http://www.ohwr.org/projects/conv-ttl-rs485
## Date 30/10/2014
##-------------------------------------------------------------------------------------------------
##
##-------------------------------------------------------------------------------------------------
## GNU LESSER GENERAL PUBLIC LICENSE
## ------------------------------------
## This source file is free software; you can redistribute it and/or modify it under the terms of
## the GNU Lesser General Public License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
## This source is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
## without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
## See the GNU Lesser General Public License for more details.
## You should have received a copy of the GNU Lesser General Public License along with this
## source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
##-------------------------------------------------------------------------------------------------
##------------------------------------------------------------------------------------------------
## Import
##------------------------------------------------------------------------------------------------
import sys
import ptsexcept
import time
import traceback
import socket
from optparse import OptionParser
from vv_pts import *
from os import path, access, R_OK, readlink
sys.path.append('.')
##-------------------------------------------------------------------------------------------------
## Method to get the test program a symlink points to
##-------------------------------------------------------------------------------------------------
def lnk_ptr(tname):
lname = "./%s.py" % (tname)
if path.islink(lname):
return readlink(lname)
else:
return tname
##-------------------------------------------------------------------------------------------------
## Method to run the test
##-------------------------------------------------------------------------------------------------
def run_test(tname,bus,inf,log):
# Each test should have a main function in it running the necessary steps
# to run. Here we import the name of the test and run the main function,
# printing the docstring at the beginning of this function.
#
# The number of errors returned by the test's main function is returned
# by this function to the JPTS program.
try:
mod = __import__(tname)
msg = mod.main.__doc__
print msg
log.write("%s\n" % (msg))
inf.write("%s\n" % (msg))
time.sleep(1)
return mod.main(bus,tname,inf,log)
except PtsError, e:
msg = "%s %s->%s\n" % (e, tname, lnk_ptr(tname))
print "ABORT: %s" % (msg)
inf.write(msg)
log.write(msg)
return 1
##-------------------------------------------------------------------------------------------------
## Main "method" of JPTS
##-------------------------------------------------------------------------------------------------
if __name__ == '__main__':
# Print usage information
use = "Usage: %prog [--lun=0 --snum=1234 5678 --debug] test_num,run_count test_num,run_count..."
parser = OptionParser(usage=use, version="pts version 2.0")
parser.add_option("-l", "--lun", help="Logical Unit Number", type="int", default=4, dest="lun")
parser.add_option("-s", "--snum", help="Serial number(s)", dest="snum", action="store", nargs=2, default=("0","0"))
parser.add_option("-n", "--name", help="Board name", dest="board_name", default="ttlbl")
parser.add_option("-b", "--bus", help="Bus VME/PCI/SKT", dest="bus_type", default="SKT")
parser.add_option("-o", "--outdir", help="Path to log directory", dest="dir_name", default=".")
parser.add_option("-d", "--debug", help="Debug Option", dest="debug", default=False, action="store_true")
options, args = parser.parse_args()
# Print further information if in debug mode
if options.debug:
print "\n"
print "options (Logical Unit Number) lun :%d" % options.lun
print "options (Serial numbers pair) snum :%s %s" % options.snum
print "options (Board name ) name :%s" % options.board_name
print "options (Bus VME PCI or SKT ) bus :%s" % options.bus_type
print "options (Location of log dir) outdir:%s" % options.dir_name
print "options (Debug printing flag) debug :%d" % options.debug
print "arglist (List: Test,RunCount) :%s" % (args)
# Create test array from existing test links
tns = []
if len(args):
for a in args:
nstr = a.split(',')
tn = int(nstr[0])
if len(nstr) == 2:
tc = int(nstr[1])
else:
tc = 1
tns.append((tn,tc))
else:
for a in range(19):
tns.append((a,1))
# Get logical unit number, serial numbers, board name, log file dir from command line args
# and create path strings for log and info files
lun = options.lun
sno, xno = options.snum
bnm = options.board_name
dir = options.dir_name
now = time.asctime(time.localtime(time.time()))
now = now.replace(" ","-")
now = now.replace(":","-")
lgf = "%s/log/%s-%s-%s-%s-%1d.log" % (dir,bnm,sno,xno,now,lun)
inf = "%s/log/%s-%s-%s-%s-%1d.inf" % (dir,bnm,sno,xno,now,lun)
# Open the log and info files
try:
log = open(lgf, "w")
inf = open(inf, "w")
except Exception, e:
msg = "Exception: %s" % (e)
print "Fatal: %s" % (msg)
sys.exit(1)
# and print them to console if in debug mode
if options.debug:
print "\n"
print "Log file is: %s" % lgf
print "Inf file is: %s" % inf
print "\n"
# Open up a bus object, can be one of following (depending on tested device):
# * VME -- VME board (SVEC, etc.)
# * PCI -- PCI board (SPEC, etc.)
# * SKT -- board connecting through I2C lines on VME backplane (CONV-TTL-BLO, etc.)
try:
if options.bus_type == "VME":
bus = VME(lun)
elif options.bus_type == "PCI":
bus = PCI(lun)
else:
bus = SKT(lun)
bus.vv_init()
except BusException, e:
print "Fatal:BUS Exception: %s" % (e)
except BusWarning, e:
print "Warning:Bus Exception: %s" % (e)
# Start running the tests.
for t in tns:
tname = "test%02d" % t[0]
pyt = "%s/%s.py" % (dir, tname)
if path.exists(pyt) and path.isfile(pyt) and access(pyt, R_OK):
for n in range(t[1]):
if n == 10:
msg = "Printing suppresses after 10 runs"
print msg
log.write('\n' + msg + '\n')
inf.write('\n' + msg + '\n')
if n < 10:
msg = "Run:%d Begin:%s" % (n+1,tname)
print msg
log.write('\n' + msg + '\n')
inf.write('\n' + msg + '\n')
try:
# First load a firmware and read back a register to confirm correct load.
if bus.vv_load()==1:
msg = "INFO:Found TTLBL board in slot:%d OK\n" % (lun)
inf.write(msg + '\n')
# Each test is passed the test name, the log and info files and the
# bus object. The test program is expected to return the number of
# errors that occured. If no errors occur, the test PASSes, otherwise
# it FAILs.
cc = run_test(tname,bus,inf,log)
if cc == 0:
msg = "PASS: %s" % (tname)
log.write(msg + '\n')
inf.write(msg + '\n')
print msg
else:
msg = "FAIL: %s->%s" % (tname, lnk_ptr(tname))
log.write(msg + '\n')
inf.write(msg + '\n')
print msg
except Exception, e:
if options.debug:
print e
traceback.print_exc()
msg = "FAIL: %s->%s (%s)" % (tname, lnk_ptr(tname), e)
log.write(msg + '\n')
inf.write(msg + '\n')
print msg
if n < 10:
msg = "Run:%d End:%s\n" % (n+1,tname)
print msg
log.write(msg + '\n')
inf.write(msg + '\n')
# Close the bus and the files
bus.vv_close()
log.close()
inf.close()
# Print info file to console if in debug mode
if options.debug:
print "Debug: printing:%s" % (inf)
inf = open(inf, "r")
try:
for line in inf:
l = line.split("\n")
print "%s" % l[0]
finally:
inf.close()
sys.exit(1)
##_______________________________________________________________________________________________
##
## CONV-TTL-RS485 PTS
##
## CERN,BE/CO-HT
##_______________________________________________________________________________________________
##
##-----------------------------------------------------------------------------------------------
##
## CONV-TTL-RS485 LEDs test
##
##-----------------------------------------------------------------------------------------------
##
## Description Testing of the Front Panel status LEDs (IC1 and bi-color LEDs) and pulse
## LEDs (IC5 and channel LEDs) of the CONV-TTL-BLO board.
##
## For this test, the operator's intervention is needed; when prompted, the operator
## needs to visually check the LEDS.
##
## The FPGA firmware sequences through each of the front panel LEDs (pulse LEDs
## status LEDs) based on the value of the current test field in the PTS control
## register. In order to start and stop LED sequencing, the test sets and clears
## control bits in the PTS CSR.
##
## Authors Julian Lewis (Julian.Lewis@cern.ch)
## Theodor-Adrian Stana (t.stana@cern.ch)
## Website http://www.ohwr.org/projects/pts
## Date 30/10/2014
##-----------------------------------------------------------------------------------------------
##
##------------------------------------------------------------------------------------------------
## GNU LESSER GENERAL PUBLIC LICENSE
## ------------------------------------
## This source file is free software; you can redistribute it and/or modify it under the terms of
## the GNU Lesser General Public License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
## This source is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
## without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
## See the GNU Lesser General Public License for more details.
## You should have received a copy of the GNU Lesser General Public License along with this
## source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
##-------------------------------------------------------------------------------------------------
##-------------------------------------------------------------------------------------------------
## Import
##-------------------------------------------------------------------------------------------------
# Import system modules
import sys
import time
import os, errno, re, sys, struct
import os.path
import traceback
# Import common modules
from ctypes import *
from ptsexcept import *
from vv_pts import *
from pts_memmap import *
##-------------------------------------------------------------------------------------------------
## main --
##-------------------------------------------------------------------------------------------------
def main(bus,tname,inf,log):
"""
tests : Front Panel LEDs with Schmitt trigger driver ICxxx, bicolor LEDs with transceiver ICxx
"""
pel = PTS_ERROR_LOGGER(inf,log)
try:
# First phase of LED test, enable pulse LED sequencing
bus.vv_write(CSR, 1 << CSR_PULSE_LED_EN_OFS)
# The firmware should blink the LEDs, ask the operator for input
inp = raw_input("--> Are the channel LEDs blinking one by one? yes/no: ")
while True:
if inp.find("yes") != -1 or inp.find("YES") != -1:
break
if inp.find("no") != -1 or inp.find("NO") != -1:
msg = "ERROR: Front Panel LEDs or Schmitt trigger IC5"
pel.set(msg)
break
inp = raw_input('Please type "yes" or "no" to continue:')
# Second phase of LED test, enable status LED sequencing
bus.vv_write(CSR, 1 << CSR_STAT_LED_EN_OFS)
# The firmware should blink the LEDs, ask the operator for input
inp = raw_input("--> Are the status LEDs blinking one by one? yes/no: ")
while True:
if inp.find("yes") != -1 or inp.find("YES") != -1:
break
if inp.find("no") != -1 or inp.find("NO") != -1:
msg = "ERROR: Status LEDs or transceiver IC1"
pel.set(msg)
break
inp = raw_input('Please type "yes" or "no" to continue:')
return pel.get()
except BusException, e:
raise PtsError("SKT Exception: %s" % (e))
except BusWarning, e:
raise PtsError("SKT Warning: %s" % (e))
iso.3.6.1.4.1.37968.1.1.5.2.1.3.1 = INTEGER: 15100
iso.3.6.1.4.1.37968.1.1.5.2.1.3.2 = INTEGER: 15100
iso.3.6.1.4.1.37968.1.1.5.2.1.3.3 = INTEGER: 0
iso.3.6.1.4.1.37968.1.1.5.2.1.3.4 = INTEGER: 0
#! /usr/bin/python
# coding: utf8
##________________________________________________________________________________________________
##
## CONV-TTL-RS485 PTS
##
## CERN,BE/CO-HT
##________________________________________________________________________________________________
##
##------------------------------------------------------------------------------------------------
##
## CONV-TTL-RS485 PTS main program
##
##------------------------------------------------------------------------------------------------
##
## Description This is the main program of the PTS suite. It is the high-level program of the
## suite, running scripts to turn the test system on and off and downloading bitfiles
## to the DUT FPGA(s) before finally running the test programs. This latter part is
## handled by JPTS (jpts.py), a Python program that cycles through the various tests
## to be performed and writes results to log (.log) and info (.inf) files.
##
## Each board has a barcode associated to it, which can be either read via a barcode
## reader device, or manually input by the user from a keyboard. The barcode is used
## as part of the output file names to identify a DUT board.
##
## The program begins by asking for this barcode and downloading a bitstream to the
## FPGA once the board has been plugged in. Then, JPTS gets called in an external
## shell to run the tests defined for a board's PTS.
##
## After the tests have finished running, the log and info files get stored to a USB
## stick provided with the test system.
##
## Authors Julian Lewis (Julian.Lewis@cern.ch)
## Theodor Stana (t.stana@cern.ch)
## Website http://www.ohwr.org/projects/conv-ttl-rs485
## Date 30/10/2014
##-------------------------------------------------------------------------------------------------
##
##-------------------------------------------------------------------------------------------------
## GNU LESSER GENERAL PUBLIC LICENSE
## ------------------------------------
## This source file is free software; you can redistribute it and/or modify it under the terms of
## the GNU Lesser General Public License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
## This source is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
## without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
## See the GNU Lesser General Public License for more details.
## You should have received a copy of the GNU Lesser General Public License along with this
## source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
##-------------------------------------------------------------------------------------------------
##-------------------------------------------------------------------------------------------------
## Import
##-------------------------------------------------------------------------------------------------
import sys
import time
import traceback
import os
import subprocess
import re
sys.path.append('.')
##-------------------------------------------------------------------------------------------------
## Method to turn on the ELMA crate.
##-------------------------------------------------------------------------------------------------
## It calls the get-fan-speeds script to check if the crate is on.
##-------------------------------------------------------------------------------------------------
def men_is_on():
on = 0
subprocess.call("shell/get-fan-speeds", shell=True, stdout=sys.stdout, \
stderr=sys.stderr)
try:
btxt = tuple(open("log/fan-speeds","r"))
for i in range(1,len(btxt)):
if btxt[i].find("INTEGER: 0") == -1:
on = on + 1
return on
except IOError:
return 0
##-------------------------------------------------------------------------------------------------
## Method to turn on the VME crate.
##-------------------------------------------------------------------------------------------------
## It calls the men-on script which sends the necessary SMTP commands to the ELMA crate to turn on
## power to the VME backplane.
##-------------------------------------------------------------------------------------------------
def men_on():
tmo = 1
while men_is_on() == 0:
print "Try:%d Switching ON the VME Crate" % (tmo)
subprocess.call("shell/men-on", shell=True, stdout=fnull, stderr=fnull)
tmo = tmo + 1
if tmo > 10:
print "FATAL ERROR: VME Crate: Unable to switch ON"
sys.exit(1)
time.sleep(1)
##-------------------------------------------------------------------------------------------------
## Method to turn off the VME crate.
##-------------------------------------------------------------------------------------------------
## It calls the men-off script which sends the necessary SMTP commands to the ELMA crate to turn off
## power to the VME backplane.
##-------------------------------------------------------------------------------------------------
def men_off():
tmo = 1
while men_is_on() != 0:
print "Try:%d Switching OFF the VME Crate" % (tmo)
subprocess.call("shell/men-off", shell=True, stdout=fnull, stderr=fnull)
tmo = tmo + 1
if tmo > 10:
print "FATAL ERROR: VME Crate: Unable to switch OFF"
sys.exit(1)
time.sleep(10)
##-------------------------------------------------------------------------------------------------
## Main "method" of PTS
##-------------------------------------------------------------------------------------------------
if __name__ == '__main__':
print "\nHello and Welcome to the CONV-TTL-RS485 PTS!\n"
# Open NULL File and turn the crate off
fnull = open(os.devnull, "w")
# Clear the log dir (if any) and (re-)create it to store log and info files
subprocess.call("rm -rf ./log; mkdir log; chmod 777 log", shell=True, stdout=fnull, stderr=fnull)
men_off()
# Scan the first barcode
while True:
sn1 = raw_input("--> Scan the 1st barcode: ")
m = re.search(r"[^a-z\-A-Z0-9_]+",sn1)
if m:
print "Bad character in barcode"
else:
break
# Scan the second barcode
while True:
sn2 = raw_input("--> Scan the 2nd barcode: ")
if len(sn2) > 2:
m = re.search(r"[^a-z\-A-Z0-9_]+",sn2)
if m:
print "Bad character in barcode"
else:
break
else:
sn2 = "0"
break
# Ask the user to plug in the board, turn on the crate and call the flash_* script to download bitstream
# to FPGA
msg = "\n--> Plug the CONV-TTL-RS485 board '%s-%s' into the VME crate.\n Then type 'ok': " % (sn1, sn2)
ok = raw_input(msg)
while True:
if ok.find("ok") != -1 or ok.find("OK") != -1:
break
else:
ok = raw_input("--> Please type 'ok' to continue: ")
print "\n"
men_on()
print "Loading FPGA bitstream..."
subprocess.call("cd boot; ./flash.sh; cd ..", shell=True, stdout=fnull, stderr=fnull)
time.sleep(1)
# Run JPTS in another shell script; JPTS will handle running each of the test scripts
cmd = "xterm -e ./jpts.py -s %s %s" % (sn1, sn2)
print "Running tests :%s\n" % (cmd)
subprocess.call(cmd, shell=True, stdout=sys.stdout, stderr=sys.stderr)
# # After JPTS has finished, download release bitstream to EEPROM chip if none of the tests has failed
# print "Loading CONV-TTL-RS485 release bitstream\n"
# ret = subprocess.call("cd /home/pts/ubuntu/ttlbl/boot; ./flash_release.sh", shell=True, stdout=sys.stdout, stderr=sys.stderr)
# if (ret == 0):
# time.sleep(1)
#
# # ... power-cycle the crate
# print "VME Crate power-cycle..."
# men_off()
# time.sleep(5)
# men_on()
#
# time.sleep(5)
#
# print ''
# # .. and run the flash test
# cmd = "cd /home/pts/ubuntu/ttlbl/pyts; python flash_test.py"
# subprocess.call(cmd, shell=True, stdout=sys.stdout, stderr=sys.stderr)
#
# # After all testing has finished, grep the log files for PASS and FAIL messages and print the outcomes to the console
# subprocess.call("grep PASS /home/pts/ubuntu/ttlbl/log/*.log", shell=True, stdout=sys.stdout, stderr=sys.stderr)
# subprocess.call("grep FAIL /home/pts/ubuntu/ttlbl/log/*.log", shell=True, stdout=sys.stdout, stderr=sys.stderr)
#
# # Save results on USB key...
# print "\nSaving test results on USB key"
# try:
# subprocess.call("mkdir -p /media/pts/log", shell=True, stdout=sys.stdout, stderr=sys.stderr)
# subprocess.call("cp /home/pts/ubuntu/ttlbl/log/*.log /media/pts/log", shell=True, stdout=sys.stdout, stderr=sys.stderr)
# subprocess.call("cp /home/pts/ubuntu/ttlbl/log/*.inf /media/pts/log", shell=True, stdout=sys.stdout, stderr=sys.stderr)
# except e:
# print "ERROR: No access to USB key at /media/pts"
# print e
#
# We're done, turn off the VME crate
print "\nTesting completed!"
men_off()
# Finally, print anything that went wrong throughout the test programs by grepping the log and info files and
# exit when the user desires.
msg = "\n--> To see all the PTS errors, type 'ok': "
ok = raw_input(msg)
if ok.find("ok") != -1:
subprocess.call("grep FAIL /home/pts/ubuntu/ttlbl/log/*.log", shell=True, stdout=sys.stdout, stderr=sys.stderr)
subprocess.call("grep ERROR /home/pts/ubuntu/ttlbl/log/*.inf", shell=True, stdout=sys.stdout, stderr=sys.stderr)
subprocess.call("grep WARNING /home/pts/ubuntu/ttlbl/log/*.inf", shell=True, stdout=sys.stdout, stderr=sys.stderr)
print ""
print "--> You may now unplug the CONV-TTL-BLO board %s-%s\n" % (sn1, sn2)
msg = "--> To exit PTS, type 'ok': "
ok = raw_input(msg)
while True:
if ok.find("ok") != -1 or ok.find("OK") != -1:
print "Exited PTS"
time.sleep(1)
sys.exit(1)
else:
ok = raw_input("--> To exit PTS, type 'ok': ")
#!/bin/bash
echo Get ELMA fan speeds and store them in log/fan-speeds
rm -f ../log/fan-speeds
snmpwalk -v2c -c Gr@nBr@st0 cfvm-864-celma1 1.3.6.1.4.1.37968.1.1.5.2.1.3 > ../log/fan-speeds
#!/bin/bash
echo Power OFF ELMA crate
snmpset -v2c -c Gr@nBr@st0 cfvm-864-celma1 1.3.6.1.4.1.37968.1.1.7.2.1.3.1 i 1
#!/bin/bash
echo Power ON ELMA crate
snmpset -v2c -c Gr@nBr@st0 cfvm-864-celma1 1.3.6.1.4.1.37968.1.1.7.2.1.3.1 i 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment