Skip to content

Commit

Permalink
validation: use new ODPH_MIN and ODPH_MAX macros
Browse files Browse the repository at this point in the history
Utilize new ODPH_MIN() and ODPH_MAX() macros in validation tests.

Signed-off-by: Matias Elo <matias.elo@nokia.com>
  • Loading branch information
MatiasElo committed Aug 28, 2023
1 parent 67df648 commit 89c983e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 48 deletions.
9 changes: 3 additions & 6 deletions test/validation/api/atomic/atomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@

#define UNUSED __attribute__((__unused__))

#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)

typedef __volatile uint32_t volatile_u32_t;
typedef __volatile uint64_t volatile_u64_t;

Expand Down Expand Up @@ -929,7 +926,7 @@ static void test_atomic_validate_max_min(void)
* a long test, counter may overflow, in which case max is saturated at
* UINT32_MAX, and min at 0.
*/
const uint32_t a32u_max = min(U32_INIT_VAL + total_count - 1, UINT32_MAX);
const uint32_t a32u_max = ODPH_MIN(U32_INIT_VAL + total_count - 1, UINT32_MAX);
const uint32_t a32u_min = U32_INIT_VAL + total_count - 1 > UINT32_MAX ? 0 : U32_INIT_VAL;

CU_ASSERT(odp_atomic_load_u32(&global_mem->a32u_max) == a32u_max);
Expand Down Expand Up @@ -1546,7 +1543,7 @@ static void test_atomic_validate_max(void)
{
const uint64_t total_count = CNT * global_mem->g_num_threads - 1;
/* In a long test, counter may overflow, in which case max is saturated at UINT32_MAX. */
const uint32_t a32u_max = min(U32_INIT_VAL + total_count, UINT32_MAX);
const uint32_t a32u_max = ODPH_MIN(U32_INIT_VAL + total_count, UINT32_MAX);

CU_ASSERT(a32u_max == odp_atomic_load_u32(&global_mem->a32u_max));
CU_ASSERT(U64_INIT_VAL + total_count == odp_atomic_load_u64(&global_mem->a64u_max));
Expand All @@ -1561,7 +1558,7 @@ static void test_atomic_validate_min(void)
{
const uint64_t total_count = CNT * global_mem->g_num_threads - 1;
/* In a long test, counter may underflow, in which case min is saturated at 0. */
const uint32_t a32u_min = max((int64_t)U32_INIT_VAL - (int64_t)total_count, 0);
const uint32_t a32u_min = ODPH_MAX((int64_t)U32_INIT_VAL - (int64_t)total_count, 0);

CU_ASSERT(a32u_min == odp_atomic_load_u32(&global_mem->a32u_min));
CU_ASSERT(U64_INIT_VAL - total_count == odp_atomic_load_u64(&global_mem->a64u_min));
Expand Down
24 changes: 11 additions & 13 deletions test/validation/api/dma/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
#define MULTI 1
#define RESULT 1
#define USER_DATA 0xdeadbeef
#define ELEM_NUM 10
#define ELEM_NUM 10u
#define UAREA 0xaa

#define MIN(a, b) (a < b ? a : b)

typedef struct global_t {
odp_dma_capability_t dma_capa;
odp_shm_t shm;
Expand Down Expand Up @@ -105,7 +103,7 @@ static int dma_suite_init(void)
if (pkt_len == 0)
pkt_len = 4000;

pkt_len = MIN(pkt_len, global.dma_capa.max_seg_len);
pkt_len = ODPH_MIN(pkt_len, global.dma_capa.max_seg_len);
odp_pool_param_init(&pool_param);
pool_param.type = ODP_POOL_PACKET;
pool_param.pkt.num = global.dma_capa.max_src_segs + global.dma_capa.max_dst_segs;
Expand Down Expand Up @@ -426,7 +424,7 @@ static void test_dma_compl_pool_max_pools(void)
static void test_dma_compl_user_area(void)
{
odp_dma_pool_param_t dma_pool_param;
uint32_t num = MIN(ELEM_NUM, global.dma_capa.pool.max_num),
uint32_t num = ODPH_MIN(ELEM_NUM, global.dma_capa.pool.max_num),
size = global.dma_capa.pool.max_uarea_size, i;
odp_pool_t pool;
odp_dma_compl_t compl_evs[num];
Expand Down Expand Up @@ -482,7 +480,7 @@ static void init_event_uarea(void *uarea, uint32_t size, void *args, uint32_t in
static void test_dma_compl_user_area_init(void)
{
odp_dma_pool_param_t dma_pool_param;
uint32_t num = MIN(ELEM_NUM, global.dma_capa.pool.max_num), i;
uint32_t num = ODPH_MIN(ELEM_NUM, global.dma_capa.pool.max_num), i;
odp_pool_t pool;
uarea_init_t data;
odp_dma_compl_t compl_evs[num];
Expand Down Expand Up @@ -724,7 +722,7 @@ static void test_dma_addr_to_addr(odp_dma_compl_mode_t compl_mode_mask, uint32_t
uint32_t i, cur_len;
uint8_t *src = global.src_addr + OFFSET;
uint8_t *dst = global.dst_addr + OFFSET;
uint32_t seg_len = MIN(global.len / num, global.dma_capa.max_seg_len);
uint32_t seg_len = ODPH_MIN(global.len / num, global.dma_capa.max_seg_len);
uint32_t len = seg_len * num;
uint32_t offset = 0;

Expand Down Expand Up @@ -784,7 +782,7 @@ static void test_dma_addr_to_addr_trs(odp_dma_compl_mode_t compl_mode_mask, uint
odp_dma_compl_mode_t compl_mode;
uint8_t *src = global.src_addr + OFFSET;
uint8_t *dst = global.dst_addr + OFFSET;
uint32_t trs_len = MIN(global.len / num_trs, global.dma_capa.max_seg_len);
uint32_t trs_len = ODPH_MIN(global.len / num_trs, global.dma_capa.max_seg_len);
uint32_t len = trs_len * num_trs;
uint32_t offset = 0;
int ret = -1;
Expand Down Expand Up @@ -855,7 +853,7 @@ static void test_dma_addr_to_addr_max_trs(odp_dma_compl_mode_t compl_mode_mask)
uint32_t i, cur_len;
uint8_t *src = global.src_addr + OFFSET;
uint8_t *dst = global.dst_addr + OFFSET;
uint32_t seg_len = MIN(global.len / num_trs, global.dma_capa.max_seg_len);
uint32_t seg_len = ODPH_MIN(global.len / num_trs, global.dma_capa.max_seg_len);
uint32_t len = seg_len * num_trs;
uint32_t offset = 0;

Expand Down Expand Up @@ -1318,9 +1316,9 @@ static void test_dma_addr_to_addr_sync_res(void)

static void get_seg_lens(uint32_t max_len, uint32_t *src, uint32_t *dst)
{
uint32_t src_segs = *src, dst_segs = *dst, denom = MIN(src_segs, dst_segs);
uint32_t src_segs = *src, dst_segs = *dst, denom = ODPH_MIN(src_segs, dst_segs);

max_len = MIN(max_len / denom, global.dma_capa.max_seg_len) * denom;
max_len = ODPH_MIN(max_len / denom, global.dma_capa.max_seg_len) * denom;
*src = max_len / src_segs;
*dst = *src * src_segs / dst_segs + *src * src_segs % dst_segs;
}
Expand Down Expand Up @@ -1361,7 +1359,7 @@ static void test_dma_addr_to_addr_sync_max_seg(void)

memset(&dst_seg[i], 0, sizeof(odp_dma_seg_t));
dst_seg[i].addr = addr;
dst_seg[i].len = MIN(len, dst_len);
dst_seg[i].len = ODPH_MIN(len, dst_len);
len -= dst_len;
}

Expand Down Expand Up @@ -1444,7 +1442,7 @@ static void test_dma_pkt_to_pkt_sync_max_seg(void)
memset(odp_packet_data(pkt), 0, dst_len);
memset(&dst_seg[i], 0, sizeof(odp_dma_seg_t));
dst_seg[i].packet = pkt;
dst_seg[i].len = MIN(len, dst_len);
dst_seg[i].len = ODPH_MIN(len, dst_len);
len -= dst_len;
}

Expand Down
22 changes: 10 additions & 12 deletions test/validation/api/pool/pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#define VEC_LEN 32
#define PKT_LEN 400
#define PKT_NUM 500
#define ELEM_NUM 10
#define ELEM_SIZE 128
#define ELEM_NUM 10u
#define ELEM_SIZE 128u
#define CACHE_SIZE 32
#define MAX_NUM_DEFAULT (10 * 1024 * 1024)
#define UAREA 0xaa
Expand All @@ -34,8 +34,6 @@
#define EXT_HEADROOM 16
#define MAGIC_U8 0x7a

#define MIN(a, b) (((a) < (b)) ? (a) : (b))

typedef struct {
odp_barrier_t init_barrier;
odp_atomic_u32_t index;
Expand Down Expand Up @@ -204,8 +202,8 @@ static void init_event_uarea(void *uarea, uint32_t size, void *args, uint32_t in
static void pool_test_buffer_uarea_init(void)
{
odp_pool_param_t param;
uint32_t num = MIN(global_pool_capa.buf.max_num, ELEM_NUM),
size = MIN(global_pool_capa.buf.max_size, ELEM_SIZE), i;
uint32_t num = ODPH_MIN(global_pool_capa.buf.max_num, ELEM_NUM),
size = ODPH_MIN(global_pool_capa.buf.max_size, ELEM_SIZE), i;
odp_pool_t pool;
uarea_init_t data;
odp_buffer_t bufs[num];
Expand Down Expand Up @@ -246,8 +244,8 @@ static void pool_test_buffer_uarea_init(void)
static void pool_test_packet_uarea_init(void)
{
odp_pool_param_t param;
uint32_t num = MIN(global_pool_capa.pkt.max_num, ELEM_NUM),
size = MIN(global_pool_capa.pkt.max_len, ELEM_SIZE), i;
uint32_t num = ODPH_MIN(global_pool_capa.pkt.max_num, ELEM_NUM),
size = ODPH_MIN(global_pool_capa.pkt.max_len, ELEM_SIZE), i;
odp_pool_t pool;
uarea_init_t data;
odp_packet_t pkts[num];
Expand Down Expand Up @@ -288,8 +286,8 @@ static void pool_test_packet_uarea_init(void)
static void pool_test_vector_uarea_init(void)
{
odp_pool_param_t param;
uint32_t num = MIN(global_pool_capa.vector.max_num, ELEM_NUM),
size = MIN(global_pool_capa.vector.max_size, ELEM_NUM), i;
uint32_t num = ODPH_MIN(global_pool_capa.vector.max_num, ELEM_NUM),
size = ODPH_MIN(global_pool_capa.vector.max_size, ELEM_NUM), i;
odp_pool_t pool;
uarea_init_t data;
odp_packet_vector_t vecs[num];
Expand Down Expand Up @@ -332,7 +330,7 @@ static void pool_test_vector_uarea_init(void)
static void pool_test_timeout_uarea_init(void)
{
odp_pool_param_t param;
uint32_t num = MIN(global_pool_capa.tmo.max_num, ELEM_NUM), i;
uint32_t num = ODPH_MIN(global_pool_capa.tmo.max_num, ELEM_NUM), i;
odp_pool_t pool;
uarea_init_t data;
odp_timeout_t tmos[num];
Expand Down Expand Up @@ -2034,7 +2032,7 @@ static void test_packet_pool_ext_uarea_init(void)
pool_ext_init_packet_pool_param(&param);
param.uarea_init.init_fn = init_event_uarea;
param.uarea_init.args = &data;
num = MIN(num, param.pkt.num_buf);
num = ODPH_MIN(num, param.pkt.num_buf);
param.pkt.num_buf = num;
param.pkt.uarea_size = 1;
pool = odp_pool_ext_create(NULL, &param);
Expand Down
2 changes: 0 additions & 2 deletions test/validation/api/timer/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

#define GLOBAL_SHM_NAME "GlobalTimerTest"

#define MAX(a, b) (((a) > (b)) ? (a) : (b))

#define MAX_TIMER_POOLS 1024

/* Timeout range in milliseconds (ms) */
Expand Down
27 changes: 12 additions & 15 deletions test/validation/api/traffic_mngr/traffic_mngr.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#define NUM_LEVELS 3
#define NUM_PRIORITIES 4
#define NUM_QUEUES_PER_NODE NUM_PRIORITIES
#define FANIN_RATIO 8
#define FANIN_RATIO 8u
#define NUM_LEVEL0_TM_NODES 1
#define NUM_LEVEL1_TM_NODES FANIN_RATIO
#define NUM_LEVEL2_TM_NODES (FANIN_RATIO * FANIN_RATIO)
Expand Down Expand Up @@ -65,7 +65,7 @@
#define MED_DROP_PROB 4
#define MAX_DROP_PROB 8

#define MAX_PKTS 1000
#define MAX_PKTS 1000u
#define PKT_BUF_SIZE 1460
#define MAX_PAYLOAD 1400
#define USE_IPV4 false
Expand Down Expand Up @@ -109,9 +109,6 @@
#define MBPS 1000000
#define GBPS 1000000000

#define MIN(a, b) (((a) <= (b)) ? (a) : (b))
#define MAX(a, b) (((a) <= (b)) ? (b) : (a))

#define TM_PERCENT(percent) ((uint32_t)(100 * percent))

#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
Expand Down Expand Up @@ -400,13 +397,13 @@ static odp_bool_t approx_eq64(uint64_t val, uint64_t correct)
static uint64_t
clamp_rate(uint64_t rate)
{
return MIN(MAX(rate, tm_shaper_min_rate), tm_shaper_max_rate);
return ODPH_MIN(ODPH_MAX(rate, tm_shaper_min_rate), tm_shaper_max_rate);
}

static uint32_t
clamp_burst(uint32_t burst)
{
return MIN(MAX(burst, tm_shaper_min_burst), tm_shaper_max_burst);
return ODPH_MIN(ODPH_MAX(burst, tm_shaper_min_burst), tm_shaper_max_burst);
}

static int test_overall_capabilities(void)
Expand Down Expand Up @@ -1464,8 +1461,8 @@ static inline void calc_rcv_stats(rcv_stats_t *rcv_stats,
last_rcv_gap_idx = (rcv_gap_cnt * (100 - ending_drop_percent)) / 100;
for (idx = first_rcv_gap_idx; idx <= last_rcv_gap_idx; idx++) {
rcv_gap = rcv_gaps[idx];
rcv_stats->min_rcv_gap = MIN(rcv_stats->min_rcv_gap, rcv_gap);
rcv_stats->max_rcv_gap = MAX(rcv_stats->max_rcv_gap, rcv_gap);
rcv_stats->min_rcv_gap = ODPH_MIN(rcv_stats->min_rcv_gap, rcv_gap);
rcv_stats->max_rcv_gap = ODPH_MAX(rcv_stats->max_rcv_gap, rcv_gap);
rcv_stats->total_rcv_gap += rcv_gap;
rcv_stats->total_rcv_gap_squared += rcv_gap * rcv_gap;
rcv_stats->num_samples++;
Expand Down Expand Up @@ -2365,7 +2362,7 @@ static int traffic_mngr_suite_init(void)

payload_len = 0;
while (payload_len < MAX_PAYLOAD) {
copy_len = MIN(MAX_PAYLOAD - payload_len, sizeof(ALPHABET));
copy_len = ODPH_MIN(MAX_PAYLOAD - payload_len, sizeof(ALPHABET));
memcpy(&payload_data[payload_len], ALPHABET, copy_len);
payload_len += copy_len;
}
Expand Down Expand Up @@ -3087,7 +3084,7 @@ static int set_sched_fanin(const char *node_name,
CU_ASSERT_FATAL(odp_tm_stop(odp_tm_systems[0]) == 0);
}

fanin_cnt = MIN(node_desc->num_children, FANIN_RATIO);
fanin_cnt = ODPH_MIN(node_desc->num_children, FANIN_RATIO);
for (fanin = 0; fanin < fanin_cnt; fanin++) {
odp_tm_sched_params_init(&sched_params);
sched_weight = sched_weights[fanin];
Expand Down Expand Up @@ -3352,7 +3349,7 @@ static int test_sched_wfq(const char *sched_base_name,
/* Now determine at least one tm_queue that feeds into each fanin/
* child node. */
priority = 0;
fanin_cnt = MIN(node_desc->num_children, FANIN_RATIO);
fanin_cnt = ODPH_MIN(node_desc->num_children, FANIN_RATIO);
for (fanin = 0; fanin < fanin_cnt; fanin++) {
child_desc = node_desc->children[fanin];
num_queues = find_child_queues(0, child_desc, priority,
Expand Down Expand Up @@ -3482,15 +3479,15 @@ static int test_threshold(const char *threshold_name,

odp_tm_threshold_params_init(&threshold_params);
if (max_pkts != 0) {
max_pkts = MIN(max_pkts, MAX_PKTS / 3);
max_pkts = ODPH_MIN(max_pkts, MAX_PKTS / 3);
threshold_params.max_pkts = max_pkts;
threshold_params.enable_max_pkts = true;
num_pkts = 2 * max_pkts;
pkt_len = 256;
}

if (max_bytes != 0) {
max_bytes = MIN(max_bytes, MAX_PKTS * MAX_PAYLOAD / 3);
max_bytes = ODPH_MIN(max_bytes, MAX_PKTS * MAX_PAYLOAD / 3);
threshold_params.max_bytes = max_bytes;
threshold_params.enable_max_bytes = true;
num_pkts = 2 * max_bytes / MAX_PAYLOAD;
Expand Down Expand Up @@ -4662,7 +4659,7 @@ static void traffic_mngr_test_queue_stats(void)
odp_tm_capabilities_t capa;
pkt_info_t pkt_info;
uint32_t pkts_sent;
uint32_t num_pkts = MIN(50, MAX_PKTS);
uint32_t num_pkts = ODPH_MIN(50u, MAX_PKTS);
uint32_t pkt_len = 256;

CU_ASSERT_FATAL(odp_tm_capability(odp_tm_systems[0], &capa) == 0);
Expand Down

0 comments on commit 89c983e

Please sign in to comment.