|
15 | 15 | #include <linux/fs.h> |
16 | 16 | #include <linux/mm.h> |
17 | 17 | #include <linux/mman.h> |
| 18 | +#include <linux/seq_buf.h> |
18 | 19 | #include <linux/sizes.h> |
19 | 20 |
|
20 | 21 | #include "../binder_alloc.h" |
@@ -107,40 +108,33 @@ static const char *const buf_end_align_type_strs[LOOP_END] = { |
107 | 108 | }; |
108 | 109 |
|
109 | 110 | struct binder_alloc_test_case_info { |
| 111 | + char alignments[ALIGNMENTS_BUFLEN]; |
| 112 | + struct seq_buf alignments_sb; |
110 | 113 | size_t *buffer_sizes; |
111 | 114 | int *free_sequence; |
112 | | - char alignments[ALIGNMENTS_BUFLEN]; |
113 | 115 | bool front_pages; |
114 | 116 | }; |
115 | 117 |
|
116 | | -static void stringify_free_seq(struct kunit *test, int *seq, char *buf, |
117 | | - size_t buf_len) |
| 118 | +static void stringify_free_seq(struct kunit *test, int *seq, struct seq_buf *sb) |
118 | 119 | { |
119 | | - size_t bytes = 0; |
120 | 120 | int i; |
121 | 121 |
|
122 | | - for (i = 0; i < BUFFER_NUM; i++) { |
123 | | - bytes += snprintf(buf + bytes, buf_len - bytes, "[%d]", seq[i]); |
124 | | - if (bytes >= buf_len) |
125 | | - break; |
126 | | - } |
127 | | - KUNIT_EXPECT_LT(test, bytes, buf_len); |
| 122 | + for (i = 0; i < BUFFER_NUM; i++) |
| 123 | + seq_buf_printf(sb, "[%d]", seq[i]); |
| 124 | + |
| 125 | + KUNIT_EXPECT_FALSE(test, seq_buf_has_overflowed(sb)); |
128 | 126 | } |
129 | 127 |
|
130 | 128 | static void stringify_alignments(struct kunit *test, int *alignments, |
131 | | - char *buf, size_t buf_len) |
| 129 | + struct seq_buf *sb) |
132 | 130 | { |
133 | | - size_t bytes = 0; |
134 | 131 | int i; |
135 | 132 |
|
136 | | - for (i = 0; i < BUFFER_NUM; i++) { |
137 | | - bytes += snprintf(buf + bytes, buf_len - bytes, "[ %d:%s ]", i, |
138 | | - buf_end_align_type_strs[alignments[i]]); |
139 | | - if (bytes >= buf_len) |
140 | | - break; |
141 | | - } |
| 133 | + for (i = 0; i < BUFFER_NUM; i++) |
| 134 | + seq_buf_printf(sb, "[ %d:%s ]", i, |
| 135 | + buf_end_align_type_strs[alignments[i]]); |
142 | 136 |
|
143 | | - KUNIT_EXPECT_LT(test, bytes, buf_len); |
| 137 | + KUNIT_EXPECT_FALSE(test, seq_buf_has_overflowed(sb)); |
144 | 138 | } |
145 | 139 |
|
146 | 140 | static bool check_buffer_pages_allocated(struct kunit *test, |
@@ -311,19 +305,20 @@ static void permute_frees(struct kunit *test, struct binder_alloc *alloc, |
311 | 305 | int i; |
312 | 306 |
|
313 | 307 | if (index == BUFFER_NUM) { |
314 | | - char freeseq_buf[FREESEQ_BUFLEN]; |
| 308 | + DECLARE_SEQ_BUF(freeseq_sb, FREESEQ_BUFLEN); |
315 | 309 |
|
316 | 310 | case_failed = binder_alloc_test_alloc_free(test, alloc, tc, end); |
317 | 311 | *runs += 1; |
318 | 312 | *failures += case_failed; |
319 | 313 |
|
320 | 314 | if (case_failed || PRINT_ALL_CASES) { |
321 | | - stringify_free_seq(test, tc->free_sequence, freeseq_buf, |
322 | | - FREESEQ_BUFLEN); |
| 315 | + stringify_free_seq(test, tc->free_sequence, |
| 316 | + &freeseq_sb); |
323 | 317 | kunit_err(test, "case %lu: [%s] | %s - %s - %s", *runs, |
324 | 318 | case_failed ? "FAILED" : "PASSED", |
325 | 319 | tc->front_pages ? "front" : "back ", |
326 | | - tc->alignments, freeseq_buf); |
| 320 | + seq_buf_str(&tc->alignments_sb), |
| 321 | + seq_buf_str(&freeseq_sb)); |
327 | 322 | } |
328 | 323 |
|
329 | 324 | return; |
@@ -383,8 +378,9 @@ static void gen_buf_offsets(struct kunit *test, struct binder_alloc *alloc, |
383 | 378 | if (index == BUFFER_NUM) { |
384 | 379 | struct binder_alloc_test_case_info tc = {0}; |
385 | 380 |
|
386 | | - stringify_alignments(test, alignments, tc.alignments, |
387 | | - ALIGNMENTS_BUFLEN); |
| 381 | + seq_buf_init(&tc.alignments_sb, tc.alignments, |
| 382 | + ALIGNMENTS_BUFLEN); |
| 383 | + stringify_alignments(test, alignments, &tc.alignments_sb); |
388 | 384 |
|
389 | 385 | gen_buf_sizes(test, alloc, &tc, end_offset, runs, failures); |
390 | 386 | return; |
|
0 commit comments