Skip to content

Commit 8fb4417

Browse files
committed
[LLVMFronted][tests] Add basic OpenMP parsing tests.
As noticed in D91470, some of the functions of LLVMFrontend, are not tested within the library itself (but indirectly by its users clang and flang). In particular, the file OMP.cpp which is generated by tablegen was not tested at all. Add tests for the parsing helpers in OMP.cpp. These are not meant to be exhaustive tests, just to ensure that we have some basic tests for all API functions. Reviewed By: clementval Differential Revision: https://reviews.llvm.org/D91643
1 parent bc98034 commit 8fb4417

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

llvm/unittests/Frontend/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(LLVM_LINK_COMPONENTS
1111
add_llvm_unittest(LLVMFrontendTests
1212
OpenMPContextTest.cpp
1313
OpenMPIRBuilderTest.cpp
14+
OpenMPParsingTest.cpp
1415

1516
DEPENDS
1617
omp_gen
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//===- llvm/unittest/IR/OpenMPIRParsingTest.cpp ---------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "llvm/Frontend/OpenMP/OMPConstants.h"
10+
#include "gtest/gtest.h"
11+
12+
using namespace llvm;
13+
using namespace llvm::omp;
14+
15+
namespace {
16+
17+
TEST(OpenMPParsingTest, OpenMPDirectiveKind) {
18+
EXPECT_EQ(getOpenMPDirectiveKind("foobar"), OMPD_unknown);
19+
20+
EXPECT_EQ(getOpenMPDirectiveKind("for"), OMPD_for);
21+
EXPECT_EQ(getOpenMPDirectiveKind("simd"), OMPD_simd);
22+
EXPECT_EQ(getOpenMPDirectiveKind("for simd"), OMPD_for_simd);
23+
}
24+
25+
TEST(OpenMPParsingTest, getOpenMPDirectiveName) {
26+
EXPECT_EQ(getOpenMPDirectiveName(OMPD_unknown), "unknown");
27+
28+
EXPECT_EQ(getOpenMPDirectiveName(OMPD_for), "for");
29+
EXPECT_EQ(getOpenMPDirectiveName(OMPD_simd), "simd");
30+
EXPECT_EQ(getOpenMPDirectiveName(OMPD_for_simd), "for simd");
31+
}
32+
33+
TEST(OpenMPParsingTest, getOpenMPClauseKind) {
34+
EXPECT_EQ(getOpenMPClauseKind("foobar"), OMPC_unknown);
35+
36+
EXPECT_EQ(getOpenMPClauseKind("schedule"), OMPC_schedule);
37+
EXPECT_EQ(getOpenMPClauseKind("if"), OMPC_if);
38+
}
39+
40+
TEST(OpenMPParsingTest, getOpenMPClauseName) {
41+
EXPECT_EQ(getOpenMPClauseName(OMPC_unknown), "unknown");
42+
43+
EXPECT_EQ(getOpenMPClauseName(OMPC_schedule), "schedule");
44+
EXPECT_EQ(getOpenMPClauseName(OMPC_if), "if");
45+
}
46+
47+
TEST(OpenMPParsingTest, isAllowedClauseForDirective) {
48+
EXPECT_TRUE(isAllowedClauseForDirective(OMPD_for, OMPC_schedule, 30));
49+
EXPECT_FALSE(isAllowedClauseForDirective(OMPD_for, OMPC_num_teams, 30));
50+
51+
EXPECT_FALSE(isAllowedClauseForDirective(OMPD_for, OMPC_order, 30));
52+
EXPECT_FALSE(isAllowedClauseForDirective(OMPD_for, OMPC_order, 45));
53+
EXPECT_TRUE(isAllowedClauseForDirective(OMPD_for, OMPC_order, 50));
54+
EXPECT_TRUE(isAllowedClauseForDirective(OMPD_for, OMPC_order, 51));
55+
}
56+
57+
TEST(OpenMPParsingTest, getOrderKind) {
58+
EXPECT_EQ(getOrderKind("foobar"), OMP_ORDER_concurrent);
59+
EXPECT_EQ(getOrderKind("default"), OMP_ORDER_concurrent);
60+
}
61+
62+
TEST(OpenMPParsingTest, getProcBindKind) {
63+
EXPECT_EQ(getProcBindKind("foobar"), OMP_PROC_BIND_unknown);
64+
65+
EXPECT_EQ(getProcBindKind("master"), OMP_PROC_BIND_master);
66+
EXPECT_EQ(getProcBindKind("close"), OMP_PROC_BIND_close);
67+
EXPECT_EQ(getProcBindKind("spread"), OMP_PROC_BIND_spread);
68+
EXPECT_EQ(getProcBindKind("default"), OMP_PROC_BIND_default);
69+
EXPECT_EQ(getProcBindKind("unknown"), OMP_PROC_BIND_unknown);
70+
}
71+
72+
TEST(OpenMPParsingTest, getScheduleKind) {
73+
EXPECT_EQ(getScheduleKind("foobar"), OMP_SCHEDULE_Default);
74+
75+
// FIXME: Why are these not lower case?
76+
EXPECT_EQ(getScheduleKind("Static"), OMP_SCHEDULE_Static);
77+
EXPECT_EQ(getScheduleKind("Dynamic"), OMP_SCHEDULE_Dynamic);
78+
EXPECT_EQ(getScheduleKind("Guided"), OMP_SCHEDULE_Guided);
79+
EXPECT_EQ(getScheduleKind("Auto"), OMP_SCHEDULE_Auto);
80+
EXPECT_EQ(getScheduleKind("Runtime"), OMP_SCHEDULE_Runtime);
81+
EXPECT_EQ(getScheduleKind("Default"), OMP_SCHEDULE_Default);
82+
}
83+
84+
} // namespace

0 commit comments

Comments
 (0)