File: testrun

package info (click to toggle)
wine 0.0.20000109-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 22,652 kB
  • ctags: 59,973
  • sloc: ansic: 342,054; perl: 3,697; yacc: 3,059; tcl: 2,647; makefile: 2,466; lex: 1,494; sh: 394
file content (260 lines) | stat: -rwxr-xr-x 7,019 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/usr/bin/perl
# Copyright 1996-1998 Marcus Meissner
# IPC remove code Copyright 1995 Michael Veksler
#
# This perl script automatically test runs ALL windows .exe and .scr binaries
# it finds (and can access) on your computer. It creates a subdirectory called
# runs/ and stores the output there. It also does (unique) diffs between runs.
#
# It only reruns the test if ChangeLog or the executeable is NEWER than the
# run file. (If you want to rerun everything inbetween releases, touch
# ChangeLog.)

#
# BEGIN OF USER CONFIGURATION
#
# Path to WINE executeable. If not specified, 'wine' is searched in the path.
#
$wine = 'wine';
#
# WINE options. -managed when using a windowmanager is probably not good in
# automatic testruns.
#
$wineoptions='';
#
# Path to WINE ChangeLog. Used as timestamp for new releases...
#
$changelog = '/home/marcus/wine/ChangeLog';
# 
# How long before automatically killing all subprocesses
# 30 is good for automatic testing, 300 or more for interactive testing.
#
$waittime = 50;
#
#diff command
#
$diff='diff -u';
#
# truncate at how-much-lines
#
$trunclines=200;
#
$<||die "Running this script under UID 0 is a great security risk (and risk for existing windows installations on mounted DOS/W95 partitions). If you really want to, comment out this line.\n";
#
# END OF USER CONFIGURATION
#

if (! -d "runs") { die "no subdirectory runs/ found in $cwd. Please create one first!\n";}

