FFmpeg
Data Structures | Macros | Functions
utils.h File Reference

Utility functions for checkasm tests. More...

#include <stdint.h>
#include "checkasm/attributes.h"

Go to the source code of this file.

Data Structures

struct  CheckasmDist
 Describes a normal (Gaussian) distribution. More...
 

Macros

#define checkasm_dist_standard   ((CheckasmDist) { 0.0, 1.0 })
 Standard normal distribution (mean=0, stddev=1) More...
 
#define CLEAR_BUF(buf)   checkasm_clear(buf, sizeof(buf))
 Clear a fixed size buffer (convenience macro) More...
 
#define RANDOMIZE_BUF(buf)   checkasm_randomize(buf, sizeof(buf))
 Fill a fixed size buffer with random data (convenience macro) More...
 
#define INITIALIZE_BUF(buf)   checkasm_init(buf, sizeof(buf))
 Fill a fixed size buffer with pathological test data (convenience macro) More...
 
#define float_near_ulp   checkasm_float_near_ulp
 
#define float_near_abs_eps   checkasm_float_near_abs_eps
 
#define float_near_abs_eps_ulp   checkasm_float_near_abs_eps_ulp
 
#define float_near_ulp_array   checkasm_float_near_ulp_array
 
#define float_near_abs_eps_array   checkasm_float_near_abs_eps_array
 
#define float_near_abs_eps_array_ulp   checkasm_float_near_abs_eps_array_ulp
 
#define double_near_abs_eps   checkasm_double_near_abs_eps
 
#define double_near_abs_eps_array   checkasm_double_near_abs_eps_array
 
#define CHECKASM_ALIGN(x)   x __attribute__((aligned(CHECKASM_ALIGNMENT)))
 Declare a variable with platform-specific alignment requirements. More...
 
#define DECL_CHECK_FUNC(NAME, TYPE)
 
#define DECL_CHECKASM_CHECK_FUNC(type)   CHECKASM_API DECL_CHECK_FUNC(checkasm_check_impl_##type, type)
 
#define checkasm_check_impl2(type)   checkasm_check_impl_##type
 
#define checkasm_check_impl(type)   checkasm_check_impl2(type)
 
#define checkasm_check1(type, ...)   checkasm_check_impl_##type(__VA_ARGS__)
 
#define checkasm_check2(type, ...)   checkasm_check1(type, __FILE__, __LINE__, __VA_ARGS__)
 
#define checkasm_check2d(type, ...)   checkasm_check2(type, __VA_ARGS__, 0, 0, 0)
 Compare two 2D buffers and fail test if different. More...
 
#define checkasm_check2d_padded(type, ...)   checkasm_check2(type, __VA_ARGS__)
 Compare two 2D buffers, including padding regions (detect over-write) More...
 
#define BUF_RECT(type, name, w, h)
 
#define CLEAR_BUF_RECT(name)   CLEAR_BUF(name##_buf)
 Clear a rectangular buffer (including padding) More...
 
#define INITIALIZE_BUF_RECT(name)   INITIALIZE_BUF(name##_buf)
 Initialize a rectangular buffer (including padding) with pathological values. More...
 
#define RANDOMIZE_BUF_RECT(name)   RANDOMIZE_BUF(name##_buf)
 Randomize a rectangular buffer (including padding) More...
 
#define checkasm_check_rect(rect1, ...)   checkasm_check2d(rect1##_type, rect1, __VA_ARGS__)
 Compare two rectangular buffers. More...
 
#define checkasm_check_rect_padded(rect1, ...)   checkasm_check2d_padded(rect1##_type, rect1, __VA_ARGS__, 1, 1, 8)
 Compare two rectangular buffers including padding. More...
 
#define checkasm_check_rect_padded_align(rect1, ...)   checkasm_check2d_padded(rect1##_type, rect1, __VA_ARGS__, 8)
 Compare two rectangular buffers, with custom alignment (over-write) More...
 
#define CHECK_BUF_RECT(buf1, buf2, w, h)
 Compare two rectangular buffers (convenience macro) More...
 

Functions

CHECKASM_API int checkasm_rand (void)
 Generate a random non-negative integer. More...
 
CHECKASM_API double checkasm_randf (void)
 Generate a random double-precision floating-point number. More...
 
CHECKASM_API uint32_t checkasm_rand_uint32 (void)
 Generate a random 32-bit unsigned integer. More...
 
CHECKASM_API int32_t checkasm_rand_int32 (void)
 Generate a random 32-bit signed integer. More...
 
CHECKASM_API double checkasm_rand_dist (CheckasmDist dist)
 Generate a normally distributed random number. More...
 
CHECKASM_API double checkasm_rand_norm (void)
 Generate a random number from the standard normal distribution. More...
 
CHECKASM_API void checkasm_randomize (void *buf, size_t bytes)
 Fill a buffer with uniformly chosen random bytes. More...
 
CHECKASM_API void checkasm_randomize_mask8 (uint8_t *buf, int width, uint8_t mask)
 Fill a uint8_t buffer with random values chosen uniformly within a mask. More...
 
CHECKASM_API void checkasm_randomize_mask16 (uint16_t *buf, int width, uint16_t mask)
 Fill a uint16_t buffer with random values chosen uniformly within a mask. More...
 
