diff --git a/adaptors/python/Makefile b/adaptors/python/Makefile index 108541740db6f76d1d009267b2866375311c5eda..9f966ec414f14b119092b8ec03a6e9715fb3d347 100644 --- a/adaptors/python/Makefile +++ b/adaptors/python/Makefile @@ -1,8 +1,8 @@ MOBERG_VERSION=$(shell git describe --tags) -all: BUILD +all: BUILD INSTALL -.PHONY: BUILD +.PHONY: BUILD BUILD: python2 ./setup.py build python3 ./setup.py build diff --git a/plugins/libtest/libtest.c b/plugins/libtest/libtest.c index eb202de83f1cd31305ee6f050474d10ad7adc820..c0b6f2c55159826e82ecd55f7e2cd1079c0e5523 100644 --- a/plugins/libtest/libtest.c +++ b/plugins/libtest/libtest.c @@ -141,7 +141,7 @@ static struct moberg_status encoder_in_read( struct moberg_channel_context *channel = &encoder_in->channel_context; struct moberg_device_context *device = channel->device; - *value = device->digital; + *value = device->digital * (channel->index + 1); return MOBERG_OK; err_einval: return MOBERG_ERRNO(EINVAL); diff --git a/test/Makefile b/test/Makefile index ca3141846f7a7f964a245fd2a7ebb06a3462246b..6f0426a81f63c4b59d7e00d6d898cd408be8d273 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,19 +1,27 @@ -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 LDFLAGS += -L$(shell pwd)/build/ -lmoberg ENV_TEST = LD_LIBRARY_PATH=../build XDG_CONFIG_HOME=.config XDG_CONFIG_DIRS=. LDFLAGS_test_moberg4simulink = -lmoberg4simulink 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: .PHONY: test -test: $(TEST:%=run_%) +test: $(PYTEST:%=run_py_%) $(CTEST:%=run_c_%) echo Tests run -run_%: build/% +.PHONY: run_c_% +run_c_%: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/% build/%: %.c | build diff --git a/test/test_moberg4simulink.c b/test/test_moberg4simulink.c index bfe8ee5e7832cfc626129c7f6ad768f31966df9e..6dd57056cae2c8dd5eaab7a32bb81b0fbdbc28d1 100644 --- a/test/test_moberg4simulink.c +++ b/test/test_moberg4simulink.c @@ -8,6 +8,7 @@ int main(int argc, char *argv[]) goto out; } moberg4simulink_analog_in_close(0, ain); + return(0); out: return 1; } diff --git a/test/test_py.py b/test/test_py.py new file mode 100644 index 0000000000000000000000000000000000000000..5753a1f233df0f5e071654b2aa5062e3667d622c --- /dev/null +++ b/test/test_py.py @@ -0,0 +1,19 @@ +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 +