Skip to content

Commit

Permalink
Run test_omp_target_offload with environment var set
Browse files Browse the repository at this point in the history
Pull Req. #262
* sys/scripts/run_test.sh: Add --env argument.
* Makefile (%.c.run, %.c.runonly): Automatically set environment
  variable based on the test-case name (test_<envname>_env_<val>.c).
* tests/5.0/program_control/test_omp_target_offload.c: Renamed ...
  tests/5.0/program_control/test_omp_target_offload_env_DEFAULT.c: to this;
  add 'EXPECTED_POLICY' #define and check that the env var matches.
* tests/5.0/program_control/test_omp_target_offload_env_DISABLED.c: New;
  #define EXPECTED_POLICY and include the _DEFAULT file.
* tests/5.0/program_control/test_omp_target_offload_env_MANDATORY.c:
  Likewise.
  • Loading branch information
tob2 committed Feb 11, 2021
1 parent d791970 commit 710d534
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 13 deletions.
39 changes: 31 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,19 @@ $(CURDIR)/tests/4.5/application_kernels/qmcpack_target_static_lib.c.o: $(CURDIR)
%.c.run: $(OBJS_C)
$(call log_section_header,"RUN",$(SYSTEM),$(@:.run=),$(LOG_NOTE),$(OMP_VERSION),$(notdir $(@:.run=.log)))
@echo -e $(TXTGRN)"\n\n" running: $@ $(TXTNOC) $(if $(LOG), ${RECORD}$(notdir $(@:.run=.log)))
-$(call loadModules,$(C_COMPILER_MODULE)) $(BSRUN)$(RUN_TEST) $(@:.run=.o) $(VERBOSE) $(if $(LOG),$(RECORD)$(notdir $(@:.run=.log))\
&& echo "PASS" > $(LOGTEMPFILE) \
|| echo "FAIL" > $(LOGTEMPFILE))
# If .../test_<envname>_env_<value>...
$(if $(findstring _env_,$@), \
-$(call loadModules,$(C_COMPILER_MODULE)) \
$(BSRUN)$(RUN_TEST) --env \
$(shell echo "$@" | sed -e 's@.*/@@' -e 's@test_\(.*\)_env_.*@\1@' | tr 'a-z' 'A-Z') \
$(shell echo "$@" | sed -e 's@.*/@@' -e 's@.*_env_\([^.]*\).*@\1@') \
$(@:.run=.o) $(VERBOSE) $(if $(LOG),$(RECORD)$(notdir $(@:.run=.log)) \
&& echo "PASS" > $(LOGTEMPFILE) \
|| echo "FAIL" > $(LOGTEMPFILE)), \
-$(call loadModules,$(C_COMPILER_MODULE)) $(BSRUN)$(RUN_TEST) $(@:.run=.o) $(VERBOSE) $(if $(LOG),$(RECORD)$(notdir $(@:.run=.log))\
&& echo "PASS" > $(LOGTEMPFILE) \
|| echo "FAIL" > $(LOGTEMPFILE)) \
)
-$(call log_section_footer,"RUN",$(SYSTEM),$$(cat $(LOGTEMPFILE)),$(LOG_NOTE),$(notdir $(@:.run=.log)))
-@$(if $(LOG), rm $(LOGTEMPFILE))

Expand All @@ -324,7 +334,8 @@ $(CURDIR)/tests/4.5/application_kernels/qmcpack_target_static_lib.c.o: $(CURDIR)
|| echo "FAIL" > $(LOGTEMPFILE))
-$(call log_section_footer,"RUN",$(SYSTEM),$$(cat $(LOGTEMPFILE)),$(LOG_NOTE),$(notdir $(@:.run=.log)))
-@$(if $(LOG), rm $(LOGTEMPFILE))
# run c app rule

