summaryrefslogtreecommitdiffstats
path: root/lib/test_string.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-07-17 11:58:04 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-17 11:58:04 -0400
commit57a8ec387e1441ea5e1232bc0749fb99a8cba7e7 (patch)
treeb5fb03fc6bc5754de8b5b1f8b0e4f36d67c8315c /lib/test_string.c
parent0a8ad0ffa4d80a544f6cbff703bf6394339afcdf (diff)
parent43e11fa2d1d3b6e35629fa556eb7d571edba2010 (diff)
Merge branch 'akpm' (patches from Andrew)
Merge more updates from Andrew Morton: "VM: - z3fold fixes and enhancements by Henry Burns and Vitaly Wool - more accurate reclaimed slab caches calculations by Yafang Shao - fix MAP_UNINITIALIZED UAPI symbol to not depend on config, by Christoph Hellwig - !CONFIG_MMU fixes by Christoph Hellwig - new novmcoredd parameter to omit device dumps from vmcore, by Kairui Song - new test_meminit module for testing heap and pagealloc initialization, by Alexander Potapenko - ioremap improvements for huge mappings, by Anshuman Khandual - generalize kprobe page fault handling, by Anshuman Khandual - device-dax hotplug fixes and improvements, by Pavel Tatashin - enable synchronous DAX fault on powerpc, by Aneesh Kumar K.V - add pte_devmap() support for arm64, by Robin Murphy - unify locked_vm accounting with a helper, by Daniel Jordan - several misc fixes core/lib: - new typeof_member() macro including some users, by Alexey Dobriyan - make BIT() and GENMASK() available in asm, by Masahiro Yamada - changed LIST_POISON2 on x86_64 to 0xdead000000000122 for better code generation, by Alexey Dobriyan - rbtree code size optimizations, by Michel Lespinasse - convert struct pid count to refcount_t, by Joel Fernandes get_maintainer.pl: - add --no-moderated switch to skip moderated ML's, by Joe Perches misc: - ptrace PTRACE_GET_SYSCALL_INFO interface - coda updates - gdb scripts, various" [ Using merge message suggestion from Vlastimil Babka, with some editing - Linus ] * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (100 commits) fs/select.c: use struct_size() in kmalloc() mm: add account_locked_vm utility function arm64: mm: implement pte_devmap support mm: introduce ARCH_HAS_PTE_DEVMAP mm: clean up is_device_*_page() definitions mm/mmap: move common defines to mman-common.h mm: move MAP_SYNC to asm-generic/mman-common.h device-dax: "Hotremove" persistent memory that is used like normal RAM mm/hotplug: make remove_memory() interface usable device-dax: fix memory and resource leak if hotplug fails include/linux/lz4.h: fix spelling and copy-paste errors in documentation ipc/mqueue.c: only perform resource calculation if user valid include/asm-generic/bug.h: fix "cut here" for WARN_ON for __WARN_TAINT architectures scripts/gdb: add helpers to find and list devices scripts/gdb: add lx-genpd-summary command drivers/pps/pps.c: clear offset flags in PPS_SETPARAMS ioctl kernel/pid.c: convert struct pid count to refcount_t drivers/rapidio/devices/rio_mport_cdev.c: NUL terminate some strings select: shift restore_saved_sigmask_unless() into poll_select_copy_remaining() select: change do_poll() to return -ERESTARTNOHAND rather than -EINTR ...
Diffstat (limited to 'lib/test_string.c')
-rw-r--r--lib/test_string.c83
1 files changed, 80 insertions, 3 deletions
diff --git a/lib/test_string.c b/lib/test_string.c
index bf8def01ed20..7b31f4a505bf 100644
--- a/lib/test_string.c
+++ b/lib/test_string.c
@@ -36,7 +36,7 @@ static __init int memset16_selftest(void)
36fail: 36fail:
37 kfree(p); 37 kfree(p);
38 if (i < 256) 38 if (i < 256)
39 return (i << 24) | (j << 16) | k; 39 return (i << 24) | (j << 16) | k | 0x8000;
40 return 0; 40 return 0;
41} 41}
42 42
@@ -72,7 +72,7 @@ static __init int memset32_selftest(void)
72fail: 72fail:
73 kfree(p); 73 kfree(p);
74 if (i < 256) 74 if (i < 256)
75 return (i << 24) | (j << 16) | k; 75 return (i << 24) | (j << 16) | k | 0x8000;
76 return 0; 76 return 0;
77} 77}
78 78
@@ -108,7 +108,74 @@ static __init int memset64_selftest(void)
108fail: 108fail:
109 kfree(p); 109 kfree(p);
110 if (i < 256) 110 if (i < 256)
111 return (i << 24) | (j << 16) | k; 111 return (i << 24) | (j << 16) | k | 0x8000;
112 return 0;
113}
114
115static __init int strchr_selftest(void)
116{
117 const char *test_string = "abcdefghijkl";
118 const char *empty_string = "";
119 char *result;
120 int i;
121
122 for (i = 0; i < strlen(test_string) + 1; i++) {
123 result = strchr(test_string, test_string[i]);
124 if (result - test_string != i)
125 return i + 'a';
126 }
127
128 result = strchr(empty_string, '\0');
129 if (result != empty_string)
130 return 0x101;
131
132 result = strchr(empty_string, 'a');
133 if (result)
134 return 0x102;
135
136 result = strchr(test_string, 'z');
137 if (result)
138 return 0x103;
139
140 return 0;
141}
142
143static __init int strnchr_selftest(void)
144{
145 const char *test_string = "abcdefghijkl";
146 const char *empty_string = "";
147 char *result;
148 int i, j;
149
150 for (i = 0; i < strlen(test_string) + 1; i++) {
151 for (j = 0; j < strlen(test_string) + 2; j++) {
152 result = strnchr(test_string, j, test_string[i]);
153 if (j <= i) {
154 if (!result)
155 continue;
156 return ((i + 'a') << 8) | j;
157 }
158 if (result - test_string != i)
159 return ((i + 'a') << 8) | j;
160 }
161 }
162
163 result = strnchr(empty_string, 0, '\0');
164 if (result)
165 return 0x10001;
166
167 result = strnchr(empty_string, 1, '\0');
168 if (result != empty_string)
169 return 0x10002;
170
171 result = strnchr(empty_string, 1, 'a');
172 if (result)
173 return 0x10003;
174
175 result = strnchr(NULL, 0, '\0');
176 if (result)
177 return 0x10004;
178
112 return 0; 179 return 0;
113} 180}
114 181
@@ -131,6 +198,16 @@ static __init int string_selftest_init(void)
131 if (subtest) 198 if (subtest)
132 goto fail; 199 goto fail;
133 200
201 test = 4;
202 subtest = strchr_selftest();
203 if (subtest)
204 goto fail;
205
206 test = 5;
207 subtest = strnchr_selftest();
208 if (subtest)
209 goto fail;
210
134 pr_info("String selftests succeeded\n"); 211 pr_info("String selftests succeeded\n");
135 return 0; 212 return 0;
136fail: 213fail: