| 1 | /* |
| 2 | * Copyright 2021 Simon Marchi <simon.marchi@efficios.com> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | */ |
| 18 | |
| 19 | /* |
| 20 | * This file is meant to verify that headers are compatible with both C and |
| 21 | * C++. It includes all exported headers and is compiled as C and C++ source. |
| 22 | */ |
| 23 | |
| 24 | #ifndef DYNAMIC_LINK_TEST |
| 25 | # define _LGPL_SOURCE |
| 26 | #endif |
| 27 | |
| 28 | #include <urcu/arch.h> |
| 29 | #include <urcu/call-rcu.h> |
| 30 | #include <urcu/cds.h> |
| 31 | #include <urcu/compiler.h> |
| 32 | #include <urcu/debug.h> |
| 33 | #include <urcu/defer.h> |
| 34 | #include <urcu/flavor.h> |
| 35 | #include <urcu/futex.h> |
| 36 | #include <urcu/hlist.h> |
| 37 | #include <urcu/lfstack.h> |
| 38 | #include <urcu/list.h> |
| 39 | #include <urcu/pointer.h> |
| 40 | #include <urcu/rcuhlist.h> |
| 41 | #include <urcu/rculfhash.h> |
| 42 | #include <urcu/rculfqueue.h> |
| 43 | #include <urcu/rculfstack.h> |
| 44 | #include <urcu/rculist.h> |
| 45 | #include <urcu/ref.h> |
| 46 | #include <urcu/syscall-compat.h> |
| 47 | #include <urcu/system.h> |
| 48 | #include <urcu/tls-compat.h> |
| 49 | #include <urcu/uatomic.h> |
| 50 | #include <urcu/urcu-bp.h> |
| 51 | #include <urcu/urcu.h> |
| 52 | #include <urcu/urcu-mb.h> |
| 53 | #include <urcu/urcu-memb.h> |
| 54 | #include <urcu/urcu-qsbr.h> |
| 55 | #include <urcu/urcu-signal.h> |
| 56 | #include <urcu/wfcqueue.h> |
| 57 | #include <urcu/wfqueue.h> |
| 58 | #include <urcu/wfstack.h> |
| 59 | |
| 60 | #include "tap.h" |
| 61 | |
| 62 | struct my_tls_struct { |
| 63 | int int1; |
| 64 | char char1; |
| 65 | void *void1; |
| 66 | }; |
| 67 | |
| 68 | static DEFINE_URCU_TLS(int, my_tls_int); |
| 69 | static DEFINE_URCU_TLS(struct my_tls_struct, my_tls_struct); |
| 70 | |
| 71 | static void test_lfstack(void) |
| 72 | { |
| 73 | struct cds_lfs_stack s; |
| 74 | |
| 75 | cds_lfs_init(&s); |
| 76 | ok(cds_lfs_empty(&s), "cds_lfs_empty"); |
| 77 | } |
| 78 | |
| 79 | static void test_wfstack(void) |
| 80 | { |
| 81 | struct cds_wfs_stack s; |
| 82 | |
| 83 | cds_wfs_init(&s); |
| 84 | ok(cds_wfs_empty(&s), "cds_lfs_empty"); |
| 85 | } |
| 86 | |
| 87 | static void test_wfcqueue(void) |
| 88 | { |
| 89 | struct cds_wfcq_head head; |
| 90 | struct cds_wfcq_tail tail; |
| 91 | |
| 92 | cds_wfcq_init(&head, &tail); |
| 93 | ok(cds_wfcq_empty(&head, &tail), "cds_wfcq_empty"); |
| 94 | } |
| 95 | |
| 96 | static |
| 97 | void test_build_cds_list_head_init(void) |
| 98 | { |
| 99 | /* Test that the CDS_LIST_HEAD_INIT macro builds correctly. */ |
| 100 | struct struct_with_list { |
| 101 | struct cds_list_head head; |
| 102 | }; |
| 103 | |
| 104 | struct struct_with_list list = { |
| 105 | .head = CDS_LIST_HEAD_INIT(list.head), |
| 106 | }; |
| 107 | } |
| 108 | |
| 109 | static |
| 110 | void test_urcu_tls(void) |
| 111 | { |
| 112 | URCU_TLS(my_tls_int) = 1; |
| 113 | URCU_TLS(my_tls_struct).int1 = 1; |
| 114 | URCU_TLS(my_tls_struct).char1 = 'a'; |
| 115 | URCU_TLS(my_tls_struct).void1 = NULL; |
| 116 | } |
| 117 | |
| 118 | struct an_opaque_struct; |
| 119 | struct a_clear_struct |
| 120 | { |
| 121 | int x; |
| 122 | }; |
| 123 | |
| 124 | static |
| 125 | void test_build_rcu_dereference(void) |
| 126 | { |
| 127 | static struct an_opaque_struct *opaque = NULL; |
| 128 | static struct an_opaque_struct *const opaque_const = NULL; |
| 129 | static struct a_clear_struct *clear = NULL; |
| 130 | static struct a_clear_struct *const clear_const = NULL; |
| 131 | |
| 132 | rcu_dereference(opaque); |
| 133 | rcu_dereference(opaque_const); |
| 134 | rcu_dereference(clear); |
| 135 | rcu_dereference(clear_const); |
| 136 | } |
| 137 | |
| 138 | int main(void) |
| 139 | { |
| 140 | plan_tests(3); |
| 141 | |
| 142 | test_lfstack(); |
| 143 | test_wfstack(); |
| 144 | test_wfcqueue(); |
| 145 | test_build_cds_list_head_init(); |
| 146 | test_urcu_tls(); |
| 147 | test_build_rcu_dereference(); |
| 148 | |
| 149 | return exit_status(); |
| 150 | } |