summaryrefslogtreecommitdiff
path: root/tests/trajectory-planner/circular-arcs/run_all_tests.py
blob: 2c28b1a1811759657c4550e3d76acfb7984d1bf1 (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python
'''Copied from m61-test'''

import linuxcnc
from linuxcnc_control import  LinuxcncControl
import hal
import sys

from time import sleep

from os import listdir
from os.path import isfile, join
import re
import Tkinter, os

def query_yes_no(question, default="yes"):
    """Ask a yes/no question via raw_input() and return their answer.

    "question" is a string that is presented to the user.
    "default" is the presumed answer if the user just hits <Enter>.
        It must be "yes" (the default), "no" or None (meaning
        an answer is required of the user).

    The "answer" return value is one of "yes" or "no".
    """
    valid = {"yes":True,   "y":True,  "ye":True,
             "no":False,     "n":False}
    if default == None:
        prompt = " [y/n] "
    elif default == "yes":
        prompt = " [Y/n] "
    elif default == "no":
        prompt = " [y/N] "
    else:
        raise ValueError("invalid default answer: '%s'" % default)

    while True:
        sys.stdout.write(question + prompt)
        choice = raw_input().lower()
        if default is not None and choice == '':
            return valid[default]
        elif choice in valid:
            return valid[choice]
        else:
            sys.stdout.write("Please respond with 'yes' or 'no' "\
                             "(or 'y' or 'n').\n")

def find_test_nc_files(testpath='nc_files', show=False):
    files = [ testpath + '/' + f for f in listdir(testpath) if isfile(join(testpath,f)) and re.search('.ngc$',f) is not None ]
    if show:
        print "In folder {0}, found {1} files:".format(testpath,len(files))
        for f in files:
            print f
    return files

def axis_open_program(t,f):
    return t.tk.call("send", "axis", ("remote","open_file_name", os.path.abspath(f)))

t = Tkinter.Tk()
t.wm_withdraw()

"""Run the test"""

raw_input("Press any key when the LinuxCNC GUI has loaded")
test_files = []
run_quick = query_yes_no("Run quick tests?")
if run_quick:
    test_files.extend(find_test_nc_files('nc_files/quick-tests',True))

run_spindle = query_yes_no("Run spindle synchronization tests?")

if run_spindle:
    test_files.extend(find_test_nc_files('nc_files/spindle',True))

run_performance = query_yes_no("Do run time performance tests?")

if run_performance:
    test_files.extend(find_test_nc_files('nc_files/performance',True))


h = hal.component("python-ui")
h.ready() # mark the component as 'ready'

#Don't need this with axis?
#os.system("halcmd source ./postgui.hal")

#
# connect to LinuxCNC
#

e = LinuxcncControl(1)
e.g_raise_except = False
e.set_mode(linuxcnc.MODE_MANUAL)
e.set_state(linuxcnc.STATE_ESTOP_RESET)
e.set_state(linuxcnc.STATE_ON)
e.do_home(-1)
sleep(1)
e.set_mode(linuxcnc.MODE_AUTO)
sleep(1)
for f in test_files:
    if re.search('\.ngc$',f) is not None:
        print "Loading program {0}".format(f)
        e.set_mode(linuxcnc.MODE_AUTO)
        sleep(1)
        axis_open_program(t,f)
        sleep(1)
        e.set_mode(linuxcnc.MODE_AUTO)
        while e.run_full_program():
            sleep(.5)
        res = e.wait_on_program()
        if res == False:
            print "Program {0} failed to complete!".format(f)
            sys.exit(1)

print "All tests completed!"