18
18
#define ITERS_PER_TEST 2000
19
19
20
20
/* Test requirements. */
21
- static bool test_requires (void )
21
+ static bool __init test_requires (void )
22
22
{
23
23
/* random should be initialized for the below tests */
24
24
return prandom_u32 () + prandom_u32 () != 0 ;
@@ -28,14 +28,18 @@ static bool test_requires(void)
28
28
* Test watchpoint encode and decode: check that encoding some access's info,
29
29
* and then subsequent decode preserves the access's info.
30
30
*/
31
- static bool test_encode_decode (void )
31
+ static bool __init test_encode_decode (void )
32
32
{
33
33
int i ;
34
34
35
35
for (i = 0 ; i < ITERS_PER_TEST ; ++ i ) {
36
36
size_t size = prandom_u32_max (MAX_ENCODABLE_SIZE ) + 1 ;
37
37
bool is_write = !!prandom_u32_max (2 );
38
+ unsigned long verif_masked_addr ;
39
+ long encoded_watchpoint ;
40
+ bool verif_is_write ;
38
41
unsigned long addr ;
42
+ size_t verif_size ;
39
43
40
44
prandom_bytes (& addr , sizeof (addr ));
41
45
if (addr < PAGE_SIZE )
@@ -44,53 +48,37 @@ static bool test_encode_decode(void)
44
48
if (WARN_ON (!check_encodable (addr , size )))
45
49
return false;
46
50
47
- /* Encode and decode */
48
- {
49
- const long encoded_watchpoint =
50
- encode_watchpoint (addr , size , is_write );
51
- unsigned long verif_masked_addr ;
52
- size_t verif_size ;
53
- bool verif_is_write ;
54
-
55
- /* Check special watchpoints */
56
- if (WARN_ON (decode_watchpoint (
57
- INVALID_WATCHPOINT , & verif_masked_addr ,
58
- & verif_size , & verif_is_write )))
59
- return false;
60
- if (WARN_ON (decode_watchpoint (
61
- CONSUMED_WATCHPOINT , & verif_masked_addr ,
62
- & verif_size , & verif_is_write )))
63
- return false;
64
-
65
- /* Check decoding watchpoint returns same data */
66
- if (WARN_ON (!decode_watchpoint (
67
- encoded_watchpoint , & verif_masked_addr ,
68
- & verif_size , & verif_is_write )))
69
- return false;
70
- if (WARN_ON (verif_masked_addr !=
71
- (addr & WATCHPOINT_ADDR_MASK )))
72
- goto fail ;
73
- if (WARN_ON (verif_size != size ))
74
- goto fail ;
75
- if (WARN_ON (is_write != verif_is_write ))
76
- goto fail ;
77
-
78
- continue ;
79
- fail :
80
- pr_err ("%s fail: %s %zu bytes @ %lx -> encoded: %lx -> %s %zu bytes @ %lx\n" ,
81
- __func__ , is_write ? "write" : "read" , size ,
82
- addr , encoded_watchpoint ,
83
- verif_is_write ? "write" : "read" , verif_size ,
84
- verif_masked_addr );
51
+ encoded_watchpoint = encode_watchpoint (addr , size , is_write );
52
+
53
+ /* Check special watchpoints */
54
+ if (WARN_ON (decode_watchpoint (INVALID_WATCHPOINT , & verif_masked_addr , & verif_size , & verif_is_write )))
85
55
return false;
86
- }
56
+ if (WARN_ON (decode_watchpoint (CONSUMED_WATCHPOINT , & verif_masked_addr , & verif_size , & verif_is_write )))
57
+ return false;
58
+
59
+ /* Check decoding watchpoint returns same data */
60
+ if (WARN_ON (!decode_watchpoint (encoded_watchpoint , & verif_masked_addr , & verif_size , & verif_is_write )))
61
+ return false;
62
+ if (WARN_ON (verif_masked_addr != (addr & WATCHPOINT_ADDR_MASK )))
63
+ goto fail ;
64
+ if (WARN_ON (verif_size != size ))
65
+ goto fail ;
66
+ if (WARN_ON (is_write != verif_is_write ))
67
+ goto fail ;
68
+
69
+ continue ;
70
+ fail :
71
+ pr_err ("%s fail: %s %zu bytes @ %lx -> encoded: %lx -> %s %zu bytes @ %lx\n" ,
72
+ __func__ , is_write ? "write" : "read" , size , addr , encoded_watchpoint ,
73
+ verif_is_write ? "write" : "read" , verif_size , verif_masked_addr );
74
+ return false;
87
75
}
88
76
89
77
return true;
90
78
}
91
79
92
80
/* Test access matching function. */
93
- static bool test_matching_access (void )
81
+ static bool __init test_matching_access (void )
94
82
{
95
83
if (WARN_ON (!matching_access (10 , 1 , 10 , 1 )))
96
84
return false;
0 commit comments