# HG changeset patch # User Edouard Tisserant # Date 1645193526 -3600 # Node ID 40b8b2ffb3fd82568f3cc180a680f4d3c0a65223 # Parent 5bcef31e276d5f90104c218ad5b8552922594a48 Tests: Various enhancements in Makefile and sikuli common python code. diff -r 5bcef31e276d -r 40b8b2ffb3fd tests/Makefile --- a/tests/Makefile Fri Feb 18 15:00:04 2022 +0100 +++ b/tests/Makefile Fri Feb 18 15:12:06 2022 +0100 @@ -68,10 +68,12 @@ OWN_PROJECTS=beremiz matiec +tar_opts=--absolute-names --exclude=.hg --exclude=.git --exclude=.*.pyc --exclude=.*.swp + # sha1 checksum of source is used to force copy/compile on each change define make_checksum_assign -$(1)_checksum = $(shell tar --exclude=.hg --exclude=.git --exclude=.*.swp -c $(workspace)/$(1) | sha1sum | cut -d ' ' -f 1) +$(1)_checksum = $(shell tar $(tar_opts) -c $(workspace)/$(1) | sha1sum | cut -d ' ' -f 1) endef $(foreach project,$(OWN_PROJECTS),$(eval $(call make_checksum_assign,$(project)))) @@ -81,7 +83,8 @@ define make_src_rule $(build_dir)/$(1)/$($(1)_checksum).sha1: $(build_dir) $(workspace)/$(1) rm -rf $(build_dir)/$(1) - cp -a $(workspace)/$(1) $(build_dir)/$(1) + tar -C $(workspace) $(tar_opts) -c $(1) | tar -C $(build_dir) -x + #cp -a $(workspace)/$(1) $(build_dir)/$(1) touch $$@ endef $(foreach project,$(OWN_PROJECTS),$(eval $(call make_src_rule,$(project)))) @@ -99,7 +102,7 @@ ide_tests = $(subst $(src)/ide_tests/,,$(wildcard $(src)/ide_tests/*.sikuli)) define idetest_command - (fluxbox &); BEREMIZPATH=$(build_dir)/beremiz sikulix -r $(src)/ide_tests/$(1) | tee test_stdout.txt; exit $$$${pipestatus[0]} + (fluxbox >/dev/null 2>&1 &); BEREMIZPATH=$(build_dir)/beremiz sikulix -r $(src)/ide_tests/$(1) | tee test_stdout.txt; exit $$$${pipestatus[0]} endef # Xnest based interactive sessions for tests edit and debug. @@ -109,13 +112,17 @@ Xnest :42 -geometry 1920x1080+0+0 & export xnestpid=$$!; sleep 1; DISPLAY=:42 $(1); export res=$$?; kill $${xnestpid} 2>/dev/null; exit $${res} endef +define prep_test + rm -rf $(test_dir)/$(1)_idetest + mkdir $(test_dir)/$(1)_idetest + cd $(test_dir)/$(1)_idetest +endef + xserver_command ?= xvfb-run -s '-screen 0 1920x1080x24' define make_idetest_rule $(test_dir)/$(1)_idetest/.passed: own_apps - rm -rf $(test_dir)/$(1)_idetest - mkdir $(test_dir)/$(1)_idetest - cd $(test_dir)/$(1)_idetest; $(xserver_command) bash -c '$(call idetest_command, $(1))' + $(call prep_test,$(1)); $(xserver_command) bash -c '$(call idetest_command,$(1))' touch $$@ # Manually invoked rule {testname}.sikuli @@ -124,9 +131,7 @@ # Manually invoked rule xnest_{testname}.sikuli # runs test in xnest so that one can see what happens xnest_$(1): own_apps - rm -rf $(test_dir)/$(1)_idetest - mkdir $(test_dir)/$(1)_idetest - cd $(test_dir)/$(1)_idetest; $$(call xnest_run, bash -c '$(call idetest_command, $(1))') + $(call prep_test,$(1)); $$(call xnest_run, bash -c '$(call idetest_command,$(1))') ide_tests_targets += $(test_dir)/$(1)_idetest/.passed endef @@ -139,7 +144,7 @@ $(call xnest_run, bash -c '(fluxbox &);xterm') xnest_sikuli: own_apps - $(call xnest_run, bash -c '(fluxbox &);(xterm -e sikulix &);xterm') + $(call xnest_run, bash -c '(fluxbox &);(BEREMIZPATH=$(build_dir)/beremiz xterm -e sikulix &);xterm') # in case VNC would be used diff -r 5bcef31e276d -r 40b8b2ffb3fd tests/ide_tests/new_project.sikuli/new_project.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/ide_tests/new_project.sikuli/new_project.py Fri Feb 18 15:12:06 2022 +0100 @@ -0,0 +1,149 @@ +""" This test opens, builds and runs exemple project named "python". +Test succeeds if runtime's stdout behaves as expected +""" + +import os +import time + +# allow module import from current test directory's parent +addImportPath(os.path.dirname(getBundlePath())) + +# common test definitions module +from sikuliberemiz import * + +# Start the app without any project given +proc,app = StartBeremizApp() + +new_project_path = os.path.join(os.path.abspath(os.path.curdir), "new_test_project") + +# New project path must exist (usually created in directory selection dialog) +os.mkdir(new_project_path) + +# To detect when actions did finish because IDE content isn't changing +idle = IDEIdleObserver(app) + +# To send keyboard shortuts +k = KBDShortcut(app) + +idle.Wait(1,15) + +# Create new project (opens new project directory selection dialog) +k.New() + +idle.Wait(1,15) + +# Move to "Home" section of file selecor, otherwise address is +# "file ignored" at first run +type("f", Key.CTRL) +type(Key.ESC) +type(Key.TAB) + +# Enter directory by name +k.Address() + +# Fill address bar +type(new_project_path + Key.ENTER) + +idle.Wait(1,15) + +# When prompted for creating first program select type ST +type(Key.TAB*4) # go to lang dropdown +type(Key.DOWN*2) # change selected language +type(Key.ENTER) # validate + +idle.Wait(1,15) + +# Name created program +type("Test program") + +idle.Wait(1,15) + +# Focus on Variable grid +type(Key.TAB*4) + +# Add 2 variables +type(Key.ADD*2) + +# Focus on ST text +idle.Wait(1,15) + +type(Key.TAB*8) + +type("""\ +LocalVar0 := LocalVar1; +{printf("Test OK\\n");fflush(stdout);} +""") + +k.Save() + +# Close ST POU +type("w", Key.CTRL) + +idle.Wait(1,15) + +# Focus project tree and select root item +type(Key.TAB) + +type(Key.LEFT) + +type(Key.UP) + +# Edit root item +type(Key.ENTER) + +idle.Wait(1,15) + +# Switch to config tab +type(Key.RIGHT*2) + +# Focus on URI +type(Key.TAB) + +# Set URI +type("LOCAL://") + +# FIXME: Select other field to ensure URI is validated +type(Key.TAB) + +k.Save() + +# Close project config editor +type("w", Key.CTRL) + +idle.Wait(1,15) + +# Focus seems undefined at that time (FIXME) +# Force focussing on "something" so that next shortcut is taken +type(Key.TAB) + +del idle + +stdoutIdle = stdoutIdleObserver(proc) +stdoutIdle.Wait(2,15) + +k.Build() + +stdoutIdle.Wait(5,15) + +k.Connect() + +stdoutIdle.Wait(2,15) + +k.Transfer() + +stdoutIdle.Wait(2,15) + +del stdoutIdle + +k.Run() + +# wait 10 seconds +found = waitPatternInStdout(proc, "Test OK", 10) + +app.close() + +if found: + exit(0) +else: + exit(1) + diff -r 5bcef31e276d -r 40b8b2ffb3fd tests/ide_tests/sikuliberemiz.py --- a/tests/ide_tests/sikuliberemiz.py Fri Feb 18 15:00:04 2022 +0100 +++ b/tests/ide_tests/sikuliberemiz.py Fri Feb 18 15:12:06 2022 +0100 @@ -4,15 +4,16 @@ import sys import subprocess from threading import Thread, Event + +typeof=type + from sikuli import * -home = os.environ["HOME"] beremiz_path = os.environ["BEREMIZPATH"] python_bin = os.environ.get("BEREMIZPYTHONPATH", "/usr/bin/python") opj = os.path.join - def StartBeremizApp(projectpath=None, exemple=None): """ Starts Beremiz IDE, waits for main window to appear, maximize it. @@ -90,18 +91,23 @@ "Transfer": Key.F6, "Connect": Key.F7, "Clean": Key.F9, - "Build": Key.F11} + "Build": Key.F11, + "Save": ("s",Key.CTRL), + "New": ("n",Key.CTRL), + "Address": ("l",Key.CTRL)} # to reach address bar in GTK's file selector def __init__(self, app): self.app = app def __getattr__(self, name): fkey = self.fkeys[name] + if typeof(fkey) != tuple: + fkey = (fkey,) app = self.app def PressShortCut(): app.focus() - type(fkey) + type(*fkey) return PressShortCut @@ -127,7 +133,6 @@ self.r.stopObserver() def _OnIDEWindowChange(self, event): - print event self.idechanged = True def Wait(self, period, timeout): @@ -162,7 +167,7 @@ self.thread = Thread(target = self._waitStdoutProc).start() - def _waitStdoutProc(): + def _waitStdoutProc(self): while True: a = self.proc.stdout.read(1) if len(a) == 0 or a is None: diff -r 5bcef31e276d -r 40b8b2ffb3fd tests/tools/Docker/beremiz-sikuli/build_in_docker.sh --- a/tests/tools/Docker/beremiz-sikuli/build_in_docker.sh Fri Feb 18 15:00:04 2022 +0100 +++ b/tests/tools/Docker/beremiz-sikuli/build_in_docker.sh Fri Feb 18 15:12:06 2022 +0100 @@ -3,6 +3,6 @@ CONTAINER=beremiz_sikuli_current docker start $CONTAINER -docker exec -i -t $CONTAINER bash -i -c do_test $1 +docker exec -i -t $CONTAINER bash -i -c "do_tests $1" docker stop $CONTAINER