Added Sleep and Assert commands in test scripts.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37374 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Tommaso Cucinotta 2011-01-30 15:58:08 +00:00
parent 40dcf20b5d
commit 8ef0abbacc
2 changed files with 62 additions and 19 deletions

View File

@ -1,5 +1,11 @@
Automated tests based on the "MonKey Testing" keytest program. Automated tests based on the "MonKey Testing" keytest program.
DEPENDENCIES
xvkbd, wmctrl, pcregrep
USAGE
In order to launch all the tests available in this folder, just run In order to launch all the tests available in this folder, just run
./run-tests.sh ./run-tests.sh
@ -11,3 +17,19 @@ as argument to the script, e.g.:
For failed tests you get a folder with the logs that help you identify For failed tests you get a folder with the logs that help you identify
the problem. the problem.
SYNTAX
Each test-case script should be named as xxx-in.txt. The syntax of the
script is described in detail in the sample test-case script
hello-world-in.txt.
TODO
Speed-up the execution of the tests as much as possible (i.e., get rid
of heuristic waits when present and replace them with exact check of
the condition we're waiting for).
Allow for tests with multiple LyX instances, e.g., for copy&paste
across LyX instances, or multiple applications, i.e., for testing
the interaction between LyX and other applications.

View File

@ -142,7 +142,7 @@ class CommandSourceFromFile(CommandSource):
os._exit(0) os._exit(0)
if self.i >= len(self.lines): if self.i >= len(self.lines):
self.loops = self.loops + 1 self.loops = self.loops + 1
if self.loops >= max_loops: if self.loops >= int(max_loops):
os._exit(0) os._exit(0)
self.i = 0 self.i = 0
return 'Loop' return 'Loop'
@ -153,13 +153,14 @@ class CommandSourceFromFile(CommandSource):
sys.stdout.write('r') sys.stdout.write('r')
return line.rstrip('\n').rstrip() return line.rstrip('\n').rstrip()
def lyx_exists():
if lyx_pid is None:
return False
fname = '/proc/' + lyx_pid + '/status'
return os.path.exists(fname)
def lyx_sleeping(): def lyx_sleeping():
if lyx_pid is None:
return True
fname = '/proc/' + lyx_pid + '/status' fname = '/proc/' + lyx_pid + '/status'
if not os.path.exists(fname):
return False
f = open(fname, 'r') f = open(fname, 'r')
lines = f.readlines() lines = f.readlines()
sleeping = lines[1].find('(sleeping)') > 0 sleeping = lines[1].find('(sleeping)') > 0
@ -177,7 +178,7 @@ def sendKeystring(keystr, LYX_PID):
print 'print .' + keystr + '.\n' print 'print .' + keystr + '.\n'
keystr = 'a' keystr = 'a'
before_secs = time.time() before_secs = time.time()
while not lyx_sleeping(): while lyx_exists() and not lyx_sleeping():
time.sleep(0.02) time.sleep(0.02)
sys.stdout.write('.') sys.stdout.write('.')
sys.stdout.flush() sys.stdout.flush()
@ -189,7 +190,7 @@ def sendKeystring(keystr, LYX_PID):
os._exit(1) os._exit(1)
if not screenshot_out is None: if not screenshot_out is None:
while not lyx_sleeping(): while lyx_exists() and not lyx_sleeping():
time.sleep(0.02) time.sleep(0.02)
sys.stdout.write('.') sys.stdout.write('.')
sys.stdout.flush() sys.stdout.flush()
@ -199,7 +200,7 @@ def sendKeystring(keystr, LYX_PID):
time.sleep(0.1) time.sleep(0.1)
sys.stdout.flush() sys.stdout.flush()
if (subprocess.call( if (subprocess.call(
["xvkbd", "-xsendevent", "-delay", DELAY, "-text", keystr], ["xvkbd", "-xsendevent", "-window", lyx_window_name, "-delay", DELAY, "-text", keystr],
stdout=FNULL,stderr=FNULL stdout=FNULL,stderr=FNULL
) == 0): ) == 0):
sys.stdout.write('*') sys.stdout.write('*')
@ -277,8 +278,9 @@ if lyx_pid != "":
sendKeystring("\Afn", lyx_pid) sendKeystring("\Afn", lyx_pid)
write_commands = True write_commands = True
failed = False
while True: while not failed:
#os.system('echo -n LOADAVG:; cat /proc/loadavg') #os.system('echo -n LOADAVG:; cat /proc/loadavg')
c = x.getCommand() c = x.getCommand()
outfile.writelines(c + '\n') outfile.writelines(c + '\n')
@ -304,6 +306,7 @@ while True:
time.sleep(1) time.sleep(1)
print 'lyx_pid: ' + lyx_pid + '\n' print 'lyx_pid: ' + lyx_pid + '\n'
print 'lyx_win: ' + lyx_window_name + '\n' print 'lyx_win: ' + lyx_window_name + '\n'
time.sleep(1)
#RaiseWindow() #RaiseWindow()
#sendKeystring("\Afn", lyx_pid) #sendKeystring("\Afn", lyx_pid)
elif c[0:5] == 'Sleep': elif c[0:5] == 'Sleep':
@ -321,7 +324,7 @@ while True:
print 'Raising Lyx' print 'Raising Lyx'
RaiseWindow() RaiseWindow()
elif c[0:4] == 'KK: ': elif c[0:4] == 'KK: ':
if os.path.exists('/proc/' + lyx_pid + '/status'): if lyx_exists():
sendKeystring(c[4:], lyx_pid) sendKeystring(c[4:], lyx_pid)
else: else:
##os.system('killall lyx; sleep 2 ; killall -9 lyx') ##os.system('killall lyx; sleep 2 ; killall -9 lyx')
@ -333,18 +336,36 @@ while True:
elif c == 'Loop': elif c == 'Loop':
RaiseWindow() RaiseWindow()
sendKeystring(ResetCommand, lyx_pid) sendKeystring(ResetCommand, lyx_pid)
elif c[0:6] == 'Assert':
cmd = c[7:].rstrip()
print "\nExecuting " + cmd
result = os.system(cmd)
failed = failed or (result != 0)
print "result=" + str(result) + ", failed=" + str(failed)
elif c[0:7] == 'TestEnd': elif c[0:7] == 'TestEnd':
time.sleep(1) time.sleep(0.5)
print "\nTerminating lyx instance: " + str(lyx_pid) + "\n" print "\nTerminating lyx instance: " + str(lyx_pid) + "\n"
os.system("kill -9 " + str(lyx_pid) + "\n"); os.system("kill -9 " + str(lyx_pid) + "\n");
cmd = c[7:].rstrip() while lyx_exists():
print "Waiting for lyx to die...\n"
time.sleep(0.5)
cmd = c[8:].rstrip()
print "\nExecuting " + cmd
result = os.system(cmd) result = os.system(cmd)
print "Test case terminated: " failed = failed or (result != 0)
if result == 0: print "result=" + str(result) + ", failed=" + str(failed)
print "Ok\n" elif c[0:4] == 'Lang':
os._exit(0) lang = c[5:].rstrip()
else: print "\nSetting LANG=" + lang
print "FAIL\n" os.environ['LANG'] = lang
os._exit(1)
else: else:
print "Unrecognised Command '" + c + "'\n" print "Unrecognised Command '" + c + "'\n"
failed = True
print "Test case terminated: "
if failed:
print "FAIL\n"
os._exit(1)
else:
print "Ok\n"
os._exit(0)