Add support for MinGW32.

This primarily involved changing the configure script and adding
several utility functions to regressions/common.h for unit testing.

Signed-off-by: Samy Al Bahra <sbahra@appnexus.com>
ck_pring
David Joseph 12 years ago committed by Samy Al Bahra
parent 9152cc7cea
commit 1298a6c335

18
configure vendored

@ -249,7 +249,7 @@ fi
DCORES=2
printf "Detecting operating system......."
SYSTEM=`uname -s 2> /dev/null`
SYSTEM=`uname -s 2> /dev/null | grep "^[A-Za-z0-9]*" -o`
case "$SYSTEM" in
"SunOS")
SYSTEM=solaris
@ -278,6 +278,11 @@ case "$SYSTEM" in
DCORES=`sysctl -n hw.ncpu`
SYSTEM=darwin
;;
"MINGW32")
DCORES=2
SYSTEM=mingw32
LDFLAGS="-mthreads $LDFLAGS"
;;
*)
SYSTEM=
;;
@ -481,7 +486,14 @@ assert "$CC" "not found"
cat << EOF > .1.c
#include <stdio.h>
int main(void) {
#if defined(__clang__) && (__clang_major__ >= 4)
#if defined(_WIN32)
#if defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION >= 3)
puts("mingw32");
return (0);
#else
return (1);
#endif
#elif defined(__clang__) && (__clang_major__ >= 4)
puts("clang");
return (0);
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5110)
@ -512,7 +524,7 @@ if test "$COMPILER" = "suncc"; then
LDFLAGS="-G -z text -h libck.so.$VERSION_MAJOR $LDFLAGS"
CFLAGS="-xO5 $CFLAGS"
PTHREAD_CFLAGS="-mt -lpthread"
elif test "$COMPILER" = "gcc" || test "$COMPILER" = "clang"; then
elif test "$COMPILER" = "gcc" || test "$COMPILER" = "clang" || test "$COMPILER" = "mingw32"; then
LD=$CC
if test "$SYSTEM" = "darwin"; then
CC_WL_OPT="-install_name"

@ -279,7 +279,7 @@ main(int argc, char **argv)
}
fprintf(stderr, "Waiting...");
sleep(30);
common_sleep(30);
fprintf(stderr, "done\n");
ck_pr_store_int(&leave, 1);

@ -114,7 +114,7 @@ main(int argc, char *argv[])
}
fprintf(stderr, "done\n");
sleep(10);
common_sleep(10);
count = 0;
ck_pr_store_int(&done, 1);

@ -148,7 +148,7 @@ main(int argc, char *argv[])
}
fprintf(stderr, "done\n");
sleep(10);
common_sleep(10);
ck_pr_store_uint(&flag, 1);
fprintf(stderr, "Waiting for threads to finish acquisition regression...");

