diff options
author | Amit Shah <amit.shah@redhat.com> | 2009-10-27 21:51:35 +0530 |
---|---|---|
committer | Amit Shah <amit.shah@redhat.com> | 2009-10-27 22:01:38 +0530 |
commit | 17d67594540f587d9d04adbe128daf907ff1b8e5 (patch) | |
tree | 2ca29128eb00310bb189837e9813c52b237f3d85 | |
parent | 74ab3612c25320b60bab817b934441ae1d85b6e6 (diff) | |
download | test-virtserial-17d67594540f587d9d04adbe128daf907ff1b8e5.tar.gz test-virtserial-17d67594540f587d9d04adbe128daf907ff1b8e5.tar.xz test-virtserial-17d67594540f587d9d04adbe128daf907ff1b8e5.zip |
auto-test: add tests for checking sysfs, debugfs entries and udev rules
This commit tests for:
1. sysfs entries created (the 'name' attribute)
2. debugfs entries created for ports (in /sys/kernel/debug/virtio-console/vconNN)
(this needs debugfs to be mounted in /sys/kernel/debug)
3. udev rule that creates a symlink based on the port 'name' attribute
(this needs a udev rule to create a symlink, like:
KERNEL==vcon*, SYMLINK+=virtio-console/{name}
in a file in the /etc/udev/rules.d/ directory)
Signed-off-by: Amit Shah <amit.shah@redhat.com>
-rw-r--r-- | auto-virtserial-guest.c | 68 | ||||
-rw-r--r-- | auto-virtserial.c | 32 | ||||
-rw-r--r-- | virtserial.h | 2 |
3 files changed, 102 insertions, 0 deletions
diff --git a/auto-virtserial-guest.c b/auto-virtserial-guest.c index 8f984f4..901cfc4 100644 --- a/auto-virtserial-guest.c +++ b/auto-virtserial-guest.c @@ -42,6 +42,8 @@ static int g_fd; static int g_bigfile_fd; /* The length to read / write. Set by the length message. Unset at close */ static int g_length; +/* The 'name' field in the debugfs port info */ +static char g_sysfs_name[1024]; static char *get_port_dev(unsigned int nr) { @@ -221,6 +223,64 @@ static int send_csum(int nr) return ret; } +static int check_sysfs(int nr) +{ + char filename[1024]; + char *str; + int fd, ret; + + sprintf(filename, "/sys/kernel/debug/virtio-console/vcon%u", nr); + fd = open(filename, O_RDONLY); + if (fd < 0) + return -errno; + + ret = read(fd, g_sysfs_name, 1024); + if (ret < 0) { + ret = -errno; + goto out_close; + } + str = strstr(g_sysfs_name, "name: "); + if (!str) { + ret = -ERANGE; + goto out_close; + } + ret = 0; + +out_close: + close(fd); + return ret; +} + +static int check_udev(int nr) +{ + char filename[1024], buf[1024]; + char *str; + int ret, i; + + str = strstr(g_sysfs_name, "name: "); + str += 6; /* Skip 'name: ' */ + for (i = 0; *str && *str != '\n'; i++, str++) + buf[i] = *str; + + buf[i] = 0; + sprintf(filename, "/dev/virtio-console/%s", buf); + ret = readlink(filename, buf, 1024); + if (ret < 0) { + ret = -errno; + goto out; + } + sprintf(filename, "../vcon%u", nr); + for (i = 0; i < ret; i++) { + if (buf[i] != filename[i]) { + ret = -ERANGE; + break; + } + } + ret = 0; +out: + return ret; +} + static void send_report(int cfd, int ret) { struct guest_packet gpkt; @@ -327,6 +387,14 @@ back_to_open: ret = send_csum(gpkt.value); send_report(cfd, ret); break; + case KEY_CHECK_SYSFS: + ret = check_sysfs(gpkt.value); + send_report(cfd, ret); + break; + case KEY_CHECK_UDEV: + ret = check_udev(gpkt.value); + send_report(cfd, ret); + break; } } return 0; diff --git a/auto-virtserial.c b/auto-virtserial.c index 1776615..1fa7208 100644 --- a/auto-virtserial.c +++ b/auto-virtserial.c @@ -305,6 +305,35 @@ static int test_close(int nr) return ret; } +static int test_sysfs_and_udev(int nr) +{ + struct guest_packet gpkt; + int ret; + + gpkt.key = KEY_CHECK_SYSFS; + gpkt.value = nr; + ret = guest_cmd(&gpkt); + if (ret < 0) { + fail(__func__, "sysfs"); + if (ret == -ERANGE) + debug("%s: no name specified for port %u\n", + __func__, nr); + else + debug("%s: ret = %d\n", __func__, ret); + return ret; + } + gpkt.key = KEY_CHECK_UDEV; + gpkt.value = nr; + ret = guest_cmd(&gpkt); + if (ret < 0) { + fail(__func__, "udev"); + debug("%s: ret = %d\n", __func__, ret); + } else { + pass(__func__, "sysfs-udev"); + } + return ret; +} + /* Reads should return 0 when host chardev isn't connected */ static int test_read_without_host(int nr) { @@ -948,6 +977,9 @@ static int start_tests(void) test_open(2); test_close(2); test_multiple_open(2); + + test_sysfs_and_udev(2); + test_read_without_host(2); test_blocking_read(2); diff --git a/virtserial.h b/virtserial.h index ea9abf5..d7de61d 100644 --- a/virtserial.h +++ b/virtserial.h @@ -11,6 +11,8 @@ #define KEY_OPEN_BIGFILE 11 #define KEY_BYTESTREAM 12 #define KEY_CSUM 13 +#define KEY_CHECK_SYSFS 14 +#define KEY_CHECK_UDEV 15 #define BIG_FILE "/tmp/amit/big-file" |