# run Fortran app rule
%.FOR.run: $(OBJS_F)
$(call log_section_header,"RUN",$(SYSTEM),$(@:.FOR.run=),$(LOG_NOTE),$(OMP_VERSION),$(notdir $(@:.FOR.run=.log)))
@echo -e $(TXTGRN)"\n\n" running: $@ $(TXTNOC) $(if $(LOG), ${RECORD}$(notdir $(@:.FOR.run=.log)))
Expand All @@ -334,16 +345,27 @@ $(CURDIR)/tests/4.5/application_kernels/qmcpack_target_static_lib.c.o: $(CURDIR)
-$(call log_section_footer,"RUN",$(SYSTEM),$$(cat $(LOGTEMPFILE)),$(LOG_NOTE),$(notdir $(@:.FOR.run=.log)))
-@$(if $(LOG), rm $(LOGTEMPFILE))


##################################################
# Running only no compile rules
##################################################
# run c app rule
%.c.runonly:
$(call log_section_header,"RUN",$(SYSTEM),$(@:.runonly=),$(LOG_NOTE),$(OMP_VERSION),$(notdir $(@:.runonly=.log)))
@echo -e $(TXTGRN)"\n\n" running previously compiled: $@ $(TXTNOC) $(if $(LOG), ${RECORD}$(notdir $(@:.runonly=.log)))
-$(call loadModules,$(C_COMPILER_MODULE)) $(BSRUN)$(RUN_TEST) $(@:.runonly=.o) $(VERBOSE) $(if $(LOG),$(RECORD)$(notdir $(@:.runonly=.log))\
&& echo "PASS" > $(LOGTEMPFILE) \
|| echo "FAIL" > $(LOGTEMPFILE))
# If .../test_<envname>_env_<value>...
$(if $(findstring _env_,$@), \
$(call loadModules,$(C_COMPILER_MODULE)) \
$(BSRUN)$(RUN_TEST) --env \
$(shell echo "$@" | sed -e 's@.*/@@' -e 's@test_\(.*\)_env_.*@\1@' | tr 'a-z' 'A-Z') \
$(shell echo "$@" | sed -e 's@.*/@@' -e 's@.*_env_\([^.]*\).*@\1@') \
$(@:.runonly=.o) $(VERBOSE) $(if $(LOG),$(RECORD)$(notdir $(@:.runonly=.log))\
&& echo "PASS" > $(LOGTEMPFILE) \
|| echo "FAIL" > $(LOGTEMPFILE)) \
$(call loadModules,$(C_COMPILER_MODULE)) $(BSRUN)$(RUN_TEST) $(@:.runonly=.o) $(VERBOSE) $(if $(LOG),$(RECORD)$(notdir $(@:.runonly=.log))\
&& echo "PASS" > $(LOGTEMPFILE) \
|| echo "FAIL" > $(LOGTEMPFILE)) \
)
-$(call log_section_footer,"RUN",$(SYSTEM),$$(cat $(LOGTEMPFILE)),$(LOG_NOTE),$(notdir $(@:.runonly=.log)))
-@$(if $(LOG), rm $(LOGTEMPFILE))

Expand All @@ -356,7 +378,8 @@ $(CURDIR)/tests/4.5/application_kernels/qmcpack_target_static_lib.c.o: $(CURDIR)
|| echo "FAIL" > $(LOGTEMPFILE))
-$(call log_section_footer,"RUN",$(SYSTEM),$$(cat $(LOGTEMPFILE)),$(LOG_NOTE),$(notdir $(@:.runonly=.log)))
-@$(if $(LOG), rm $(LOGTEMPFILE))
# run c app rule

# run Fortran app rule
%.FOR.runonly:
$(call log_section_header,"RUN",$(SYSTEM),$(@:.FOR.runonly=),$(LOG_NOTE),$(OMP_VERSION),$(notdir $(@:.FOR.runonly=.log)))
@echo -e $(TXTGRN)"\n\n" running previously compiled: $@ $(TXTNOC) $(if $(LOG), ${RECORD}$(notdir $(@:.FOR.runonly=.log)))
Expand Down
17 changes: 14 additions & 3 deletions sys/scripts/run_test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash

# USAGE: ./run_test.sh <APP> <LOG>.
# <LOG>: if present then it will output of the tests in LOG.
# USAGE: ./run_test.sh [--env name val ...] <APP> [<LOG>].
# --env name val: set environment variable name to the given value
# <LOG>: if present then it will output of the tests in LOG.

export OMP_THREAD_LIMIT=$(lscpu -p | grep -c "^[0-9]")

