netdev-bsd: Fix a build error.
[sliver-openvswitch.git] / tests / test-atomic.c
1 /*
2  * Copyright (c) 2013 Nicira, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <config.h>
18
19 #include "ovs-atomic.h"
20 #include "util.h"
21
22 #define TEST_ATOMIC_TYPE(ATOMIC_TYPE, BASE_TYPE)        \
23     {                                                   \
24         ATOMIC_TYPE x = ATOMIC_VAR_INIT(1);             \
25         BASE_TYPE value;                                \
26                                                         \
27         atomic_read(&x, &value);                        \
28         ovs_assert(value == 1);                         \
29                                                         \
30         atomic_store(&x, 2);                            \
31         atomic_read(&x, &value);                        \
32         ovs_assert(value == 2);                         \
33                                                         \
34         atomic_init(&x, 3);                             \
35         atomic_read(&x, &value);                        \
36         ovs_assert(value == 3);                         \
37     }
38
39 int
40 main(void)
41 {
42     TEST_ATOMIC_TYPE(atomic_char, char);
43     TEST_ATOMIC_TYPE(atomic_uchar, unsigned char);
44     TEST_ATOMIC_TYPE(atomic_schar, signed char);
45     TEST_ATOMIC_TYPE(atomic_short, short);
46     TEST_ATOMIC_TYPE(atomic_ushort, unsigned short);
47     TEST_ATOMIC_TYPE(atomic_int, int);
48     TEST_ATOMIC_TYPE(atomic_uint, unsigned int);
49     TEST_ATOMIC_TYPE(atomic_long, long int);
50     TEST_ATOMIC_TYPE(atomic_ulong, unsigned long int);
51     TEST_ATOMIC_TYPE(atomic_llong, long long int);
52     TEST_ATOMIC_TYPE(atomic_ullong, unsigned long long int);
53     TEST_ATOMIC_TYPE(atomic_size_t, size_t);
54     TEST_ATOMIC_TYPE(atomic_ptrdiff_t, ptrdiff_t);
55     TEST_ATOMIC_TYPE(atomic_intmax_t, intmax_t);
56     TEST_ATOMIC_TYPE(atomic_uintmax_t, uintmax_t);
57     TEST_ATOMIC_TYPE(atomic_intptr_t, intptr_t);
58     TEST_ATOMIC_TYPE(atomic_uintptr_t, uintptr_t);
59     TEST_ATOMIC_TYPE(atomic_uint8_t, uint8_t);
60     TEST_ATOMIC_TYPE(atomic_int8_t, int8_t);
61     TEST_ATOMIC_TYPE(atomic_uint16_t, uint16_t);
62     TEST_ATOMIC_TYPE(atomic_int16_t, int16_t);
63     TEST_ATOMIC_TYPE(atomic_uint32_t, uint32_t);
64     TEST_ATOMIC_TYPE(atomic_int32_t, int32_t);
65     TEST_ATOMIC_TYPE(atomic_uint64_t, uint64_t);
66     TEST_ATOMIC_TYPE(atomic_int64_t, int64_t);
67
68     return 0;
69 }