]>
git.proxmox.com Git - mirror_ovs.git/blob - tests/test-atomic.c
2 * Copyright (c) 2013 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "ovs-atomic.h"
22 #define TEST_ATOMIC_TYPE(ATOMIC_TYPE, BASE_TYPE) \
24 ATOMIC_TYPE x = ATOMIC_VAR_INIT(1); \
25 BASE_TYPE value, orig; \
27 atomic_read(&x, &value); \
28 ovs_assert(value == 1); \
30 atomic_store(&x, 2); \
31 atomic_read(&x, &value); \
32 ovs_assert(value == 2); \
35 atomic_read(&x, &value); \
36 ovs_assert(value == 3); \
38 atomic_add(&x, 1, &orig); \
39 ovs_assert(orig == 3); \
40 atomic_read(&x, &value); \
41 ovs_assert(value == 4); \
43 atomic_sub(&x, 2, &orig); \
44 ovs_assert(orig == 4); \
45 atomic_read(&x, &value); \
46 ovs_assert(value == 2); \
48 atomic_or(&x, 6, &orig); \
49 ovs_assert(orig == 2); \
50 atomic_read(&x, &value); \
51 ovs_assert(value == 6); \
53 atomic_and(&x, 10, &orig); \
54 ovs_assert(orig == 6); \
55 atomic_read(&x, &value); \
56 ovs_assert(value == 2); \
58 atomic_xor(&x, 10, &orig); \
59 ovs_assert(orig == 2); \
60 atomic_read(&x, &value); \
61 ovs_assert(value == 8); \
67 TEST_ATOMIC_TYPE(atomic_char
, char);
68 TEST_ATOMIC_TYPE(atomic_uchar
, unsigned char);
69 TEST_ATOMIC_TYPE(atomic_schar
, signed char);
70 TEST_ATOMIC_TYPE(atomic_short
, short);
71 TEST_ATOMIC_TYPE(atomic_ushort
, unsigned short);
72 TEST_ATOMIC_TYPE(atomic_int
, int);
73 TEST_ATOMIC_TYPE(atomic_uint
, unsigned int);
74 TEST_ATOMIC_TYPE(atomic_long
, long int);
75 TEST_ATOMIC_TYPE(atomic_ulong
, unsigned long int);
76 TEST_ATOMIC_TYPE(atomic_llong
, long long int);
77 TEST_ATOMIC_TYPE(atomic_ullong
, unsigned long long int);
78 TEST_ATOMIC_TYPE(atomic_size_t
, size_t);
79 TEST_ATOMIC_TYPE(atomic_ptrdiff_t
, ptrdiff_t);
80 TEST_ATOMIC_TYPE(atomic_intmax_t
, intmax_t);
81 TEST_ATOMIC_TYPE(atomic_uintmax_t
, uintmax_t);
82 TEST_ATOMIC_TYPE(atomic_intptr_t
, intptr_t);
83 TEST_ATOMIC_TYPE(atomic_uintptr_t
, uintptr_t);
84 TEST_ATOMIC_TYPE(atomic_uint8_t
, uint8_t);
85 TEST_ATOMIC_TYPE(atomic_int8_t
, int8_t);
86 TEST_ATOMIC_TYPE(atomic_uint16_t
, uint16_t);
87 TEST_ATOMIC_TYPE(atomic_int16_t
, int16_t);
88 TEST_ATOMIC_TYPE(atomic_uint32_t
, uint32_t);
89 TEST_ATOMIC_TYPE(atomic_int32_t
, int32_t);
90 TEST_ATOMIC_TYPE(atomic_uint64_t
, uint64_t);
91 TEST_ATOMIC_TYPE(atomic_int64_t
, int64_t);