fs/unicode/tests/utf8_kunit.c
Source file repositories/reference/linux-study-clean/fs/unicode/tests/utf8_kunit.c
File Facts
- System
- Linux kernel
- Corpus path
fs/unicode/tests/utf8_kunit.c- Extension
.c- Size
- 8402 bytes
- Lines
- 298
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/unicode.hkunit/test.h../utf8n.h
Detected Declarations
function utf8lenfunction utf8cursorfunction check_utf8_nfdifunction check_utf8_nfdicffunction check_utf8_comparisonsfunction check_supported_versionsfunction init_test_ucdfunction exit_test_ucd
Annotated Snippet
while ((c = utf8byte(&u8c)) > 0) {
KUNIT_EXPECT_EQ_MSG(test, c, nfdi_test_data[i].dec[j],
"Unexpected byte 0x%x should be 0x%x\n",
c, nfdi_test_data[i].dec[j]);
j++;
}
KUNIT_EXPECT_EQ(test, j, nlen);
}
}
static void check_utf8_nfdicf(struct kunit *test)
{
int i;
struct utf8cursor u8c;
struct unicode_map *um = test->priv;
for (i = 0; i < ARRAY_SIZE(nfdicf_test_data); i++) {
int len = strlen(nfdicf_test_data[i].str);
int nlen = strlen(nfdicf_test_data[i].ncf);
int j = 0;
int ret;
unsigned char c;
KUNIT_EXPECT_EQ(test, utf8len(um, UTF8_NFDICF, nfdicf_test_data[i].str),
nlen);
KUNIT_EXPECT_EQ(test, utf8nlen(um, UTF8_NFDICF, nfdicf_test_data[i].str, len),
nlen);
ret = utf8cursor(&u8c, um, UTF8_NFDICF, nfdicf_test_data[i].str);
KUNIT_EXPECT_TRUE_MSG(test, ret >= 0, "Can't create cursor\n");
while ((c = utf8byte(&u8c)) > 0) {
KUNIT_EXPECT_EQ_MSG(test, c, nfdicf_test_data[i].ncf[j],
"Unexpected byte 0x%x should be 0x%x\n",
c, nfdicf_test_data[i].ncf[j]);
j++;
}
KUNIT_EXPECT_EQ(test, j, nlen);
}
}
static void check_utf8_comparisons(struct kunit *test)
{
int i;
struct unicode_map *um = test->priv;
for (i = 0; i < ARRAY_SIZE(nfdi_test_data); i++) {
const struct qstr s1 = {.name = nfdi_test_data[i].str,
.len = sizeof(nfdi_test_data[i].str)};
const struct qstr s2 = {.name = nfdi_test_data[i].dec,
.len = sizeof(nfdi_test_data[i].dec)};
/* strncmp returns 0 when strings are equal */
KUNIT_EXPECT_TRUE_MSG(test, utf8_strncmp(um, &s1, &s2) == 0,
"%s %s comparison mismatch\n", s1.name, s2.name);
}
for (i = 0; i < ARRAY_SIZE(nfdicf_test_data); i++) {
const struct qstr s1 = {.name = nfdicf_test_data[i].str,
.len = sizeof(nfdicf_test_data[i].str)};
const struct qstr s2 = {.name = nfdicf_test_data[i].ncf,
.len = sizeof(nfdicf_test_data[i].ncf)};
/* strncasecmp returns 0 when strings are equal */
KUNIT_EXPECT_TRUE_MSG(test, utf8_strncasecmp(um, &s1, &s2) == 0,
"%s %s comparison mismatch\n", s1.name, s2.name);
}
}
static void check_supported_versions(struct kunit *test)
{
struct unicode_map *um = test->priv;
/* Unicode 7.0.0 should be supported. */
KUNIT_EXPECT_TRUE(test, utf8version_is_supported(um, UNICODE_AGE(7, 0, 0)));
/* Unicode 9.0.0 should be supported. */
KUNIT_EXPECT_TRUE(test, utf8version_is_supported(um, UNICODE_AGE(9, 0, 0)));
/* Unicode 1x.0.0 (the latest version) should be supported. */
KUNIT_EXPECT_TRUE(test, utf8version_is_supported(um, UTF8_LATEST));
/* Next versions don't exist. */
KUNIT_EXPECT_FALSE(test, utf8version_is_supported(um, UNICODE_AGE(13, 0, 0)));
KUNIT_EXPECT_FALSE(test, utf8version_is_supported(um, UNICODE_AGE(0, 0, 0)));
KUNIT_EXPECT_FALSE(test, utf8version_is_supported(um, UNICODE_AGE(-1, -1, -1)));
}
static struct kunit_case unicode_normalization_test_cases[] = {
Annotation
- Immediate include surface: `linux/unicode.h`, `kunit/test.h`, `../utf8n.h`.
- Detected declarations: `function utf8len`, `function utf8cursor`, `function check_utf8_nfdi`, `function check_utf8_nfdicf`, `function check_utf8_comparisons`, `function check_supported_versions`, `function init_test_ucd`, `function exit_test_ucd`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.