]>
git.proxmox.com Git - mirror_spl-debian.git/blob - module/splat/splat-kobj.c
2 * This file is part of the SPL: Solaris Porting Layer.
4 * Copyright (c) 2008 Lawrence Livermore National Security, LLC.
5 * Produced at Lawrence Livermore National Laboratory
7 * Brian Behlendorf <behlendorf1@llnl.gov>,
8 * Herb Wartens <wartens2@llnl.gov>,
9 * Jim Garlick <garlick@llnl.gov>
12 * This is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "splat-internal.h"
29 #define SPLAT_KOBJ_NAME "kobj"
30 #define SPLAT_KOBJ_DESC "Kernel Kobj Tests"
32 #define SPLAT_KOBJ_TEST1_ID 0x0a01
33 #define SPLAT_KOBJ_TEST1_NAME "open"
34 #define SPLAT_KOBJ_TEST1_DESC "Kobj Open/Close Test"
36 #define SPLAT_KOBJ_TEST2_ID 0x0a02
37 #define SPLAT_KOBJ_TEST2_NAME "size/read"
38 #define SPLAT_KOBJ_TEST2_DESC "Kobj Size/Read Test"
40 #define SPLAT_KOBJ_TEST_FILE "/etc/fstab"
43 splat_kobj_test1(struct file
*file
, void *arg
)
47 f
= kobj_open_file(SPLAT_KOBJ_TEST_FILE
);
48 if (f
== (struct _buf
*)-1) {
49 splat_vprint(file
, SPLAT_KOBJ_TEST1_NAME
, "Failed to open "
50 "test file: %s\n", SPLAT_KOBJ_TEST_FILE
);
55 splat_vprint(file
, SPLAT_KOBJ_TEST1_NAME
, "Successfully opened and "
56 "closed test file: %s\n", SPLAT_KOBJ_TEST_FILE
);
59 } /* splat_kobj_test1() */
62 splat_kobj_test2(struct file
*file
, void *arg
)
69 f
= kobj_open_file(SPLAT_KOBJ_TEST_FILE
);
70 if (f
== (struct _buf
*)-1) {
71 splat_vprint(file
, SPLAT_KOBJ_TEST2_NAME
, "Failed to open "
72 "test file: %s\n", SPLAT_KOBJ_TEST_FILE
);
76 rc
= kobj_get_filesize(f
, &size
);
78 splat_vprint(file
, SPLAT_KOBJ_TEST2_NAME
, "Failed stat of "
79 "test file: %s (%d)\n", SPLAT_KOBJ_TEST_FILE
, rc
);
83 buf
= kmalloc(size
+ 1, GFP_KERNEL
);
86 splat_vprint(file
, SPLAT_KOBJ_TEST2_NAME
, "Failed to alloc "
87 "%lld bytes for tmp buffer (%d)\n",
92 memset(buf
, 0, size
+ 1);
93 rc
= kobj_read_file(f
, buf
, size
, 0);
95 splat_vprint(file
, SPLAT_KOBJ_TEST2_NAME
, "Failed read of "
96 "test file: %s (%d)\n", SPLAT_KOBJ_TEST_FILE
, rc
);
100 /* Validate we read as many bytes as expected based on the stat. This
101 * isn't a perfect test since we didn't create the file however it is
102 * pretty unlikely there are garbage characters in your /etc/fstab */
103 if (size
!= (uint64_t)strlen(buf
)) {
105 splat_vprint(file
, SPLAT_KOBJ_TEST2_NAME
, "Stat'ed size "
106 "(%lld) does not match number of bytes read "
107 "(%lld)\n", (long long)size
,
108 (long long)strlen(buf
));
113 splat_vprint(file
, SPLAT_KOBJ_TEST2_NAME
, "\n%s\n", buf
);
114 splat_vprint(file
, SPLAT_KOBJ_TEST2_NAME
, "Successfully stat'ed "
115 "and read expected number of bytes (%lld) from test "
116 "file: %s\n", (long long)size
, SPLAT_KOBJ_TEST_FILE
);
123 } /* splat_kobj_test2() */
126 splat_kobj_init(void)
128 splat_subsystem_t
*sub
;
130 sub
= kmalloc(sizeof(*sub
), GFP_KERNEL
);
134 memset(sub
, 0, sizeof(*sub
));
135 strncpy(sub
->desc
.name
, SPLAT_KOBJ_NAME
, SPLAT_NAME_SIZE
);
136 strncpy(sub
->desc
.desc
, SPLAT_KOBJ_DESC
, SPLAT_DESC_SIZE
);
137 INIT_LIST_HEAD(&sub
->subsystem_list
);
138 INIT_LIST_HEAD(&sub
->test_list
);
139 spin_lock_init(&sub
->test_lock
);
140 sub
->desc
.id
= SPLAT_SUBSYSTEM_KOBJ
;
142 SPLAT_TEST_INIT(sub
, SPLAT_KOBJ_TEST1_NAME
, SPLAT_KOBJ_TEST1_DESC
,
143 SPLAT_KOBJ_TEST1_ID
, splat_kobj_test1
);
144 SPLAT_TEST_INIT(sub
, SPLAT_KOBJ_TEST2_NAME
, SPLAT_KOBJ_TEST2_DESC
,
145 SPLAT_KOBJ_TEST2_ID
, splat_kobj_test2
);
148 } /* splat_kobj_init() */
151 splat_kobj_fini(splat_subsystem_t
*sub
)
155 SPLAT_TEST_FINI(sub
, SPLAT_KOBJ_TEST2_ID
);
156 SPLAT_TEST_FINI(sub
, SPLAT_KOBJ_TEST1_ID
);
159 } /* splat_kobj_fini() */
164 return SPLAT_SUBSYSTEM_KOBJ
;
165 } /* splat_kobj_id() */