]>
git.proxmox.com Git - mirror_spl-debian.git/blob - modules/splat/splat-kobj.c
1 #include "splat-internal.h"
3 #define SPLAT_SUBSYSTEM_KOBJ 0x0a00
4 #define SPLAT_KOBJ_NAME "kobj"
5 #define SPLAT_KOBJ_DESC "Kernel Kobj Tests"
7 #define SPLAT_KOBJ_TEST1_ID 0x0a01
8 #define SPLAT_KOBJ_TEST1_NAME "open"
9 #define SPLAT_KOBJ_TEST1_DESC "Kobj Open/Close Test"
11 #define SPLAT_KOBJ_TEST2_ID 0x0a02
12 #define SPLAT_KOBJ_TEST2_NAME "size/read"
13 #define SPLAT_KOBJ_TEST2_DESC "Kobj Size/Read Test"
15 #define SPLAT_KOBJ_TEST_FILE "/etc/fstab"
18 splat_kobj_test1(struct file
*file
, void *arg
)
22 f
= kobj_open_file(SPLAT_KOBJ_TEST_FILE
);
23 if (f
== (struct _buf
*)-1) {
24 splat_vprint(file
, SPLAT_KOBJ_TEST1_NAME
, "Failed to open "
25 "test file: %s\n", SPLAT_KOBJ_TEST_FILE
);
30 splat_vprint(file
, SPLAT_KOBJ_TEST1_NAME
, "Successfully opened and "
31 "closed test file: %s\n", SPLAT_KOBJ_TEST_FILE
);
34 } /* splat_kobj_test1() */
37 splat_kobj_test2(struct file
*file
, void *arg
)
44 f
= kobj_open_file(SPLAT_KOBJ_TEST_FILE
);
45 if (f
== (struct _buf
*)-1) {
46 splat_vprint(file
, SPLAT_KOBJ_TEST2_NAME
, "Failed to open "
47 "test file: %s\n", SPLAT_KOBJ_TEST_FILE
);
51 rc
= kobj_get_filesize(f
, &size
);
53 splat_vprint(file
, SPLAT_KOBJ_TEST2_NAME
, "Failed stat of "
54 "test file: %s (%d)\n", SPLAT_KOBJ_TEST_FILE
, rc
);
58 buf
= kmalloc(size
+ 1, GFP_KERNEL
);
61 splat_vprint(file
, SPLAT_KOBJ_TEST2_NAME
, "Failed to alloc "
62 "%lld bytes for tmp buffer (%d)\n", size
, rc
);
66 memset(buf
, 0, size
+ 1);
67 rc
= kobj_read_file(f
, buf
, size
, 0);
69 splat_vprint(file
, SPLAT_KOBJ_TEST2_NAME
, "Failed read of "
70 "test file: %s (%d)\n", SPLAT_KOBJ_TEST_FILE
, rc
);
74 /* Validate we read as many bytes as expected based on the stat. This
75 * isn't a perfect test since we didn't create the file however it is
76 * pretty unlikely there are garbage characters in your /etc/fstab */
77 if (size
!= (uint64_t)strlen(buf
)) {
79 splat_vprint(file
, SPLAT_KOBJ_TEST2_NAME
, "Stat'ed size "
80 "(%lld) does not match number of bytes read "
81 "(%lld)\n", size
, (uint64_t)strlen(buf
));
86 splat_vprint(file
, SPLAT_KOBJ_TEST2_NAME
, "\n%s\n", buf
);
87 splat_vprint(file
, SPLAT_KOBJ_TEST2_NAME
, "Successfully stat'ed "
88 "and read expected number of bytes (%lld) from test "
89 "file: %s\n", size
, SPLAT_KOBJ_TEST_FILE
);
96 } /* splat_kobj_test2() */
101 splat_subsystem_t
*sub
;
103 sub
= kmalloc(sizeof(*sub
), GFP_KERNEL
);
107 memset(sub
, 0, sizeof(*sub
));
108 strncpy(sub
->desc
.name
, SPLAT_KOBJ_NAME
, SPLAT_NAME_SIZE
);
109 strncpy(sub
->desc
.desc
, SPLAT_KOBJ_DESC
, SPLAT_DESC_SIZE
);
110 INIT_LIST_HEAD(&sub
->subsystem_list
);
111 INIT_LIST_HEAD(&sub
->test_list
);
112 spin_lock_init(&sub
->test_lock
);
113 sub
->desc
.id
= SPLAT_SUBSYSTEM_KOBJ
;
115 SPLAT_TEST_INIT(sub
, SPLAT_KOBJ_TEST1_NAME
, SPLAT_KOBJ_TEST1_DESC
,
116 SPLAT_KOBJ_TEST1_ID
, splat_kobj_test1
);
117 SPLAT_TEST_INIT(sub
, SPLAT_KOBJ_TEST2_NAME
, SPLAT_KOBJ_TEST2_DESC
,
118 SPLAT_KOBJ_TEST2_ID
, splat_kobj_test2
);
121 } /* splat_kobj_init() */
124 splat_kobj_fini(splat_subsystem_t
*sub
)
128 SPLAT_TEST_FINI(sub
, SPLAT_KOBJ_TEST2_ID
);
129 SPLAT_TEST_FINI(sub
, SPLAT_KOBJ_TEST1_ID
);
132 } /* splat_kobj_fini() */
137 return SPLAT_SUBSYSTEM_KOBJ
;
138 } /* splat_kobj_id() */