Skip to content

Commit f18a8d7

Browse files
authored
Merge pull request #4947 from grandixximo/test-waits
tests: wait for the machine to be on and homed, and for the abort's plane cancel
2 parents 187b6c4 + 43f8b29 commit f18a8d7

16 files changed

Lines changed: 86 additions & 32 deletions

File tree

‎lib/python/linuxcnc_util.py‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,49 @@ def wait_for_home(self, joints, timeout=10.0):
102102
raise LinuxCNC_Exception("timeout waiting for homing to complete:\nstatus.homed:" + str(self.status.homed) + "\nstatus.position:" + str(self.status.position))
103103

104104

105+
def wait_for_machine_on(self, timeout=10.0):
106+
"""Returns once the machine is on, raises LinuxCNC_Exception if
107+
it did not turn on before the timeout. state(STATE_ON) is done
108+
once task has passed it on, the machine is on some cycles later,
109+
and motion refuses to home until it is."""
110+
111+
start_time = time.time()
112+
while True:
113+
self.status.poll()
114+
if self.status.task_state == linuxcnc.STATE_ON:
115+
return
116+
if (time.time() - start_time) > timeout:
117+
raise LinuxCNC_Exception("timeout waiting for the machine to turn on: task_state %d" % self.status.task_state)
118+
time.sleep(0.01)
119+
120+
121+
def home_all(self, timeout=30.0):
122+
"""Arguments:
123+
124+
'timeout' is a float, the number of seconds to wait for the
125+
machine to turn on and then for the joints to home.
126+
127+
Homes every joint with home(-1) once the machine is on. A
128+
command is done once task has passed it on: the machine is on
129+
and the joints are homed some cycles later, and task refuses
130+
homing and MDI until they are.
131+
132+
Returns once every joint is homed, raises LinuxCNC_Exception if
133+
the machine did not turn on or a joint did not home before the
134+
timeout."""
135+
136+
self.wait_for_machine_on(timeout)
137+
self.command.home(-1)
138+
start_time = time.time()
139+
while True:
140+
self.status.poll()
141+
if all(self.status.homed[:self.status.joints]):
142+
return
143+
if (time.time() - start_time) > timeout:
144+
raise LinuxCNC_Exception("timeout waiting for homing to complete:\nstatus.homed:" + str(self.status.homed) + "\nstatus.position:" + str(self.status.position))
145+
time.sleep(0.01)
146+
147+
105148
def home_joints(self, joints, timeout=10.0):
106149
"""Arguments:
107150
@@ -118,6 +161,7 @@ def home_joints(self, joints, timeout=10.0):
118161
Returns once all the joints are homed, raises
119162
LinuxCNC_Exception if one did not home before the timeout."""
120163

164+
self.wait_for_machine_on(timeout)
121165
for joint in joints:
122166
self.command.home(joint)
123167
start_time = time.time()

‎tests/kins-limits/box/test-ui.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# The [AXIS_L] box is the machine frame envelope, the carriage and not the
33
# tool tip: see README.
44
import linuxcnc
5+
import linuxcnc_util
56
import sys
67
import time
78

@@ -84,9 +85,7 @@ def refused(cmd, needle):
8485

8586
c.state(linuxcnc.STATE_ESTOP_RESET)
8687
c.state(linuxcnc.STATE_ON)
87-
c.wait_complete(30)
88-
c.home(-1)
89-
c.wait_complete(60)
88+
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
9089
c.mode(linuxcnc.MODE_MDI)
9190
c.wait_complete(30)
9291
drain()

‎tests/kins-limits/jog-travel/test-ui.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# reaches its soft limit, and a jog away from it is free: see README.
44
import hal
55
import linuxcnc
6+
import linuxcnc_util
67
import os
78
import sys
89
import time
@@ -145,8 +146,7 @@ def jog_ended(what):
145146
c.state(linuxcnc.STATE_ESTOP_RESET)
146147
c.state(linuxcnc.STATE_ON)
147148
c.wait_complete(30)
148-
c.home(-1)
149-
c.wait_complete(60)
149+
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
150150
c.mode(linuxcnc.MODE_MDI)
151151
c.wait_complete(30)
152152
drain()

