test/rcu: fix memory size integer truncate
[dpdk.git] / app / test / test_rcu_qsbr.c
index 97af087..2f71ec6 100644 (file)
@@ -3,7 +3,6 @@
  */
 
 #include <stdio.h>
-#include <stdbool.h>
 #include <rte_pause.h>
 #include <rte_rcu_qsbr.h>
 #include <rte_hash.h>
@@ -27,7 +26,7 @@
 #define TEST_RCU_QSBR_CNT_INIT 1
 
 uint16_t enabled_core_ids[RTE_MAX_LCORE];
-uint8_t num_cores;
+unsigned int num_cores;
 
 static uint32_t *keys;
 #define TOTAL_ENTRY (1024 * 8)
@@ -53,7 +52,7 @@ static int
 alloc_rcu(void)
 {
        int i;
-       uint32_t sz;
+       size_t sz;
 
        sz = rte_rcu_qsbr_get_memsize(RTE_MAX_LCORE);
 
@@ -82,20 +81,24 @@ free_rcu(void)
 static int
 test_rcu_qsbr_get_memsize(void)
 {
-       uint32_t sz;
+       size_t sz;
 
        printf("\nTest rte_rcu_qsbr_thread_register()\n");
 
        sz = rte_rcu_qsbr_get_memsize(0);
        TEST_RCU_QSBR_RETURN_IF_ERROR((sz != 1), "Get Memsize for 0 threads");
 
-       sz = rte_rcu_qsbr_get_memsize(RTE_MAX_LCORE);
+       sz = rte_rcu_qsbr_get_memsize(128);
        /* For 128 threads,
         * for machines with cache line size of 64B - 8384
         * for machines with cache line size of 128 - 16768
         */
-       TEST_RCU_QSBR_RETURN_IF_ERROR((sz != 8384 && sz != 16768),
-               "Get Memsize");
+       if (RTE_CACHE_LINE_SIZE == 64)
+               TEST_RCU_QSBR_RETURN_IF_ERROR((sz != 8384),
+                       "Get Memsize for 128 threads");
+       else if (RTE_CACHE_LINE_SIZE == 128)
+               TEST_RCU_QSBR_RETURN_IF_ERROR((sz != 16768),
+                       "Get Memsize for 128 threads");
 
        return 0;
 }
@@ -389,7 +392,7 @@ test_rcu_qsbr_synchronize_reader(void *arg)
 static int
 test_rcu_qsbr_synchronize(void)
 {
-       int i;
+       unsigned int i;
 
        printf("\nTest rte_rcu_qsbr_synchronize()\n");
 
@@ -890,8 +893,8 @@ error:
 static int
 test_rcu_qsbr_mw_mv_mqs(void)
 {
-       int i, j;
-       uint8_t test_cores;
+       unsigned int i, j;
+       unsigned int test_cores;
 
        writer_done = 0;
        test_cores = num_cores / 4;
@@ -978,17 +981,17 @@ test_rcu_qsbr_main(void)
 {
        uint16_t core_id;
 
+       if (rte_lcore_count() < 5) {
+               printf("Not enough cores for rcu_qsbr_autotest, expecting at least 5\n");
+               return TEST_SKIPPED;
+       }
+
        num_cores = 0;
        RTE_LCORE_FOREACH_SLAVE(core_id) {
                enabled_core_ids[num_cores] = core_id;
                num_cores++;
        }
 
-       if (num_cores < 4) {
-               printf("Test failed! Need 4 or more cores\n");
-               goto test_fail;
-       }
-
        /* Error-checking test cases */
        if (test_rcu_qsbr_get_memsize() < 0)
                goto test_fail;