test-scripts.text 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. 1. Running a set of test scripts 2by sequencer.py
  2. This program can run one or more scripts from the command line;
  3. each script is run in the order that it appears.
  4. If a directory is given, then the entire tree is searched for .py
  5. files beginning with 'test', these files are sorted and each is
  6. run. Any one failing file will not affect the whole run. After
  7. the files have bee processed the sub directories are processed.
  8. 2. User interface for running individual test files (ui.py)
  9. This is a GUI to run an individual test script one or more times.
  10. First select Open from the file menu then choose the script to run.
  11. Select the number of iterations (between 1 and 1000) using the spin
  12. button. left mouse click increments or decrements by 1; middle
  13. button by +/-10 and the right button will set 1 or 1000.
  14. Just below this is the status line that indicated if the test is
  15. running or stopped.
  16. Finally click the run button the tests will then be run. Failing a
  17. test will not stop the entire sequence. The stop button with abort
  18. the run at the end of one pass of the script. The status line will
  19. indicate that the sequence will be stopped.
  20. The contents of the log window can be saved as a text file by
  21. selecting "Save" from the file menu.
  22. The log window is cleared when a new test is loaded, or if the
  23. "Clear screen" button is clicked (when a test is not running).
  24. 3. Test script.
  25. This is a python program the file name must begin with 'test' and
  26. end with '.py'.
  27. the script consists of several funtions.
  28. a) setUp
  29. This is the first function run and is used to configure any
  30. global resources require by the tests themselves. For example
  31. it might initialise and turn on a power supply.
  32. b) tearDown
  33. This is run at the end of all the tests in this script or if
  34. any individual test function fails. This would most likely
  35. turn of the power and free the global resources allocated by
  36. the setUp function.
  37. c) testXXXXXXX
  38. These routines comprise the test steps, they are sorted by
  39. name before running them to ensure that the test order is
  40. always the same. Do not rely on the order of tests in the
  41. file, bu choose a name ing scheme.
  42. For example: test_0001_on test_002_next test_003_more
  43. Test scripts make use of imported modules to control the external
  44. devices by various interfaces such as USB or GPIB. here is a simple example
  45. of the setUp and TearDown functions. It also shows use of the debug
  46. global variable that is provided by the sequencer.py program.
  47. dvm = None
  48. psu = None
  49. def setUp():
  50. """Set up power supply and turn on
  51. Also put a message on the PSU LCD to warn operator"""
  52. global debug, psu, dvm
  53. info('setUp: **initialising**')
  54. dvm = Agilent.DMM34401A()
  55. dvm.setVoltageDC()
  56. psu = Keithley.PSU2303()
  57. psu.setCurrent(SUPPLY_CURRENT_LIMIT)
  58. psu.setVoltage(SUPPLY_STANDARD_VOLTAGE)
  59. psu.powerOff()
  60. if debug > 50:
  61. psu.settings()
  62. psu.measure()
  63. psu.message('Test in progress Do NOT Touch ')
  64. def tearDown():
  65. """Shutdown the power supply"""
  66. global debug, psu, dvm
  67. psu.powerOff()
  68. psu.setCurrent(0)
  69. psu.setVoltage(0)
  70. psu.messageOff()
  71. info('tearDown: **cleanup**')
  72. del psu
  73. psu = None
  74. del dvm
  75. dvm = None
  76. del relay
  77. relay = None
  78. The individual test functions can use the value of debug to display
  79. various messages; but they will normally indicate progress using
  80. the info function. The test function can indicate failure at any
  81. point using fail_if or fail_unless functions: These API calls are
  82. summarised here:
  83. a) info(message)
  84. e.g. info('set point = %7.3f V @ %7.3f mA' %(v, i))
  85. This displays the text 'INFO:' and the message to standard output.
  86. When running under the ui the message will appear in the log buffer.
  87. b) fail_if(condition, message)
  88. e.g. fail_if(i > 100, 'current %7.3f is too high' % i)
  89. If the condition is True then output 'FAIL:' followed by the
  90. message to standard output, or the log buffer if running under
  91. the ui program.
  92. c) fail_unless(condition, message)
  93. e.g. fail_unless(i > 10, 'failed to reach minimum current')
  94. If the condition is False the perform the same action as b
  95. above.
  96. 4) Keithley Power supply 2303 API
  97. Create a power supply object at a specific GPIB address
  98. psu = Keithley.PSU2303(address = 5, gpib_card = 0)
  99. Set the voltage and current
  100. psu.setVoltage(v, max = 4)
  101. psu.setCurrent(i, max = 1)
  102. Control the output circuit
  103. psu.powerOff()
  104. psu.powerOn()
  105. Measure the actual output
  106. v = psu.voltage
  107. i = psu.current
  108. Display some text on the power supply's LCD
  109. psu.message(text)
  110. psu.messageOff()
  111. Some routines used for debugging
  112. psu.settings()
  113. psu.measure():
  114. 5) Agilent 34401A Digital Multimeter
  115. Create a digital multimeter object at a specific GPIB address
  116. dmm = Agilent.DMM34401A(address = 22, gpib_card = 0)
  117. Select operating mode
  118. dmm.setVoltageDC()
  119. dmm.setCurrentDC()
  120. Read a value depends of the last mode selected
  121. v = dmm.voltage
  122. i = dmm.current
  123. 6) 16 channel USB relay board
  124. Create a relay board object at a specific USB port
  125. relay = RelayBoard.PIC16F873A(port = '/dev/ttyUSB0', bps = 19200, timeout = 0.1)
  126. Turn off all relays immediately
  127. relay.allOff()
  128. Mark a relay as pending on, the current state of the relay is not affected
  129. (n in the range 1 .. 16)
  130. relay.set(n)
  131. Mark a relay as pending off, the current state of the relay is not affected
  132. (n in the range 1 .. 16)
  133. relay.clear(n)
  134. Update all pending on/off changes to the relay board, all relays
  135. will be affected simultaneously
  136. relay.update()
  137. Read the state of the last packet sent to the relays as a 16 bit
  138. integer, bit zero represents relay 1
  139. s = relay.state()
  140. Read the pending state that would be sent if the update funtion is
  141. called as a 16 bit integer, bit zero represents relay 1
  142. p = pending()
  143. Turn on a relay immediately, this is euivalent to set+update
  144. relay.on(n)
  145. Turn off a relay immediately, this is euivalent to clear+update
  146. relay.off(n)