@ -99,7 +99,7 @@ queue_50_50(void *elements)
/* 50/50 enqueue-dequeue */
for(j = 0; j < element_count; j++) {
/* rand_r with thread local state should be thread safe */
if( 50 < (1+(int) (100.0*rand_r(&seed)/(RAND_MAX+1.0)))) {
if( 50 < (1+(int) (100.0*common_rand_r(&seed)/(RAND_MAX+1.0)))) {
/* This is the container for the enqueued data. */
fifo_entry = malloc(sizeof(ck_hp_fifo_entry_t));

@ -23,7 +23,6 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "../../common.h"
#include <ck_hs.h>
#include "../../../src/ck_ht_hash.h"
@ -71,6 +70,8 @@ struct hs_epoch {
ck_epoch_entry_t epoch_entry;
};
COMMON_ALARM_DECLARE_GLOBAL(alarm_event, next_stage)
static void
alarm_handler(int s)
{
@ -142,8 +143,8 @@ set_init(void)
ck_epoch_init(&epoch_hs);
ck_epoch_register(&epoch_hs, &epoch_wr);
srand48((long int)time(NULL));
if (ck_hs_init(&hs, CK_HS_MODE_OBJECT | CK_HS_MODE_SPMC, hs_hash, hs_compare, &my_allocator, 65536, lrand48()) == false) {
common_srand48((long int)time(NULL));
if (ck_hs_init(&hs, CK_HS_MODE_OBJECT | CK_HS_MODE_SPMC, hs_hash, hs_compare, &my_allocator, 65536, common_lrand48()) == false) {
perror("ck_hs_init");
exit(EXIT_FAILURE);
}
@ -204,6 +205,7 @@ set_reset(void)
return ck_hs_reset(&hs);
}
static void *
reader(void *unused)
{
@ -285,6 +287,8 @@ main(int argc, char *argv[])
pthread_t *readers;
double p_r, p_d;
COMMON_ALARM_DECLARE_LOCAL(alarm_event)
r = 20;
s = 8;
p_d = 0.5;
@ -323,6 +327,8 @@ main(int argc, char *argv[])
}
}
COMMON_ALARM_INIT(alarm_event, r)
affinerator.delta = 1;
readers = malloc(sizeof(pthread_t) * n_threads);
assert(readers != NULL);
@ -446,7 +452,7 @@ main(int argc, char *argv[])
while (ck_pr_load_int(&barrier[HS_STATE_STOP]) != n_threads)
ck_pr_stall();
ck_pr_inc_int(&barrier[HS_STATE_STOP]);
sleep(r);
common_sleep(r);
ck_pr_store_int(&state, HS_STATE_STRICT_REPLACEMENT);
while (ck_pr_load_int(&barrier[HS_STATE_GET]) != n_threads)
ck_pr_stall();
@ -457,8 +463,7 @@ main(int argc, char *argv[])
fprintf(stderr, " | Executing strict replacement test...");
a = repeated = 0;
signal(SIGALRM, alarm_handler);
alarm(r);
common_alarm(alarm_handler, &alarm_event, r);
ck_pr_inc_int(&barrier[HS_STATE_GET]);
for (;;) {
@ -483,8 +488,7 @@ main(int argc, char *argv[])
fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n",
a / (repeated * keys_length), acc(HS_STATE_STRICT_REPLACEMENT) / n_threads);
signal(SIGALRM, alarm_handler);
alarm(r);
common_alarm(alarm_handler, &alarm_event, r);
fprintf(stderr, " | Executing deletion test (%.2f)...", p_d * 100);
a = repeated = 0;
@ -497,7 +501,7 @@ main(int argc, char *argv[])
for (i = 0; i < keys_length; i++) {
set_insert(keys[i]);
if (p_d != 0.0) {
delete = drand48();
delete = common_drand48();
if (delete <= p_d)
set_remove(keys[i]);
}
@ -519,8 +523,7 @@ main(int argc, char *argv[])
fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n",
a / (repeated * keys_length), acc(HS_STATE_DELETION) / n_threads);
signal(SIGALRM, alarm_handler);
alarm(r);
common_alarm(alarm_handler, &alarm_event, r);
fprintf(stderr, " | Executing replacement test (%.2f)...", p_r * 100);
a = repeated = 0;
@ -533,12 +536,12 @@ main(int argc, char *argv[])
for (i = 0; i < keys_length; i++) {
set_insert(keys[i]);
if (p_d != 0.0) {
delete = drand48();
delete = common_drand48();
if (delete <= p_d)
set_remove(keys[i]);
}
if (p_r != 0.0) {
replace = drand48();
replace = common_drand48();
if (replace <= p_r)
set_replace(keys[i]);
}

@ -88,8 +88,8 @@ static void
set_init(void)
{
srand48((long int)time(NULL));
if (ck_hs_init(&hs, CK_HS_MODE_OBJECT | CK_HS_MODE_SPMC, hs_hash, hs_compare, &my_allocator, 8, lrand48()) == false) {
common_srand48((long int)time(NULL));
if (ck_hs_init(&hs, CK_HS_MODE_OBJECT | CK_HS_MODE_SPMC, hs_hash, hs_compare, &my_allocator, 8, common_lrand48()) == false) {
perror("ck_hs_init");
exit(EXIT_FAILURE);
}

@ -71,6 +71,8 @@ struct ht_epoch {
ck_epoch_entry_t epoch_entry;
};
COMMON_ALARM_DECLARE_GLOBAL(alarm_event, next_stage)
static void
alarm_handler(int s)
{
@ -125,8 +127,8 @@ table_init(void)
ck_epoch_init(&epoch_ht);
ck_epoch_register(&epoch_ht, &epoch_wr);
srand48((long int)time(NULL));
if (ck_ht_init(&ht, CK_HT_MODE_BYTESTRING, NULL, &my_allocator, 8, lrand48()) == false) {
common_srand48((long int)time(NULL));
if (ck_ht_init(&ht, CK_HT_MODE_BYTESTRING, NULL, &my_allocator, 8, common_lrand48()) == false) {
perror("ck_ht_init");
exit(EXIT_FAILURE);
}
@ -263,6 +265,8 @@ main(int argc, char *argv[])
pthread_t *readers;
double p_r, p_d;
COMMON_ALARM_DECLARE_LOCAL(alarm_event)
r = 20;
s = 8;
p_d = 0.5;
@ -301,6 +305,8 @@ main(int argc, char *argv[])
}
}
COMMON_ALARM_INIT(alarm_event, r)
affinerator.delta = 1;
readers = malloc(sizeof(pthread_t) * n_threads);
assert(readers != NULL);
@ -424,7 +430,7 @@ main(int argc, char *argv[])
while (ck_pr_load_int(&barrier[HT_STATE_STOP]) != n_threads)
ck_pr_stall();
ck_pr_inc_int(&barrier[HT_STATE_STOP]);
sleep(r);
common_sleep(r);
ck_pr_store_int(&state, HT_STATE_STRICT_REPLACEMENT);
while (ck_pr_load_int(&barrier[HT_STATE_GET]) != n_threads)
ck_pr_stall();
@ -434,8 +440,7 @@ main(int argc, char *argv[])
fprintf(stderr, " | Executing strict replacement test...");
a = repeated = 0;
signal(SIGALRM, alarm_handler);
alarm(r);
common_alarm(alarm_handler, &alarm_event, r);
ck_pr_inc_int(&barrier[HT_STATE_GET]);
for (;;) {
@ -460,8 +465,7 @@ main(int argc, char *argv[])
fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n",
a / (repeated * keys_length), accumulator[HT_STATE_STRICT_REPLACEMENT] / n_threads);
signal(SIGALRM, alarm_handler);
alarm(r);
common_alarm(alarm_handler, &alarm_event, r);
fprintf(stderr, " | Executing deletion test (%.2f)...", p_d * 100);
a = repeated = 0;
@ -474,7 +478,7 @@ main(int argc, char *argv[])
for (i = 0; i < keys_length; i++) {
table_insert(keys[i]);
if (p_d != 0.0) {
delete = drand48();
delete = common_drand48();
if (delete <= p_d)
table_remove(keys[i]);
}
@ -496,8 +500,7 @@ main(int argc, char *argv[])
fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n",
a / (repeated * keys_length), accumulator[HT_STATE_DELETION] / n_threads);
signal(SIGALRM, alarm_handler);
alarm(r);
common_alarm(alarm_handler, &alarm_event, r);
fprintf(stderr, " | Executing replacement test (%.2f)...", p_r * 100);
a = repeated = 0;
@ -510,12 +513,12 @@ main(int argc, char *argv[])
for (i = 0; i < keys_length; i++) {
table_insert(keys[i]);
if (p_d != 0.0) {
delete = drand48();
delete = common_drand48();
if (delete <= p_d)
table_remove(keys[i]);
}
if (p_r != 0.0) {
replace = drand48();
replace = common_drand48();
if (replace <= p_r)
table_replace(keys[i]);
}

@ -70,6 +70,8 @@ struct ht_epoch {
ck_epoch_entry_t epoch_entry;
};
COMMON_ALARM_DECLARE_GLOBAL(alarm_event, next_stage)
static void
alarm_handler(int s)
{
@ -135,8 +137,8 @@ table_init(void)
ck_epoch_init(&epoch_ht);
ck_epoch_register(&epoch_ht, &epoch_wr);
srand48((long int)time(NULL));
if (ck_ht_init(&ht, CK_HT_MODE_DIRECT, hash_function, &my_allocator, 8, lrand48()) == false) {
common_srand48((long int)time(NULL));
if (ck_ht_init(&ht, CK_HT_MODE_DIRECT, hash_function, &my_allocator, 8, common_lrand48()) == false) {
perror("ck_ht_init");
exit(EXIT_FAILURE);
}
@ -267,6 +269,8 @@ main(int argc, char *argv[])
pthread_t *readers;
double p_r, p_d;
COMMON_ALARM_DECLARE_LOCAL(alarm_event)
r = 20;
s = 8;
p_d = 0.5;
@ -305,6 +309,8 @@ main(int argc, char *argv[])
}
}
COMMON_ALARM_INIT(alarm_event, r)
affinerator.delta = 1;
readers = malloc(sizeof(pthread_t) * n_threads);
assert(readers != NULL);
@ -316,9 +322,9 @@ main(int argc, char *argv[])
table_init();
for (i = 0; i < keys_length; i++) {
keys[i] = (uintptr_t)lrand48();
keys[i] = (uintptr_t)common_lrand48();
while (keys[i] == 2)
keys[i] = (uintptr_t)lrand48();
keys[i] = (uintptr_t)common_lrand48();
}
for (i = 0; i < (size_t)n_threads; i++) {
@ -415,7 +421,7 @@ main(int argc, char *argv[])
while (ck_pr_load_int(&barrier[HT_STATE_STOP]) != n_threads)
ck_pr_stall();
ck_pr_inc_int(&barrier[HT_STATE_STOP]);
sleep(r);
common_sleep(r);
ck_pr_store_int(&state, HT_STATE_STRICT_REPLACEMENT);
while (ck_pr_load_int(&barrier[HT_STATE_GET]) != n_threads)
ck_pr_stall();
@ -425,8 +431,7 @@ main(int argc, char *argv[])
fprintf(stderr, " | Executing strict replacement test...");
a = repeated = 0;
signal(SIGALRM, alarm_handler);
alarm(r);
common_alarm(alarm_handler, &alarm_event, r);
ck_pr_inc_int(&barrier[HT_STATE_GET]);
for (;;) {
@ -451,8 +456,7 @@ main(int argc, char *argv[])
fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n",
a / (repeated * keys_length), accumulator[HT_STATE_STRICT_REPLACEMENT] / n_threads);
signal(SIGALRM, alarm_handler);
alarm(r);
common_alarm(alarm_handler, &alarm_event, r);
fprintf(stderr, " | Executing deletion test (%.2f)...", p_d * 100);
a = repeated = 0;
@ -465,7 +469,7 @@ main(int argc, char *argv[])
for (i = 0; i < keys_length; i++) {
table_insert(keys[i]);
if (p_d != 0.0) {
delete = drand48();
delete = common_drand48();
if (delete <= p_d)
table_remove(keys[i]);
}
@ -487,8 +491,7 @@ main(int argc, char *argv[])
fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n",
a / (repeated * keys_length), accumulator[HT_STATE_DELETION] / n_threads);
signal(SIGALRM, alarm_handler);
alarm(r);
common_alarm(alarm_handler, &alarm_event, r);
fprintf(stderr, " | Executing replacement test (%.2f)...", p_r * 100);
a = repeated = 0;
@ -501,12 +504,12 @@ main(int argc, char *argv[])
for (i = 0; i < keys_length; i++) {
table_insert(keys[i]);
if (p_d != 0.0) {
delete = drand48();
delete = common_drand48();
if (delete <= p_d)
table_remove(keys[i]);
}
if (p_r != 0.0) {
replace = drand48();
replace = common_drand48();
if (replace <= p_r)
table_replace(keys[i]);
}

@ -72,8 +72,8 @@ static void
table_init(void)
{
srand48((long int)time(NULL));
if (ck_ht_init(&ht, CK_HT_MODE_BYTESTRING, NULL, &my_allocator, 8, lrand48()) == false) {
common_srand48((long int)time(NULL));
if (ck_ht_init(&ht, CK_HT_MODE_BYTESTRING, NULL, &my_allocator, 8, common_lrand48()) == false) {
perror("ck_ht_init");
exit(EXIT_FAILURE);
}

@ -103,7 +103,7 @@ main(int argc, char *argv[])
fprintf(stderr, "done\n");
ck_pr_store_uint(&ready, 1);
sleep(10);
common_sleep(10);
ck_pr_store_uint(&ready, 0);
fprintf(stderr, "Waiting for threads to finish acquisition regression...");

@ -33,6 +33,7 @@
#include <ck_pr.h>
#include "../../common.h"
#ifndef R_REPEAT
#define R_REPEAT 200000
#endif
@ -56,8 +57,8 @@
if (w < 10) \
printf(" "); \
for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
uint##w##_t a = random() % ((uint##w##_t)-1 / 2); \
uint##w##_t b = random() % ((uint##w##_t)-1 / 2); \
uint##w##_t a = common_rand() % ((uint##w##_t)-1 / 2); \
uint##w##_t b = common_rand() % ((uint##w##_t)-1 / 2); \
CK_PR_ADD_T(w, a, b); \
} \
rg_width(w); \
@ -127,7 +128,7 @@ int
main(void)
{
srandom((unsigned int)getpid());
common_srand((unsigned int)getpid());
#ifdef CK_F_PR_ADD_64
CK_PR_ADD_B(64);
@ -147,3 +148,4 @@ main(void)
return (0);
}

@ -33,6 +33,7 @@
#include <ck_pr.h>
#include "../../common.h"
#ifndef R_REPEAT
#define R_REPEAT 200000
#endif
@ -58,8 +59,8 @@
if (w < 10) \
printf(" "); \
for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
uint##w##_t a = (uint##w##_t)random(); \
uint##w##_t b = (uint##w##_t)random(); \
uint##w##_t a = (uint##w##_t)common_rand(); \
uint##w##_t b = (uint##w##_t)common_rand(); \
CK_PR_AND_T(w, a, b); \
} \
rg_width(w); \
@ -123,7 +124,7 @@ int
main(void)
{
srandom((unsigned int)getpid());
common_srand((unsigned int)getpid());
#ifdef CK_F_PR_AND_64
CK_PR_AND_B(64);
@ -143,3 +144,4 @@ main(void)
return (0);
}

@ -29,6 +29,7 @@
#include <stdlib.h>
#include <unistd.h>
#include "../../common.h"
#define REPEAT 2000000
#define TEST_BINARY(K, S, T, P, D) \
@ -40,9 +41,9 @@
T ck_result = 65535; \
\
puts("***TESTING ck_pr_" #K "_" #S "***"); \
srandom((unsigned int)getpid()); \
common_srand((unsigned int)getpid()); \
for (i = 0; i < REPEAT; ++i) { \
r = random(); \
r = common_rand(); \
serial_result = serial_result P r; \
ck_pr_##K##_##S(&ck_result, r); \
} \
@ -90,3 +91,4 @@ main(void)
return (0);
}

@ -33,6 +33,7 @@
#include <ck_pr.h>
#include "../../common.h"
#ifndef R_REPEAT
#define R_REPEAT 200000
#endif
@ -62,7 +63,7 @@
unsigned int i; \
printf("ck_pr_btc_" #w ": "); \
for (i = 0; i < R_REPEAT; i++) { \
o = (uint##w##_t)random(); \
o = (uint##w##_t)common_rand(); \
CK_PR_BTC_T(w, o); \
} \
printf(" SUCCESS\n"); \
@ -72,7 +73,7 @@ int
main(void)
{
srandom((unsigned int)getpid());
common_srand((unsigned int)getpid());
#ifdef CK_F_PR_BTC_64
CK_PR_BTC_B(64);
@ -92,3 +93,4 @@ main(void)
return (0);
}

@ -33,6 +33,7 @@
#include <ck_pr.h>
#include "../../common.h"
#ifndef R_REPEAT
#define R_REPEAT 200000
#endif
@ -63,7 +64,7 @@
unsigned int i; \
printf("ck_pr_btr_" #w ": "); \
for (i = 0; i < R_REPEAT; i++) { \
o = (uint##w##_t)random(); \
o = (uint##w##_t)common_rand(); \
CK_PR_BTR_T(w, o); \
} \
printf(" SUCCESS\n"); \
@ -73,7 +74,7 @@ int
main(void)
{
srandom((unsigned int)getpid());
common_srand((unsigned int)getpid());
#ifdef CK_F_PR_BTR_64
CK_PR_BTR_B(64);
@ -93,3 +94,4 @@ main(void)
return (0);
}

@ -33,6 +33,7 @@
#include <ck_pr.h>
#include "../../common.h"
#ifndef R_REPEAT
#define R_REPEAT 200000
#endif
@ -63,7 +64,7 @@
unsigned int i; \
printf("ck_pr_bts_" #w ": "); \
for (i = 0; i < R_REPEAT; i++) { \
o = (uint##w##_t)random(); \
o = (uint##w##_t)common_rand(); \
CK_PR_BTS_T(w, o); \
} \
printf(" SUCCESS\n"); \
@ -73,7 +74,7 @@ int
main(void)
{
srandom((unsigned int)getpid());
common_srand((unsigned int)getpid());
#ifdef CK_F_PR_BTS_64
CK_PR_BTS_B(64);
@ -93,3 +94,4 @@ main(void)
return (0);
}

@ -30,6 +30,7 @@
#include <stdbool.h>
#include <ck_pr.h>
#include "../../common.h"
#define REPEAT 2000000
#define TEST_BTX(K, S, M, T, L, P, D, R) \
@ -50,12 +51,12 @@
bool serial_t, ck_pr_t; \
T x = 65535, y = 65535; \
\
srandom((unsigned int)getpid()); \
common_srand((unsigned int)getpid()); \
m = sizeof(T) * 8; \
\
puts("***TESTING ck_pr_"#K"_"#S"***"); \
for (i = 0; i < REPEAT; ++i) { \
offset = random() % m; \
offset = common_rand() % m; \
serial_t = test_##K##_##S(&x, offset); \
ck_pr_t = ck_pr_##K##_##S(&y, offset); \
\
@ -108,3 +109,4 @@ main(void)
return (0);
}

@ -33,6 +33,7 @@
#include <ck_pr.h>
#include "../../common.h"
#ifndef R_REPEAT
#define R_REPEAT 200000
#endif
@ -60,7 +61,7 @@
if (w < 10) \
printf(" "); \
for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
uint##w##_t a = random() % (uint##w##_t)-1; \
uint##w##_t a = common_rand() % (uint##w##_t)-1; \
CK_PR_CAS_T(w, a, a + 1, (a - 1)); \
CK_PR_CAS_T(w, a, a, (a - 1)); \
CK_PR_CAS_T(w, a, a + 1, a); \
@ -126,7 +127,7 @@ int
main(void)
{
srandom((unsigned int)getpid());
common_srand((unsigned int)getpid());
#ifdef CK_F_PR_CAS_64
CK_PR_CAS_B(64);
@ -154,3 +155,4 @@ main(void)
return (0);
}

@ -33,6 +33,7 @@
#include <ck_pr.h>
#include "../../common.h"
#ifndef R_REPEAT
#define R_REPEAT 200000
#endif
@ -55,7 +56,7 @@
if (w < 10) \
printf(" "); \
for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
uint##w##_t a = random() % ((uint##w##_t)-1); \
uint##w##_t a = common_rand() % ((uint##w##_t)-1); \
CK_PR_DEC_T(w, a); \
} \
rg_width(w); \
@ -119,7 +120,7 @@ int
main(void)
{
srandom((unsigned int)getpid());
common_srand((unsigned int)getpid());
#ifdef CK_F_PR_DEC_64
CK_PR_DEC_B(64);
@ -139,3 +140,4 @@ main(void)
return (0);
}

@ -33,6 +33,7 @@
#include <ck_pr.h>
#include "../../common.h"
#ifndef R_REPEAT
#define R_REPEAT 200000
#endif
@ -57,8 +58,8 @@
if (w < 10) \
printf(" "); \
for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
uint##w##_t a = random() % ((uint##w##_t)-1 / 2); \
uint##w##_t b = random() % ((uint##w##_t)-1 / 2); \
uint##w##_t a = common_rand() % ((uint##w##_t)-1 / 2); \
uint##w##_t b = common_rand() % ((uint##w##_t)-1 / 2); \
CK_PR_FAA_T(w, a, b); \
} \
rg_width(w); \
@ -128,7 +129,7 @@ int
main(void)
{
srandom((unsigned int)getpid());
common_srand((unsigned int)getpid());
#ifdef CK_F_PR_FAA_64
CK_PR_FAA_B(64);
@ -148,3 +149,4 @@ main(void)
return (0);
}

@ -33,6 +33,7 @@
#include <ck_pr.h>
#include "../../common.h"
#ifndef R_REPEAT
#define R_REPEAT 200000
#endif
@ -59,8 +60,8 @@
if (w < 10) \
printf(" "); \
for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
uint##w##_t a = random(); \
uint##w##_t b = random(); \
uint##w##_t a = common_rand(); \
uint##w##_t b = common_rand(); \
CK_PR_FAS_T(w, a, b); \
} \
rg_width(w); \
@ -124,7 +125,7 @@ int
main(void)
{
srandom((unsigned int)getpid());
common_srand((unsigned int)getpid());
#ifdef CK_F_PR_FAS_64
CK_PR_FAS_B(64);
@ -144,3 +145,4 @@ main(void)
return (0);
}

@ -29,6 +29,7 @@
#include <unistd.h>
#include <ck_pr.h>
#include "../../common.h"
#define REPEAT 2000000
#define TEST_FAX_FN(S, T, M) \
@ -65,9 +66,9 @@ TEST_FAX_FN_S(uint, unsigned int)
T x = 0, y = 0, x_b, y_b; \
\
puts("***TESTING ck_pr_"#K"_"#S"***"); \
srandom((unsigned int)getpid()); \
common_srand((unsigned int)getpid()); \
for (i = 0; i < REPEAT; ++i) { \
r = random(); \
r = common_rand(); \
x_b = test_##K##_##S(&x, r); \
y_b = ck_pr_##K##_##S(&y, r); \
\
@ -117,3 +118,4 @@ main(void)
return (0);
}

@ -33,6 +33,7 @@
#include <ck_pr.h>
#include "../../common.h"
#ifndef R_REPEAT
#define R_REPEAT 200000
#endif
@ -55,7 +56,7 @@
if (w < 10) \
printf(" "); \
for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
uint##w##_t a = random() % ((uint##w##_t)-1); \
uint##w##_t a = common_rand() % ((uint##w##_t)-1); \
CK_PR_INC_T(w, a); \
} \
rg_width(w); \
@ -119,7 +120,7 @@ int
main(void)
{
srandom((unsigned int)getpid());
common_srand((unsigned int)getpid());
#ifdef CK_F_PR_INC_64
CK_PR_INC_B(64);
@ -139,3 +140,4 @@ main(void)
return (0);
}

@ -33,6 +33,7 @@
#include <ck_pr.h>
#include "../../common.h"
#ifndef R_REPEAT
#define R_REPEAT 200000
#endif
@ -50,7 +51,7 @@
exit(EXIT_FAILURE); \
} \
for (i = 0; i < R_REPEAT; i++) { \
t = (uint##w##_t)random(); \
t = (uint##w##_t)common_rand(); \
a = ck_pr_load_##w(&t); \
if (a != t) { \
printf("FAIL [%#" PRIx##w " != %#" PRIx##w "]\n", a, t);\
@ -118,7 +119,7 @@ int
main(void)
{
srandom((unsigned int)getpid());
common_srand((unsigned int)getpid());
#ifdef CK_F_PR_LOAD_64
CK_PR_LOAD_B(64);
@ -145,3 +146,4 @@ main(void)
return (0);
}

@ -29,6 +29,7 @@
#include <unistd.h>
#include <ck_pr.h>
#include "../../common.h"
#define REPEAT 2000000
#define TEST_N(K, S, T, P, D) \
@ -39,9 +40,9 @@
T x = 0, y = 0; \
\
puts("***TESTING ck_pr_"#K"_"#S"***"); \
srandom((unsigned int)getpid()); \
common_srand((unsigned int)getpid()); \
for (i = 0; i < REPEAT; ++i) { \
r = random(); \
r = common_rand(); \
x += r; \
x = P x; \
y += r; \
@ -86,3 +87,4 @@ main(void)
return (0);
}

@ -33,6 +33,7 @@
#include <ck_pr.h>
#include "../../common.h"
#ifndef R_REPEAT
#define R_REPEAT 200000
#endif
@ -58,8 +59,8 @@
if (w < 10) \
printf(" "); \
for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
uint##w##_t a = (uint##w##_t)random(); \
uint##w##_t b = (uint##w##_t)random(); \
uint##w##_t a = (uint##w##_t)common_rand(); \
uint##w##_t b = (uint##w##_t)common_rand(); \
CK_PR_OR_T(w, a, b); \
} \
rg_width(w); \
@ -123,7 +124,7 @@ int
main(void)
{
srandom((unsigned int)getpid());
common_srand((unsigned int)getpid());
#ifdef CK_F_PR_OR_64
CK_PR_OR_B(64);
@ -143,3 +144,4 @@ main(void)
return (0);
}

@ -51,7 +51,7 @@
exit(EXIT_FAILURE); \
} \
for (i = 0; i < R_REPEAT; i++) { \
t = (uint##w##_t)random(); \
t = (uint##w##_t)common_rand(); \
ck_pr_store_##w(&a, t); \
if (a != t) { \
printf("FAIL [%#" PRIx##w " != %#" PRIx##w "]\n", a, t);\
@ -127,7 +127,7 @@ main(void)
}
#endif
srandom((unsigned int)getpid());
common_srand((unsigned int)getpid());
#ifdef CK_F_PR_STORE_64
CK_PR_STORE_B(64);

@ -33,6 +33,7 @@
#include <ck_pr.h>
#include "../../common.h"
#ifndef R_REPEAT
#define R_REPEAT 200000
#endif
@ -56,8 +57,8 @@
if (w < 10) \
printf(" "); \
for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
uint##w##_t a = random() % ((uint##w##_t)-1 / 2); \
uint##w##_t b = random() % ((uint##w##_t)-1 / 2); \
uint##w##_t a = common_rand() % ((uint##w##_t)-1 / 2); \
uint##w##_t b = common_rand() % ((uint##w##_t)-1 / 2); \
CK_PR_SUB_T(w, a, b); \
} \
rg_width(w); \
@ -127,7 +128,7 @@ int
main(void)
{
srandom((unsigned int)getpid());
common_srand((unsigned int)getpid());
#ifdef CK_F_PR_SUB_64
CK_PR_SUB_B(64);
@ -147,3 +148,4 @@ main(void)
return (0);
}

@ -33,6 +33,7 @@
#include <ck_pr.h>
#include "../../common.h"
#ifndef R_REPEAT
#define R_REPEAT 200000
#endif
@ -58,8 +59,8 @@
if (w < 10) \
printf(" "); \
for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
uint##w##_t a = (uint##w##_t)random(); \
uint##w##_t b = (uint##w##_t)random(); \
uint##w##_t a = (uint##w##_t)common_rand(); \
uint##w##_t b = (uint##w##_t)common_rand(); \
CK_PR_XOR_T(w, a, b); \
} \
rg_width(w); \
@ -123,7 +124,7 @@ int
main(void)
{
srandom((unsigned int)getpid());
common_srand((unsigned int)getpid());
#ifdef CK_F_PR_XOR_64
CK_PR_XOR_B(64);
@ -143,3 +144,4 @@ main(void)
return (0);
}

@ -146,7 +146,7 @@ main(int argc, char *argv[])
}
fprintf(stderr, "done\n");
sleep(10);
common_sleep(10);
ck_pr_store_uint(&flag, 1);
fprintf(stderr, "Waiting for threads to finish acquisition regression...");

@ -117,7 +117,7 @@ fairness(void *null)
count[i].value++;
if (critical) {
base = lrand48() % critical;
base = common_lrand48() % critical;
for (j = 0; j < base; j++);
}
@ -189,7 +189,7 @@ main(int argc, char *argv[])
fprintf(stderr, "done\n");
ck_pr_store_uint(&ready, 1);
sleep(10);
common_sleep(10);
ck_pr_store_uint(&ready, 0);
fprintf(stderr, "Waiting for threads to finish acquisition regression...");

@ -120,7 +120,7 @@ stack_thread(void *buffer)
#endif
if (critical) {
j = rand_r(&seed) % critical;
j = common_rand_r(&seed) % critical;
while (j--)
__asm__ __volatile__("" ::: "memory");
}

@ -127,7 +127,7 @@ stack_thread(void *unused CK_CC_UNUSED)
#endif
if (critical) {
j = rand_r(&seed) % critical;
j = common_rand_r(&seed) % critical;
while (j--)
__asm__ __volatile__("" ::: "memory");
}

@ -122,7 +122,7 @@ stack_thread(void *buffer)
#endif
if (critical) {
j = rand_r(&seed) % critical;
j = common_rand_r(&seed) % critical;
while (j--)
__asm__ __volatile__("" ::: "memory");
}

@ -38,12 +38,165 @@
#elif defined(__MACH__)
#include <mach/mach.h>
#include <mach/thread_policy.h>
#include <unistd.h>
#elif defined(_WIN32)
#include <assert.h>
#include <windows.h>
#endif
#ifndef CORES
#define CORES 8
#endif
CK_CC_INLINE static void
common_srand(unsigned int i)
{
#ifdef _WIN32
srand(i);
#else
srandom(i);
#endif
}
CK_CC_INLINE static int
common_rand(void)
{
#ifdef _WIN32
return rand();
#else
return random();
#endif
}
CK_CC_INLINE static int
common_rand_r(unsigned int *i)
{
#ifdef _WIN32
(void)i;
/*
* When linked with -mthreads, rand() is thread-safe.
* rand_s is also an option.
*/
return rand();
#else
return rand_r(i);
#endif
}
CK_CC_INLINE static void
common_srand48(long int i)
{
#ifdef _WIN32
srand(i);
#else
srand48(i);
#endif
}
CK_CC_INLINE static long int
common_lrand48(void)
{
#ifdef _WIN32
return rand();
#else
return lrand48();
#endif
}
CK_CC_INLINE static double
common_drand48(void)
{
#ifdef _WIN32
return (double)rand()/RAND_MAX;
#else
return drand48();
#endif
}
CK_CC_INLINE static void
common_sleep(unsigned int n)
{
#ifdef _WIN32
Sleep(n * 1000);
#else
sleep(n);
#endif
}
CK_CC_UNUSED static unsigned int
common_alarm(void (*sig_handler)(int), void *alarm_event, unsigned int duration)
{
#ifdef _WIN32
(void)sig_handler;
(void)duration;
bool success;
HANDLE *alarm_handle = (HANDLE *)alarm_event;
success = SetEvent(*alarm_handle);
assert(success != false);
return 0;
#else
(void)alarm_event;
signal(SIGALRM, sig_handler);
return alarm(duration);
#endif
}
#ifdef _WIN32
#ifndef SECOND_TIMER
#define SECOND_TIMER 10000000
#endif
#define COMMON_ALARM_DECLARE_GLOBAL(alarm_event_name, flag_name) \
static HANDLE common_win_alarm_timer; \
static HANDLE alarm_event_name; \
static LARGE_INTEGER timer_length; \
\
static void CALLBACK \
common_win_alarm_handler(LPVOID arg, DWORD timer_low_value, DWORD timer_high_value) \
{ \
(void)arg; \
(void)timer_low_value; \
(void)timer_high_value; \
flag_name = true; \
return; \
} \
\
static void * \
common_win_alarm(void *unused) \
{ \
(void)unused; \
bool timer_success = false; \
for (;;) { \
WaitForSingleObjectEx(alarm_event_name, INFINITE, true); \
timer_success = SetWaitableTimer(common_win_alarm_timer, &timer_length, 0, common_win_alarm_handler, NULL, false); \
assert(timer_success != false); \
WaitForSingleObjectEx(common_win_alarm_timer, INFINITE, true); \
} \
\
return NULL; \
}
#define COMMON_ALARM_DECLARE_LOCAL(alarm_event_name) \
__int64 tl; \
pthread_t common_win_alarm_thread;
#define COMMON_ALARM_INIT(alarm_event_name, duration) \
tl = -1 * duration * SECOND_TIMER; \
timer_length.LowPart = (DWORD) (tl & 0xFFFFFFFF); \
timer_length.HighPart = (LONG) (tl >> 32); \
alarm_event_name = CreateEvent(NULL, false, false, NULL); \
assert(alarm_event_name != NULL); \
common_win_alarm_timer = CreateWaitableTimer(NULL, true, NULL); \
assert(common_win_alarm_timer != NULL); \
if (pthread_create(&common_win_alarm_thread, NULL, common_win_alarm, NULL) != 0) \
ck_error("ERROR: Failed to create common_win_alarm thread.\n");
#else
#define COMMON_ALARM_DECLARE_GLOBAL(alarm_event_name, flag_name)
#define COMMON_ALARM_DECLARE_LOCAL(alarm_event_name) \
int alarm_event_name = 0;
#define COMMON_ALARM_INIT(alarm_event_name, duration)
#endif
struct affinity {
unsigned int delta;
unsigned int request;
@ -161,3 +314,4 @@ ck_error(const char *message, ...)
exit(EXIT_FAILURE);
}

Loading…
Cancel
Save