summaryrefslogtreecommitdiff
path: root/ILTest/XST/XOrgConfDriver.pm
blob: d86a0e5fc963c794b8b0034a6550130df23a936d (plain)
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
#!/usr/bin/perl

# Copyright © 2011 by Red Hat, Inc.
#                                                                            
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software 
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# 
# Authors: Peter Hutterer <peter.hutterer@redhat.com>


=head1 NAME

ILtest::XST::xorgconf-driver - ILTest for xorg.conf devices

=head1 DESCRIPTION

This ILTest::TestCase configures the X Server to use a specific driver input
device and then checks for this device's presence in the server.

=head2 Paramaters

=over

=item B<driver>

The driver to be used. Required parameter.

=item B<identifier>

The identifier for this device. If unset, the identifier is "$driver
identifier".

=back 

=cut

package ILTest::XST::XOrgConfDriver;

use ILTest::TestCase;
use ILTest::Error;

use XOrg::xorgconf;
use XOrg::xorglog;
use XOrg::xinput;

use warnings;
use strict;

our @ISA = qw(ILTest::TestCase);

sub pre {
	my $self = shift;

	my $driver = $self->parameters->{driver};
	my $identifier = $self->parameters->{identifier};
	my %opts;

	if (not defined $driver) {
		return ILTest::Error->new(msg => "Driver required but not defined\n");
	}

	$identifier = "$driver identifier" if not defined $identifier;

	$self->iltest->file_backup("/etc/X11/xorg.conf");

	for (keys %{$self->{parameters}}) {
		next if $_ eq "driver";
		next if $_ eq "identifier";
		$opts{$_} = $self->{parameters}->{$_};
	}

	my $conf = XOrg::xorgconf->new();
	$conf->add_serverlayout("driver testing layout", {"AutoAddDevices" => "off"});
	$conf->add_input_device($identifier, $driver, \%opts);

	$self->{identifier} = $identifier;
	$self->{driver} = $driver;

	$self->iltest->print(7, $conf->print);
	if (not $conf->save) {
		return ILTest::Error->new(msg => "Failed to write config\n");
	}

	$self->iltest->add_results_file("/etc/X11/xorg.conf", "$driver-xorg.conf");

	return undef;
}

sub run {
	my $self = shift;

	my $xinput = XOrg::xinput->new();
	my @xinput_devices = $xinput->get_devices;

	my $log = XOrg::xorglog->new(file=> "/var/log/Xorg.0.log");
	my $server = $log->server;
	my $driver = $self->{driver};
	my $identifier = $self->{identifier};


	if (not defined $server->modules->{$driver}) {
		return ILTest::Error->new(msg => "Unable to find module $driver.\n");
	}

	if ($server->auto_add_devices) {
		return ILTest::Error->new(msg => "AAD is on but should be off.\n");
	}

	my @devices = @{$server->devices};

	my $found = 0;
	for (@devices) {
		$self->iltest->println(8, "Found device '".$_->name."' present: ". $_->present);
		next if $_->name ne $identifier;

		for my $dev (@xinput_devices) {
			next if $dev->name ne $_->name;
			if (not $_->present) {
				$self->iltest->error(1, "Parsing bug: Log says '". $_->name ."' not present, xinput shows it is\n");
				$_->present = 1;
			}
			$found = 1;
		}

		last;
	}

	if (not $found) {
		return ILTest::Error->new(msg => "Could not find device '$identifier' in log\n");
	}

	return undef;
}

sub post {
	my $self = shift;

	$self->iltest->file_restore("/etc/X11/xorg.conf");
	$self->iltest->add_results_file("/var/log/Xorg.0.log", $self->{driver}."-Xorg.log");

	return undef;
}

1;
# vim: set noexpandtab shiftwidth=8 tabstop=8: