Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / runtime / test / env / omp_target_offload.c
blob4771e3c75dc7bf77a05a54036c231f48f847b710
1 // RUN: %libomp-compile-and-run
2 #include <string.h>
3 #include <stdlib.h>
5 enum kmp_target_offload_kind {
6 tgt_disabled = 0,
7 tgt_default = 1,
8 tgt_mandatory = 2
9 };
11 extern int __kmpc_get_target_offload();
12 extern void kmp_set_defaults(char const *str);
14 const char *disabled_examples[] = {
15 // Allowed inputs
16 "disabled", "DISABLED", "Disabled", "dIsAbLeD", "DiSaBlEd"};
18 const char *default_examples[] = {
19 // Allowed inputs
20 "default", "DEFAULT", "Default", "deFAulT", "DEfaULt",
21 // These should be changed to default (failed match)
22 "mandatry", "defaults", "disable", "enabled", "mandatorynot"};
24 const char *mandatory_examples[] = {
25 // Allowed inputs
26 "mandatory", "MANDATORY", "Mandatory", "manDatoRy", "MANdATOry"};
28 // Return target-offload-var ICV
29 int get_target_offload_icv() {
30 #pragma omp parallel
32 return __kmpc_get_target_offload();
35 int main() {
36 int i;
37 const char *omp_target_offload = "OMP_TARGET_OFFLOAD=";
38 char buf[80];
40 for (i = 0; i < sizeof(disabled_examples) / sizeof(char *); ++i) {
41 strcpy(buf, omp_target_offload);
42 strcat(buf, disabled_examples[i]);
43 kmp_set_defaults(buf);
44 if (tgt_disabled != get_target_offload_icv())
45 return EXIT_FAILURE;
47 for (i = 0; i < sizeof(default_examples) / sizeof(char *); ++i) {
48 strcpy(buf, omp_target_offload);
49 strcat(buf, default_examples[i]);
50 kmp_set_defaults(buf);
51 if (tgt_default != get_target_offload_icv())
52 return EXIT_FAILURE;
54 for (i = 0; i < sizeof(mandatory_examples) / sizeof(char *); ++i) {
55 strcpy(buf, omp_target_offload);
56 strcat(buf, mandatory_examples[i]);
57 kmp_set_defaults(buf);
58 if (tgt_mandatory != get_target_offload_icv())
59 return EXIT_FAILURE;
62 return EXIT_SUCCESS;