summaryrefslogtreecommitdiffstats
path: root/lib/test_string.c
diff options
context:
space:
mode:
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: