summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2013-05-30 08:37:48 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2013-05-30 08:40:43 +0100
commit2e1c11546a4aa69c1e774aaa653bb9d84552e133 (patch)
tree5829bf02d3ac9d43fca382f80d12b56e8ca06eb7
parent1cb4f90946289457c3b92773f2ce96b0b03e4a22 (diff)
gem_reg_read: Only check errno after a definite error
As upon success, errno is invalid and may give spurious false results. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=65157 Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r--tests/gem_reg_read.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/tests/gem_reg_read.c b/tests/gem_reg_read.c
index 692dd987..743beac8 100644
--- a/tests/gem_reg_read.c
+++ b/tests/gem_reg_read.c
@@ -37,11 +37,11 @@ struct local_drm_i915_reg_read {
#define REG_READ_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x31, struct local_drm_i915_reg_read)
-static void handle_bad(int ret, int lerrno, int expected, const char *desc)
+static void handle_bad(int ret, int expected, const char *desc)
{
- if (ret != 0 && lerrno != expected) {
+ if (ret != 0 && errno != expected) {
fprintf(stderr, "%s - errno was %d, but should have been %d\n",
- desc, lerrno, expected);
+ desc, errno, expected);
exit(EXIT_FAILURE);
} else if (ret == 0) {
fprintf(stderr, "%s - Command succeeded, but should have failed\n",
@@ -53,11 +53,9 @@ static void handle_bad(int ret, int lerrno, int expected, const char *desc)
static uint64_t timer_query(int fd)
{
struct local_drm_i915_reg_read reg_read;
- int ret;
reg_read.offset = 0x2358;
- ret = drmIoctl(fd, REG_READ_IOCTL, &reg_read);
- if (ret) {
+ if (drmIoctl(fd, REG_READ_IOCTL, &reg_read)) {
perror("positive test case failed: ");
exit(EXIT_FAILURE);
}
@@ -68,31 +66,26 @@ static uint64_t timer_query(int fd)
int main(int argc, char *argv[])
{
struct local_drm_i915_reg_read reg_read;
- int ret, fd;
- uint64_t val;
+ int fd;
fd = drm_open_any();
reg_read.offset = 0x2358;
- ret = drmIoctl(fd, REG_READ_IOCTL, &reg_read);
- if (errno == EINVAL)
- exit(77);
- else if (ret)
- exit(EXIT_FAILURE);
+ if (drmIoctl(fd, REG_READ_IOCTL, &reg_read))
+ exit(errno == EINVAL ? 77 : EXIT_FAILURE);
- val = timer_query(fd);
+ reg_read.val = timer_query(fd);
sleep(1);
- if (timer_query(fd) == val) {
+ if (timer_query(fd) == reg_read.val) {
fprintf(stderr, "Timer isn't moving, probably busted\n");
exit(EXIT_FAILURE);
}
/* bad reg */
reg_read.offset = 0x12345678;
- ret = drmIoctl(fd, REG_READ_IOCTL, &reg_read);
- handle_bad(ret, errno, EINVAL, "bad register");
+ handle_bad(drmIoctl(fd, REG_READ_IOCTL, &reg_read),
+ EINVAL, "bad register");
close(fd);
-
exit(EXIT_SUCCESS);
}