test_hexdump.c (002c6ca75289a4ac4f6738213dd2d258704886e4) | test_hexdump.c (8032bf1233a74627ce69b803608e650f3f35971c) |
---|---|
1/* 2 * Test cases for lib/hexdump.c module. 3 */ 4#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 5 6#include <linux/init.h> 7#include <linux/kernel.h> 8#include <linux/module.h> --- 135 unchanged lines hidden (view full) --- 144 pr_err("Expect: '%s'\n", test); 145 failed_tests++; 146 } 147} 148 149static void __init test_hexdump_set(int rowsize, bool ascii) 150{ 151 size_t d = min_t(size_t, sizeof(data_b), rowsize); | 1/* 2 * Test cases for lib/hexdump.c module. 3 */ 4#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 5 6#include <linux/init.h> 7#include <linux/kernel.h> 8#include <linux/module.h> --- 135 unchanged lines hidden (view full) --- 144 pr_err("Expect: '%s'\n", test); 145 failed_tests++; 146 } 147} 148 149static void __init test_hexdump_set(int rowsize, bool ascii) 150{ 151 size_t d = min_t(size_t, sizeof(data_b), rowsize); |
152 size_t len = prandom_u32_max(d) + 1; | 152 size_t len = get_random_u32_below(d) + 1; |
153 154 test_hexdump(len, rowsize, 4, ascii); 155 test_hexdump(len, rowsize, 2, ascii); 156 test_hexdump(len, rowsize, 8, ascii); 157 test_hexdump(len, rowsize, 1, ascii); 158} 159 160static void __init test_hexdump_overflow(size_t buflen, size_t len, --- 42 unchanged lines hidden (view full) --- 203 pr_err("Expect: %d '%s'\n", e, test); 204 failed_tests++; 205 } 206} 207 208static void __init test_hexdump_overflow_set(size_t buflen, bool ascii) 209{ 210 unsigned int i = 0; | 153 154 test_hexdump(len, rowsize, 4, ascii); 155 test_hexdump(len, rowsize, 2, ascii); 156 test_hexdump(len, rowsize, 8, ascii); 157 test_hexdump(len, rowsize, 1, ascii); 158} 159 160static void __init test_hexdump_overflow(size_t buflen, size_t len, --- 42 unchanged lines hidden (view full) --- 203 pr_err("Expect: %d '%s'\n", e, test); 204 failed_tests++; 205 } 206} 207 208static void __init test_hexdump_overflow_set(size_t buflen, bool ascii) 209{ 210 unsigned int i = 0; |
211 int rs = (prandom_u32_max(2) + 1) * 16; | 211 int rs = (get_random_u32_below(2) + 1) * 16; |
212 213 do { 214 int gs = 1 << i; | 212 213 do { 214 int gs = 1 << i; |
215 size_t len = prandom_u32_max(rs) + gs; | 215 size_t len = get_random_u32_below(rs) + gs; |
216 217 test_hexdump_overflow(buflen, rounddown(len, gs), rs, gs, ascii); 218 } while (i++ < 3); 219} 220 221static int __init test_hexdump_init(void) 222{ 223 unsigned int i; 224 int rowsize; 225 | 216 217 test_hexdump_overflow(buflen, rounddown(len, gs), rs, gs, ascii); 218 } while (i++ < 3); 219} 220 221static int __init test_hexdump_init(void) 222{ 223 unsigned int i; 224 int rowsize; 225 |
226 rowsize = (prandom_u32_max(2) + 1) * 16; | 226 rowsize = (get_random_u32_below(2) + 1) * 16; |
227 for (i = 0; i < 16; i++) 228 test_hexdump_set(rowsize, false); 229 | 227 for (i = 0; i < 16; i++) 228 test_hexdump_set(rowsize, false); 229 |
230 rowsize = (prandom_u32_max(2) + 1) * 16; | 230 rowsize = (get_random_u32_below(2) + 1) * 16; |
231 for (i = 0; i < 16; i++) 232 test_hexdump_set(rowsize, true); 233 234 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++) 235 test_hexdump_overflow_set(i, false); 236 237 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++) 238 test_hexdump_overflow_set(i, true); --- 18 unchanged lines hidden --- | 231 for (i = 0; i < 16; i++) 232 test_hexdump_set(rowsize, true); 233 234 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++) 235 test_hexdump_overflow_set(i, false); 236 237 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++) 238 test_hexdump_overflow_set(i, true); --- 18 unchanged lines hidden --- |