File: test-ui.py

package info (click to toggle)
linuxcnc 1%3A2.9.7-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 285,604 kB
  • sloc: python: 202,568; ansic: 109,036; cpp: 99,239; tcl: 16,054; xml: 10,631; sh: 10,303; makefile: 1,255; javascript: 138; sql: 72; asm: 15
file content (82 lines) | stat: -rwxr-xr-x 1,661 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3

import linuxcnc
import hal

import time
import sys
import subprocess
import os
import signal
import glob
import re

comp = hal.component("test-ui")
comp.newpin("reopen-log", hal.HAL_BIT, hal.HAL_IO)
comp.ready()

os.system("halcmd net reopen-log test-ui.reopen-log motion-logger.reopen-log")

# This will be the return value of this program.
# Any failure sets it to 1.
retval = 0


def end_log(logfile_name):
    c.wait_complete()
    comp['reopen-log'] = True
    while comp['reopen-log']: time.sleep(.01)
    os.rename("out.motion-logger", 'result.%s' % logfile_name)
    status = subprocess.call(['diff', '-u', 'expected.%s' % logfile_name, 'result.%s' % logfile_name], shell=False)
    if status == 0:
        print("sub-test %s ok" % logfile_name)
    else:
        print("unexpected output in logfile '%s'" % logfile_name)
        global retval
        retval = 1
    sys.stdout.flush()


#
# connect to LinuxCNC
#

c = linuxcnc.command()
s = linuxcnc.stat()
e = linuxcnc.error_channel()


#
# Come out of E-stop, turn the machine on, and switch to Auto mode.
#

c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.mode(linuxcnc.MODE_AUTO)

end_log('builtin-startup')


#
# run each .ngc test file in the test directory
#

for ngc in glob.glob('*.ngc'):
    if ngc == 'reset.ngc': continue

    m = re.match('(.*)\.ngc', ngc)
    basename = m.group(1)

    c.program_open('reset.ngc')
    c.auto(linuxcnc.AUTO_RUN, 0)
    c.wait_complete()
    end_log('reset')

    c.program_open(ngc)
    c.auto(linuxcnc.AUTO_RUN, 0)
    c.wait_complete()
    end_log(basename)


sys.stderr.write("trying to exit")
sys.exit(retval)