tests/Makefile
branchwxPython4
changeset 3424 7db96e011fe7
child 3428 803ce245f72f
equal deleted inserted replaced
3423:84afcc0ebadd 3424:7db96e011fe7
       
     1 #! gmake
       
     2 
       
     3 # beremiz/tests/Makefile :
       
     4 #
       
     5 #   Makefile to prepare and run Beremiz tests.
       
     6 #
       
     7 #   For developper to:
       
     8 #       - quickly run a test (TDD) on current code 
       
     9 #       - write new tests, debug existing tests 
       
    10 #
       
    11 #     Use cases :
       
    12 #
       
    13 #       run given tests
       
    14 #           $ make run_python_exemple.sikuli
       
    15 #
       
    16 #       run tests from particular test classes
       
    17 #           $ make ide_tests
       
    18 #
       
    19 #       run one particular test in a Xnest window
       
    20 #           $ make xnest_run_python_exemple.sikuli
       
    21 #
       
    22 #       run Xnest window with just xterm
       
    23 #           $ make xnest_xterm
       
    24 #
       
    25 #       run Xnest window with sikuli IDE and xterm
       
    26 #           $ make xnest_xterm
       
    27 #
       
    28 #       build minimal beremiz and matiec to run tests
       
    29 #           $ make own_apps
       
    30 #
       
    31 #   For CI/CD scripts to catch and report all failures. Use cases :
       
    32 #
       
    33 #       run all tests
       
    34 #           $ make
       
    35 #
       
    36 #   
       
    37 #   Variable $(src) is directory such that executed 
       
    38 #   $(src)/beremiz/tests/Makefile is this file.
       
    39 #   
       
    40 #   Test results, and other test byproducts are in $(test_dir), 
       
    41 #   $(test_dir) defaults to $(HOME)/test and can be overloaded:
       
    42 #       $ make test_dir=${HOME}/other_test_dir
       
    43 #
       
    44 #
       
    45 #   Matiec and Beremiz code are expected to be clean as if after hg clean --all.
       
    46 #   Any change in Matiec directory triggers rebuild of matiec.
       
    47 #   Any change in Matiec and Beremiz directory triggers copy of source code
       
    48 #   to $(test_dir)/build.
       
    49 #
       
    50 #
       
    51 #   Please note:
       
    52 #       In order to run asside a freshly build Matiec, tested beremiz instance
       
    53 #       needs to run on code from $(test_dir)/build/beremiz, a fresh copy
       
    54 #       of the Beremiz directory $(src)/beremiz, where we run tests from.
       
    55 #   
       
    56 
       
    57 all: source_check cli_tests ide_tests runtime_tests 
       
    58 
       
    59 src := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
       
    60 workspace ?= $(abspath $(src)/../..)
       
    61 
       
    62 test_dir ?= $(HOME)/test
       
    63 build_dir = $(test_dir)/build
       
    64 
       
    65 OWN_PROJECTS=beremiz matiec
       
    66 
       
    67 # sha1 checksum of source is used to force copy/compile on each change
       
    68 
       
    69 define make_checksum_assign
       
    70 $(1)_checksum = $(shell tar --exclude=.hg --exclude=.git --exclude=.*.swp -c $(workspace)/$(1) | sha1sum | cut -d ' ' -f 1)
       
    71 endef
       
    72 $(foreach project,$(OWN_PROJECTS),$(eval $(call make_checksum_assign,$(project))))
       
    73 
       
    74 $(build_dir):
       
    75 	mkdir -p $(build_dir)
       
    76 
       
    77 define make_src_rule
       
    78 $(build_dir)/$(1)/$($(1)_checksum).sha1: $(build_dir) $(workspace)/$(1)
       
    79 	rm -rf $(build_dir)/$(1)
       
    80 	cp -a $(workspace)/$(1) $(build_dir)/$(1)
       
    81 	touch $$@
       
    82 endef
       
    83 $(foreach project,$(OWN_PROJECTS),$(eval $(call make_src_rule,$(project))))
       
    84 
       
    85 $(build_dir)/matiec/iec2c: | $(build_dir)/matiec/$(matiec_checksum).sha1
       
    86 	cd $(build_dir)/matiec && \
       
    87     autoreconf -i && \
       
    88     ./configure && \
       
    89     make
       
    90 
       
    91 # TODO: use packge (deb/snap ?)
       
    92 own_apps: $(build_dir)/matiec/iec2c $(build_dir)/beremiz/$(beremiz_checksum).sha1
       
    93 	touch $@
       
    94 
       
    95 ide_tests = $(subst $(src)/ide_tests/,,$(wildcard $(src)/ide_tests/*.sikuli))
       
    96 
       
    97 define idetest_command
       
    98 	(fluxbox &); BEREMIZPATH=$(build_dir)/beremiz sikulix -r $(src)/ide_tests/$(1) | tee test_stdout.txt; exit $$$${pipestatus[0]}
       
    99 endef
       
   100 
       
   101 # Xnest based interactive sessions for tests edit and debug. 
       
   102 # Would be nice with something equivalent to xvfb-run, waiting for USR1.
       
   103 # Arbitrary "sleep 1" is probably enough for interactive use
       
   104 define xnest_run
       
   105 	Xnest :42 -geometry 1920x1080+0+0 & export xnestpid=$$!; sleep 1; DISPLAY=:42 $(1); export res=$$?; kill $${xnestpid} 2>/dev/null; exit $${res}
       
   106 endef
       
   107 
       
   108 # Manually invoked rule {testname}.sikuli
       
   109 define make_idetest_rule
       
   110 $(test_dir)/$(1)_idetest/.passed: own_apps
       
   111 	rm -rf $(test_dir)/$(1)_idetest
       
   112 	mkdir $(test_dir)/$(1)_idetest
       
   113 	cd $(test_dir)/$(1)_idetest; xvfb-run -s '-screen 0 1920x1080x24' bash -c '$$(call idetest_command, $(1))'
       
   114 	touch $$@
       
   115 
       
   116 $(1): $(test_dir)/$(1)_idetest/.passed
       
   117 
       
   118 # Manually invoked rule xnest_{testname}.sikuli
       
   119 # runs test in xnest so that one can see what happens
       
   120 # depends on docker arguments "-v /tmp/.X11-unix/X0:/tmp/.X11-unix/X0 -e DISPLAY=$DISPLAY"
       
   121 xnest_$(1): own_apps
       
   122 	rm -rf $(test_dir)/$(1)_idetest
       
   123 	mkdir $(test_dir)/$(1)_idetest
       
   124 	cd $(test_dir)/$(1)_idetest; $$(call xnest_run, bash -c '$(call idetest_command, $(1))')
       
   125 
       
   126 ide_tests_targets += $(test_dir)/$(1)_idetest/.passed
       
   127 endef
       
   128 $(foreach idetest,$(ide_tests),$(eval $(call make_idetest_rule,$(idetest))))
       
   129 
       
   130 ide_tests : $(ide_tests_targets)
       
   131 	echo "$(ide_tests_targets)" : Passed
       
   132 
       
   133 xnest_xterm: own_apps
       
   134 	$(call xnest_run, bash -c '(fluxbox &);xterm')
       
   135 
       
   136 xnest_sikuli: own_apps
       
   137 	$(call xnest_run, bash -c '(fluxbox &);(xterm -e sikulix &);xterm')
       
   138 
       
   139 
       
   140 # in case VNC would be used 
       
   141 	#xvfb-run -s '-screen 0 1920x1080x24' bash -c '(fluxbox &);(x11vnc &);xterm;'
       
   142 
       
   143 
       
   144 clean:
       
   145 	rm -rf $(ide_tests_targets) $(build_dir)
       
   146 
       
   147 
       
   148 # TODOs 
       
   149 
       
   150 source_check:
       
   151 	echo TODO $@
       
   152 
       
   153 cli_tests :
       
   154 	echo TODO $@
       
   155 
       
   156 runtime_tests:
       
   157 	echo TODO $@
       
   158 
       
   159 
       
   160