# look for the exact path to wine executeable in case we need it for a 
# replacement changelog.
if (! ($wine =~ /\//)) { # no path specified. Look it up.
	@paths = split(/:/,$ENV{'PATH'});
	foreach $path (@paths) {
		if (-e "$path/$wine" && -x "$path/$wine") {
			$wine = "$path/$wine";
			last;
		}
	}
}

# if we don't have a changelog use the modification date of the WINE executeable
if (! -e $changelog) {
	$changelog = $wine;
}

# sanity check so we just fill runs/ with errors.
(-x $wine)  || die "no $wine executable found!\n";
# dito. will print usage
system("$wine -h >/dev/null")||die "wine call failed:$!\n";

print "Using $wine as WINE executeable.\n";
print "Using $changelog as testrun timereference.\n";

chomp($cwd = `pwd`);

# Find out all present semaphores so we don't remove them later.
$IPC_RMID=0;
$USER=$ENV{'USER'};
open(IPCS,"ipcs|");
while(<IPCS>) {
    split;
    # try to find out the IPC-ID, assume it is the first number.
    foreach (@_) {
	$_ ne int($_) && next;	# not a decimal number
	$num=$_;
	last;
    }
    if (/sem/i .. /^\s*$/ ) {
	index($_,$USER)>=0 || next;
	$sem_used{$num}=1;
	print "found $num\n";
    }
}
close(IPCS);

sub kill_subprocesses {
	local($killedalready,%parentof,%kids,$changed,%cmdline);

	# FIXME: substitute ps command that shows PID,PPID and COMMAND
	# On Linux' latest procps this is "ps aulc"
	#
	open(PSAUX,"ps aulc|");
	# lookup all processes, remember their parents and cmdlines.
	%parentof=();
	$xline = <PSAUX>; # fmtline 
	@psformat = split(/\s\s*/,$xline);

	psline: while (<PSAUX>) {
		chop;
		@psline = split(/\s\s*/);
		$pid=0;
		for ($i=0;$i<=$#psformat;$i++) {
			if ($psformat[$i] =~ /COMMAND/) {
				die unless $pid;
				$cmdline{$pid}=$psline[$i];
				break;
			}
			if ($psformat[$i] =~ /PPID/ ) {
				$parentof{$pid} = $psline[$i];
				next;
			}
			if ($psformat[$i] =~ /PID/ ) {
				$pid = $psline[$i];
				next;
			}
		}
	}
	close(PSAUX);

	# find out all kids of this perlscript
	%kids = ();
	$kids{$$} = 1;
	$changed = 1;
	while ($changed) {
		$changed = 0;
		foreach (keys %parentof) {
			next if ($kids{$_});
			if ($kids{$parentof{$_}}) {
				$changed = 1;
				$kids{$_}=1;
			}
		}
	}
	# .. but do not consider us for killing
	delete $kids{$$};
	# remove all processes killed in the meantime from %killedalready.
	foreach $pid (keys %killedalready) {
		delete $killedalready{$pid} if (!$kids{$pid} );
	}
	# kill all subprocesses called 'wine'. Do not kill find, diff, sh
	# and friends, which are also subprocesses of us.
	foreach (keys %kids) {
		next unless ($cmdline{$_} =~ /((.|)wine|dosmod)/);
		# if we have already killed it using -TERM, use -KILL
		if ($killedalready{$_}) {
			kill(9,$_);	# FIXME: use correct number?
		} else {
			kill(15,$_);	# FIXME: use correct number?
		}
		$killedalready{$_}=1;
	}
	alarm($waittime);		# wait again...
};

# borrowed from tools/ipcl. See comments there.
# killing wine subprocesses unluckily leaves all of their IPC stuff lying
# around. We have to wipe it or we run out of it.
sub cleanup_wine_ipc {
	open(IPCS,"ipcs|");
	while(<IPCS>) {
	    split;
	    # try to find out the IPC-ID, assume it is the first number.
	    foreach (@_) {
		$_ ne int($_) && next;	# not a decimal number
		$num=$_;
		last;
	    }
	    # was there before start of this script, skip it.
	    #
	    # FIXME: this doesn't work for programs started during the testrun.
	    #
	    if (/sem/i .. /^\s*$/ ) {
		index($_,$USER)>=0 || next;
		push(@sem,$num);
	    }
	}
	foreach (@sem) {
	    $sem_used{$_} && next;
	    semctl($_, 0, $IPC_RMID,0);
	}
	close(IPCS);
}

# kill all subwineprocesses for automatic runs.
sub alarmhandler {
	print "timer triggered.\n";
	&kill_subprocesses;
}

$SIG{'ALRM'} = "alarmhandler";

# NOTE: following find will also cross NFS mounts, so be sure to have nothing
# mounted that's not on campus or add relevant ! -fstype nfs or similar.
#

$startdir = '/';

$startdir = $ARGV[0] if ($ARGV[0] && (-d $ARGV[0]));

open(FIND,"find $startdir -type f  \\( -name \"*.EXE\" -o -name \"*.exe\" -o -name \"*.scr\" -o -name \"*.SCR\" \\) -print|");
while ($exe=<FIND>) {
	chop($exe);

	# This could change during a testrun (by doing 'make' for instance)
	# FIXME: doesn't handle missing libwine.so during compile...
	(-x $wine)  || die "no $wine executable found!\n";

	# Skip all mssetup, acmsetup , installshield whatever exes. 
	# they seem to work, mostly and starting them is just annoying.
	next if ($exe =~ /acmsetup|unwise|testexit|_msset|isun|st4u|st5u|_mstest|_isdel|ms-setup|~ms|unin/io);

	$runfile = $exe;
	$runfile =~ s/[\/ ]/_/g;
	$runfile =~ s/\.exe$//g;
	$runfile =~ s/\.scr$//ig;
	$flag=0;
	#
	# Check if changelog is newer, if not, continue
	#
	if (	-e "runs/${runfile}.out" && 
		(-M $changelog > -M "runs/${runfile}.out") && 
		(-M $exe > -M "runs/${runfile}.out")
	) {
		#print "skipping $exe, already done.\n";
		next;
	}
	# now testrun...
	print "$exe:\n";
	$dir = $exe;
	$dir =~ s/^(.*)\/[^\/]*$/$1/; #cut of the basename.

	alarm($waittime);

	chdir($dir)||die "$dir:$!";
	if ($exe =~ /\.scr/i) {
		system("echo quit|$wine $wineoptions \"$exe /s\" >$cwd/${runfile}.out 2>&1");
	} else {
		system("echo quit|$wine $wineoptions \"$exe\" >$cwd/${runfile}.out 2>&1");
	}
	alarm(1000);# so it doesn't trigger in the diff, kill or find.

	system("touch $cwd/runs/${runfile}.out");
	system("$diff $cwd/runs/${runfile}.out $cwd/${runfile}.out|head -$trunclines");
	system("head -$trunclines $cwd/${runfile}.out >$cwd/runs/${runfile}.out");
	unlink("$cwd/${runfile}.out");
	&kill_subprocesses;
	&cleanup_wine_ipc;
	chdir($cwd);
}
close(FIND);