‎tests/kins-limits/jog/test-ui.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# own limits: see README.
44
import hal
55
import linuxcnc
6+
import linuxcnc_util
67
import os
78
import sys
89
import time
@@ -124,8 +125,7 @@ def tip_held(what):
124125
c.state(linuxcnc.STATE_ESTOP_RESET)
125126
c.state(linuxcnc.STATE_ON)
126127
c.wait_complete(30)
127-
c.home(-1)
128-
c.wait_complete(60)
128+
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
129129
c.mode(linuxcnc.MODE_MDI)
130130
c.wait_complete(30)
131131
drain()

‎tests/kins-limits/swing/test-ui.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# its own limits: see README.
44
import hal
55
import linuxcnc
6+
import linuxcnc_util
67
import os
78
import sys
89
import time
@@ -70,8 +71,7 @@ def log_samples():
7071
c.state(linuxcnc.STATE_ESTOP_RESET)
7172
c.state(linuxcnc.STATE_ON)
7273
c.wait_complete(30)
73-
c.home(-1)
74-
c.wait_complete(60)
74+
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
7575
c.mode(linuxcnc.MODE_MDI)
7676
c.wait_complete(30)
7777
drain()

‎tests/kins-orient-linear/test-ui.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# 5axiskins orients with B and C; [AXIS_B] TYPE = LINEAR: see README.
33

44
import linuxcnc
5+
import linuxcnc_util
56
import os
67
import sys
78

@@ -11,8 +12,7 @@
1112

1213
c.state(linuxcnc.STATE_ESTOP_RESET)
1314
c.state(linuxcnc.STATE_ON)
14-
c.home(-1)
15-
c.wait_complete()
15+
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
1616
c.mode(linuxcnc.MODE_MDI)
1717
c.wait_complete()
1818

‎tests/kins-switch/test-ui.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# where the interpreter reads far ahead of the machine.
55
import hal
66
import linuxcnc
7+
import linuxcnc_util
78
import os
89
import sys
910
import time
@@ -88,8 +89,7 @@ def mdi(cmd):
8889
c.state(linuxcnc.STATE_ESTOP_RESET)
8990
c.state(linuxcnc.STATE_ON)
9091
done(30)
91-
c.home(-1)
92-
done(60)
92+
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
9393
# start in identity every run, the abort's G13.1 may or may not have run yet
9494
c.mode(linuxcnc.MODE_MDI)
9595
done(30)

‎tests/kins-switchkins-core/test-ui.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# as type 0 and an X offset of 5 as type 1, and switchkins_core does the rest.
44
import hal
55
import linuxcnc
6+
import linuxcnc_util
67
import sys
78
import time
89

@@ -60,8 +61,7 @@ def check(what, got, want):
6061
c.state(linuxcnc.STATE_ESTOP_RESET)
6162
c.state(linuxcnc.STATE_ON)
6263
c.wait_complete(30)
63-
c.home(-1)
64-
c.wait_complete(60)
64+
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
6565
c.mode(linuxcnc.MODE_MDI)
6666
c.wait_complete(30)
6767
drain()

‎tests/kins-tool-offset/test-ui.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# length back out again through motion alone.
99

1010
import linuxcnc
11+
import linuxcnc_util
1112
import hal
1213
import subprocess
1314
import sys
@@ -23,8 +24,7 @@
2324

2425
c.state(linuxcnc.STATE_ESTOP_RESET)
2526
c.state(linuxcnc.STATE_ON)
26-
c.home(-1)
27-
c.wait_complete()
27+
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
2828
c.mode(linuxcnc.MODE_MDI)
2929

3030
errors = 0

‎tests/ptp-machine-frame/test-ui.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# frame: see README.
44

55
import linuxcnc
6+
import linuxcnc_util
67
import hal
78
import gcode
89
import preview_helpers
@@ -22,8 +23,7 @@
2223

2324
c.state(linuxcnc.STATE_ESTOP_RESET)
2425
c.state(linuxcnc.STATE_ON)
25-
c.home(-1)
26-
c.wait_complete()
26+
linuxcnc_util.LinuxCNC(command=c, status=s).home_all()
2727
c.mode(linuxcnc.MODE_MDI)
2828

2929
errors = 0

0 commit comments

Comments
 (0)