Skip to content

Commit

Permalink
Add C11 generic bindings test cases
Browse files Browse the repository at this point in the history
These test cases are derived from the generic tests written by Nick Park
and placed in the public domain (https://github.com/nspark/shmemx).

Note: covers some, but not all of the new generic API.

Signed-off-by: James Dinan <[email protected]>
  • Loading branch information
James Dinan committed Feb 10, 2016
1 parent e12bb15 commit b98e8e9
Show file tree
Hide file tree
Showing 9 changed files with 637 additions and 1 deletion.
34 changes: 33 additions & 1 deletion test/unit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ TESTS = \
asym_alloc \
set_fetch \
alltoall \
alltoalls
alltoalls \
c11_test_shmem_add \
c11_test_shmem_fetch \
c11_test_shmem_g \
c11_test_shmem_get \
c11_test_shmem_inc \
c11_test_shmem_p \
c11_test_shmem_put \
c11_test_shmem_set

if USE_PORTALS4
TESTS += \
Expand Down Expand Up @@ -258,3 +266,27 @@ alltoall_LDADD = $(top_builddir)/src/libsma.la

alltoalls_SOURCES = alltoalls.c
alltoalls_LDADD = $(top_builddir)/src/libsma.la

c11_test_shmem_add_SOURCES = c11_test_shmem_add.c
c11_test_shmem_add_LDADD = $(top_builddir)/src/libsma.la

c11_test_shmem_g_SOURCES = c11_test_shmem_g.c
c11_test_shmem_g_LDADD = $(top_builddir)/src/libsma.la

c11_test_shmem_get_SOURCES = c11_test_shmem_get.c
c11_test_shmem_get_LDADD = $(top_builddir)/src/libsma.la

c11_test_shmem_inc_SOURCES = c11_test_shmem_inc.c
c11_test_shmem_inc_LDADD = $(top_builddir)/src/libsma.la

c11_test_shmem_p_SOURCES = c11_test_shmem_p.c
c11_test_shmem_p_LDADD = $(top_builddir)/src/libsma.la

c11_test_shmem_put_SOURCES = c11_test_shmem_put.c
c11_test_shmem_put_LDADD = $(top_builddir)/src/libsma.la

c11_test_shmem_fetch_SOURCES = c11_test_shmem_fetch.c
c11_test_shmem_fetch_LDADD = $(top_builddir)/src/libsma.la

c11_test_shmem_set_SOURCES = c11_test_shmem_set.c
c11_test_shmem_set_LDADD = $(top_builddir)/src/libsma.la
72 changes: 72 additions & 0 deletions test/unit/c11_test_shmem_add.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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) 2016 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>

#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)

#define TEST_SHMEM_ADD(TYPE) \
do { \
static TYPE remote = (TYPE)0; \
const int mype = shmem_my_pe(); \
const int npes = shmem_n_pes(); \
for (int i = 0; i < npes; i++) \
shmem_add(&remote, (TYPE)(mype + 1), i); \
shmem_barrier_all(); \
if (remote != (TYPE)(npes * (npes + 1) / 2)) { \
fprintf(stderr, \
"PE %i observed error with shmem_add(%s, ...)\n", \
mype, #TYPE); \
rc = EXIT_FAILURE; \
} \
} while (false)

#else
#define TEST_SHMEM_ADD(TYPE)

#endif

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

int rc = EXIT_SUCCESS;
TEST_SHMEM_ADD(int);
TEST_SHMEM_ADD(long);
TEST_SHMEM_ADD(long long);

shmem_finalize();
return rc;
}
74 changes: 74 additions & 0 deletions test/unit/c11_test_shmem_fetch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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) 2016 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>

#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)

#define TEST_SHMEM_FETCH(TYPE) \
do { \
static TYPE remote; \
const int mype = shmem_my_pe(); \
const int npes = shmem_n_pes(); \
remote = (TYPE)mype; \
shmem_barrier_all(); \
TYPE val = shmem_fetch(&remote, (mype + 1) % npes); \
if (val != (TYPE)((mype + 1) % npes)) { \
fprintf(stderr, \
"PE %i received incorrect value " \
"for shmem_fetch(%s, ...)\n", mype, #TYPE); \
rc = EXIT_FAILURE; \
} \
} while (false)

#else
#define TEST_SHMEM_FETCH(TYPE)

#endif

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

int rc = EXIT_SUCCESS;
TEST_SHMEM_FETCH(float);
TEST_SHMEM_FETCH(double);
TEST_SHMEM_FETCH(int);
TEST_SHMEM_FETCH(long);
TEST_SHMEM_FETCH(long long);

shmem_finalize();
return rc;
}
77 changes: 77 additions & 0 deletions test/unit/c11_test_shmem_g.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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) 2016 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>

#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)

#define TEST_SHMEM_G(TYPE) \
do { \
static TYPE remote; \
const int mype = shmem_my_pe(); \
const int npes = shmem_n_pes(); \
remote = (TYPE)mype; \
shmem_barrier_all(); \
TYPE val = shmem_g(&remote, (mype + 1) % npes); \
if (val != (TYPE)((mype + 1) % npes)) { \
fprintf(stderr, \
"PE %i received incorrect value " \
"for shmem_g(%s, ...)\n", mype, #TYPE); \
rc = EXIT_FAILURE; \
} \
} while (false)

#else
#define TEST_SHMEM_G(TYPE)

#endif

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

int rc = EXIT_SUCCESS;
TEST_SHMEM_G(float);
TEST_SHMEM_G(double);
TEST_SHMEM_G(long double);
TEST_SHMEM_G(char);
TEST_SHMEM_G(short);
TEST_SHMEM_G(int);
TEST_SHMEM_G(long);
TEST_SHMEM_G(long long);

shmem_finalize();
return rc;
}
80 changes: 80 additions & 0 deletions test/unit/c11_test_shmem_get.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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) 2016 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>

#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)

#define TEST_SHMEM_GET(TYPE) \
do { \
static TYPE remote[10]; \
const int mype = shmem_my_pe(); \
const int npes = shmem_n_pes(); \
TYPE local[10]; \
for (int i = 0; i < 10; i++) \
remote[i] = (TYPE)mype; \
shmem_barrier_all(); \
shmem_get(local, remote, 10, (mype + 1) % npes); \
for (int i = 0; i < 10; i++) \
if (local[i] != (TYPE)((mype + 1) % npes)) { \
fprintf(stderr, \
"PE %i received incorrect value " \
"for shmem_get(%s,...)\n", mype, #TYPE); \
rc = EXIT_FAILURE; \
} \
} while (false)

#else
#define TEST_SHMEM_GET(TYPE)

#endif

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

int rc = EXIT_SUCCESS;
TEST_SHMEM_GET(float);
TEST_SHMEM_GET(double);
TEST_SHMEM_GET(long double);
TEST_SHMEM_GET(char);
TEST_SHMEM_GET(short);
TEST_SHMEM_GET(int);
TEST_SHMEM_GET(long);
TEST_SHMEM_GET(long long);

shmem_finalize();
return rc;
}
Loading

0 comments on commit b98e8e9

Please sign in to comment.