|
lib/ucs2_string.c is used for EFI variable names (efivarfs, efi-pstore),
Apple device properties, the EFI stub's load options and Hyper-V interface
aliases, but has no unit tests.
Add a KUnit suite that covers:
- ucs2_strnlen(), ucs2_strlen() and ucs2_strsize(), including a
byte limit that is not a whole number of characters;
- ucs2_strscpy(): exact fit, truncation with -E2BIG and NUL
termination, and the zero-sized and oversized buffer checks;
- ucs2_strncmp(): ordering, the length limit, prefixes and unsigned
comparison of characters above 0x7fff;
- ucs2_utf8size() and ucs2_as_utf8() for the one, two and three byte
UTF-8 boundaries (U+007F/U+0080, U+07FF/U+0800, U+FFFF);
- truncation in ucs2_as_utf8(): a multi-byte character is never
split, and the terminator is written only when there is room;
- ucs2_as_utf8_l() on a source that is not NUL terminated, which is
why it was split out of ucs2_as_utf8().
An AI coding assistant (Claude Opus 5.5) was used to pick the untested
helpers and draft the tests. They were run with
"tools/testing/kunit/kunit.py run" on UML (19/19 pass), built with W=1
without warnings, and checked against deliberately broken versions of
ucs2_strscpy() and ucs2_as_utf8_l(), which the suite catches.
Link: https://lore.kernel.org/20261106-kunit-ucs2-string-v1-1-28d8e134ba1f@gmail.com
Signed-off-by: Amit Patole <amit.patole@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Brendan Higgins <brendan.higgins@linux.dev>
Cc: David Gow <david@davidgow.net>
Cc: Rae Moar <raemoar63@gmail.com>
|