Add some trivial regression tests, one of which fails.

main
Eric Anholt 2007-07-19 04:59:59 -07:00
parent 51de9ec5e3
commit d7cf298e54
10 changed files with 261 additions and 29 deletions

5
.gitignore vendored
View File

@ -109,3 +109,8 @@ sis.kld
stamp-h1
tdfx.kld
via.kld
tests/dristat
tests/drmstat
tests/getclient
tests/getversion
tests/openclose

View File

@ -22,7 +22,7 @@
# here too, but let's just do libdrm for now
AUTOMAKE_OPTIONS = foreign
SUBDIRS = libdrm shared-core
SUBDIRS = libdrm shared-core tests
pkgconfigdir = @pkgconfigdir@
pkgconfig_DATA = libdrm.pc

View File

@ -35,4 +35,9 @@ AC_SYS_LARGEFILE
pkgconfigdir=${libdir}/pkgconfig
AC_SUBST(pkgconfigdir)
AC_OUTPUT([Makefile libdrm/Makefile shared-core/Makefile libdrm.pc])
AC_OUTPUT([
Makefile
libdrm/Makefile
shared-core/Makefile
tests/Makefile
libdrm.pc])

View File

@ -1,27 +0,0 @@
# These definitions are for handling dependencies in the out of kernel build.
PROGS = dristat drmstat
CLEANFILES = *.o *.ko $(PROGS) .depend .*.flags .*.d
# Build test utilities
PRGCFLAGS = $(CFLAGS) -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \
-D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \
-I. -I../libdrm -I../shared-core
DRMSTATLIBS = -L../libdrm -ldrm
programs: $(PROGS)
dristat: dristat.c
$(CC) $(PRGCFLAGS) $< -o $@
drmstat: drmstat.c
$(CC) $(PRGCFLAGS) $< -o $@ $(DRMSTATLIBS)
clean:
rm -f $(CLEANFILES)

24
tests/Makefile.am Normal file
View File

@ -0,0 +1,24 @@
AM_CFLAGS = \
-I $(top_srcdir)/shared-core
noinst_PROGRAMS = \
dristat \
drmstat
EXTRA_LTLIBRARIES = libdrmtest.la
libdrmtest_la_SOURCES = \
drmtest.c \
drmtest.h
libdrmtest_la_LIBADD = \
$(top_builddir)/libdrm/libdrm.la
LDADD = libdrmtest.la
TESTS = openclose \
getversion \
getclient
XFAIL_TESTS = getclient
EXTRA_PROGRAMS = $(TESTS)
CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES)

45
tests/drmtest.c Normal file
View File

@ -0,0 +1,45 @@
/*
* Copyright © 2007 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Authors:
* Eric Anholt <eric@anholt.net>
*
*/
#include <fcntl.h>
#include "drmtest.h"
/** Open the first DRM device we can find, searching up to 16 device nodes */
int drm_open_any(void)
{
char name[20];
int i, fd;
for (i = 0; i < 16; i++) {
sprintf(name, "/dev/dri/card%d", i);
fd = open(name, O_RDWR);
if (fd != -1)
return fd;
}
abort();
}

36
tests/drmtest.h Normal file
View File

@ -0,0 +1,36 @@
/*
* Copyright © 2007 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Authors:
* Eric Anholt <eric@anholt.net>
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
#include "xf86drm.h"
int drm_open_any(void);

60
tests/getclient.c Normal file
View File

@ -0,0 +1,60 @@
/*
* Copyright © 2007 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Authors:
* Eric Anholt <eric@anholt.net>
*
*/
#include <limits.h>
#include "drmtest.h"
/**
* Checks DRM_IOCTL_GET_CLIENT.
*/
int main(int argc, char **argv)
{
int fd, ret;
drm_client_t client;
fd = drm_open_any();
/* Look for client index 0. This should exist whether we're operating
* on an otherwise unused drm device, or the X Server is running on
* the device.
*/
client.idx = 0;
ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
assert(ret == 0);
/* Look for some absurd client index and make sure it's invalid.
* The DRM drivers currently always return data, so the user has
* no real way to detect when the list has terminated. That's bad,
* and this test is XFAIL as a result.
*/
client.idx = 0x7fffffff;
ret = ioctl(fd, DRM_IOCTL_GET_CLIENT, &client);
assert(ret == -1 && errno == EINVAL);
close(fd);
return 0;
}

47
tests/getversion.c Normal file
View File

@ -0,0 +1,47 @@
/*
* Copyright © 2007 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Authors:
* Eric Anholt <eric@anholt.net>
*
*/
#include "drmtest.h"
/**
* Checks DRM_IOCTL_GET_VERSION and libdrm's drmGetVersion() interface to it.
*/
int main(int argc, char **argv)
{
int fd;
drmVersionPtr v;
fd = drm_open_any();
v = drmGetVersion(fd);
assert(strlen(v->name) != 0);
assert(strlen(v->date) != 0);
assert(strlen(v->desc) != 0);
assert(v->version_major >= 1);
drmFree(v);
close(fd);
return 0;
}

37
tests/openclose.c Normal file
View File

@ -0,0 +1,37 @@
/*
* Copyright © 2007 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Authors:
* Eric Anholt <eric@anholt.net>
*
*/
#include "drmtest.h"
int main(int argc, char **argv)
{
int fd;
fd = drm_open_any();
close(fd);
return 0;
}