Skip to content

Commit

Permalink
Merge pull request #6 from minsii/cxx-tests
Browse files Browse the repository at this point in the history
Add standard cxx tests
  • Loading branch information
jdinan authored Dec 5, 2018
2 parents ec3d1db + 67fbc18 commit 06d9060
Show file tree
Hide file tree
Showing 32 changed files with 3,821 additions and 1,151 deletions.
40 changes: 40 additions & 0 deletions test/shmemx/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ check_PROGRAMS += \
endif
endif SHMEMX_TESTS

if HAVE_CXX
if SHMEMX_TESTS
check_PROGRAMS += \
cxx_test_shmem_g \
cxx_test_shmem_get \
cxx_test_shmem_p \
cxx_test_shmem_put \
cxx_test_shmem_atomic_fetch \
cxx_test_shmem_atomic_set \
cxx_test_shmem_atomic_add \
cxx_test_shmem_atomic_inc \
cxx_test_shmem_atomic_and \
cxx_test_shmem_atomic_or \
cxx_test_shmem_atomic_xor \
cxx_test_shmem_atomic_swap \
cxx_test_shmem_atomic_cswap \
cxx_test_shmem_wait_until \
cxx_test_shmem_test
endif
endif

TESTS = $(check_PROGRAMS)

NPROCS ?= 2
Expand Down Expand Up @@ -65,4 +86,23 @@ gettid_register_LDFLAGS = $(AM_LDFLAGS) $(PTHREAD_LIBS)
gettid_register_CFLAGS = $(PTHREAD_CFLAGS)
gettid_register_LDADD = $(LDADD) $(PTHREAD_CFLAGS)

AM_CPPFLAGS += -DENABLE_SHMEMX_TESTS

# C++ Tests
cxx_test_shmem_g_SOURCES = cxx_test_shmem_g.cpp
cxx_test_shmem_get_SOURCES = cxx_test_shmem_get.cpp
cxx_test_shmem_p_SOURCES = cxx_test_shmem_p.cpp
cxx_test_shmem_put_SOURCES = cxx_test_shmem_put.cpp
cxx_test_shmem_atomic_fetch_SOURCES = cxx_test_shmem_atomic_fetch.cpp
cxx_test_shmem_atomic_set_SOURCES = cxx_test_shmem_atomic_set.cpp
cxx_test_shmem_atomic_add_SOURCES = cxx_test_shmem_atomic_add.cpp
cxx_test_shmem_atomic_inc_SOURCES = cxx_test_shmem_atomic_inc.cpp
cxx_test_shmem_atomic_and_SOURCES = cxx_test_shmem_atomic_and.cpp
cxx_test_shmem_atomic_or_SOURCES = cxx_test_shmem_atomic_or.cpp
cxx_test_shmem_atomic_xor_SOURCES = cxx_test_shmem_atomic_xor.cpp
cxx_test_shmem_atomic_swap_SOURCES = cxx_test_shmem_atomic_swap.cpp
cxx_test_shmem_atomic_cswap_SOURCES = cxx_test_shmem_atomic_cswap.cpp
cxx_test_shmem_wait_until_SOURCES = cxx_test_shmem_wait_until.cpp
cxx_test_shmem_test_SOURCES = cxx_test_shmem_test.cpp

endif
251 changes: 251 additions & 0 deletions test/shmemx/cxx_test_shmem_atomic_add.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
/*
* This test program is derived from a unit test created by Nick Park.
* The original unit test is a work of the U.S. Government and is not subject
* to copyright protection in the United States. Foreign copyrights may
* apply.
*
* Copyright (c) 2017 Intel Corporation. All rights reserved.
* This software is available to you under the BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <shmem.h>

#ifdef ENABLE_SHMEMX_TESTS
#include <shmemx.h>
#endif

enum op { ADD = 0, ATOMIC_ADD, CTX_ATOMIC_ADD, FADD, ATOMIC_FETCH_ADD,
CTX_ATOMIC_FETCH_ADD, ATOMIC_FETCH_ADD_NBI, CTX_ATOMIC_FETCH_ADD_NBI };

#ifdef ENABLE_DEPRECATED_TESTS
#define DEPRECATED_ADD shmem_add
#define DEPRECATED_FADD shmem_fadd
#else
#define DEPRECATED_ADD shmem_atomic_add
#define DEPRECATED_FADD shmem_atomic_fetch_add
#endif

#ifdef ENABLE_SHMEMX_TESTS
#define SHMEMX_NBI_OPS_CASES(OP, TYPE) \
case ATOMIC_FETCH_ADD_NBI: \
shmemx_atomic_fetch_add_nbi(&old, &remote, (TYPE)(mype + 1), i); \
shmem_quiet(); \
if (old > (TYPE)(npes * (npes + 1) / 2)) { \
printf("PE %i error inconsistent value of old (%s, %s)\n", \
mype, #OP, #TYPE); \
rc = EXIT_FAILURE; \
} \
break; \
case CTX_ATOMIC_FETCH_ADD_NBI: \
shmemx_atomic_fetch_add_nbi(SHMEM_CTX_DEFAULT, &old, &remote, \
(TYPE)(mype + 1), i); \
shmem_quiet(); \
if (old > (TYPE)(npes * (npes + 1) / 2)) { \
printf("PE %i error inconsistent value of old (%s, %s)\n", \
mype, #OP, #TYPE); \
rc = EXIT_FAILURE; \
} \
break;
#else
#define SHMEMX_NBI_OPS_CASES(OP, TYPE)
#endif

#define TEST_SHMEM_ADD(OP, TYPE) \
do { \
static TYPE remote; \
TYPE old; \
const int mype = shmem_my_pe(); \
const int npes = shmem_n_pes(); \
remote = (TYPE)0; \
shmem_barrier_all(); \
for (int i = 0; i < npes; i++) \
switch (OP) { \
case ADD: \
DEPRECATED_ADD(&remote, (TYPE)(mype + 1), i); \
break; \
case ATOMIC_ADD: \
shmem_atomic_add(&remote, (TYPE)(mype + 1), i); \
break; \
case CTX_ATOMIC_ADD: \
shmem_atomic_add(SHMEM_CTX_DEFAULT, &remote, (TYPE)(mype + 1), i); \
break; \
case FADD: \
old = DEPRECATED_FADD(&remote, (TYPE)(mype + 1), i); \
if (old > (TYPE)(npes * (npes + 1) / 2)) { \
printf("PE %i error inconsistent value of old (%s, %s)\n", \
mype, #OP, #TYPE); \
rc = EXIT_FAILURE; \
} \
break; \
case ATOMIC_FETCH_ADD: \
old = shmem_atomic_fetch_add(&remote, (TYPE)(mype + 1), i); \
if (old > (TYPE)(npes * (npes + 1) / 2)) { \
printf("PE %i error inconsistent value of old (%s, %s)\n", \
mype, #OP, #TYPE); \
rc = EXIT_FAILURE; \
} \
break; \
case CTX_ATOMIC_FETCH_ADD: \
old = shmem_atomic_fetch_add(SHMEM_CTX_DEFAULT, &remote, (TYPE)(mype + 1), i); \
if (old > (TYPE)(npes * (npes + 1) / 2)) { \
printf("PE %i error inconsistent value of old (%s, %s)\n", \
mype, #OP, #TYPE); \
rc = EXIT_FAILURE; \
} \
break; \
SHMEMX_NBI_OPS_CASES(OP, TYPE) \
default: \
printf("Invalid operation (%d)\n", OP); \
shmem_global_exit(1); \
} \
shmem_barrier_all(); \
if (remote != (TYPE)(npes * (npes + 1) / 2)) { \
printf("PE %i observed error with TEST_SHMEM_ADD(%s, %s)\n", \
mype, #OP, #TYPE); \
rc = EXIT_FAILURE; \
} \
} while (false)


int main(int argc, char* argv[]) {
shmem_init();

int rc = EXIT_SUCCESS;

#ifdef ENABLE_DEPRECATED_TESTS
TEST_SHMEM_ADD(ADD, int);
TEST_SHMEM_ADD(ADD, long);
TEST_SHMEM_ADD(ADD, long long);
TEST_SHMEM_ADD(ADD, unsigned int);
TEST_SHMEM_ADD(ADD, unsigned long);
TEST_SHMEM_ADD(ADD, unsigned long long);
TEST_SHMEM_ADD(ADD, int32_t);
TEST_SHMEM_ADD(ADD, int64_t);
TEST_SHMEM_ADD(ADD, uint32_t);
TEST_SHMEM_ADD(ADD, uint64_t);
TEST_SHMEM_ADD(ADD, size_t);
TEST_SHMEM_ADD(ADD, ptrdiff_t);
#endif /* ENABLE_DEPRECATED_TESTS */

TEST_SHMEM_ADD(ATOMIC_ADD, int);
TEST_SHMEM_ADD(ATOMIC_ADD, long);
TEST_SHMEM_ADD(ATOMIC_ADD, long long);
TEST_SHMEM_ADD(ATOMIC_ADD, unsigned int);
TEST_SHMEM_ADD(ATOMIC_ADD, unsigned long);
TEST_SHMEM_ADD(ATOMIC_ADD, unsigned long long);
TEST_SHMEM_ADD(ATOMIC_ADD, int32_t);
TEST_SHMEM_ADD(ATOMIC_ADD, int64_t);
TEST_SHMEM_ADD(ATOMIC_ADD, uint32_t);
TEST_SHMEM_ADD(ATOMIC_ADD, uint64_t);
TEST_SHMEM_ADD(ATOMIC_ADD, size_t);
TEST_SHMEM_ADD(ATOMIC_ADD, ptrdiff_t);

TEST_SHMEM_ADD(CTX_ATOMIC_ADD, int);
TEST_SHMEM_ADD(CTX_ATOMIC_ADD, long);
TEST_SHMEM_ADD(CTX_ATOMIC_ADD, long long);
TEST_SHMEM_ADD(CTX_ATOMIC_ADD, unsigned int);
TEST_SHMEM_ADD(CTX_ATOMIC_ADD, unsigned long);
TEST_SHMEM_ADD(CTX_ATOMIC_ADD, unsigned long long);
TEST_SHMEM_ADD(CTX_ATOMIC_ADD, int32_t);
TEST_SHMEM_ADD(CTX_ATOMIC_ADD, int64_t);
TEST_SHMEM_ADD(CTX_ATOMIC_ADD, uint32_t);
TEST_SHMEM_ADD(CTX_ATOMIC_ADD, uint64_t);
TEST_SHMEM_ADD(CTX_ATOMIC_ADD, size_t);
TEST_SHMEM_ADD(CTX_ATOMIC_ADD, ptrdiff_t);

TEST_SHMEM_ADD(FADD, int);
TEST_SHMEM_ADD(FADD, long);
TEST_SHMEM_ADD(FADD, long long);
TEST_SHMEM_ADD(FADD, unsigned int);
TEST_SHMEM_ADD(FADD, unsigned long);
TEST_SHMEM_ADD(FADD, unsigned long long);
TEST_SHMEM_ADD(FADD, int32_t);
TEST_SHMEM_ADD(FADD, int64_t);
TEST_SHMEM_ADD(FADD, uint32_t);
TEST_SHMEM_ADD(FADD, uint64_t);
TEST_SHMEM_ADD(FADD, size_t);
TEST_SHMEM_ADD(FADD, ptrdiff_t);

TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, int);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, long);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, long long);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, unsigned int);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, unsigned long);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, unsigned long long);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, int32_t);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, int64_t);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, uint32_t);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, uint64_t);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, size_t);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD, ptrdiff_t);

TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, int);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, long);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, long long);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, unsigned int);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, unsigned long);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, unsigned long long);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, int32_t);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, int64_t);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, uint32_t);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, uint64_t);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, size_t);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD, ptrdiff_t);

#ifdef ENABLE_SHMEMX_TESTS
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, int);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, long);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, long long);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, unsigned int);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, unsigned long);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, unsigned long long);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, int32_t);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, int64_t);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, uint32_t);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, uint64_t);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, size_t);
TEST_SHMEM_ADD(ATOMIC_FETCH_ADD_NBI, ptrdiff_t);

TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, int);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, long);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, long long);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, unsigned int);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, unsigned long);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, unsigned long long);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, int32_t);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, int64_t);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, uint32_t);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, uint64_t);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, size_t);
TEST_SHMEM_ADD(CTX_ATOMIC_FETCH_ADD_NBI, ptrdiff_t);
#endif

shmem_finalize();
return rc;
}
Loading

0 comments on commit 06d9060

Please sign in to comment.