From 5cf6f4f6569ed4a55dff7a39a8d549683dce24a7 Mon Sep 17 00:00:00 2001 From: Pavel Sanda Date: Mon, 15 Jun 2009 20:20:14 +0000 Subject: [PATCH] Test of brute-force key typing to test lyx for crashes. Vanilla sources from John McCabe-Dansted. http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg152155.html git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30121 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/keystest/README | 40 ++++++++++++++++++++++ development/keystest/autolyx | 16 +++++++++ development/keystest/killtest.sh | 14 ++++++++ development/keystest/lyx_make.sh | 20 +++++++++++ development/keystest/maketar.sh | 2 ++ development/keystest/report.sh | 52 +++++++++++++++++++++++++++++ development/keystest/start_tests.sh | 6 ++++ development/keystest/stock_text | 1 + development/keystest/test.py | 47 ++++++++++++++++++++++++++ 9 files changed, 198 insertions(+) create mode 100644 development/keystest/README create mode 100755 development/keystest/autolyx create mode 100755 development/keystest/killtest.sh create mode 100755 development/keystest/lyx_make.sh create mode 100755 development/keystest/maketar.sh create mode 100755 development/keystest/report.sh create mode 100755 development/keystest/start_tests.sh create mode 100644 development/keystest/stock_text create mode 100755 development/keystest/test.py diff --git a/development/keystest/README b/development/keystest/README new file mode 100644 index 0000000000..8f6cf52994 --- /dev/null +++ b/development/keystest/README @@ -0,0 +1,40 @@ +--- LyXtest --- + +This is a program to spam LyX with millions of randomly generated key +presses, and collect the crash results. + +Since the code involves spamming random keypresses, I'd recommend +running it in a VM, well away from your main X windows session. + +In short, to use this, move this directory LT into your LyX source directory +(e.g. lyx-1.6.x, but not lyx-1.6.x/src). Then run LT/lyx_make.sh + +It requires the following packages to run + xvkbd wmctrl +the following are also useful: + lyx libqt4-dbg subversion automake + +It is run by running ./autolyx in one xterm, and ./test.py in another. +I wrote lyx_make.sh as a easy way of updating lyx and running these two +programs together. + +CONTENTS: + +README: this readme file +report.sh: A quick way of generating bug reports and an overview from the logs. +autolyx: A script to continually restart lyx and collect the bug reports +lyx_make.sh: should updates, compiles, and everything needed to generated logs. +maketar.sh: Makes this tar file :) +test.py: Sends LT100 randomly generated keypresses per second to the LyX window. +killtest: stop the testing +stock_text: The stock test to add to each bug report. + +OUTPUTS: + +autolyx: Outputs out/GDB, a log of all output, including backtraces. +test.py: Outputs out/KEYCODES, a list of all keycodes sent to LyX + +reports.sh: Outputs + out/overview: an overview of all the frequency of each error + out/overview_sort: as above but sorted + out/report_*: A collection of autogenerated bug reports. diff --git a/development/keystest/autolyx b/development/keystest/autolyx new file mode 100755 index 0000000000..20477dc4da --- /dev/null +++ b/development/keystest/autolyx @@ -0,0 +1,16 @@ +#!/bin/bash +# This script starts LyX, and restarts LyX if it is closed +# it logs all output, including backtraces to LT/out/GDB + +#rename other windows to avoid confusion. +wmctrl -N __renamed__ -r lyx +wmctrl -N __renamed__ -r lyx +wmctrl -N __renamed__ -r lyx +wmctrl -N __renamed__ -r lyx + +while true +do + ( (echo SECONDS: `date +%s` + (echo "run + bt" ; yes q) | gdb src/lyx 2>&1) | strings| tee -a LT/out/GDB) +done diff --git a/development/keystest/killtest.sh b/development/keystest/killtest.sh new file mode 100755 index 0000000000..8d8d30ada9 --- /dev/null +++ b/development/keystest/killtest.sh @@ -0,0 +1,14 @@ +AUTOLYX=`ps gaux | grep autolyx | grep -v grep | sed 's/[^ ]* //' | sed s/0.0.*//g` +killall autolyx +killall test.py +killall lyx +killall gdb +killall xterm +kill $AUTOLYX +sleep 0.3 +killall autolyx -9 +killall test.py -9 +killall lyx -9 +killall gdb -9 +killall xterm -9 +kill $AUTOLYX -9 diff --git a/development/keystest/lyx_make.sh b/development/keystest/lyx_make.sh new file mode 100755 index 0000000000..e6c92e8ff1 --- /dev/null +++ b/development/keystest/lyx_make.sh @@ -0,0 +1,20 @@ +#!/bin/bash +#This script updates LyX, runs LyX, starts spamming it with hundreds of +#keypresses, and logs all output, including backtraces to LT/out/GDB +#Use report.sh to generated the more useful bug reports in LT/out/{or}* + +#LYXDIR=LT/lyx-1.6.x-test +cd ~/lyx-1.6.x-test +mkdir -p LT/out +if which wmctrl xvkbd bash xterm python +then + #cd "$LYXDIR" || echo CANNOT FIND LT/lyx-1.6.x-test + #cd "$LYXDIR" || exit + svn up Makefile.am autogen.sh boost/ config/ configure.ac lib/ lyx.1in m4/ rename.sh src/ + export CFLAGS="-g" + export CXXFLAGS="$CFLAGS" + ./autogen.sh && ./configure && nice -18 make && (bash LT/autolyx & sleep 9 ; xterm -e python LT/test.py) +else + echo NEEDS the following packages: + echo wmctrl xvkbd bash xterm python +fi diff --git a/development/keystest/maketar.sh b/development/keystest/maketar.sh new file mode 100755 index 0000000000..670d300b5c --- /dev/null +++ b/development/keystest/maketar.sh @@ -0,0 +1,2 @@ +tar -c LT/start_tests.sh LT/killt* LT/README LT/stock_text LT/report.sh LT/autolyx LT/lyx_make.sh LT/maketar.sh LT/test.py | gzip -9 > LT/lyxtestc.tar.gz +#cp lyxtestb.tar.gz LT/share diff --git a/development/keystest/report.sh b/development/keystest/report.sh new file mode 100755 index 0000000000..fd059c7929 --- /dev/null +++ b/development/keystest/report.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# echo 'grep "#1 " LT/out/GDB | sed 's/0x[^ )]*[ )]/.*/g' | sort | uniq' >> report.sh + +UNIQUE_LINE=1 + +while [ ! -e LT/out/GDB ] +do + cd .. + if [ `pwd` = '/' ] + then + exit + fi +done + +strings LT/out/GDB > LT/out/GDBs +grep "#$UNIQUE_LINE " LT/out/GDBs > LT/out/list +#cat LT/out/list | grep -o ' in [[:alnum:]:]* ' | sort | uniq| tee LT/out/listuniq +#cat LT/out/list | grep -o ' in [[:alnum:]:]* ' | sort | uniq| tee LT/out/listuniq +cat LT/out/list | sed 's/0x[^ )]*[ )]/.*/g' | sort | uniq | tee LT/out/listuniq + +NUM_REPORTS=`wc -l < LT/out/list` +echo NUM_REPORTS $NUM_REPORTS + +echo > LT/out/overview + +cat LT/out/listuniq | while read l +do + #name=`echo $l | sed s/in// | sed 's/ //g'` + grep "$l" -B $UNIQUE_LINE -A 100 LT/out/GDBs | head -n 100 | grep '#[0-9]' >LT/out/tmp + name=`cat LT/out/tmp | ( grep -o ' in lyx::[[:alnum:]:]*' || cat LT/out/tmp | grep -o ' [ai][nt] [[:alnum:]:]*' ) | head -n1 | sed s/in// | sed 's/ //g'` + echo NAME: $name + echo L: $l + #out/list | grep -o ' in [[:alnum:]:]* ' | sort | uniq| tee out/listuniq + ( + cat stock_text + uname -r ; cat /etc/lsb-release| grep -i DISTRIB_DESCRIPTION + (cd src && svn info | grep Rev:) + echo + NUM_OCCURANCES=`grep "$l" LT/out/list | wc -l` + echo number_of_occurances: $NUM_OCCURANCES/$NUM_REPORTS + echo -e $NUM_OCCURANCES "\t" $name >> LT/out/overview + #echo grep "$l" LT/out/list + #grep $l LT/out/GDB + echo '{{{' + grep "$l" -B $UNIQUE_LINE -A 100 LT/out/GDBs | head -n 100 | grep '#[0-9]' + echo '}}}' + ) | tee LT/out/report_$name +done + +cat LT/out/overview | sort -rn | tee LT/out/overview_sort +#cp LT/out/r* LT/share/ +#cp LT/out/o* LT/share/ diff --git a/development/keystest/start_tests.sh b/development/keystest/start_tests.sh new file mode 100755 index 0000000000..b2332c88de --- /dev/null +++ b/development/keystest/start_tests.sh @@ -0,0 +1,6 @@ +#!/bin/bash +#This script runs LyX, starts spamming it with hundreds of +#keypresses, and logs all output, including backtraces to LT/out/GDB +#Use report.sh to generated the more useful bug reports in LT/out/{or}* + +(bash LT/autolyx & sleep 9 ; xterm -e python LT/test.py) diff --git a/development/keystest/stock_text b/development/keystest/stock_text new file mode 100644 index 0000000000..48068d43ac --- /dev/null +++ b/development/keystest/stock_text @@ -0,0 +1 @@ +[[Add stock text here]] diff --git a/development/keystest/test.py b/development/keystest/test.py new file mode 100755 index 0000000000..e4beca175d --- /dev/null +++ b/development/keystest/test.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python +#This script generated hundreds of random keypresses per second, +# and sends them to the lyx window +#It requires xvkbd and wmctrl +#It generates a log of the KEYCODES it sends as LT/out/KEYCODES + +import random +import os + +#os.system("mv LT/*lyx*_* + +#os.system("lyx &") +#os.system("sleep 20") + + +keycode=["\[Left]",'\[Right]','\[Down]','\[Up]','\[BackSpace]','\[Delete]'] +keycode[:0]=keycode +keycode[:0]=keycode + +keycode[:0]=['\\'] + +for k in range(97, 123): + keycode[:0]=chr(k) + +for k in range(97, 123): + keycode[:0]=["\A"+chr(k)] + +for k in range(97, 123): + keycode[:0]=["\A"+chr(k)] + +for k in range(97, 123): + keycode[:0]=["\C"+chr(k)] + + +print (keycode[1]) +print(keycode) +print (random.randint(1,len(keycode))) +for k in range(97, 123): + print (keycode[random.randint(1,len(keycode))-1]) + +while True: + keystr="" + for k in range(1,80): + keystr=keystr+keycode[random.randint(1,len(keycode))-1] + os.system("wmctrl -R LyX && xvkbd -xsendevent -text '"+keystr+"';sleep 1") + #os.system("echo KEYCODES: '"+keystr+"' >> LT/out/GDB") + os.system("echo `date +%s`: '"+keystr+"' >> LT/out/KEYCODES") -- 2.39.2