From 6caa909fd9e45acb6d73afb9a18980d6baecfe66 Mon Sep 17 00:00:00 2001 From: green Date: Thu, 9 Oct 2003 16:43:59 +0000 Subject: [PATCH] New test, to check that device nodes are created and then visible correctly. --- lustre/tests/cmknod.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 lustre/tests/cmknod.c diff --git a/lustre/tests/cmknod.c b/lustre/tests/cmknod.c new file mode 100644 index 0000000..fa42e2b --- /dev/null +++ b/lustre/tests/cmknod.c @@ -0,0 +1,94 @@ +/* Simple test to check that device nodes are correctly created and visible */ +#include +#include +#include +#include +#include +#include +#include +#include +#define TEST_MINOR 120 +#define TEST_MAJOR 25 + +void usage(char *prog) +{ + fprintf(stderr, "usage: %s \n", prog); + exit(1); +} + +int main( int argc, char **argv) +{ + char *prog = argv[0]; + char *filename = argv[1]; + int rc; + struct stat st; + dev_t device = makedev(TEST_MAJOR, TEST_MINOR); + + if (argc != 2) + usage(prog); + + unlink(filename); + /* First try block devices */ + rc = mknod(filename, 0700 | S_IFBLK, device); + if ( rc < 0 ) { + fprintf(stderr, "%s: mknod(%s) failed: rc %d: %s\n", + prog, filename, errno, strerror(errno)); + return 2; + } + + rc = stat(filename, &st); + if ( rc < 0 ) { + fprintf(stderr, "%s: stat(%s) failed: rc %d: %s\n", + prog, filename, errno, strerror(errno)); + return 3; + } + if ( st.st_rdev != device) { + fprintf(stderr, "%s: created device other than requested: (%d,%d) instead of (%d,%d)\n", prog, major(st.st_rdev),minor(st.st_rdev),major(device),minor(device)); + return 4; + } + if ( ! (st.st_mode | S_IFBLK) ) { + fprintf(stderr, "%s: created device of different type. Requested block device, got mode %o\n", prog, st.st_mode); + return 5; + } + + rc = unlink(filename); + if ( rc < 0 ) { + fprintf(stderr, "%s: Cannot unlink created device %s, rc %d: %s\n", + prog, filename, errno, strerror(errno)); + return 6; + } + + /* Second try char devices */ + rc = mknod(filename, 0700 | S_IFCHR, device); + if ( rc < 0 ) { + fprintf(stderr, "%s: mknod(%s) failed: rc %d: %s\n", + prog, filename, errno, strerror(errno)); + return 7; + } + + rc = stat(filename, &st); + if ( rc < 0 ) { + fprintf(stderr, "%s: stat(%s) failed: rc %d: %s\n", + prog, filename, errno, strerror(errno)); + return 8; + } + if ( st.st_rdev != device) { + fprintf(stderr, "%s: created device other than requested: (%d,%d) instead of (%d,%d)\n", prog, major(st.st_rdev),minor(st.st_rdev),major(device),minor(device)); + return 9; + } + if ( ! (st.st_mode | S_IFCHR) ) { + fprintf(stderr, "%s: created device of different type. Requested char device, got mode %o\n", prog, st.st_mode); + return 10; + } + + rc = unlink(filename); + if ( rc < 0 ) { + fprintf(stderr, "%s: Cannot unlink created device %s, rc %d: %s\n", + prog, filename, errno, strerror(errno)); + return 11; + } + + printf("%s: device nodes created correctly\n", prog); + + return 0; +} -- 1.8.3.1