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

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
133133 test_hexdump(len, rowsize, 1, ascii);
134134 }
135135
136−static void __init test_hexdump_overflow(size_t buflen, bool ascii)
136+static void __init test_hexdump_overflow(size_t buflen, size_t len,
137+ int rowsize, int groupsize,
138+ bool ascii)
137139 {
138140 char test[TEST_HEXDUMP_BUF_SIZE];
139141 char buf[TEST_HEXDUMP_BUF_SIZE];
@@ -176,6 +178,19 @@ static void __init test_hexdump_overflow(size_t buflen, bool ascii) · 36 unmodified lines
176178 }
177179 }
178180
181+static 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+
179194 static int __init test_hexdump_init(void)
180195 {
181196 unsigned int i;
@@ -192,10 +207,10 @@ static int __init test_hexdump_init(void) · 10 unmodified lines
192207 test_hexdump_set(rowsize, true);
193208
194209 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++)
195− test_hexdump_overflow(i, false);
210+ test_hexdump_overflow_set(i, false);
196211
197212 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++)
198− test_hexdump_overflow(i, true);
213+ test_hexdump_overflow_set(i, true);
199214
200215 return -EINVAL;
201216 }