From 89c983ece5f761c4c96c6faffae916fbc412f1d3 Mon Sep 17 00:00:00 2001 From: Matias Elo Date: Fri, 25 Aug 2023 16:07:35 +0300 Subject: [PATCH] validation: use new ODPH_MIN and ODPH_MAX macros Utilize new ODPH_MIN() and ODPH_MAX() macros in validation tests. Signed-off-by: Matias Elo --- test/validation/api/atomic/atomic.c | 9 +++---- test/validation/api/dma/dma.c | 24 ++++++++--------- test/validation/api/pool/pool.c | 22 +++++++-------- test/validation/api/timer/timer.c | 2 -- .../api/traffic_mngr/traffic_mngr.c | 27 +++++++++---------- 5 files changed, 36 insertions(+), 48 deletions(-) diff --git a/test/validation/api/atomic/atomic.c b/test/validation/api/atomic/atomic.c index 17d9dc82a35..76e3c0d4974 100644 --- a/test/validation/api/atomic/atomic.c +++ b/test/validation/api/atomic/atomic.c @@ -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; @@ -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); @@ -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)); @@ -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)); diff --git a/test/validation/api/dma/dma.c b/test/validation/api/dma/dma.c index 36a025b0dcb..150fde83b64 100644 --- a/test/validation/api/dma/dma.c +++ b/test/validation/api/dma/dma.c @@ -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; @@ -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; @@ -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]; @@ -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]; @@ -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; @@ -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; @@ -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; @@ -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; } @@ -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; } @@ -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; } diff --git a/test/validation/api/pool/pool.c b/test/validation/api/pool/pool.c index 5176bb96f2d..cadea3ce50f 100644 --- a/test/validation/api/pool/pool.c +++ b/test/validation/api/pool/pool.c @@ -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 @@ -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; @@ -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]; @@ -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]; @@ -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]; @@ -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]; @@ -2034,7 +2032,7 @@ static void test_packet_pool_ext_uarea_init(void) pool_ext_init_packet_pool_param(¶m); 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, ¶m); diff --git a/test/validation/api/timer/timer.c b/test/validation/api/timer/timer.c index 1927156badb..20dfc572db6 100644 --- a/test/validation/api/timer/timer.c +++ b/test/validation/api/timer/timer.c @@ -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) */ diff --git a/test/validation/api/traffic_mngr/traffic_mngr.c b/test/validation/api/traffic_mngr/traffic_mngr.c index 28d163fd34e..edb845b6030 100644 --- a/test/validation/api/traffic_mngr/traffic_mngr.c +++ b/test/validation/api/traffic_mngr/traffic_mngr.c @@ -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) @@ -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 @@ -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])) @@ -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) @@ -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++; @@ -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; } @@ -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]; @@ -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, @@ -3482,7 +3479,7 @@ 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; @@ -3490,7 +3487,7 @@ static int test_threshold(const char *threshold_name, } 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; @@ -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);