Expand All @@ -25,6 +26,16 @@ function report ()
fi
}

declare -a env_data
while [[ "$1" = "--env" ]]; do
if [[ -z "$2" ]]; then
echo 'ERROR: Expected 'name val' arguments with --env' 1>&2
exit -1
fi
env_data+=("$2" "$3")
shift 3
done

if [ "$#" -lt "1" ]; then
exit -1
elif [ ! -f "$1" ]; then
Expand All @@ -35,7 +46,7 @@ elif [ ! -f "$1" ]; then
fi

app=$1
output=`timeout 60s $app 2>&1`
output=$(for ((idx=0; $idx < ${#env_data[*]}; idx=$((idx+2)))); do export "${env_data[$idx]}"="${env_data[$((idx+1))]}"; done; timeout 60s "$app" 2>&1)
status=$?
output=$(printf "$output" | uniq)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===--- test_omp_target_offload.c ----------------------------------------------------------------===//
//===--- test_omp_target_offload_DEFAULT.c ---------------------------------------------------------===//
//
// OpenMP API Version 5.0 Nov 2018
//
Expand All @@ -10,9 +10,16 @@
// the program will terminate execution when a target construct is encountered and a target device
// is not available or supported by the implementation.
//
// The actually checked variant is set by EXPECTED_POLICY; if not overridden DEFAULT is tested.
// See also test_omp_target_offload_DISABLED.c and test_omp_target_offload_MANDATORY.c
//
// This test was adopted from OpenMP 5.0 Examples Doc -> target_offload_control.1.c
////===--------------------------------------------------------------------------------------------===//

#ifndef EXPECTED_POLICY
#define EXPECTED_POLICY DEFAULT
#endif

#include <omp.h>
#include <stdio.h>
#include <ctype.h>
Expand Down Expand Up @@ -89,8 +96,9 @@ int main() {
OMPVV_ERROR_IF(policy==MANDATORY && isOffloading == 1 && on_init_dev != 0, "Did not follow MANDATORY, instead executed target region on host even though device was available");
OMPVV_TEST_AND_SET(errors, policy==MANDATORY && isOffloading == 1 && on_init_dev != 0);

OMPVV_ERROR_IF(policy==UNKNOWN,"OMP_TARGET_OFFLOAD has an unknown value");
OMPVV_ERROR_IF(policy==NOTSET, "OMP_TARGET_OFFLOAD has not been set");
OMPVV_ERROR_IF(policy==UNKNOWN,"OMP_TARGET_OFFLOAD has an unknown value '%s'", getenv("OMP_TARGET_OFFLOAD"));
OMPVV_ERROR_IF(policy!=NOTSET && policy!=EXPECTED_POLICY, "OMP_TARGET_OFFLOAD set to %s but expected %s", getenv("OMP_TARGET_OFFLOAD"), EXPECTED_POLICY);

OMPVV_REPORT_AND_RETURN(errors);
}
13 changes: 13 additions & 0 deletions tests/5.0/program_control/test_omp_target_offload_env_DISABLED.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===--- test_omp_target_offload_env_DISABLED.c ----------------------------------------------------===//
//
// OpenMP API Version 5.0 Nov 2018
//
// This test checks for offloading behavior when OMP_TARGET_OFFLOAD is set to DISABLED.
//
// See test_omp_target_offload_env_DEFAULT.c for details.
//
////===--------------------------------------------------------------------------------------------===//

#define EXPECTED_POLICY DISABLED

#include "./test_omp_target_offload_env_DEFAULT.c"
13 changes: 13 additions & 0 deletions tests/5.0/program_control/test_omp_target_offload_env_MANDATORY.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===--- test_omp_target_offload_env_MANDATORY.c --------------------------------------------------===//
//
// OpenMP API Version 5.0 Nov 2018
//
// This test checks for offloading behavior when OMP_TARGET_OFFLOAD is set to MANDATORY.
//
// See test_omp_target_offload_env_DEFAULT.c for details.
//
////===--------------------------------------------------------------------------------------------===//

#define EXPECTED_POLICY MANDATORY

#include "test_omp_target_offload_env_DEFAULT.c"

0 comments on commit 710d534

Please sign in to comment.