2013-06-28 15:54:40 -07:00
|
|
|
/*
|
2014-03-11 13:16:54 -07:00
|
|
|
* Copyright (c) 2013, 2014 Nicira, Inc.
|
2013-06-28 15:54:40 -07:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2014-10-29 11:34:40 -07:00
|
|
|
#undef NDEBUG
|
2015-04-07 17:34:27 -07:00
|
|
|
#include "fatal-signal.h"
|
2013-06-28 15:54:40 -07:00
|
|
|
#include "ovs-atomic.h"
|
2014-04-01 00:47:01 -07:00
|
|
|
#include "ovstest.h"
|
2014-08-05 13:51:19 -07:00
|
|
|
#include "ovs-thread.h"
|
2015-01-13 16:39:46 -08:00
|
|
|
#include "timeval.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "openvswitch/vlog.h"
|
|
|
|
|
|
|
|
VLOG_DEFINE_THIS_MODULE(test_atomic);
|
2013-06-28 15:54:40 -07:00
|
|
|
|
|
|
|
#define TEST_ATOMIC_TYPE(ATOMIC_TYPE, BASE_TYPE) \
|
|
|
|
{ \
|
2023-02-28 18:30:56 -08:00
|
|
|
ATOMIC_TYPE x = 1; \
|
2013-07-15 14:14:05 -07:00
|
|
|
BASE_TYPE value, orig; \
|
2013-06-28 15:54:40 -07:00
|
|
|
\
|
|
|
|
atomic_read(&x, &value); \
|
|
|
|
ovs_assert(value == 1); \
|
|
|
|
\
|
|
|
|
atomic_store(&x, 2); \
|
|
|
|
atomic_read(&x, &value); \
|
|
|
|
ovs_assert(value == 2); \
|
|
|
|
\
|
|
|
|
atomic_init(&x, 3); \
|
|
|
|
atomic_read(&x, &value); \
|
|
|
|
ovs_assert(value == 3); \
|
2013-07-15 14:14:05 -07:00
|
|
|
\
|
|
|
|
atomic_add(&x, 1, &orig); \
|
|
|
|
ovs_assert(orig == 3); \
|
|
|
|
atomic_read(&x, &value); \
|
|
|
|
ovs_assert(value == 4); \
|
|
|
|
\
|
|
|
|
atomic_sub(&x, 2, &orig); \
|
|
|
|
ovs_assert(orig == 4); \
|
|
|
|
atomic_read(&x, &value); \
|
|
|
|
ovs_assert(value == 2); \
|
|
|
|
\
|
|
|
|
atomic_or(&x, 6, &orig); \
|
|
|
|
ovs_assert(orig == 2); \
|
|
|
|
atomic_read(&x, &value); \
|
|
|
|
ovs_assert(value == 6); \
|
|
|
|
\
|
|
|
|
atomic_and(&x, 10, &orig); \
|
|
|
|
ovs_assert(orig == 6); \
|
|
|
|
atomic_read(&x, &value); \
|
|
|
|
ovs_assert(value == 2); \
|
|
|
|
\
|
|
|
|
atomic_xor(&x, 10, &orig); \
|
|
|
|
ovs_assert(orig == 2); \
|
|
|
|
atomic_read(&x, &value); \
|
|
|
|
ovs_assert(value == 8); \
|
2013-06-28 15:54:40 -07:00
|
|
|
}
|
|
|
|
|
2014-08-05 13:51:19 -07:00
|
|
|
#define TEST_ATOMIC_TYPE_EXPLICIT(ATOMIC_TYPE, BASE_TYPE, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW) \
|
|
|
|
{ \
|
2023-02-28 18:30:56 -08:00
|
|
|
ATOMIC_TYPE x = 1; \
|
2014-08-05 13:51:19 -07:00
|
|
|
BASE_TYPE value, orig; \
|
|
|
|
\
|
|
|
|
atomic_read_explicit(&x, &value, ORDER_READ); \
|
|
|
|
ovs_assert(value == 1); \
|
|
|
|
\
|
|
|
|
atomic_store_explicit(&x, 2, ORDER_STORE); \
|
|
|
|
atomic_read_explicit(&x, &value, ORDER_READ); \
|
|
|
|
ovs_assert(value == 2); \
|
|
|
|
\
|
|
|
|
atomic_init(&x, 3); \
|
|
|
|
atomic_read_explicit(&x, &value, ORDER_READ); \
|
|
|
|
ovs_assert(value == 3); \
|
|
|
|
\
|
|
|
|
atomic_add_explicit(&x, 1, &orig, ORDER_RMW); \
|
|
|
|
ovs_assert(orig == 3); \
|
|
|
|
atomic_read_explicit(&x, &value, ORDER_READ); \
|
|
|
|
ovs_assert(value == 4); \
|
|
|
|
\
|
|
|
|
atomic_sub_explicit(&x, 2, &orig, ORDER_RMW); \
|
|
|
|
ovs_assert(orig == 4); \
|
|
|
|
atomic_read_explicit(&x, &value, ORDER_READ); \
|
|
|
|
ovs_assert(value == 2); \
|
|
|
|
\
|
|
|
|
atomic_or_explicit(&x, 6, &orig, ORDER_RMW); \
|
|
|
|
ovs_assert(orig == 2); \
|
|
|
|
atomic_read_explicit(&x, &value, ORDER_READ); \
|
|
|
|
ovs_assert(value == 6); \
|
|
|
|
\
|
|
|
|
atomic_and_explicit(&x, 10, &orig, ORDER_RMW); \
|
|
|
|
ovs_assert(orig == 6); \
|
|
|
|
atomic_read_explicit(&x, &value, ORDER_READ); \
|
|
|
|
ovs_assert(value == 2); \
|
|
|
|
\
|
|
|
|
atomic_xor_explicit(&x, 10, &orig, ORDER_RMW); \
|
|
|
|
ovs_assert(orig == 2); \
|
|
|
|
atomic_read_explicit(&x, &value, ORDER_READ); \
|
|
|
|
ovs_assert(value == 8); \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define TEST_ATOMIC_ORDER(ORDER_READ, ORDER_STORE, ORDER_RMW) \
|
|
|
|
{ \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_char, char, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_uchar, unsigned char, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_schar, signed char, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_short, short, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_ushort, unsigned short, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_int, int, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_uint, unsigned int, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_long, long int, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_ulong, unsigned long int, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_llong, long long int, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_ullong, unsigned long long int, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_size_t, size_t, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_ptrdiff_t, ptrdiff_t, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_intmax_t, intmax_t, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_uintmax_t, uintmax_t, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_intptr_t, intptr_t, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_uintptr_t, uintptr_t, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_uint8_t, uint8_t, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_int8_t, int8_t, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_uint16_t, uint16_t, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_int16_t, int16_t, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_uint32_t, uint32_t, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
TEST_ATOMIC_TYPE_EXPLICIT(atomic_int32_t, int32_t, \
|
|
|
|
ORDER_READ, ORDER_STORE, ORDER_RMW); \
|
|
|
|
}
|
|
|
|
|
2013-07-31 16:09:11 -07:00
|
|
|
static void
|
|
|
|
test_atomic_flag(void)
|
|
|
|
{
|
|
|
|
atomic_flag flag = ATOMIC_FLAG_INIT;
|
|
|
|
ovs_assert(atomic_flag_test_and_set(&flag) == false);
|
2013-08-17 16:40:11 -04:00
|
|
|
ovs_assert(atomic_flag_test_and_set(&flag) == true);
|
2013-07-31 16:09:11 -07:00
|
|
|
atomic_flag_clear(&flag);
|
2013-08-17 16:40:11 -04:00
|
|
|
ovs_assert(atomic_flag_test_and_set(&flag) == false);
|
2013-07-31 16:09:11 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 01:35:11 +00:00
|
|
|
static uint32_t a;
|
2014-08-05 13:51:19 -07:00
|
|
|
|
|
|
|
struct atomic_aux {
|
2014-10-02 09:12:11 -07:00
|
|
|
ATOMIC(uint64_t) count;
|
2014-08-05 13:51:19 -07:00
|
|
|
uint32_t b;
|
|
|
|
ATOMIC(uint32_t *) data;
|
2014-10-02 09:12:11 -07:00
|
|
|
ATOMIC(uint64_t) data64;
|
2014-08-05 13:51:19 -07:00
|
|
|
};
|
|
|
|
|
2023-02-28 18:30:56 -08:00
|
|
|
static ATOMIC(struct atomic_aux *) paux = NULL;
|
2014-08-05 13:51:19 -07:00
|
|
|
static struct atomic_aux *auxes = NULL;
|
|
|
|
|
|
|
|
#define ATOMIC_ITEM_COUNT 1000000
|
2015-10-14 15:21:49 +00:00
|
|
|
#define DURATION 5000
|
2014-08-05 13:51:19 -07:00
|
|
|
|
|
|
|
static void *
|
|
|
|
atomic_consumer(void * arg1 OVS_UNUSED)
|
|
|
|
{
|
|
|
|
struct atomic_aux *old_aux = NULL;
|
2014-10-02 09:12:11 -07:00
|
|
|
uint64_t count;
|
2015-10-14 15:21:49 +00:00
|
|
|
long long int stop_time = time_msec() + DURATION;
|
2014-08-05 13:51:19 -07:00
|
|
|
|
|
|
|
do {
|
|
|
|
struct atomic_aux *aux;
|
|
|
|
uint32_t b;
|
|
|
|
|
|
|
|
/* Wait for a new item. We may not be fast enough to process every
|
|
|
|
* item, but we are guaranteed to see the last one. */
|
|
|
|
do {
|
|
|
|
atomic_read_explicit(&paux, &aux, memory_order_consume);
|
|
|
|
} while (aux == old_aux);
|
|
|
|
|
|
|
|
b = aux->b;
|
|
|
|
atomic_read_explicit(&aux->count, &count, memory_order_relaxed);
|
|
|
|
ovs_assert(b == count + 42);
|
|
|
|
|
|
|
|
old_aux = aux;
|
2015-01-13 16:39:46 -08:00
|
|
|
} while (count < ATOMIC_ITEM_COUNT - 1 && time_msec() < stop_time);
|
|
|
|
|
|
|
|
if (time_msec() >= stop_time) {
|
|
|
|
if (count < 10) {
|
|
|
|
VLOG_WARN("atomic_consumer test stopped due to excessive runtime. "
|
|
|
|
"Count = %"PRIu64, count);
|
|
|
|
}
|
|
|
|
}
|
2014-08-05 13:51:19 -07:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
atomic_producer(void * arg1 OVS_UNUSED)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < ATOMIC_ITEM_COUNT; i++) {
|
|
|
|
struct atomic_aux *aux = &auxes[i];
|
|
|
|
|
2023-02-28 18:30:56 -08:00
|
|
|
aux->count = i;
|
2014-08-05 13:51:19 -07:00
|
|
|
aux->b = i + 42;
|
|
|
|
|
|
|
|
/* Publish the new item. */
|
|
|
|
atomic_store_explicit(&paux, aux, memory_order_release);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-04-01 00:47:01 -07:00
|
|
|
|
|
|
|
static void
|
2014-08-05 13:51:19 -07:00
|
|
|
test_cons_rel(void)
|
|
|
|
{
|
|
|
|
pthread_t reader, writer;
|
|
|
|
|
|
|
|
atomic_init(&paux, NULL);
|
|
|
|
|
|
|
|
auxes = xmalloc(sizeof *auxes * ATOMIC_ITEM_COUNT);
|
|
|
|
|
|
|
|
reader = ovs_thread_create("consumer", atomic_consumer, NULL);
|
|
|
|
writer = ovs_thread_create("producer", atomic_producer, NULL);
|
|
|
|
|
|
|
|
xpthread_join(reader, NULL);
|
|
|
|
xpthread_join(writer, NULL);
|
|
|
|
|
|
|
|
free(auxes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
atomic_reader(void *aux_)
|
|
|
|
{
|
|
|
|
struct atomic_aux *aux = aux_;
|
2014-10-02 09:12:11 -07:00
|
|
|
uint64_t count;
|
|
|
|
uint64_t data;
|
2015-01-13 16:39:46 -08:00
|
|
|
long long int now = time_msec();
|
2015-10-14 15:21:49 +00:00
|
|
|
long long int stop_time = now + DURATION;
|
2014-08-05 13:51:19 -07:00
|
|
|
|
|
|
|
do {
|
|
|
|
/* Non-synchronized add. */
|
|
|
|
atomic_add_explicit(&aux->count, 1, &count, memory_order_relaxed);
|
|
|
|
|
|
|
|
do {
|
2014-10-02 09:12:11 -07:00
|
|
|
atomic_read_explicit(&aux->data64, &data, memory_order_acquire);
|
2015-01-13 16:39:46 -08:00
|
|
|
} while (!data && (now = time_msec()) < stop_time);
|
|
|
|
|
|
|
|
if (now >= stop_time) {
|
|
|
|
if (count < 10) {
|
|
|
|
VLOG_WARN("atomic_reader test stopped due to excessive "
|
|
|
|
"runtime. Count = %"PRIu64, count);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-08-05 13:51:19 -07:00
|
|
|
|
2014-10-02 09:12:11 -07:00
|
|
|
ovs_assert(data == a && data == aux->b && a == aux->b);
|
2014-08-05 13:51:19 -07:00
|
|
|
|
|
|
|
atomic_read_explicit(&aux->count, &count, memory_order_relaxed);
|
|
|
|
|
2014-10-02 09:12:11 -07:00
|
|
|
ovs_assert(count == 2 * a && count == 2 * aux->b && count == 2 * data);
|
2014-08-05 13:51:19 -07:00
|
|
|
|
2014-10-02 09:12:11 -07:00
|
|
|
atomic_store_explicit(&aux->data64, UINT64_C(0), memory_order_release);
|
2014-08-05 13:51:19 -07:00
|
|
|
} while (count < 2 * ATOMIC_ITEM_COUNT);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
atomic_writer(void *aux_)
|
|
|
|
{
|
|
|
|
struct atomic_aux *aux = aux_;
|
2014-10-02 09:12:11 -07:00
|
|
|
uint64_t old_count;
|
|
|
|
uint64_t data;
|
2014-08-05 13:51:19 -07:00
|
|
|
size_t i;
|
2015-01-13 16:39:46 -08:00
|
|
|
long long int now = time_msec();
|
2015-10-14 15:21:49 +00:00
|
|
|
long long int stop_time = now + DURATION;
|
2014-08-05 13:51:19 -07:00
|
|
|
|
|
|
|
for (i = 0; i < ATOMIC_ITEM_COUNT; i++) {
|
|
|
|
/* Wait for the reader to be done with the data. */
|
|
|
|
do {
|
2014-10-02 09:12:11 -07:00
|
|
|
atomic_read_explicit(&aux->data64, &data, memory_order_acquire);
|
2015-01-13 16:39:46 -08:00
|
|
|
} while (data && (now = time_msec()) < stop_time);
|
|
|
|
|
|
|
|
if (now >= stop_time) {
|
|
|
|
if (i < 10) {
|
|
|
|
VLOG_WARN("atomic_writer test stopped due to excessive "
|
|
|
|
"runtime, Count = %"PRIuSIZE, i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-08-05 13:51:19 -07:00
|
|
|
|
|
|
|
a = i + 1;
|
|
|
|
atomic_add_explicit(&aux->count, 1, &old_count, memory_order_relaxed);
|
|
|
|
aux->b++;
|
2014-10-02 09:12:11 -07:00
|
|
|
atomic_store_explicit(&aux->data64,
|
|
|
|
(i & 1) ? (uint64_t)aux->b : a, memory_order_release);
|
2014-08-05 13:51:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_acq_rel(void)
|
|
|
|
{
|
|
|
|
pthread_t reader, writer;
|
|
|
|
struct atomic_aux *aux = xmalloc(sizeof *aux);
|
|
|
|
|
|
|
|
a = 0;
|
|
|
|
aux->b = 0;
|
|
|
|
|
2023-02-28 18:30:56 -08:00
|
|
|
aux->count = 0;
|
2014-08-05 13:51:19 -07:00
|
|
|
atomic_init(&aux->data, NULL);
|
2023-02-28 18:30:56 -08:00
|
|
|
aux->data64 = 0;
|
2014-08-05 13:51:19 -07:00
|
|
|
|
|
|
|
reader = ovs_thread_create("reader", atomic_reader, aux);
|
|
|
|
writer = ovs_thread_create("writer", atomic_writer, aux);
|
|
|
|
|
|
|
|
xpthread_join(reader, NULL);
|
|
|
|
xpthread_join(writer, NULL);
|
|
|
|
free(aux);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_atomic_plain(void)
|
2013-06-28 15:54:40 -07:00
|
|
|
{
|
|
|
|
TEST_ATOMIC_TYPE(atomic_char, char);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_uchar, unsigned char);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_schar, signed char);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_short, short);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_ushort, unsigned short);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_int, int);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_uint, unsigned int);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_long, long int);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_ulong, unsigned long int);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_llong, long long int);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_ullong, unsigned long long int);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_size_t, size_t);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_ptrdiff_t, ptrdiff_t);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_intmax_t, intmax_t);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_uintmax_t, uintmax_t);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_intptr_t, intptr_t);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_uintptr_t, uintptr_t);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_uint8_t, uint8_t);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_int8_t, int8_t);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_uint16_t, uint16_t);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_int16_t, int16_t);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_uint32_t, uint32_t);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_int32_t, int32_t);
|
2017-09-29 10:10:27 -07:00
|
|
|
TEST_ATOMIC_TYPE(atomic_uint64_t, uint64_t);
|
|
|
|
TEST_ATOMIC_TYPE(atomic_int64_t, int64_t);
|
2014-08-05 13:51:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_atomic_relaxed(void)
|
|
|
|
{
|
|
|
|
TEST_ATOMIC_ORDER(memory_order_relaxed, memory_order_relaxed,
|
|
|
|
memory_order_relaxed);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_atomic_consume(void)
|
|
|
|
{
|
|
|
|
TEST_ATOMIC_ORDER(memory_order_consume, memory_order_release,
|
|
|
|
memory_order_release);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_atomic_acquire(void)
|
|
|
|
{
|
|
|
|
TEST_ATOMIC_ORDER(memory_order_acquire, memory_order_release,
|
|
|
|
memory_order_release);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_atomic_acq_rel(void)
|
|
|
|
{
|
|
|
|
TEST_ATOMIC_ORDER(memory_order_acquire, memory_order_release,
|
|
|
|
memory_order_acq_rel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_atomic_seq_cst(void)
|
|
|
|
{
|
|
|
|
TEST_ATOMIC_ORDER(memory_order_seq_cst, memory_order_seq_cst,
|
|
|
|
memory_order_seq_cst);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_atomic_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
|
|
|
|
{
|
2015-04-07 17:34:27 -07:00
|
|
|
fatal_signal_init();
|
2014-08-05 13:51:19 -07:00
|
|
|
test_atomic_plain();
|
|
|
|
test_atomic_relaxed();
|
|
|
|
test_atomic_consume();
|
|
|
|
test_atomic_acquire();
|
|
|
|
test_atomic_acq_rel();
|
|
|
|
test_atomic_seq_cst();
|
2013-06-28 15:54:40 -07:00
|
|
|
|
2013-07-31 16:09:11 -07:00
|
|
|
test_atomic_flag();
|
2014-08-05 13:51:19 -07:00
|
|
|
|
|
|
|
test_acq_rel();
|
|
|
|
test_cons_rel();
|
2013-06-28 15:54:40 -07:00
|
|
|
}
|
2014-04-01 00:47:01 -07:00
|
|
|
|
|
|
|
OVSTEST_REGISTER("test-atomic", test_atomic_main);
|