aboutsummaryrefslogtreecommitdiffstats
path: root/tests/checkasm/checkasm.h
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2025-03-22 00:49:47 +0200
committerMartin Storsjö <martin@martin.st>2025-04-01 18:34:51 +0300
commitb863b81500f374a2829e9dfb3a244c61e3fc1a60 (patch)
treeac2c1a0bdbf7e94cf1e5c22f1b2919c4c7eb02d7 /tests/checkasm/checkasm.h
parent37c664a2533b2c53beda450899c1a06ac37637ec (diff)
downloadffmpeg-b863b81500f374a2829e9dfb3a244c61e3fc1a60.tar.gz
checkasm: Implement helpers for defining and checking padded rects
This backports similar functionality from dav1d, from commits 35d1d011fda4a92bcaf42d30ed137583b27d7f6d and d130da9c315d5a1d3968d278bbee2238ad9051e7. This allows detecting writes out of bounds, on all 4 sides of the intended destination rectangle. The bounds checking also can optionally allow small overwrites (up to a specified alignment), while still checking for larger overwrites past the intended allowed region. Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'tests/checkasm/checkasm.h')
-rw-r--r--tests/checkasm/checkasm.h55
1 files changed, 46 insertions, 9 deletions
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index c2f2f6861e..67b7df42d2 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -375,11 +375,30 @@ typedef struct CheckasmPerf {
#define PERF_STOP(t) while(0)
#endif
+#define BUF_RECT(type, name, w, h) \
+ LOCAL_ALIGNED_32(type, name##_buf, [((h)+32)*(FFALIGN(w,64)+64) + 64]); \
+ av_unused ptrdiff_t name##_stride = sizeof(type)*(FFALIGN(w,64)+64); \
+ av_unused int name##_buf_h = (h)+32; \
+ type *name = name##_buf + (FFALIGN(w,64)+64)*16 + 64
+
+#define PIXEL_RECT(name, w, h) \
+ LOCAL_ALIGNED_32(uint8_t, name##_buf, [sizeof(uint16_t) * (((h)+32)*(FFALIGN(w,64)+64) + 64)],); \
+ av_unused ptrdiff_t name##_stride = sizeof(uint16_t) * (FFALIGN(w,64)+64); \
+ av_unused int name##_buf_h = (h)+32; \
+ uint8_t *name = name##_buf + (FFALIGN(w,64)+64)*16 + 64
+
+#define CLEAR_BUF_RECT(name) \
+ memset(name##_buf, 0x99, name##_stride * name##_buf_h + 64)
+#define CLEAR_PIXEL_RECT(name) \
+ CLEAR_BUF_RECT(name)
+
#define DECL_CHECKASM_CHECK_FUNC(type) \
int checkasm_check_##type(const char *file, int line, \
const type *buf1, ptrdiff_t stride1, \
const type *buf2, ptrdiff_t stride2, \
- int w, int h, const char *name)
+ int w, int h, const char *name, \
+ int align_w, int align_h, \
+ int padding)
DECL_CHECKASM_CHECK_FUNC(uint8_t);
DECL_CHECKASM_CHECK_FUNC(uint16_t);
@@ -390,18 +409,36 @@ DECL_CHECKASM_CHECK_FUNC(int32_t);
#define PASTE(a,b) a ## b
#define CONCAT(a,b) PASTE(a,b)
-#define checkasm_check(prefix, ...) CONCAT(checkasm_check_, prefix)(__FILE__, __LINE__, __VA_ARGS__)
+#define checkasm_check2(prefix, ...) CONCAT(checkasm_check_, prefix)(__FILE__, __LINE__, __VA_ARGS__)
+#define checkasm_check(prefix, ...) checkasm_check2(prefix, __VA_ARGS__, 0, 0, 0)
+/* Check a pointer from BUF_RECT, checking whether there have been
+ * writes outside of the designated area. */
+#define checkasm_check_padded(...) \
+ checkasm_check2(__VA_ARGS__, 1, 1, 8)
+/* Check a pointer from BUF_RECT, checking whether there have been
+ * writes outside of the designated area. Allow writing slightly past the
+ * end of the buffer, by aligning w/h to align_w/align_h, and checking
+ * for overwrites outside of that. */
+#define checkasm_check_padded_align(...) \
+ checkasm_check2(__VA_ARGS__, 8)
/* This assumes that there is a local variable named "bit_depth".
* For tests that don't have that and only operate on a single
* bitdepth, just call checkasm_check(uint8_t, ...) directly. */
-#define checkasm_check_pixel(buf1, stride1, buf2, stride2, ...) \
+#define checkasm_check_pixel2(buf1, stride1, buf2, stride2, ...) \
((bit_depth > 8) ? \
- checkasm_check(uint16_t, (const uint16_t*)buf1, stride1, \
- (const uint16_t*)buf2, stride2, \
- __VA_ARGS__) : \
- checkasm_check(uint8_t, (const uint8_t*) buf1, stride1, \
- (const uint8_t*) buf2, stride2, \
- __VA_ARGS__))
+ checkasm_check2(uint16_t, (const uint16_t*)buf1, stride1, \
+ (const uint16_t*)buf2, stride2, \
+ __VA_ARGS__) : \
+ checkasm_check2(uint8_t, (const uint8_t*) buf1, stride1, \
+ (const uint8_t*) buf2, stride2, \
+ __VA_ARGS__))
+#define checkasm_check_pixel(...) \
+ checkasm_check_pixel2(__VA_ARGS__, 0, 0, 0)
+#define checkasm_check_pixel_padded(...) \
+ checkasm_check_pixel2(__VA_ARGS__, 1, 1, 8)
+#define checkasm_check_pixel_padded_align(...) \
+ checkasm_check_pixel2(__VA_ARGS__, 8)
+
#endif /* TESTS_CHECKASM_CHECKASM_H */