Commit 9e6d5436 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Added a python test

parent c70bcabb
MOBERG_VERSION=$(shell git describe --tags) MOBERG_VERSION=$(shell git describe --tags)
all: BUILD all: BUILD INSTALL
.PHONY: BUILD .PHONY: BUILD
BUILD: BUILD:
python2 ./setup.py build python2 ./setup.py build
python3 ./setup.py build python3 ./setup.py build
......
...@@ -141,7 +141,7 @@ static struct moberg_status encoder_in_read( ...@@ -141,7 +141,7 @@ static struct moberg_status encoder_in_read(
struct moberg_channel_context *channel = &encoder_in->channel_context; struct moberg_channel_context *channel = &encoder_in->channel_context;
struct moberg_device_context *device = channel->device; struct moberg_device_context *device = channel->device;
*value = device->digital; *value = device->digital * (channel->index + 1);
return MOBERG_OK; return MOBERG_OK;
err_einval: err_einval:
return MOBERG_ERRNO(EINVAL); return MOBERG_ERRNO(EINVAL);
......
TEST = test_start_stop test_io test_moberg4simulink CTEST = test_start_stop test_io test_moberg4simulink
PYTEST=test_py
CCFLAGS += -Wall -Werror -I$(shell pwd) -g CCFLAGS += -Wall -Werror -I$(shell pwd) -g
LDFLAGS += -L$(shell pwd)/build/ -lmoberg LDFLAGS += -L$(shell pwd)/build/ -lmoberg
ENV_TEST = LD_LIBRARY_PATH=../build XDG_CONFIG_HOME=.config XDG_CONFIG_DIRS=. ENV_TEST = LD_LIBRARY_PATH=../build XDG_CONFIG_HOME=.config XDG_CONFIG_DIRS=.
LDFLAGS_test_moberg4simulink = -lmoberg4simulink LDFLAGS_test_moberg4simulink = -lmoberg4simulink
CCFLAGS_test_moberg4simulink = -I../adaptors/matlab -Wall -Werror -I$(shell pwd) -g CCFLAGS_test_moberg4simulink = -I../adaptors/matlab -Wall -Werror -I$(shell pwd) -g
PYTHON2PATH=$(shell realpath ../adaptors/python/install/usr/lib*/python2*/site-packages)
PYTHON3PATH=$(shell realpath ../adaptors/python/install/usr/lib*/python3*/site-packages)
all: all:
.PHONY: test .PHONY: test
test: $(TEST:%=run_%) test: $(PYTEST:%=run_py_%) $(CTEST:%=run_c_%)
echo Tests run echo Tests run
run_%: build/% .PHONY: run_c_%
run_c_%:build/%
$(ENV_TEST) valgrind --leak-check=full ./build/$* $(ENV_TEST) valgrind --leak-check=full ./build/$*
.PHONY: run_py_%
run_py_%: %.py
$(ENV_TEST) PYTHONPATH=$(PYTHON2PATH) python2 $*.py
$(ENV_TEST) PYTHONPATH=$(PYTHON3PATH) python3 $*.py
.PRECIOUS: build/% .PRECIOUS: build/%
build/%: %.c | build build/%: %.c | build
......
...@@ -8,6 +8,7 @@ int main(int argc, char *argv[]) ...@@ -8,6 +8,7 @@ int main(int argc, char *argv[])
goto out; goto out;
} }
moberg4simulink_analog_in_close(0, ain); moberg4simulink_analog_in_close(0, ain);
return(0);
out: out:
return 1; return 1;
} }
import moberg
m = moberg.Moberg()
ain = [ m.analog_in(i) for i in range(8) ]
aout = [ m.analog_out(i) for i in range(8) ]
din = [ m.digital_in(i) for i in range(8) ]
dout = [ m.digital_out(i) for i in range(8) ]
ein = [ m.encoder_in(i) for i in range(8) ]
for v in range(10):
aout[0].write(v)
print([ c.read() for c in ain ])
for v in range(10):
for c,w in zip(dout, range(100)):
dout[w].write(v & (1<<w))
print([ c.read() for c in din ])
print([ c.read() for c in ein ])
pass
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment