Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,37 @@
# CMakeLists.txt file for unit testing OpenMP host runtime library.
include(CheckFunctionExists)
include(CheckLibraryExists)
# Some tests use math functions
check_library_exists(m sqrt "" LIBOMP_HAVE_LIBM)
# When using libgcc, -latomic may be needed for atomics
# (but when using compiler-rt, the atomics will be built-in)
# Note: we can not check for __atomic_load because clang treats it
# as special built-in and that breaks CMake checks
check_function_exists(__atomic_load_1 LIBOMP_HAVE_BUILTIN_ATOMIC)
if(NOT LIBOMP_HAVE_BUILTIN_ATOMIC)
check_library_exists(atomic __atomic_load_1 "" LIBOMP_HAVE_LIBATOMIC)
else()
# not needed
set(LIBOMP_HAVE_LIBATOMIC 0)
endif()
macro(pythonize_bool var)
if (${var})
set(${var} True)
else()
set(${var} False)
endif()
endmacro()
pythonize_bool(LIBOMP_USE_HWLOC)
pythonize_bool(LIBOMP_OMPT_SUPPORT)
pythonize_bool(LIBOMP_OMPT_OPTIONAL)
pythonize_bool(LIBOMP_HAVE_LIBM)
pythonize_bool(LIBOMP_HAVE_LIBATOMIC)
add_openmp_testsuite(check-libomp "Running libomp tests" ${CMAKE_CURRENT_BINARY_DIR} DEPENDS omp)
# Configure the lit.site.cfg.in file
set(AUTO_GEN_COMMENT "## Autogenerated by libomp configuration.\n# Do not edit!")
configure_file(lit.site.cfg.in lit.site.cfg @ONLY)

View File

@@ -0,0 +1,23 @@
// RUN: %libomp-compile-and-run
#include <stdio.h>
#include <stdlib.h>
#include "omp_testsuite.h"
int test_has_openmp()
{
int rvalue = 0;
#ifdef _OPENMP
rvalue = 1;
#endif
return (rvalue);
}
int main()
{
int i;
int num_failed=0;
if(!test_has_openmp()) {
num_failed++;
}
return num_failed;
}

View File

@@ -0,0 +1,62 @@
// RUN: %libomp-compile-and-run
#include <stdio.h>
#include <stdint.h>
#include <omp.h>
#include "omp_testsuite.h"
int alignments[] = {64, 128, 256, 512, 1024, 2048, 4096};
unsigned aligned_by(uint64_t addr) {
uint64_t alignment = 1;
while((addr & (alignment-1)) == 0) {
alignment <<= 1;
}
return (alignment >> 1);
}
int test_kmp_aligned_malloc()
{
int err = 0;
#pragma omp parallel shared(err)
{
int i;
int* ptr;
uint64_t addr;
int tid = omp_get_thread_num();
for(i = 0; i < sizeof(alignments)/sizeof(int); i++) {
int alignment = alignments[i];
// allocate 64 bytes with 64-byte alignment
// allocate 128 bytes with 128-byte alignment, etc.
ptr = (int*)kmp_aligned_malloc(alignment, alignment);
addr = (uint64_t)ptr;
if(addr & (alignment-1)) {
printf("thread %d: addr = %p (aligned to %u bytes) but expected "
" alignment = %d\n", tid, ptr, aligned_by(addr), alignment);
err = 1;
}
kmp_free(ptr);
}
ptr = kmp_aligned_malloc(128, 127);
if (ptr != NULL) {
printf("thread %d: kmp_aligned_malloc() didn't return NULL when "
"alignment was not power of 2\n", tid);
err = 1;
}
} /* end of parallel */
return !err;
}
int main()
{
int i;
int num_failed=0;
for(i = 0; i < REPETITIONS; i++) {
if(!test_kmp_aligned_malloc()) {
num_failed++;
}
}
return num_failed;
}

View File

@@ -0,0 +1,53 @@
// RUN: %libomp-compile-and-run
#include <stdio.h>
#include "omp_testsuite.h"
/* The bug occurs if the lock table is reallocated after
kmp_set_defaults() is called. If the table is reallocated,
then the lock will not point to a valid lock object after the
kmp_set_defaults() call.*/
omp_lock_t lock;
int test_kmp_set_defaults_lock_bug()
{
/* checks that omp_get_num_threads is equal to the number of
threads */
int nthreads_lib;
int nthreads = 0;
nthreads_lib = -1;
#pragma omp parallel
{
omp_set_lock(&lock);
nthreads++;
omp_unset_lock(&lock);
#pragma omp single
{
nthreads_lib = omp_get_num_threads ();
} /* end of single */
} /* end of parallel */
kmp_set_defaults("OMP_NUM_THREADS");
#pragma omp parallel
{
omp_set_lock(&lock);
nthreads++;
omp_unset_lock(&lock);
} /* end of parallel */
return (nthreads == 2*nthreads_lib);
}
int main()
{
int i;
int num_failed=0;
omp_init_lock(&lock);
for(i = 0; i < REPETITIONS; i++) {
if(!test_kmp_set_defaults_lock_bug()) {
num_failed++;
}
}
omp_destroy_lock(&lock);
return num_failed;
}

View File

@@ -0,0 +1,39 @@
// RUN: %libomp-compile-and-run
#include <stdio.h>
#include "omp_testsuite.h"
int test_omp_get_num_threads()
{
/* checks that omp_get_num_threads is equal to the number of
threads */
int nthreads_lib;
int nthreads = 0;
nthreads_lib = -1;
#pragma omp parallel
{
#pragma omp critical
{
nthreads++;
} /* end of critical */
#pragma omp single
{
nthreads_lib = omp_get_num_threads ();
} /* end of single */
} /* end of parallel */
return (nthreads == nthreads_lib);
}
int main()
{
int i;
int num_failed=0;
for(i = 0; i < REPETITIONS; i++) {
if(!test_omp_get_num_threads()) {
num_failed++;
}
}
return num_failed;
}

View File

@@ -0,0 +1,24 @@
// RUN: %libomp-compile-and-run
#include <stdio.h>
#include "omp_testsuite.h"
int test_omp_get_wtick()
{
double tick;
tick = -1.;
tick = omp_get_wtick ();
return ((tick > 0.0) && (tick < 0.01));
}
int main()
{
int i;
int num_failed=0;
for(i = 0; i < REPETITIONS; i++) {
if(!test_omp_get_wtick()) {
num_failed++;
}
}
return num_failed;
}

View File

@@ -0,0 +1,33 @@
// RUN: %libomp-compile-and-run
#include <stdio.h>
#include <stdlib.h>
#include "omp_testsuite.h"
#include "omp_my_sleep.h"
int test_omp_get_wtime()
{
double start;
double end;
double measured_time;
double wait_time = 5.0;
start = 0;
end = 0;
start = omp_get_wtime();
my_sleep (wait_time);
end = omp_get_wtime();
measured_time = end-start;
return ((measured_time > 0.97 * wait_time) && (measured_time < 1.03 * wait_time)) ;
}
int main()
{
int i;
int num_failed=0;
for(i = 0; i < REPETITIONS; i++) {
if(!test_omp_get_wtime()) {
num_failed++;
}
}
return num_failed;
}

View File

@@ -0,0 +1,39 @@
// RUN: %libomp-compile-and-run
#include <stdio.h>
#include "omp_testsuite.h"
/*
* Checks that false is returned when called from serial region
* and true is returned when called within parallel region.
*/
int test_omp_in_parallel()
{
int serial;
int isparallel;
serial = 1;
isparallel = 0;
serial = omp_in_parallel();
#pragma omp parallel
{
#pragma omp single
{
isparallel = omp_in_parallel();
}
}
return (!(serial) && isparallel);
}
int main()
{
int i;
int num_failed=0;
for(i = 0; i < REPETITIONS; i++) {
if(!test_omp_in_parallel()) {
num_failed++;
}
}
return num_failed;
}

View File

@@ -0,0 +1,366 @@
// RUN: %libomp-compile-and-run
#include <stdio.h>
#include <math.h>
#include "omp_testsuite.h"
#define DOUBLE_DIGITS 20 /* dt^DOUBLE_DIGITS */
#define MAX_FACTOR 10
#define KNOWN_PRODUCT 3628800 /* 10! */
int test_omp_atomic()
{
int sum;
int diff;
double dsum = 0;
double dt = 0.5; /* base of geometric row for + and - test*/
double ddiff;
int product;
int x;
int *logics;
int bit_and = 1;
int bit_or = 0;
int exclusiv_bit_or = 0;
int j;
int known_sum;
int known_diff;
int known_product;
int result = 0;
int logic_and = 1;
int logic_or = 0;
double dknown_sum;
double rounding_error = 1.E-9;
double dpt, div;
int logicsArray[LOOPCOUNT];
logics = logicsArray;
sum = 0;
diff = 0;
product = 1;
// sum of integers test
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 1; i <= LOOPCOUNT; i++) {
#pragma omp atomic
sum += i;
}
}
known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2;
if (known_sum != sum)
{
fprintf(stderr,
"Error in sum with integers: Result was %d instead of %d.\n",
sum, known_sum);
result++;
}
// difference of integers test
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 0; i < LOOPCOUNT; i++) {
#pragma omp atomic
diff -= i;
}
}
known_diff = ((LOOPCOUNT - 1) * LOOPCOUNT) / 2 * -1;
if (diff != known_diff)
{
fprintf (stderr,
"Error in difference with integers: Result was %d instead of 0.\n",
diff);
result++;
}
// sum of doubles test
dsum = 0;
dpt = 1;
for (j = 0; j < DOUBLE_DIGITS; ++j) {
dpt *= dt;
}
dknown_sum = (1 - dpt) / (1 -dt);
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 0; i < DOUBLE_DIGITS; ++i) {
#pragma omp atomic
dsum += pow (dt, i);
}
}
if (dsum != dknown_sum && (fabs (dsum - dknown_sum) > rounding_error)) {
fprintf (stderr, "Error in sum with doubles: Result was %f"
" instead of: %f (Difference: %E)\n",
dsum, dknown_sum, dsum - dknown_sum);
result++;
}
// difference of doubles test
dpt = 1;
for (j = 0; j < DOUBLE_DIGITS; ++j) {
dpt *= dt;
}
ddiff = (1 - dpt) / (1 - dt);
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 0; i < DOUBLE_DIGITS; ++i) {
#pragma omp atomic
ddiff -= pow (dt, i);
}
}
if (fabs (ddiff) > rounding_error) {
fprintf (stderr,
"Error in difference with doubles: Result was %E instead of 0.0\n",
ddiff);
result++;
}
// product of integers test
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 1; i <= MAX_FACTOR; i++) {
#pragma omp atomic
product *= i;
}
}
known_product = KNOWN_PRODUCT;
if (known_product != product) {
fprintf (stderr,
"Error in product with integers: Result was %d instead of %d\n",
product, known_product);
result++;
}
// division of integers test
product = KNOWN_PRODUCT;
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 1; i <= MAX_FACTOR; ++i) {
#pragma omp atomic
product /= i;
}
}
if (product != 1) {
fprintf (stderr,
"Error in product division with integers: Result was %d"
" instead of 1\n",
product);
result++;
}
// division of doubles test
div = 5.0E+5;
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 1; i <= MAX_FACTOR; i++) {
#pragma omp atomic
div /= i;
}
}
if (fabs(div-0.137787) >= 1.0E-4 ) {
result++;
fprintf (stderr, "Error in division with double: Result was %f"
" instead of 0.137787\n", div);
}
// ++ test
x = 0;
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 0; i < LOOPCOUNT; ++i) {
#pragma omp atomic
x++;
}
}
if (x != LOOPCOUNT) {
result++;
fprintf (stderr, "Error in ++\n");
}
// -- test
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 0; i < LOOPCOUNT; ++i) {
#pragma omp atomic
x--;
}
}
if (x != 0) {
result++;
fprintf (stderr, "Error in --\n");
}
// bit-and test part 1
for (j = 0; j < LOOPCOUNT; ++j) {
logics[j] = 1;
}
bit_and = 1;
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 0; i < LOOPCOUNT; ++i) {
#pragma omp atomic
bit_and &= logics[i];
}
}
if (!bit_and) {
result++;
fprintf (stderr, "Error in BIT AND part 1\n");
}
// bit-and test part 2
bit_and = 1;
logics[LOOPCOUNT / 2] = 0;
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 0; i < LOOPCOUNT; ++i) {
#pragma omp atomic
bit_and &= logics[i];
}
}
if (bit_and) {
result++;
fprintf (stderr, "Error in BIT AND part 2\n");
}
// bit-or test part 1
for (j = 0; j < LOOPCOUNT; j++) {
logics[j] = 0;
}
bit_or = 0;
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 0; i < LOOPCOUNT; ++i) {
#pragma omp atomic
bit_or |= logics[i];
}
}
if (bit_or) {
result++;
fprintf (stderr, "Error in BIT OR part 1\n");
}
// bit-or test part 2
bit_or = 0;
logics[LOOPCOUNT / 2] = 1;
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 0; i < LOOPCOUNT; ++i) {
#pragma omp atomic
bit_or |= logics[i];
}
}
if (!bit_or) {
result++;
fprintf (stderr, "Error in BIT OR part 2\n");
}
// bit-xor test part 1
for (j = 0; j < LOOPCOUNT; j++) {
logics[j] = 0;
}
exclusiv_bit_or = 0;
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 0; i < LOOPCOUNT; ++i) {
#pragma omp atomic
exclusiv_bit_or ^= logics[i];
}
}
if (exclusiv_bit_or) {
result++;
fprintf (stderr, "Error in EXCLUSIV BIT OR part 1\n");
}
// bit-xor test part 2
exclusiv_bit_or = 0;
logics[LOOPCOUNT / 2] = 1;
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 0; i < LOOPCOUNT; ++i) {
#pragma omp atomic
exclusiv_bit_or ^= logics[i];
}
}
if (!exclusiv_bit_or) {
result++;
fprintf (stderr, "Error in EXCLUSIV BIT OR part 2\n");
}
// left shift test
x = 1;
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 0; i < 10; ++i) {
#pragma omp atomic
x <<= 1;
}
}
if ( x != 1024) {
result++;
fprintf (stderr, "Error in <<\n");
x = 1024;
}
// right shift test
#pragma omp parallel
{
int i;
#pragma omp for
for (i = 0; i < 10; ++i) {
#pragma omp atomic
x >>= 1;
}
}
if (x != 1) {
result++;
fprintf (stderr, "Error in >>\n");
}
return (result == 0);
} // test_omp_atomic()
int main()
{
int i;
int num_failed=0;
for(i = 0; i < REPETITIONS; i++) {
if(!test_omp_atomic()) {
num_failed++;
}
}
return num_failed;
}

View File

@@ -0,0 +1,44 @@
// RUN: %libomp-compile-and-run
#include <stdio.h>
#include "omp_testsuite.h"
#include "omp_my_sleep.h"
int test_omp_barrier()
{
int result1;
int result2;
result1 = 0;
result2 = 0;
#pragma omp parallel
{
int rank;
rank = omp_get_thread_num ();
if (rank ==1) {
my_sleep(((double)SLEEPTIME)/REPETITIONS); // give 1 sec to whole test
result2 = 3;
}
#pragma omp barrier
if (rank == 2) {
result1 = result2;
}
}
return (result1 == 3);
}
int main()
{
int i;
int num_failed=0;
#ifdef _OPENMP
omp_set_dynamic(0); // prevent runtime to change number of threads
omp_set_num_threads(4); // the test expects at least 3 threads
for(i = 0; i < REPETITIONS; i++) {
if(!test_omp_barrier()) {
num_failed++;
}
}
#endif
return num_failed;
}

View File

@@ -0,0 +1,37 @@
// RUN: %libomp-compile-and-run
#include <stdio.h>
#include "omp_testsuite.h"
int test_omp_critical()
{
int sum;
int known_sum;
sum=0;
#pragma omp parallel
{
int mysum=0;
int i;
#pragma omp for
for (i = 0; i < 1000; i++)
mysum = mysum + i;
#pragma omp critical
sum = mysum +sum;
}
known_sum = 999 * 1000 / 2;
return (known_sum == sum);
}
int main()
{
int i;
int num_failed=0;
for(i = 0; i < REPETITIONS; i++) {
if(!test_omp_critical()) {
num_failed++;
}
}
return num_failed;
}

View File

@@ -0,0 +1,21 @@
// RUN: %libomp-compile && env KMP_AFFINITY=disabled KMP_TOPOLOGY_METHOD=hwloc %libomp-run
// REQUIRES: hwloc
#include <stdio.h>
#include <stdlib.h>
// Test will assert() without fix
int test_affinity_disabled_plus_hwloc() {
#pragma omp parallel
{}
return 1;
}
int main(int argc, char **argv) {
int i, j;
int failed = 0;
if (!test_affinity_disabled_plus_hwloc()) {
failed = 1;
}
return failed;
}

View File

@@ -0,0 +1,76 @@
// RUN: %libomp-compile && env KMP_DISP_NUM_BUFFERS=0 %libomp-run
// RUN: env KMP_DISP_NUM_BUFFERS=1 %libomp-run && env KMP_DISP_NUM_BUFFERS=3 %libomp-run
// RUN: env KMP_DISP_NUM_BUFFERS=4 %libomp-run && env KMP_DISP_NUM_BUFFERS=7 %libomp-run
// RUN: %libomp-compile -DMY_SCHEDULE=guided && env KMP_DISP_NUM_BUFFERS=1 %libomp-run
// RUN: env KMP_DISP_NUM_BUFFERS=3 %libomp-run && env KMP_DISP_NUM_BUFFERS=4 %libomp-run
// RUN: env KMP_DISP_NUM_BUFFERS=7 %libomp-run
#include <stdio.h>
#include <omp.h>
#include <stdlib.h>
#include <limits.h>
#include "omp_testsuite.h"
#define INCR 7
#define MY_MAX 200
#define MY_MIN -200
#define NUM_LOOPS 100
#ifndef MY_SCHEDULE
# define MY_SCHEDULE dynamic
#endif
int a, b, a_known_value, b_known_value;
int test_kmp_set_disp_num_buffers()
{
int success = 1;
a = 0;
b = 0;
// run many small dynamic loops to stress the dispatch buffer system
#pragma omp parallel
{
int i,j;
for (j = 0; j < NUM_LOOPS; j++) {
#pragma omp for schedule(MY_SCHEDULE) nowait
for (i = MY_MIN; i < MY_MAX; i+=INCR) {
#pragma omp atomic
a++;
}
#pragma omp for schedule(MY_SCHEDULE) nowait
for (i = MY_MAX; i >= MY_MIN; i-=INCR) {
#pragma omp atomic
b++;
}
}
}
// detect failure
if (a != a_known_value || b != b_known_value) {
success = 0;
printf("a = %d (should be %d), b = %d (should be %d)\n", a, a_known_value,
b, b_known_value);
}
return success;
}
int main(int argc, char** argv)
{
int i,j;
int num_failed=0;
// figure out the known values to compare with calculated result
a_known_value = 0;
b_known_value = 0;
for (j = 0; j < NUM_LOOPS; j++) {
for (i = MY_MIN; i < MY_MAX; i+=INCR)
a_known_value++;
for (i = MY_MAX; i >= MY_MIN; i-=INCR)
b_known_value++;
}
for(i = 0; i < REPETITIONS; i++) {
if(!test_kmp_set_disp_num_buffers()) {
num_failed++;
}
}
return num_failed;
}

View File

@@ -0,0 +1,82 @@
// RUN: %libomp-compile && env OMP_THREAD_LIMIT=4 %libomp-run 4
// RUN: %libomp-compile && env OMP_THREAD_LIMIT=7 %libomp-run 7
//
// OMP_THREAD_LIMIT=N should imply that no more than N threads are active in
// a contention group
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "omp_testsuite.h"
int failed = 0;
void usage() {
fprintf(stderr, "usage: omp_thread_limit <n>\n");
}
void verify(const char* file_name, int line_number, int team_size) {
int num_threads = omp_get_num_threads();
if (team_size != num_threads) {
#pragma omp critical(A)
{
char label[256];
snprintf(label, sizeof(label), "%s:%d", file_name, line_number);
failed = 1;
printf("failed: %s: team_size(%d) != omp_get_num_threads(%d)\n",
label, team_size, num_threads);
}
}
}
int main(int argc, char** argv)
{
int cl_thread_limit;
if (argc != 2) {
usage();
return 1;
}
cl_thread_limit = atoi(argv[1]);
omp_set_dynamic(0);
if (omp_get_thread_limit() != cl_thread_limit) {
fprintf(stderr, "omp_get_thread_limit failed with %d, should be%d\n",
omp_get_thread_limit(), cl_thread_limit);
return 1;
}
else if (omp_get_max_threads() > cl_thread_limit) {
#if _OPENMP
int team_size = cl_thread_limit;
#else
int team_size = 1;
#endif
omp_set_num_threads(19);
verify(__FILE__, __LINE__, 1);
#pragma omp parallel
{
verify(__FILE__, __LINE__, team_size);
verify(__FILE__, __LINE__, team_size);
}
verify(__FILE__, __LINE__, 1);
omp_set_nested(1);
#pragma omp parallel num_threads(3)
{
verify(__FILE__, __LINE__, 3);
#pragma omp master
#pragma omp parallel num_threads(21)
{
verify(__FILE__, __LINE__, team_size-2);
verify(__FILE__, __LINE__, team_size-2);
}
}
verify(__FILE__, __LINE__, 1);
return failed;
} else {
fprintf(stderr, "This test is not applicable for max num_threads='%d'\n",
omp_get_max_threads());
return 0;
}
}

View File

@@ -0,0 +1,40 @@
// RUN: %libomp-compile && env OMP_WAIT_POLICY=active %libomp-run active
// RUN: %libomp-compile && env OMP_WAIT_POLICY=passive %libomp-run passive
//
// OMP_WAIT_POLICY=active should imply blocktime == INT_MAX
// i.e., threads spin-wait forever
// OMP_WAIT_POLICY=passive should imply blocktime == 0
// i.e., threads immediately sleep
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "omp_testsuite.h"
void usage() {
fprintf(stderr, "usage: omp_wait_policy active|passive\n");
}
int main(int argc, char** argv)
{
int blocktime, retval=1;
const char* env_var_value;
if (argc != 2) {
usage();
return 1;
}
blocktime = kmp_get_blocktime();
env_var_value = argv[1];
if (!strcmp(env_var_value, "active")) {
retval = (blocktime != INT_MAX);
} else if (!strcmp(env_var_value, "passive")) {
retval = (blocktime != 0);
} else {
usage();
retval = 1;
}
return retval;
}

View File

@@ -0,0 +1,45 @@
// RUN: %libomp-compile-and-run
#include <stdio.h>
#include "omp_testsuite.h"
#include "omp_my_sleep.h"
int test_omp_flush()
{
int result1;
int result2;
int dummy;
result1 = 0;
result2 = 0;
#pragma omp parallel
{
int rank;
rank = omp_get_thread_num ();
#pragma omp barrier
if (rank == 1) {
result2 = 3;
#pragma omp flush (result2)
dummy = result2;
}
if (rank == 0) {
my_sleep(SLEEPTIME);
#pragma omp flush (result2)
result1 = result2;
}
} /* end of parallel */
return ((result1 == result2) && (result2 == dummy) && (result2 == 3));
}
int main()
{
int i;
int num_failed=0;
for (i = 0; i < REPETITIONS; i++) {
if(!test_omp_flush()) {
num_failed++;
}
}
return num_failed;
}

View File

@@ -0,0 +1,126 @@
# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
# Configuration file for the 'lit' test runner.
import os
import re
import subprocess
import lit.formats
# Tell pylint that we know config and lit_config exist somewhere.
if 'PYLINT_IMPORT' in os.environ:
config = object()
lit_config = object()
def append_dynamic_library_path(path):
if config.operating_system == 'Windows':
name = 'PATH'
sep = ';'
elif config.operating_system == 'Darwin':
name = 'DYLD_LIBRARY_PATH'
sep = ':'
else:
name = 'LD_LIBRARY_PATH'
sep = ':'
if name in config.environment:
config.environment[name] = path + sep + config.environment[name]
else:
config.environment[name] = path
# name: The name of this test suite.
config.name = 'libomp'
# suffixes: A list of file extensions to treat as test files.
config.suffixes = ['.c', '.cpp']
# test_source_root: The root path where tests are located.
config.test_source_root = os.path.dirname(__file__)
# test_exec_root: The root object directory where output is placed
config.test_exec_root = config.libomp_obj_root
# test format
config.test_format = lit.formats.ShTest()
# compiler flags
config.test_flags = " -I " + config.test_source_root + \
" -I " + config.omp_header_directory + \
" -L " + config.library_dir + \
" " + config.test_extra_flags
# extra libraries
libs = ""
if config.has_libm:
libs += " -lm"
if config.has_libatomic:
libs += " -latomic"
# Allow XFAIL to work
config.target_triple = [ ]
for feature in config.test_compiler_features:
config.available_features.add(feature)
# Setup environment to find dynamic library at runtime
append_dynamic_library_path(config.library_dir)
if config.using_hwloc:
append_dynamic_library_path(config.hwloc_library_dir)
config.available_features.add('hwloc')
# Rpath modifications for Darwin
if config.operating_system == 'Darwin':
config.test_flags += " -Wl,-rpath," + config.library_dir
if config.using_hwloc:
config.test_flags += " -Wl,-rpath," + config.hwloc_library_dir
# Find the SDK on Darwin
if config.operating_system == 'Darwin':
cmd = subprocess.Popen(['xcrun', '--show-sdk-path'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = cmd.communicate()
out = out.strip()
res = cmd.wait()
if res == 0 and out:
config.test_flags += " -isysroot " + out
# Disable OMPT tests if FileCheck was not found
if config.has_ompt and config.test_filecheck == "":
lit_config.note("Not testing OMPT because FileCheck was not found")
config.has_ompt = False
if config.has_ompt:
config.available_features.add("ompt")
# for callback.h
config.test_flags += " -I " + config.test_source_root + "/ompt"
if 'Linux' in config.operating_system:
config.available_features.add("linux")
# to run with icc INTEL_LICENSE_FILE must be set
if 'INTEL_LICENSE_FILE' in os.environ:
config.environment['INTEL_LICENSE_FILE'] = os.environ['INTEL_LICENSE_FILE']
# substitutions
config.substitutions.append(("%libomp-compile-and-run", \
"%libomp-compile && %libomp-run"))
config.substitutions.append(("%libomp-cxx-compile-and-run", \
"%libomp-cxx-compile && %libomp-run"))
config.substitutions.append(("%libomp-cxx-compile", \
"%clangXX %openmp_flags %flags -std=c++11 %s -o %t" + libs))
config.substitutions.append(("%libomp-compile", \
"%clang %openmp_flags %flags %s -o %t" + libs))
config.substitutions.append(("%libomp-run", "%t"))
config.substitutions.append(("%clangXX", config.test_cxx_compiler))
config.substitutions.append(("%clang", config.test_c_compiler))
config.substitutions.append(("%openmp_flags", config.test_openmp_flags))
config.substitutions.append(("%flags", config.test_flags))
if config.has_ompt:
config.substitutions.append(("FileCheck", config.test_filecheck))
config.substitutions.append(("%sort-threads", "sort --numeric-sort --stable"))
if config.operating_system == 'Windows':
# No such environment variable on Windows.
config.substitutions.append(("%preload-tool", "true ||"))
elif config.operating_system == 'Darwin':
config.substitutions.append(("%preload-tool", "env DYLD_INSERT_LIBRARIES=%T/tool.so"))
else:
config.substitutions.append(("%preload-tool", "env LD_PRELOAD=%T/tool.so"))

View File

@@ -0,0 +1,20 @@
@AUTO_GEN_COMMENT@
config.test_c_compiler = "@OPENMP_TEST_C_COMPILER@"
config.test_cxx_compiler = "@OPENMP_TEST_CXX_COMPILER@"
config.test_compiler_features = @OPENMP_TEST_COMPILER_FEATURES@
config.test_filecheck = "@OPENMP_FILECHECK_EXECUTABLE@"
config.test_openmp_flags = "@OPENMP_TEST_OPENMP_FLAGS@"
config.test_extra_flags = "@OPENMP_TEST_FLAGS@"
config.libomp_obj_root = "@CMAKE_CURRENT_BINARY_DIR@"
config.library_dir = "@LIBOMP_LIBRARY_DIR@"
config.omp_header_directory = "@LIBOMP_BINARY_DIR@/src"
config.operating_system = "@CMAKE_SYSTEM_NAME@"
config.hwloc_library_dir = "@LIBOMP_HWLOC_LIBRARY_DIR@"
config.using_hwloc = @LIBOMP_USE_HWLOC@
config.has_ompt = @LIBOMP_OMPT_SUPPORT@ and @LIBOMP_OMPT_OPTIONAL@
config.has_libm = @LIBOMP_HAVE_LIBM@
config.has_libatomic = @LIBOMP_HAVE_LIBATOMIC@
# Let the main config do the real work.
lit_config.load_config(config, "@LIBOMP_BASE_DIR@/test/lit.cfg")

View File

@@ -0,0 +1,42 @@
// RUN: %libomp-compile-and-run
#include "omp_testsuite.h"
#include <stdio.h>
// This should be slightly less than KMP_I_LOCK_CHUNK, which is 1024
#define LOCKS_PER_ITER 1000
#define ITERATIONS (REPETITIONS + 1)
// This tests concurrently using locks on one thread while initializing new
// ones on another thread. This exercises the global lock pool.
int test_omp_init_lock() {
int i;
omp_lock_t lcks[ITERATIONS * LOCKS_PER_ITER];
#pragma omp parallel for schedule(static) num_threads(NUM_TASKS)
for (i = 0; i < ITERATIONS; i++) {
int j;
omp_lock_t *my_lcks = &lcks[i * LOCKS_PER_ITER];
for (j = 0; j < LOCKS_PER_ITER; j++) {
omp_init_lock(&my_lcks[j]);
}
for (j = 0; j < LOCKS_PER_ITER * 100; j++) {
omp_set_lock(&my_lcks[j % LOCKS_PER_ITER]);
omp_unset_lock(&my_lcks[j % LOCKS_PER_ITER]);
}
}
// Wait until all repititions are done. The test is exercising growth of
// the global lock pool, which does not shrink when no locks are allocated.
{
int j;
for (j = 0; j < ITERATIONS * LOCKS_PER_ITER; j++) {
omp_destroy_lock(&lcks[j]);
}
}
return 0;
}
int main() {
// No use repeating this test, since it's exercising a private global pool
// which is not reset between test iterations.
return test_omp_init_lock();
}

View File

@@ -0,0 +1,47 @@
// RUN: %libomp-compile-and-run
// RUN: env KMP_LOCK_KIND=tas KMP_SPIN_BACKOFF_PARAMS=2048,200 %libomp-run
// RUN: env KMP_LOCK_KIND=futex %libomp-run
#include <stdio.h>
#include "omp_testsuite.h"
omp_lock_t lck;
int test_omp_lock()
{
int nr_threads_in_single = 0;
int result = 0;
int nr_iterations = 0;
int i;
omp_init_lock(&lck);
#pragma omp parallel shared(lck)
{
#pragma omp for
for(i = 0; i < LOOPCOUNT; i++) {
omp_set_lock(&lck);
#pragma omp flush
nr_threads_in_single++;
#pragma omp flush
nr_iterations++;
nr_threads_in_single--;
result = result + nr_threads_in_single;
omp_unset_lock(&lck);
}
}
omp_destroy_lock(&lck);
return ((result == 0) && (nr_iterations == LOOPCOUNT));
}
int main()
{
int i;
int num_failed=0;
for(i = 0; i < REPETITIONS; i++) {
if(!test_omp_lock()) {
num_failed++;
}
}
return num_failed;
}

Some files were not shown because too many files have changed in this diff Show More