CHECKASM_API void checkasm_randomize_range (double *buf, int width, double range)
 Fill a double buffer with random values chosen uniformly below a limit. More...
 
CHECKASM_API void checkasm_randomize_rangef (float *buf, int width, float range)
 Fill a float buffer with random values chosen uniformly below a limit. More...
 
CHECKASM_API void checkasm_randomize_dist (double *buf, int width, CheckasmDist dist)
 Fill a double buffer with normally distributed random values. More...
 
CHECKASM_API void checkasm_randomize_distf (float *buf, int width, CheckasmDist dist)
 Fill a float buffer with normally distributed random values. More...
 
CHECKASM_API void checkasm_randomize_norm (double *buf, int width)
 Fill a double buffer with values from a standard normal distribution. More...
 
CHECKASM_API void checkasm_randomize_normf (float *buf, int width)
 Fill a float buffer with values from a standard normal distribution. More...
 
CHECKASM_API void checkasm_clear (void *buf, size_t bytes)
 Clear a buffer to a pre-determined pattern (currently 0xAA) More...
 
CHECKASM_API void checkasm_clear8 (uint8_t *buf, int width, uint8_t val)
 Fill a uint8_t buffer with a constant value. More...
 
CHECKASM_API void checkasm_clear16 (uint16_t *buf, int width, uint16_t val)
 Fill a uint16_t buffer with a constant value. More...
 
CHECKASM_API void checkasm_init (void *buf, size_t bytes)
 Initialize a buffer with pathological test patterns. More...
 
CHECKASM_API void checkasm_init_mask8 (uint8_t *buf, int width, uint8_t mask)
 Initialize a uint8_t buffer with pathological values within a mask. More...
 
CHECKASM_API void checkasm_init_mask16 (uint16_t *buf, int width, uint16_t mask)
 Initialize a uint16_t buffer with pathological values within a mask. More...
 
CHECKASM_API int checkasm_float_near_ulp (float a, float b, unsigned max_ulp)
 Compare floats using ULP (Units in Last Place) tolerance. More...
 
CHECKASM_API int checkasm_float_near_abs_eps (float a, float b, float eps)
 Compare floats using absolute epsilon tolerance. More...
 
CHECKASM_API int checkasm_float_near_abs_eps_ulp (float a, float b, float eps, unsigned max_ulp)
 Compare floats using both epsilon and ULP tolerances. More...
 
CHECKASM_API int checkasm_float_near_ulp_array (const float *a, const float *b, unsigned max_ulp, int len)
 Compare float arrays using ULP tolerance. More...
 
CHECKASM_API int checkasm_float_near_abs_eps_array (const float *a, const float *b, float eps, int len)
 Compare float arrays using absolute epsilon tolerance. More...
 
CHECKASM_API int checkasm_float_near_abs_eps_array_ulp (const float *a, const float *b, float eps, unsigned max_ulp, int len)
 Compare float arrays using both epsilon and ULP tolerances. More...
 
CHECKASM_API int checkasm_double_near_abs_eps (double a, double b, double eps)
 Compare doubles using absolute epsilon tolerance. More...
 
CHECKASM_API int checkasm_double_near_abs_eps_array (const double *a, const double *b, double eps, unsigned len)
 Compare double arrays using absolute epsilon tolerance. More...
 
 DECL_CHECKASM_CHECK_FUNC (int)
 
 DECL_CHECKASM_CHECK_FUNC (int8_t)
 
 DECL_CHECKASM_CHECK_FUNC (int16_t)
 
 DECL_CHECKASM_CHECK_FUNC (int32_t)
 
 DECL_CHECKASM_CHECK_FUNC (unsigned)
 
 DECL_CHECKASM_CHECK_FUNC (uint8_t)
 
 DECL_CHECKASM_CHECK_FUNC (uint16_t)
 
 DECL_CHECKASM_CHECK_FUNC (uint32_t)
 
CHECKASM_API int checkasm_check_impl_float_ulp (const char *file, int line, const float *buf1, ptrdiff_t stride1, const float *buf2, ptrdiff_t stride2, int w, int h, const char *name, unsigned max_ulp, int align_w, int align_h, int padding)
 Compare float buffers with ULP tolerance. More...
 

Detailed Description

Utility functions for checkasm tests.

This header provides utility functions commonly needed when writing checkasm tests, including:

Definition in file utils.h.

Macro Definition Documentation

◆ checkasm_dist_standard

#define checkasm_dist_standard   ((CheckasmDist) { 0.0, 1.0 })

Standard normal distribution (mean=0, stddev=1)

Definition at line 98 of file utils.h.

Function Documentation

◆ checkasm_rand_dist()

CHECKASM_API double checkasm_rand_dist ( CheckasmDist  dist)

Generate a normally distributed random number.

Parameters
[in]distDistribution parameters (mean and standard deviation)
Returns
Random value from the specified normal distribution

Definition at line 196 of file utils.c.

◆ checkasm_rand_norm()

CHECKASM_API double checkasm_rand_norm ( void  )

Generate a random number from the standard normal distribution.

Returns
Random value from N(0,1) distribution
See also
checkasm_dist_standard

Definition at line 185 of file utils.c.

Referenced by checkasm_rand_dist().