t_atomic.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 2011, 2013, 2015, 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#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