Use RTE_DIM macro to calculate array size.
Suggested-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
Acked-by: David Marchand <david.marchand@redhat.com>
uint32_t event_mode;
uint32_t bypass_mode;
uint32_t timeout = bypass_timeout;
- int i;
+ unsigned int i;
static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
{"off", "1.5", "2", "3", "4", "8", "16", "32"};
"OS/board off",
"power supply off",
"timeout"};
- int num_events = (sizeof events) / (sizeof events[0]);
/* Display the bypass mode.*/
if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
printf("\tbypass timeout = %s\n", timeouts[timeout]);
/* Display the bypass events and associated modes. */
- for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
+ for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
printf("\tFailed to get bypass mode for event = %s\n",
"PIM", /**< Protocol Independent Mcast */
};
- if (ip_proto < sizeof(ip_proto_names) / sizeof(ip_proto_names[0]))
+ if (ip_proto < RTE_DIM(ip_proto_names))
return ip_proto_names[ip_proto];
switch (ip_proto) {
#ifdef IPPROTO_PGM
cmd_func_t cmd_func;
};
-#define PMD_TEST_CMD_NB (sizeof(pmd_test_menu) / sizeof(pmd_test_menu[0]))
-
/* Check the link status of all ports in up to 9s, and print them finally */
static void
check_all_ports_link_status(uint32_t port_mask)
if (recursive_call == NULL)
return -1;
- for (i = 0; i < sizeof(actions)/sizeof(actions[0]); i++) {
+ for (i = 0; i < RTE_DIM(actions); i++) {
if (strcmp(actions[i].env_var, recursive_call) == 0)
return (actions[i].action_fn)();
}
" ",
};
-#define ETHERADDR_VALID_STRS_SIZE \
- (sizeof(ether_addr_valid_strs) / sizeof(ether_addr_valid_strs[0]))
-#define ETHERADDR_GARBAGE_STRS_SIZE \
- (sizeof(ether_addr_garbage_strs) / sizeof(ether_addr_garbage_strs[0]))
-#define ETHERADDR_INVALID_STRS_SIZE \
- (sizeof(ether_addr_invalid_strs) / sizeof(ether_addr_invalid_strs[0]))
-
-
-
static int
is_addr_different(const struct rte_ether_addr addr, uint64_t num)
{
struct rte_ether_addr result;
/* test full strings */
- for (i = 0; i < ETHERADDR_INVALID_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(ether_addr_invalid_strs); i++) {
memset(&result, 0, sizeof(struct rte_ether_addr));
struct rte_ether_addr result;
/* test full strings */
- for (i = 0; i < ETHERADDR_VALID_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(ether_addr_valid_strs); i++) {
memset(&result, 0, sizeof(struct rte_ether_addr));
}
/* test garbage strings */
- for (i = 0; i < ETHERADDR_GARBAGE_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(ether_addr_garbage_strs); i++) {
memset(&result, 0, sizeof(struct rte_ether_addr));
" ",
};
-#define IPADDR_VALID_STRS_SIZE \
- (sizeof(ipaddr_valid_strs) / sizeof(ipaddr_valid_strs[0]))
-#define IPADDR_GARBAGE_ADDR4_STRS_SIZE \
- (sizeof(ipaddr_garbage_addr4_strs) / sizeof(ipaddr_garbage_addr4_strs[0]))
-#define IPADDR_GARBAGE_ADDR6_STRS_SIZE \
- (sizeof(ipaddr_garbage_addr6_strs) / sizeof(ipaddr_garbage_addr6_strs[0]))
-#define IPADDR_GARBAGE_NETWORK4_STRS_SIZE \
- (sizeof(ipaddr_garbage_network4_strs) / sizeof(ipaddr_garbage_network4_strs[0]))
-#define IPADDR_GARBAGE_NETWORK6_STRS_SIZE \
- (sizeof(ipaddr_garbage_network6_strs) / sizeof(ipaddr_garbage_network6_strs[0]))
-#define IPADDR_INVALID_STRS_SIZE \
- (sizeof(ipaddr_invalid_strs) / sizeof(ipaddr_invalid_strs[0]))
-
static void
dump_addr(cmdline_ipaddr_t addr)
{
}
/* test valid strings */
- for (i = 0; i < IPADDR_VALID_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(ipaddr_valid_strs); i++) {
/* test each valid string against different flags */
for (flags = 1; flags < 0x8; flags++) {
}
/* test garbage ipv4 address strings */
- for (i = 0; i < IPADDR_GARBAGE_ADDR4_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(ipaddr_garbage_addr4_strs); i++) {
struct in_addr tmp = IPv4_GARBAGE_ADDR;
}
/* test garbage ipv6 address strings */
- for (i = 0; i < IPADDR_GARBAGE_ADDR6_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(ipaddr_garbage_addr6_strs); i++) {
cmdline_ipaddr_t tmp = {.addr = IPv6_GARBAGE_ADDR};
/* test garbage ipv4 network strings */
- for (i = 0; i < IPADDR_GARBAGE_NETWORK4_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(ipaddr_garbage_network4_strs); i++) {
struct in_addr tmp = IPv4_GARBAGE_ADDR;
}
/* test garbage ipv6 address strings */
- for (i = 0; i < IPADDR_GARBAGE_NETWORK6_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(ipaddr_garbage_network6_strs); i++) {
cmdline_ipaddr_t tmp = {.addr = IPv6_GARBAGE_ADDR};
memset(&result, 0, sizeof(result));
/* test invalid strings */
- for (i = 0; i < IPADDR_INVALID_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(ipaddr_invalid_strs); i++) {
/* test each valid string against different flags */
for (flags = 1; flags < 0x8; flags++) {
"\0",
};
-#define NUM_POSITIVE_STRS_SIZE \
- (sizeof(num_valid_positive_strs) / sizeof(num_valid_positive_strs[0]))
-#define NUM_NEGATIVE_STRS_SIZE \
- (sizeof(num_valid_negative_strs) / sizeof(num_valid_negative_strs[0]))
-#define NUM_POSITIVE_GARBAGE_STRS_SIZE \
- (sizeof(num_garbage_positive_strs) / sizeof(num_garbage_positive_strs[0]))
-#define NUM_NEGATIVE_GARBAGE_STRS_SIZE \
- (sizeof(num_garbage_negative_strs) / sizeof(num_garbage_negative_strs[0]))
-#define NUM_INVALID_STRS_SIZE \
- (sizeof(num_invalid_strs) / sizeof(num_invalid_strs[0]))
-
-
-
static int
can_parse_unsigned(uint64_t expected_result, enum cmdline_numtype type)
{
token.num_data.type = type;
/* test full strings */
- for (i = 0; i < NUM_INVALID_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(num_invalid_strs); i++) {
memset(&result, 0, sizeof(uint64_t));
memset(&buf, 0, sizeof(buf));
token.num_data.type = type;
/* test positive strings */
- for (i = 0; i < NUM_POSITIVE_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(num_valid_positive_strs); i++) {
result = 0;
memset(&buf, 0, sizeof(buf));
}
/* test negative strings */
- for (i = 0; i < NUM_NEGATIVE_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(num_valid_negative_strs); i++) {
result = 0;
memset(&buf, 0, sizeof(buf));
token.num_data.type = type;
/* test positive garbage strings */
- for (i = 0; i < NUM_POSITIVE_GARBAGE_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(num_garbage_positive_strs); i++) {
result = 0;
memset(&buf, 0, sizeof(buf));
}
/* test negative strings */
- for (i = 0; i < NUM_NEGATIVE_GARBAGE_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(num_garbage_negative_strs); i++) {
result = 0;
memset(&buf, 0, sizeof(buf));
#include <string.h>
#include <inttypes.h>
+#include <rte_common.h>
+
#include <cmdline_parse.h>
#include <cmdline_parse_portlist.h>
"0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,2",
};
-#define PORTLIST_VALID_STRS_SIZE \
- (sizeof(portlist_valid_strs) / sizeof(portlist_valid_strs[0]))
-#define PORTLIST_GARBAGE_STRS_SIZE \
- (sizeof(portlist_garbage_strs) / sizeof(portlist_garbage_strs[0]))
-#define PORTLIST_INVALID_STRS_SIZE \
- (sizeof(portlist_invalid_strs) / sizeof(portlist_invalid_strs[0]))
-
-
-
-
/* test invalid parameters */
int
test_parse_portlist_invalid_param(void)
cmdline_portlist_t result;
/* test invalid strings */
- for (i = 0; i < PORTLIST_INVALID_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(portlist_invalid_strs); i++) {
memset(&result, 0, sizeof(cmdline_portlist_t));
cmdline_portlist_t result;
/* test full strings */
- for (i = 0; i < PORTLIST_VALID_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(portlist_valid_strs); i++) {
memset(&result, 0, sizeof(cmdline_portlist_t));
}
/* test garbage strings */
- for (i = 0; i < PORTLIST_GARBAGE_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(portlist_garbage_strs); i++) {
memset(&result, 0, sizeof(cmdline_portlist_t));
"multi#str",
};
-
-
-#define STRING_PARSE_STRS_SIZE \
- (sizeof(string_parse_strs) / sizeof(string_parse_strs[0]))
-#define STRING_HELP_STRS_SIZE \
- (sizeof(string_help_strs) / sizeof(string_help_strs[0]))
-#define STRING_ELT_STRS_SIZE \
- (sizeof(string_elt_strs) / sizeof(string_elt_strs[0]))
-#define STRING_NB_STRS_SIZE \
- (sizeof(string_nb_strs) / sizeof(string_nb_strs[0]))
-#define STRING_INVALID_STRS_SIZE \
- (sizeof(string_invalid_strs) / sizeof(string_invalid_strs[0]))
-
#define SMALL_BUF 8
/* test invalid parameters */
unsigned i;
/* test parsing invalid strings */
- for (i = 0; i < STRING_INVALID_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(string_invalid_strs); i++) {
memset(&token, 0, sizeof(token));
memset(buf, 0, sizeof(buf));
unsigned i;
/* test parsing strings */
- for (i = 0; i < STRING_PARSE_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(string_parse_strs); i++) {
memset(&token, 0, sizeof(token));
memset(buf, 0, sizeof(buf));
}
/* get number of string tokens and verify it's correct */
- for (i = 0; i < STRING_NB_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(string_nb_strs); i++) {
memset(&token, 0, sizeof(token));
token.string_data.str = string_nb_strs[i].str;
}
/* get token at specified position and verify it's correct */
- for (i = 0; i < STRING_ELT_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(string_elt_strs); i++) {
memset(&token, 0, sizeof(token));
memset(buf, 0, sizeof(buf));
}
/* cover all cases with help strings */
- for (i = 0; i < STRING_HELP_STRS_SIZE; i++) {
+ for (i = 0; i < RTE_DIM(string_help_strs); i++) {
memset(&help_token, 0, sizeof(help_token));
memset(help_str, 0, sizeof(help_str));
help_token.string_data.str = string_help_strs[i];
{
int test_vals[] = { 0, 1, 2, 255, -1 };
unsigned i;
- for (i = 0; i < sizeof(test_vals) / sizeof(test_vals[0]); i++){
+ for (i = 0; i < RTE_DIM(test_vals); i++) {
if (test_exit_val(test_vals[i]) < 0)
return -1;
}
#define memtest1 "memtest1"
#define memtest2 "memtest2"
#define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 20)
-#define launch_proc(ARGV) process_dup(ARGV, \
- sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)
enum hugepage_action {
HUGEPAGE_CHECK_EXISTS = 0,
pci_whitelist, "08:00.1,type=normal",
};
- for (i = 0; i < sizeof(wlinval) / sizeof(wlinval[0]); i++) {
+ for (i = 0; i < RTE_DIM(wlinval); i++) {
if (launch_proc(wlinval[i]) == 0) {
printf("Error - process did run ok with invalid "
"whitelist parameter\n");
int i;
- for (i = 0; i != sizeof (blinval) / sizeof (blinval[0]); i++) {
+ for (i = 0; i != RTE_DIM(blinval); i++) {
if (launch_proc(blinval[i]) == 0) {
printf("Error - process did run ok with invalid "
"blacklist parameter\n");
int i;
- for (i = 0; i != sizeof (rinval) / sizeof (rinval[0]); i++) {
+ for (i = 0; i != RTE_DIM(rinval); i++) {
if (launch_proc(rinval[i]) == 0) {
printf("Error - process did run ok with invalid "
"-r (rank) parameter\n");
if (rte_errno != 0)
return -1;
/* check for standard errors we return the same as libc */
- for (i = 0; i < sizeof(std_errs)/sizeof(std_errs[0]); i++){
+ for (i = 0; i < RTE_DIM(std_errs); i++) {
rte_retval = rte_strerror(std_errs[i]);
libc_retval = strerror(std_errs[i]);
printf("rte_strerror: '%s', strerror: '%s'\n",
/* for rte-specific errors ensure we return a different string
* and that the string for libc is for an unknown error
*/
- for (i = 0; i < sizeof(rte_errs)/sizeof(rte_errs[0]); i++){
+ for (i = 0; i < RTE_DIM(rte_errs); i++) {
rte_retval = rte_strerror(rte_errs[i]);
libc_retval = strerror(rte_errs[i]);
printf("rte_strerror: '%s', strerror: '%s'\n",
else if (rte_lcore_count() > MAX_LCORES)
printf("Too many lcores, some cores will be disabled\n");
- for (case_id = 0; case_id < sizeof(test_cases)/sizeof(struct test_case); case_id ++) {
+ for (case_id = 0; case_id < RTE_DIM(test_cases); case_id++) {
pt_case = &test_cases[case_id];
if (pt_case->func == NULL)
continue;
{
unsigned i, j, k;
- for (i = 0;
- i < sizeof(hashtest_funcs) / sizeof(rte_hash_function);
- i++) {
- for (j = 0;
- j < sizeof(hashtest_initvals) / sizeof(uint32_t);
- j++) {
- for (k = 0;
- k < sizeof(hashtest_key_lens) / sizeof(uint32_t);
- k++) {
+ for (i = 0; i < RTE_DIM(hashtest_funcs); i++) {
+ for (j = 0; j < RTE_DIM(hashtest_initvals); j++) {
+ for (k = 0; k < RTE_DIM(hashtest_key_lens); k++) {
run_hash_func_test(hashtest_funcs[i],
hashtest_initvals[j],
hashtest_key_lens[k]);
for (i = 0; i < 64; i++)
key[i] = (uint8_t) i;
- for (i = 0; i < sizeof(hashtest_key_lens) / sizeof(uint32_t); i++) {
- for (j = 0; j < sizeof(hashtest_initvals) / sizeof(uint32_t); j++) {
+ for (i = 0; i < RTE_DIM(hashtest_key_lens); i++) {
+ for (j = 0; j < RTE_DIM(hashtest_initvals); j++) {
hash = rte_jhash(key, hashtest_key_lens[i],
- hashtest_initvals[j]);
+ hashtest_initvals[j]);
if (hash != hash_values_jhash[j][i]) {
printf("jhash for %u bytes with initial value 0x%x."
"Expected 0x%x, but got 0x%x\n",
for (i = 0; i < 64; i++)
key[i] = rand() & 0xff;
- for (i = 0; i < sizeof(hashtest_key_lens) / sizeof(uint32_t); i++) {
- for (j = 0; j < sizeof(hashtest_initvals) / sizeof(uint32_t); j++) {
+ for (i = 0; i < RTE_DIM(hashtest_key_lens); i++) {
+ for (j = 0; j < RTE_DIM(hashtest_initvals); j++) {
/* Key size must be multiple of 4 (32 bits) */
if ((hashtest_key_lens[i] & 0x3) == 0) {
hash = rte_jhash(key, hashtest_key_lens[i],
test18
};
-#define NUM_LPM_TESTS (sizeof(tests)/sizeof(tests[0]))
#define MAX_DEPTH 32
#define MAX_RULES 256
#define NUMBER_TBL8S 256
unsigned i;
int status, global_status = 0;
- for (i = 0; i < NUM_LPM_TESTS; i++) {
+ for (i = 0; i < RTE_DIM(tests); i++) {
status = tests[i]();
if (status < 0) {
printf("ERROR: LPM Test %u: FAIL\n", i);
test28,
};
-#define NUM_LPM6_TESTS (sizeof(tests6)/sizeof(tests6[0]))
#define MAX_DEPTH 128
#define MAX_RULES 1000000
#define NUMBER_TBL8S (1 << 16)
unsigned i;
int status = -1, global_status = 0;
- for (i = 0; i < NUM_LPM6_TESTS; i++) {
+ for (i = 0; i < RTE_DIM(tests6); i++) {
printf("# test %02d\n", i);
status = tests6[i]();
{{234, 149, 220, 106, 0, 144, 214, 128, 35, 102, 0, 0, 0, 0, 0, 0}, 79, 106},
};
-#define NUM_ROUTE_ENTRIES \
- (sizeof(large_route_table) / sizeof(large_route_table[0]))
+#define NUM_ROUTE_ENTRIES RTE_DIM(large_route_table)
#define NUM_IPS_ENTRIES (NUM_ROUTE_ENTRIES * 100)
{"18446744073709551616", 0} /* ULLONG_MAX + 1 == out of range*/
};
unsigned i;
- for (i = 0; i < sizeof(test_values)/sizeof(test_values[0]); i++)
+ for (i = 0; i < RTE_DIM(test_values); i++)
if (rte_str_to_size(test_values[i].str) != test_values[i].value)
return -1;
return 0;
func_test(void)
{
unsigned int off_src, off_dst, i;
- unsigned int num_buf_sizes = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
int ret;
for (off_src = 0; off_src < ALIGNMENT_UNIT; off_src++) {
for (off_dst = 0; off_dst < ALIGNMENT_UNIT; off_dst++) {
- for (i = 0; i < num_buf_sizes; i++) {
+ for (i = 0; i < RTE_DIM(buf_sizes); i++) {
ret = test_single_memcpy(off_src, off_dst,
buf_sizes[i]);
if (ret != 0)
static inline void
perf_test_variable_aligned(void)
{
- unsigned n = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
unsigned i;
- for (i = 0; i < n; i++) {
+ for (i = 0; i < RTE_DIM(buf_sizes); i++) {
ALL_PERF_TESTS_FOR_SIZE((size_t)buf_sizes[i]);
}
}
static inline void
perf_test_variable_unaligned(void)
{
- unsigned n = sizeof(buf_sizes) / sizeof(buf_sizes[0]);
unsigned i;
- for (i = 0; i < n; i++) {
+ for (i = 0; i < RTE_DIM(buf_sizes); i++) {
ALL_PERF_TESTS_FOR_SIZE_UNALIGNED((size_t)buf_sizes[i]);
}
}
#include "process.h"
-#define launch_proc(ARGV) process_dup(ARGV, \
- sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)
/*
* This function is called in the primary i.e. main test, to spawn off secondary
#include "process.h"
#include "test_pdump.h"
-#define launch_p(ARGV) process_dup(ARGV, \
- sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_p(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)
struct rte_ring *ring_server;
uint16_t portid;
unsigned sz, i = 0;
struct rte_mbuf *burst[MAX_BURST] = {0};
- for (sz = 0; sz < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); sz++) {
+ for (sz = 0; sz < RTE_DIM(bulk_sizes); sz++) {
const uint64_t sc_start = rte_rdtsc();
for (i = 0; i < iterations; i++) {
rte_ring_sp_enqueue_bulk(r, (void *)burst,
PM_ENV_KVM_VM,
PM_ENV_PSTATE_CPUFREQ};
- const int envs_size = sizeof(envs)/sizeof(enum power_management_env);
-
- int i;
- for (i = 0; i < envs_size; ++i) {
+ unsigned int i;
+ for (i = 0; i < RTE_DIM(envs); ++i) {
/* Test setting a valid environment */
ret = rte_power_set_env(envs[i]);
f2 = dequeue_bulk_16B;
}
- for (i = 0; i < sizeof(bulk_sizes)/sizeof(bulk_sizes[0]); i++) {
+ for (i = 0; i < RTE_DIM(bulk_sizes); i++) {
lcore_count = 0;
param1.size = param2.size = bulk_sizes[i];
param1.r = param2.r = r;
#define TEST_INFO_MZ_NAME "test_timer_info_mz"
#define MSECPERSEC 1E3
-#define launch_proc(ARGV) \
- process_dup(ARGV, sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
+#define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)
struct test_info {
unsigned int mstr_lcore;