Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2010-2014 Intel Corporation 3 : : */ 4 : : 5 : : #include <stdio.h> 6 : : #include <stdint.h> 7 : : #include <stdarg.h> 8 : : #include <string.h> 9 : : #include <errno.h> 10 : : #include <sys/queue.h> 11 : : 12 : : #include <rte_eal.h> 13 : : #include <rte_string_fns.h> 14 : : #include <rte_tailq.h> 15 : : 16 : : #include "test.h" 17 : : 18 : : #define do_return(...) do { \ 19 : : printf("Error at %s, line %d: ", __func__, __LINE__); \ 20 : : printf(__VA_ARGS__); \ 21 : : return 1; \ 22 : : } while (0) 23 : : 24 : : static struct rte_tailq_elem rte_dummy_tailq = { 25 : : .name = "dummy", 26 : : }; 27 [ - + ]: 251 : EAL_REGISTER_TAILQ(rte_dummy_tailq) 28 : : 29 : : static struct rte_tailq_elem rte_dummy_dyn_tailq = { 30 : : .name = "dummy_dyn", 31 : : }; 32 : : static struct rte_tailq_elem rte_dummy_dyn2_tailq = { 33 : : .name = "dummy_dyn", 34 : : }; 35 : : 36 : : static struct rte_tailq_entry d_elem; 37 : : static struct rte_tailq_entry d_dyn_elem; 38 : : 39 : : static int 40 : 1 : test_tailq_early(void) 41 : : { 42 : : struct rte_tailq_entry_head *d_head; 43 : : 44 : 1 : d_head = RTE_TAILQ_CAST(rte_dummy_tailq.head, rte_tailq_entry_head); 45 [ - + ]: 1 : if (d_head == NULL) 46 : 0 : do_return("Error %s has not been initialised\n", 47 : : rte_dummy_tailq.name); 48 : : 49 : : /* check we can add an item to it */ 50 : 1 : TAILQ_INSERT_TAIL(d_head, &d_elem, next); 51 : : 52 : 1 : return 0; 53 : : } 54 : : 55 : : static int 56 : 1 : test_tailq_create(void) 57 : : { 58 : : struct rte_tailq_entry_head *d_head; 59 : : 60 : : /* create a tailq and check its non-null (since we are post-eal init) */ 61 [ + - ]: 1 : if ((rte_eal_tailq_register(&rte_dummy_dyn_tailq) < 0) || 62 [ - + ]: 1 : (rte_dummy_dyn_tailq.head == NULL)) 63 : 0 : do_return("Error allocating %s\n", rte_dummy_dyn_tailq.name); 64 : : 65 : : d_head = RTE_TAILQ_CAST(rte_dummy_dyn_tailq.head, rte_tailq_entry_head); 66 : : 67 : : /* check we can add an item to it */ 68 : 1 : TAILQ_INSERT_TAIL(d_head, &d_dyn_elem, next); 69 : : 70 [ - + ]: 1 : if (strcmp(rte_dummy_dyn2_tailq.name, rte_dummy_dyn_tailq.name)) 71 : 0 : do_return("Error, something is wrong in the tailq test\n"); 72 : : 73 : : /* try allocating again, and check for failure */ 74 [ - + ]: 1 : if (!rte_eal_tailq_register(&rte_dummy_dyn2_tailq)) 75 : 0 : do_return("Error, registering the same tailq %s did not fail\n", 76 : : rte_dummy_dyn2_tailq.name); 77 : : 78 : : return 0; 79 : : } 80 : : 81 : : static int 82 : 1 : test_tailq_lookup(void) 83 : : { 84 : : /* run successful test - check result is found */ 85 : : struct rte_tailq_entry_head *d_head; 86 : : struct rte_tailq_entry *d_ptr; 87 : : 88 : 1 : d_head = RTE_TAILQ_LOOKUP(rte_dummy_tailq.name, rte_tailq_entry_head); 89 : : /* rte_dummy_tailq has been registered by EAL_REGISTER_TAILQ */ 90 [ + - ]: 1 : if (d_head == NULL || 91 [ - + ]: 1 : d_head != RTE_TAILQ_CAST(rte_dummy_tailq.head, rte_tailq_entry_head)) 92 : 0 : do_return("Error with tailq lookup\n"); 93 : : 94 [ + + ]: 2 : TAILQ_FOREACH(d_ptr, d_head, next) 95 [ - + ]: 1 : if (d_ptr != &d_elem) 96 : 0 : do_return("Error with tailq returned from lookup - " 97 : : "expected element not found\n"); 98 : : 99 : 1 : d_head = RTE_TAILQ_LOOKUP(rte_dummy_dyn_tailq.name, rte_tailq_entry_head); 100 : : /* rte_dummy_dyn_tailq has been registered by test_tailq_create */ 101 [ + - ]: 1 : if (d_head == NULL || 102 [ - + ]: 1 : d_head != RTE_TAILQ_CAST(rte_dummy_dyn_tailq.head, rte_tailq_entry_head)) 103 : 0 : do_return("Error with tailq lookup\n"); 104 : : 105 [ + + ]: 2 : TAILQ_FOREACH(d_ptr, d_head, next) 106 [ - + ]: 1 : if (d_ptr != &d_dyn_elem) 107 : 0 : do_return("Error with tailq returned from lookup - " 108 : : "expected element not found\n"); 109 : : 110 : : /* now try a bad/error lookup */ 111 : 1 : d_head = RTE_TAILQ_LOOKUP("coucou", rte_tailq_entry_head); 112 [ - + ]: 1 : if (d_head != NULL) 113 : 0 : do_return("Error, lookup does not return NULL for bad tailq name\n"); 114 : : 115 : : return 0; 116 : : } 117 : : 118 : : static int 119 : 1 : test_tailq(void) 120 : : { 121 : : int ret = 0; 122 : 1 : ret |= test_tailq_early(); 123 : 1 : ret |= test_tailq_create(); 124 : 1 : ret |= test_tailq_lookup(); 125 : 1 : return ret; 126 : : } 127 : : 128 : 251 : REGISTER_FAST_TEST(tailq_autotest, true, true, test_tailq);