Import LinuxCNC source tree
This commit is contained in:
2
tests/halmodule.0/README
Normal file
2
tests/halmodule.0/README
Normal file
@@ -0,0 +1,2 @@
|
||||
check that the right range of values can be assigned to HAL pins of various
|
||||
types, no matter the Python type of the value
|
||||
37
tests/halmodule.0/expected
Normal file
37
tests/halmodule.0/expected
Normal file
@@ -0,0 +1,37 @@
|
||||
set s -1 ok
|
||||
set s 0 ok
|
||||
set s 1 ok
|
||||
set s -1 ok
|
||||
set s 0 ok
|
||||
set s 1 ok
|
||||
set s 2147483647 ok
|
||||
set s -2147483648 ok
|
||||
set u 0 ok
|
||||
set u 1 ok
|
||||
set u 4294967295 ok
|
||||
set f 0 ok
|
||||
set f 0.0 ok
|
||||
set f 0 ok
|
||||
set f -1 ok
|
||||
set f -1.0 ok
|
||||
set f -1 ok
|
||||
set f 1 ok
|
||||
set f 1.0 ok
|
||||
set f 1 ok
|
||||
set f 89884656743115795386465259539451236680898848947115328636715040578866337902750481566354238661203768010560056939935696678829394884407208311246423715319737062188883946712432742638151109800623047059726541476042502884419075341171231440736956555270413618581675255342293149119973622969239858152417678164812112068608 ok
|
||||
set s 2147483648 fail
|
||||
set s -2147483649 fail
|
||||
set u -1 fail
|
||||
set u 4294967296 fail
|
||||
set f 179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216 fail
|
||||
pincheck s True True True
|
||||
pincheck u True True True
|
||||
pincheck f True True True
|
||||
pincheck s True True True
|
||||
getitem not-found fail
|
||||
pincheck param False True True
|
||||
pincheck param False True True
|
||||
pincheck s True True True
|
||||
pincheck param False True True
|
||||
set u 0 0
|
||||
set u -1 fail
|
||||
96
tests/halmodule.0/test.py
Executable file
96
tests/halmodule.0/test.py
Executable file
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env python3
|
||||
import hal
|
||||
import os
|
||||
|
||||
h = hal.component("x")
|
||||
try:
|
||||
ps = h.newpin("s", hal.HAL_S32, hal.HAL_OUT)
|
||||
pu = h.newpin("u", hal.HAL_U32, hal.HAL_OUT)
|
||||
pf = h.newpin("f", hal.HAL_FLOAT, hal.HAL_OUT)
|
||||
param = h.newparam("param", hal.HAL_BIT, hal.HAL_RW)
|
||||
h.ready()
|
||||
|
||||
def try_set(p, v):
|
||||
try:
|
||||
h[p] = v
|
||||
hp = h[p]
|
||||
print("set {} {} {}".format(p, v, "ok" if hp == v else repr(hp)))
|
||||
except (ValueError, OverflowError) as e:
|
||||
print("set {} {} {}".format(p, v, "fail"))
|
||||
|
||||
def try_set_pin(p, v):
|
||||
try:
|
||||
p.set(v)
|
||||
print("set {} {} {}".format(p.get_name(), v, p.get()))
|
||||
except (ValueError, OverflowError):
|
||||
print("set {} {} {}".format(p.get_name(), v, "fail"))
|
||||
|
||||
try_set("s", -1)
|
||||
try_set("s", 0)
|
||||
try_set("s", 1)
|
||||
try_set("s", -1)
|
||||
try_set("s", 0)
|
||||
try_set("s", 1)
|
||||
try_set("s", 0x7fffffff)
|
||||
try_set("s", -0x80000000)
|
||||
|
||||
try_set("u", 0)
|
||||
try_set("u", 1)
|
||||
try_set("u", 0xffffffff)
|
||||
|
||||
try_set("f", 0)
|
||||
try_set("f", 0.0)
|
||||
try_set("f", 0)
|
||||
try_set("f", -1)
|
||||
try_set("f", -1.0)
|
||||
try_set("f", -1)
|
||||
try_set("f", 1)
|
||||
try_set("f", 1.0)
|
||||
try_set("f", 1)
|
||||
|
||||
try_set("f", 1 << 1023)
|
||||
|
||||
try_set("s", 0x80000000)
|
||||
try_set("s", -0x80000001)
|
||||
|
||||
try_set("u", -1)
|
||||
try_set("u", 1 << 32)
|
||||
|
||||
try_set("f", 1 << 1024)
|
||||
|
||||
pin = h.getitem("s")
|
||||
|
||||
def pin_validate(i, t, d):
|
||||
print("pincheck {} {} {} {}".format(
|
||||
i.get_name(), i.is_pin(), i.get_type() == t, i.get_dir() == d))
|
||||
|
||||
pin_validate(ps, hal.HAL_S32, hal.HAL_OUT)
|
||||
pin_validate(pu, hal.HAL_U32, hal.HAL_OUT)
|
||||
pin_validate(pf, hal.HAL_FLOAT, hal.HAL_OUT)
|
||||
|
||||
pin = h.getitem("s")
|
||||
|
||||
pin_validate(pin, hal.HAL_S32, hal.HAL_OUT)
|
||||
try:
|
||||
pin = h.getitem("not-found")
|
||||
print("{} {} {}".format("getitem", "not-found", "ok"))
|
||||
except:
|
||||
print("{} {} {}".format("getitem", "not-found", "fail"))
|
||||
|
||||
pin_validate(param, hal.HAL_BIT, hal.HAL_RW)
|
||||
param = h.getitem("param")
|
||||
pin_validate(param, hal.HAL_BIT, hal.HAL_RW)
|
||||
|
||||
pin = h.getpin("s")
|
||||
pin_validate(pin, hal.HAL_S32, hal.HAL_OUT)
|
||||
param = h.getparam("param")
|
||||
pin_validate(param, hal.HAL_BIT, hal.HAL_RW)
|
||||
|
||||
try_set_pin(pu, 0)
|
||||
try_set_pin(pu, -1)
|
||||
except:
|
||||
import traceback
|
||||
print("Exception: {}".format(traceback.format_exc()))
|
||||
raise
|
||||
finally:
|
||||
h.exit()
|
||||
4
tests/halmodule.0/test.sh
Executable file
4
tests/halmodule.0/test.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
$REALTIME start
|
||||
./test.py
|
||||
$REALTIME stop
|
||||
Reference in New Issue
Block a user