t_atomic.c revision f02e14c74f8ba58af09a399a8f6d75dd1bb95f7a
/*
* Copyright (C) 2011, 2013 Internet Systems Consortium, Inc. ("ISC")
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include <config.h>
#include <ctype.h>
#include <stdlib.h>
char *progname;
#if defined(ISC_PLATFORM_HAVEXADD) || defined(ISC_PLATFORM_HAVEXADDQ) || \
defined(ISC_PLATFORM_HAVEATOMICSTORE) || \
defined(ISC_PLATFORM_HAVEATOMICSTOREQ)
static void
setup(void) {
}
static void
teardown(void) {
}
#endif
#define TASKS 32
#define ITERATIONS 10000
#define COUNTS_PER_ITERATION 1000
typedef struct {
} counter_t;
#if defined(ISC_PLATFORM_HAVEXADD)
static isc_int32_t counter_32;
static void
int i;
for (i = 0 ; i < COUNTS_PER_ITERATION ; i++) {
}
} else {
isc_event_free(&ev);
}
}
static void
test_atomic_xadd() {
int test_result;
int i;
"ensure that isc_atomic_xadd() works.");
setup();
counter_32 = 0;
/*
* Create our tasks, and allocate an event to get the counters going.
*/
for (i = 0 ; i < TASKS ; i++) {
}
teardown();
if (counter_32 != EXPECTED_COUNT_32)
counter_32 = 0;
}
#endif
#if defined(ISC_PLATFORM_HAVEXADDQ)
static isc_int64_t counter_64;
static void
int i;
for (i = 0 ; i < COUNTS_PER_ITERATION ; i++) {
}
} else {
isc_event_free(&ev);
}
}
static void
int test_result;
int i;
"ensure that isc_atomic_xaddq() works.");
setup();
counter_64 = 0;
/*
* Create our tasks, and allocate an event to get the counters going.
*/
for (i = 0 ; i < TASKS ; i++) {
}
teardown();
if (counter_64 != EXPECTED_COUNT_64)
counter_64 = 0;
}
#endif
#ifdef ISC_PLATFORM_HAVEATOMICSTORE
static isc_int32_t store_32;
static void
int i;
isc_uint8_t r;
r = random() % 256;
for (i = 0 ; i < COUNTS_PER_ITERATION ; i++) {
}
} else {
isc_event_free(&ev);
}
}
static void
int test_result;
int i;
isc_uint8_t r;
"ensure that isc_atomic_store() works.");
setup();
store_32 = 0;
/*
* Create our tasks, and allocate an event to get the counters
* going.
*/
for (i = 0 ; i < TASKS ; i++) {
&counters[i],
sizeof(struct isc_event));
}
teardown();
r = store_32 & 0xff;
t_info("32-bit store 0x%x, expected 0x%x\n",
store_32 = 0;
}
#endif
#if defined(ISC_PLATFORM_HAVEATOMICSTOREQ)
static isc_int64_t store_64;
static void
int i;
isc_uint8_t r;
r = random() % 256;
((isc_uint64_t) r << 16) |
((isc_uint64_t) r << 8) |
(isc_uint64_t) r);
for (i = 0 ; i < COUNTS_PER_ITERATION ; i++) {
}
} else {
isc_event_free(&ev);
}
}
static void
int test_result;
int i;
isc_uint8_t r;
"ensure that isc_atomic_storeq() works.");
setup();
store_64 = 0;
/*
* Create our tasks, and allocate an event to get the counters going.
*/
for (i = 0 ; i < TASKS ; i++) {
}
teardown();
r = store_64 & 0xff;
((isc_uint64_t) r << 16) |
((isc_uint64_t) r << 8) |
(isc_uint64_t) r);
store_64 = 0;
}
#endif /* ISC_PLATFORM_HAVEATOMICSTOREQ */
testspec_t T_testlist[] = {
#if defined(ISC_PLATFORM_HAVEXADD)
#endif
#if defined(ISC_PLATFORM_HAVEXADDQ)
#endif
#ifdef ISC_PLATFORM_HAVEATOMICSTORE
#endif
#if defined(ISC_PLATFORM_HAVEXADDQ)
#endif
};
#ifdef WIN32
int
}
#endif