Changed the GDI driver interface to pass an opaque PHYSDEV pointer
[wine] / programs / winetest / runtest
1 #!/usr/bin/perl
2 #
3 # Wrapper script to run tests from inside the Wine tree
4 #
5 # Usage: runtest [options] input_file [perl_args...]
6 #
7 # Copyright 2002 Alexandre Julliard
8 #
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
13 #
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 #
23
24 use strict;
25
26 sub usage
27 {
28     print STDERR <<EOF;
29
30 Usage: $0 [options] input_file [perl_args...]
31
32 Options:
33     -q       quiet mode
34     -v       verbose mode (can be specified multiple times)
35     -p prog  name of the program to run for C tests
36     -I dir   prepend dir to Perl include path
37     -P name  set the current platform name
38     -M names set the module names to be tested
39     -T dir   set Wine tree top directory (autodetected if not specified)
40
41 EOF
42     exit 1;
43 }
44
45 # default values
46 my $platform = $ENV{WINETEST_PLATFORM};
47 $ENV{WINETEST_DEBUG} ||= 1;
48
49 my $topobjdir;
50 my $infile;
51 my $program;
52 my @include_dirs;
53 my @modules;
54
55 # parse command-line options
56 while ($#ARGV >= 0)
57 {
58     my $arg = shift @ARGV;
59     if ($arg eq "-h") { usage; }
60     if ($arg eq "-p") { $program = shift @ARGV; next; }
61     if ($arg eq "-q") { $ENV{WINETEST_DEBUG} = 0; next; }
62     if ($arg eq "-v") { $ENV{WINETEST_DEBUG}++; next; }
63     if ($arg eq "-P") { $platform = shift @ARGV; next; }
64     if ($arg eq "-M") { push @modules, split /,/, shift @ARGV; next; }
65     if ($arg eq "-I") { push @include_dirs, shift @ARGV; next; }
66     if ($arg eq "-T")
67     {
68         $topobjdir = shift @ARGV;
69         usage unless (-d $topobjdir);
70         next;
71     }
72     $infile = $arg;
73     last;
74 }
75
76 # we must have found an input file
77 usage unless defined($infile);
78
79 if ($infile =~ /\.c$/ && !defined($program))
80 {
81     # set program to the .c file base name if not specified otherwise
82     ($program = $infile) =~ s/\.c$//;
83 }
84
85 # check/detect topobjdir
86 if (defined($topobjdir))
87 {
88     unless (-f $topobjdir . "/server/wineserver")
89     {
90         printf STDERR "Wrong -T argument, %s/server/wineserver does not exist\n", $topobjdir;
91         usage;
92     }
93 }
94 else  # try to detect it automatically
95 {
96     if (-f "./server/wineserver") { $topobjdir = "."; }
97     elsif (-f "../server/wineserver") { $topobjdir = ".."; }
98     elsif (-f "../../server/wineserver") { $topobjdir = "../.."; }
99     elsif (-f "../../../server/wineserver") { $topobjdir = "../../.."; }
100 }
101
102 # check for include/ dir in script source directory and append it to search path
103 my $basedir = $0;
104 if ($basedir =~ /\//) { $basedir =~ s!/[^/]+$!!; }
105 else { $basedir = "."; }
106 if (-d $basedir . "/include") { push @include_dirs, $basedir . "/include"; }
107
108 $ENV{PERL5LIB} = join( ":", @include_dirs, split( ":", $ENV{PERL5LIB} ) );
109 if (@modules)
110 {
111     if (defined($ENV{WINEOPTIONS})) { $ENV{WINEOPTIONS} .= " "; }
112     $ENV{WINEOPTIONS} .= "--dll " . join(',',@modules) . "=b";
113 }
114
115 # set environment variables needed for Wine
116 if (defined($topobjdir))
117 {
118     chop($topobjdir = `cd $topobjdir && pwd`);
119     $ENV{LD_LIBRARY_PATH} = $topobjdir . ":" . $ENV{LD_LIBRARY_PATH};
120     $ENV{WINEDLLPATH} = $topobjdir . "/dlls";
121     $ENV{WINESERVER} = $topobjdir . "/server/wineserver";
122     $ENV{WINELOADER} = $topobjdir . "/wine";
123     $ENV{WINETEST_PLATFORM} = $platform || "wine";
124     $ENV{WINEPRELOAD}=($program || ($topobjdir . "/programs/winetest/winetest")) . ".so";
125     # try to exec the wine loader directly; if it fails continue on to normal exec
126     exec $ENV{WINELOADER}, $infile, @ARGV;
127 }
128 else
129 {
130     $ENV{WINETEST_PLATFORM} = $platform || "windows";
131 }
132
133 # and now exec the program
134 $program ||= "winetest";
135 exec $program, $infile, @ARGV;
136 print STDERR "Could not exec $program\n";
137 exit 1;