Home | History | Annotate | Line # | Download | only in unit
      1 // SPDX-FileCopyrightText: 2021 Simon Marchi <simon.marchi (at) efficios.com>
      2 //
      3 // SPDX-License-Identifier: GPL-2.0-or-later
      4 
      5 /*
      6  * This file is meant to verify that headers are compatible with both C and
      7  * C++.  It includes all exported headers and is compiled as C and C++ source.
      8  */
      9 
     10 #ifndef DYNAMIC_LINK_TEST
     11 # define _LGPL_SOURCE
     12 #endif
     13 
     14 #include <urcu/arch.h>
     15 #include <urcu/call-rcu.h>
     16 #include <urcu/cds.h>
     17 #include <urcu/compiler.h>
     18 #include <urcu/debug.h>
     19 #include <urcu/defer.h>
     20 #include <urcu/flavor.h>
     21 #include <urcu/futex.h>
     22 #include <urcu/hlist.h>
     23 #include <urcu/lfstack.h>
     24 #include <urcu/list.h>
     25 #include <urcu/pointer.h>
     26 #include <urcu/rcuhlist.h>
     27 #include <urcu/rculfhash.h>
     28 #include <urcu/rculfqueue.h>
     29 #include <urcu/rculfstack.h>
     30 #include <urcu/rculist.h>
     31 #include <urcu/ref.h>
     32 #include <urcu/syscall-compat.h>
     33 #include <urcu/system.h>
     34 #include <urcu/tls-compat.h>
     35 #include <urcu/uatomic.h>
     36 #include <urcu/urcu-bp.h>
     37 #include <urcu/urcu.h>
     38 #include <urcu/urcu-mb.h>
     39 #include <urcu/urcu-memb.h>
     40 #include <urcu/urcu-qsbr.h>
     41 #include <urcu/wfcqueue.h>
     42 #include <urcu/wfqueue.h>
     43 #include <urcu/wfstack.h>
     44 
     45 #include "tap.h"
     46 
     47 struct my_tls_struct {
     48 	int int1;
     49 	char char1;
     50 	void *void1;
     51 };
     52 
     53 static DEFINE_URCU_TLS(int, my_tls_int);
     54 static DEFINE_URCU_TLS(struct my_tls_struct, my_tls_struct);
     55 
     56 static void test_lfstack(void)
     57 {
     58 	struct cds_lfs_stack s;
     59 
     60 	cds_lfs_init(&s);
     61 	ok(cds_lfs_empty(&s), "cds_lfs_empty");
     62 }
     63 
     64 static void test_wfstack(void)
     65 {
     66 	struct cds_wfs_stack s;
     67 
     68 	cds_wfs_init(&s);
     69 	ok(cds_wfs_empty(&s), "cds_lfs_empty");
     70 }
     71 
     72 static void test_wfcqueue(void)
     73 {
     74 	struct cds_wfcq_head head;
     75 	struct cds_wfcq_tail tail;
     76 
     77 	cds_wfcq_init(&head, &tail);
     78 	ok(cds_wfcq_empty(&head, &tail), "cds_wfcq_empty");
     79 }
     80 
     81 static
     82 void test_build_cds_list_head_init(void)
     83 {
     84 	/* Test that the CDS_LIST_HEAD_INIT macro builds correctly.  */
     85 	struct struct_with_list {
     86 		struct cds_list_head head;
     87 	};
     88 
     89 	struct struct_with_list list = {
     90 		.head = CDS_LIST_HEAD_INIT(list.head),
     91 	};
     92 }
     93 
     94 static
     95 void test_urcu_tls(void)
     96 {
     97 	URCU_TLS(my_tls_int) = 1;
     98 	URCU_TLS(my_tls_struct).int1 = 1;
     99 	URCU_TLS(my_tls_struct).char1 = 'a';
    100 	URCU_TLS(my_tls_struct).void1 = NULL;
    101 }
    102 
    103 struct an_opaque_struct;
    104 struct a_clear_struct
    105 {
    106 	int x;
    107 };
    108 
    109 static
    110 void test_build_rcu_dereference(void)
    111 {
    112 	static struct an_opaque_struct *opaque = NULL;
    113 	static struct an_opaque_struct *const opaque_const = NULL;
    114 	static struct a_clear_struct *clear = NULL;
    115 	static struct a_clear_struct *const clear_const = NULL;
    116 
    117 	(void) rcu_dereference(opaque);
    118 	(void) rcu_dereference(opaque_const);
    119 	(void) rcu_dereference(clear);
    120 	(void) rcu_dereference(clear_const);
    121 }
    122 
    123 int main(void)
    124 {
    125 	plan_tests(3);
    126 
    127 	test_lfstack();
    128 	test_wfstack();
    129 	test_wfcqueue();
    130 	test_build_cds_list_head_init();
    131 	test_urcu_tls();
    132 	test_build_rcu_dereference();
    133 
    134 	return exit_status();
    135 }
    136