/ tests / motion-logger / basic / test-ui.py
test-ui.py
 1  #!/usr/bin/env python
 2  
 3  import linuxcnc
 4  import hal
 5  
 6  import time
 7  import sys
 8  import subprocess
 9  import os
10  import signal
11  import glob
12  import re
13  
14  comp = hal.component("test-ui")
15  comp.newpin("reopen-log", hal.HAL_BIT, hal.HAL_IO)
16  comp.ready()
17  
18  os.system("halcmd net reopen-log test-ui.reopen-log motion-logger.reopen-log")
19  
20  # This will be the return value of this program.
21  # Any failure sets it to 1.
22  retval = 0
23  
24  
25  def end_log(logfile_name):
26      c.wait_complete()
27      comp['reopen-log'] = True
28      while comp['reopen-log']: time.sleep(.01)
29      os.rename("out.motion-logger", 'result.%s' % logfile_name)
30      status = subprocess.call(['diff', '-u', 'expected.%s' % logfile_name, 'result.%s' % logfile_name], shell=False)
31      if status == 0:
32          print "sub-test %s ok" % logfile_name
33      else:
34          print "unexpected output in logfile '%s'" % logfile_name
35          global retval
36          retval = 1
37      sys.stdout.flush()
38  
39  
40  #
41  # connect to LinuxCNC
42  #
43  
44  c = linuxcnc.command()
45  s = linuxcnc.stat()
46  e = linuxcnc.error_channel()
47  
48  
49  #
50  # Come out of E-stop, turn the machine on, and switch to Auto mode.
51  #
52  
53  c.state(linuxcnc.STATE_ESTOP_RESET)
54  c.state(linuxcnc.STATE_ON)
55  c.mode(linuxcnc.MODE_AUTO)
56  
57  end_log('builtin-startup')
58  
59  
60  #
61  # run each .ngc test file in the test directory
62  #
63  
64  for ngc in glob.glob('*.ngc'):
65      if ngc == 'reset.ngc': continue
66  
67      m = re.match('(.*)\.ngc', ngc)
68      basename = m.group(1)
69  
70      c.program_open('reset.ngc')
71      c.auto(linuxcnc.AUTO_RUN, 0)
72      c.wait_complete()
73      end_log('reset')
74  
75      c.program_open(ngc)
76      c.auto(linuxcnc.AUTO_RUN, 0)
77      c.wait_complete()
78      end_log(basename)
79  
80  
81  print >>sys.stderr, "trying to exit"
82  sys.exit(retval)