diff options
author | Amit Shah <amit.shah@redhat.com> | 2010-09-28 16:51:53 +0530 |
---|---|---|
committer | Amit Shah <amit.shah@redhat.com> | 2010-09-28 16:51:53 +0530 |
commit | da4085786b76598d279996c8e6ee87d3fa6a8da1 (patch) | |
tree | 84fe02e95349d217efc797553ed188c49ae638c9 | |
parent | f3963acf119801118d585df35e8d51c0cd384f54 (diff) | |
download | test-virtserial-da4085786b76598d279996c8e6ee87d3fa6a8da1.tar.gz test-virtserial-da4085786b76598d279996c8e6ee87d3fa6a8da1.tar.xz test-virtserial-da4085786b76598d279996c8e6ee87d3fa6a8da1.zip |
auto-test: Add test for lseek()
lseek() on console ports should fail with -ESPIPE.
(This behaviour will be seen from kernel 2.6.37 onwards. Older kernels
just returned success without seeking.)
Signed-off-by: Amit Shah <amit.shah@redhat.com>
-rw-r--r-- | auto-virtserial-guest.c | 14 | ||||
-rw-r--r-- | auto-virtserial.c | 34 | ||||
-rw-r--r-- | virtserial.h | 1 |
3 files changed, 49 insertions, 0 deletions
diff --git a/auto-virtserial-guest.c b/auto-virtserial-guest.c index 85d5758..9ceda19 100644 --- a/auto-virtserial-guest.c +++ b/auto-virtserial-guest.c @@ -252,6 +252,17 @@ static int close_port(int nr) return ret; } +static int seek_port(int nr) +{ + int ret; + + ret = lseek(g_open_fds[nr], 20, SEEK_SET); + if (ret < 0) + ret = -errno; + + return ret; +} + static int set_port_nonblocking(int val) { int ret, flags; @@ -716,6 +727,9 @@ back_to_open: case KEY_SHUTDOWN: system("shutdown -h now"); break; + case KEY_LSEEK: + ret = seek_port(gpkt.value); + send_report(cfd, ret); default: send_report(cfd, -ERANGE); break; diff --git a/auto-virtserial.c b/auto-virtserial.c index d11dd28..fb3f40f 100644 --- a/auto-virtserial.c +++ b/auto-virtserial.c @@ -232,6 +232,15 @@ static int guest_poll(int nr, int events, int timeout) return guest_cmd(&gpkt); } +static int guest_lseek(int nr) +{ + struct guest_packet gpkt; + + gpkt.key = KEY_LSEEK; + gpkt.value = nr; + return guest_cmd(&gpkt); +} + static int guest_set_port_nonblocking(int nr, int value) { struct guest_packet gpkt; @@ -662,6 +671,24 @@ out: return err; } +/* lseek in guest - -ESPIPE is the desired result. */ +static int test_lseek(int nr) +{ + int err, ret; + + ret = guest_open_port(nr); + err = result(__func__, true, "open", ret, -1, -1, OP_GT, false); + if (err) + return err; + + ret = guest_lseek(nr); + err = result(__func__, true, "lseek", + ret, -ESPIPE, -ESPIPE, OP_EQ, true); + + guest_close_port(nr); + return err; +} + /* * Tests if writes to guest get throttled after sending 1M data * The invert parameter specifies the test should pass for ports @@ -1398,6 +1425,7 @@ enum { TEST_BLOCKING_WRITE, TEST_NONBLOCK_WRITE, TEST_POLL, + TEST_LSEEK, TEST_G_THROTTLE, TEST_H_THROTTLE, TEST_G_CACHING, @@ -1456,6 +1484,10 @@ static struct test_parameters { .needs_guestok = true, }, { + .test_function = test_lseek, + .needs_guestok = true, + }, + { .test_function = test_guest_throttle, .needs_guestok = true, }, @@ -1582,6 +1614,8 @@ static int start_tests(void) run_test(TEST_POLL, 2); + run_test(TEST_LSEEK, 2); + #if 0 /* * Guest throttling isn't needed anymore after design changes diff --git a/virtserial.h b/virtserial.h index 45c06ad..984ae15 100644 --- a/virtserial.h +++ b/virtserial.h @@ -21,6 +21,7 @@ #define KEY_GET_SIGIO_RESULT 21 #define KEY_POLL_EVENTS 22 #define KEY_SHUTDOWN 23 +#define KEY_LSEEK 24 #define HOST_BIG_FILE "/tmp/amit/host-big-file" #define GUEST_BIG_FILE "/tmp/amit/guest-big-file" |