History

test_hexdump: test all possible group sizes for overflow

Currently the only one combination is tested for overflow, i.e. rowsize = 16, groupsize = 1, len = 1. Do various test to go through all possible branches.

Andy Shevchenko committed 10 years ago

Commit 1dacd9d1 parent cc77a711 file · +18 −3Browse files

Showing the changes to lib (1 of 1 file). Show all

Unified · Split

lib/test_hexdump.c+18−3
@@ -133,7 +133,9 @@ static void __init test_hexdump_set(int rowsize, bool ascii) · 132 unmodified lines
133 test_hexdump(len, rowsize, 1, ascii);133 test_hexdump(len, rowsize, 1, ascii);
134}134}
135 135
136static void __init test_hexdump_overflow(size_t buflen, bool ascii)136static void __init test_hexdump_overflow(size_t buflen, size_t len,
137 int rowsize, int groupsize,
138 bool ascii)
137{139{
138 char test[TEST_HEXDUMP_BUF_SIZE];140 char test[TEST_HEXDUMP_BUF_SIZE];
139 char buf[TEST_HEXDUMP_BUF_SIZE];141 char buf[TEST_HEXDUMP_BUF_SIZE];
@@ -176,6 +178,19 @@ static void __init test_hexdump_overflow(size_t buflen, bool ascii) · 36 unmodified lines
176 }178 }
177}179}
178 180
181static void __init test_hexdump_overflow_set(size_t buflen, bool ascii)
182{
183 unsigned int i = 0;
184 int rs = (get_random_int() % 2 + 1) * 16;
185
186 do {
187 int gs = 1 << i;
188 size_t len = get_random_int() % rs + gs;
189
190 test_hexdump_overflow(buflen, rounddown(len, gs), rs, gs, ascii);
191 } while (i++ < 3);
192}
193
179static int __init test_hexdump_init(void)194static int __init test_hexdump_init(void)
180{195{
181 unsigned int i;196 unsigned int i;
@@ -192,10 +207,10 @@ static int __init test_hexdump_init(void) · 10 unmodified lines
192 test_hexdump_set(rowsize, true);207 test_hexdump_set(rowsize, true);
193 208
194 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++)209 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++)
195 test_hexdump_overflow(i, false);210 test_hexdump_overflow_set(i, false);
196 211
197 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++)212 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++)
198 test_hexdump_overflow(i, true);213 test_hexdump_overflow_set(i, true);
199 214
200 return -EINVAL;215 return -EINVAL;
201}216}