Skip to content

Commit 6f84ceb

Browse files
committed
hfsplus: introduce KUnit tests for HFS+ string operations
This patch implements the Kunit based set of unit tests for HFS+ string operations. It checks functionality of hfsplus_strcasecmp(), hfsplus_strcmp(), hfsplus_uni2asc(), hfsplus_asc2uni(), hfsplus_hash_dentry(), and hfsplus_compare_dentry(). ./tools/testing/kunit/kunit.py run --kunitconfig ./fs/hfsplus/.kunitconfig [14:38:05] Configuring KUnit Kernel ... [14:38:05] Building KUnit Kernel ... Populating config with: $ make ARCH=um O=.kunit olddefconfig Building with: $ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=22 [14:38:09] Starting KUnit Kernel (1/1)... [14:38:09] ============================================================ Running tests with: $ .kunit/linux kunit.enable=1 mem=1G console=tty kunit_shutdown=halt [14:38:09] ============== hfsplus_unicode (27 subtests) =============== [14:38:09] [PASSED] hfsplus_strcasecmp_test [14:38:09] [PASSED] hfsplus_strcmp_test [14:38:09] [PASSED] hfsplus_unicode_edge_cases_test [14:38:09] [PASSED] hfsplus_unicode_boundary_test [14:38:09] [PASSED] hfsplus_uni2asc_basic_test [14:38:09] [PASSED] hfsplus_uni2asc_special_chars_test [14:38:09] [PASSED] hfsplus_uni2asc_buffer_test [14:38:09] [PASSED] hfsplus_uni2asc_corrupted_test [14:38:09] [PASSED] hfsplus_uni2asc_edge_cases_test [14:38:09] [PASSED] hfsplus_asc2uni_basic_test [14:38:09] [PASSED] hfsplus_asc2uni_special_chars_test [14:38:09] [PASSED] hfsplus_asc2uni_buffer_limits_test [14:38:09] [PASSED] hfsplus_asc2uni_edge_cases_test [14:38:09] [PASSED] hfsplus_asc2uni_decompose_test [14:38:09] [PASSED] hfsplus_hash_dentry_basic_test [14:38:09] [PASSED] hfsplus_hash_dentry_casefold_test [14:38:09] [PASSED] hfsplus_hash_dentry_special_chars_test [14:38:09] [PASSED] hfsplus_hash_dentry_decompose_test [14:38:09] [PASSED] hfsplus_hash_dentry_consistency_test [14:38:09] [PASSED] hfsplus_hash_dentry_edge_cases_test [14:38:09] [PASSED] hfsplus_compare_dentry_basic_test [14:38:09] [PASSED] hfsplus_compare_dentry_casefold_test [14:38:09] [PASSED] hfsplus_compare_dentry_special_chars_test [14:38:09] [PASSED] hfsplus_compare_dentry_length_test [14:38:09] [PASSED] hfsplus_compare_dentry_decompose_test [14:38:09] [PASSED] hfsplus_compare_dentry_edge_cases_test [14:38:09] [PASSED] hfsplus_compare_dentry_combined_flags_test [14:38:09] ================= [PASSED] hfsplus_unicode ================= [14:38:09] ============================================================ [14:38:09] Testing complete. Ran 27 tests: passed: 27 [14:38:09] Elapsed time: 3.875s total, 0.001s configuring, 3.707s building, 0.115s running v2 Rework memory management model. Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com> cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> cc: Yangtao Li <frank.li@vivo.com> cc: linux-fsdevel@vger.kernel.org Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com>
1 parent 150ec68 commit 6f84ceb

File tree

5 files changed

+1618
-3
lines changed

5 files changed

+1618
-3
lines changed

fs/hfsplus/.kunitconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CONFIG_KUNIT=y
2+
CONFIG_HFSPLUS_FS=y
3+
CONFIG_HFSPLUS_KUNIT_TEST=y
4+
CONFIG_BLOCK=y
5+
CONFIG_BUFFER_HEAD=y
6+
CONFIG_NLS=y
7+
CONFIG_NLS_UTF8=y
8+
CONFIG_LEGACY_DIRECT_IO=y

fs/hfsplus/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,18 @@ config HFSPLUS_FS
1414
MacOS 8. It includes all Mac specific filesystem data such as
1515
data forks and creator codes, but it also has several UNIX
1616
style features such as file ownership and permissions.
17+
18+
config HFSPLUS_KUNIT_TEST
19+
tristate "KUnit tests for HFS+ filesystem" if !KUNIT_ALL_TESTS
20+
depends on HFSPLUS_FS && KUNIT
21+
default KUNIT_ALL_TESTS
22+
help
23+
This builds KUnit tests for the HFS+ filesystem.
24+
25+
KUnit tests run during boot and output the results to the debug
26+
log in TAP format (https://testanything.org/). Only useful for
27+
kernel devs running KUnit test harness and are not for inclusion
28+
into a production build.
29+
30+
For more information on KUnit and unit tests in general please
31+
refer to the KUnit documentation in Documentation/dev-tools/kunit/.

fs/hfsplus/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ obj-$(CONFIG_HFSPLUS_FS) += hfsplus.o
88
hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o btree.o \
99
bnode.o brec.o bfind.o tables.o unicode.o wrapper.o bitmap.o part_tbl.o \
1010
attributes.o xattr.o xattr_user.o xattr_security.o xattr_trusted.o
11+
12+
# KUnit tests
13+
obj-$(CONFIG_HFSPLUS_KUNIT_TEST) += unicode_test.o

fs/hfsplus/unicode.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
#include <linux/types.h>
1313
#include <linux/nls.h>
14+
15+
#include <kunit/visibility.h>
16+
1417
#include "hfsplus_fs.h"
1518
#include "hfsplus_raw.h"
1619

@@ -72,6 +75,7 @@ int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,
7275
return 0;
7376
}
7477
}
78+
EXPORT_SYMBOL_IF_KUNIT(hfsplus_strcasecmp);
7579

7680
/* Compare names as a sequence of 16-bit unsigned integers */
7781
int hfsplus_strcmp(const struct hfsplus_unistr *s1,
@@ -110,7 +114,7 @@ int hfsplus_strcmp(const struct hfsplus_unistr *s1,
110114
return len1 < len2 ? -1 :
111115
len1 > len2 ? 1 : 0;
112116
}
113-
117+
EXPORT_SYMBOL_IF_KUNIT(hfsplus_strcmp);
114118

115119
#define Hangul_SBase 0xac00
116120
#define Hangul_LBase 0x1100
@@ -143,8 +147,9 @@ static u16 *hfsplus_compose_lookup(u16 *p, u16 cc)
143147
return NULL;
144148
}
145149

146-
static int hfsplus_uni2asc(struct super_block *sb, const struct hfsplus_unistr *ustr,
147-
int max_len, char *astr, int *len_p)
150+
static int hfsplus_uni2asc(struct super_block *sb,
151+
const struct hfsplus_unistr *ustr,
152+
int max_len, char *astr, int *len_p)
148153
{
149154
const hfsplus_unichr *ip;
150155
struct nls_table *nls = HFSPLUS_SB(sb)->nls;
@@ -285,6 +290,7 @@ inline int hfsplus_uni2asc_str(struct super_block *sb,
285290
{
286291
return hfsplus_uni2asc(sb, ustr, HFSPLUS_MAX_STRLEN, astr, len_p);
287292
}
293+
EXPORT_SYMBOL_IF_KUNIT(hfsplus_uni2asc_str);
288294

289295
inline int hfsplus_uni2asc_xattr_str(struct super_block *sb,
290296
const struct hfsplus_attr_unistr *ustr,
@@ -293,6 +299,7 @@ inline int hfsplus_uni2asc_xattr_str(struct super_block *sb,
293299
return hfsplus_uni2asc(sb, (const struct hfsplus_unistr *)ustr,
294300
HFSPLUS_ATTR_MAX_STRLEN, astr, len_p);
295301
}
302+
EXPORT_SYMBOL_IF_KUNIT(hfsplus_uni2asc_xattr_str);
296303

297304
/*
298305
* Convert one or more ASCII characters into a single unicode character.
@@ -420,6 +427,7 @@ int hfsplus_asc2uni(struct super_block *sb,
420427
return -ENAMETOOLONG;
421428
return 0;
422429
}
430+
EXPORT_SYMBOL_IF_KUNIT(hfsplus_asc2uni);
423431

424432
/*
425433
* Hash a string to an integer as appropriate for the HFS+ filesystem.
@@ -472,6 +480,7 @@ int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *str)
472480

473481
return 0;
474482
}
483+
EXPORT_SYMBOL_IF_KUNIT(hfsplus_hash_dentry);
475484

476485
/*
477486
* Compare strings with HFS+ filename ordering.
@@ -563,3 +572,4 @@ int hfsplus_compare_dentry(const struct dentry *dentry,
563572
return 1;
564573
return 0;
565574
}
575+
EXPORT_SYMBOL_IF_KUNIT(hfsplus_compare_dentry);

0 commit comments

Comments
 (0)