Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

printf: add tests for generic FourCCs

This patch adds support for kunit tests of generic 32-bit FourCCs added to
vsprintf.

Acked-by: Tamir Duberstein <tamird@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Aditya Garg <gargaditya08@live.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Link: https://lore.kernel.org/r/PN3PR01MB95973AF4F6262B2D1996FB25B8B52@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>

authored by

Aditya Garg and committed by
Alyssa Rosenzweig
403ff8fd 1938479b

+32 -7
+32 -7
lib/tests/printf_kunit.c
··· 701 701 software_node_unregister_node_group(group); 702 702 } 703 703 704 + struct fourcc_struct { 705 + u32 code; 706 + const char *str; 707 + }; 708 + 709 + static void fourcc_pointer_test(struct kunit *kunittest, const struct fourcc_struct *fc, 710 + size_t n, const char *fmt) 711 + { 712 + size_t i; 713 + 714 + for (i = 0; i < n; i++) 715 + test(fc[i].str, fmt, &fc[i].code); 716 + } 717 + 704 718 static void fourcc_pointer(struct kunit *kunittest) 705 719 { 706 - struct { 707 - u32 code; 708 - char *str; 709 - } const try[] = { 720 + static const struct fourcc_struct try_cc[] = { 710 721 { 0x3231564e, "NV12 little-endian (0x3231564e)", }, 711 722 { 0xb231564e, "NV12 big-endian (0xb231564e)", }, 712 723 { 0x10111213, ".... little-endian (0x10111213)", }, 713 724 { 0x20303159, "Y10 little-endian (0x20303159)", }, 714 725 }; 715 - unsigned int i; 726 + static const struct fourcc_struct try_ch[] = { 727 + { 0x41424344, "ABCD (0x41424344)", }, 728 + }; 729 + static const struct fourcc_struct try_cn[] = { 730 + { 0x41424344, "DCBA (0x44434241)", }, 731 + }; 732 + static const struct fourcc_struct try_cl[] = { 733 + { (__force u32)cpu_to_le32(0x41424344), "ABCD (0x41424344)", }, 734 + }; 735 + static const struct fourcc_struct try_cb[] = { 736 + { (__force u32)cpu_to_be32(0x41424344), "ABCD (0x41424344)", }, 737 + }; 716 738 717 - for (i = 0; i < ARRAY_SIZE(try); i++) 718 - test(try[i].str, "%p4cc", &try[i].code); 739 + fourcc_pointer_test(kunittest, try_cc, ARRAY_SIZE(try_cc), "%p4cc"); 740 + fourcc_pointer_test(kunittest, try_ch, ARRAY_SIZE(try_ch), "%p4ch"); 741 + fourcc_pointer_test(kunittest, try_cn, ARRAY_SIZE(try_cn), "%p4cn"); 742 + fourcc_pointer_test(kunittest, try_cl, ARRAY_SIZE(try_cl), "%p4cl"); 743 + fourcc_pointer_test(kunittest, try_cb, ARRAY_SIZE(try_cb), "%p4cb"); 719 744 } 720 745 721 746 static void