Skip to content

Commit 30d953b

Browse files
authored
Run linters across test folder. (#3982)
* Also lint test. * Run the linter. * Ignore revs for Python.
1 parent f20d87a commit 30d953b

31 files changed

+688
-783
lines changed

.git-blame-ignore-revs

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ e26a49dbf5749ee92585cec9e95ca781d377ebfd
77
7a722a3fb8205c57d7e9554fc7c62c2629720d5a
88
# Switched from left to right pointer alignment.
99
f1181a071844f759b618ed3c894cf56e2df1dd05
10+
# Added a Python formatter.
11+
8947d5ec2c12157d29a2d07ad25cf0245a5792a5

cmake/Linters.cmake

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ file(
1212
lib/*.h
1313
midend/*.cpp
1414
midend/*.h
15+
test/*.cpp
16+
test/*.h
1517
tools/*.cpp
1618
tools/*.h
1719
)
@@ -92,7 +94,6 @@ file(
9294
tools/*.py
9395
)
9496
list(FILTER P4C_PYTHON_LINT_LIST EXCLUDE REGEX "backends/p4tools/submodules")
95-
list(FILTER P4C_PYTHON_LINT_LIST EXCLUDE REGEX "control-plane/p4runtime")
9697
list(FILTER P4C_PYTHON_LINT_LIST EXCLUDE REGEX "tools/cpplint.py")
9798

9899
add_black_files(${P4C_SOURCE_DIR} "${P4C_PYTHON_LINT_LIST}")

test/gtest/arch_test.cpp

+23-43
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,22 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
#include "gtest/gtest.h"
18-
#include "ir/ir.h"
19-
#include "helpers.h"
20-
#include "lib/log.h"
21-
2217
#include "frontends/common/parseInput.h"
2318
#include "frontends/common/resolveReferences/referenceMap.h"
2419
#include "frontends/common/resolveReferences/resolveReferences.h"
2520
#include "frontends/p4/createBuiltins.h"
2621
#include "frontends/p4/typeChecking/typeChecker.h"
2722
#include "frontends/p4/typeMap.h"
28-
23+
#include "gtest/gtest.h"
24+
#include "helpers.h"
25+
#include "ir/ir.h"
26+
#include "lib/log.h"
2927

3028
using namespace P4;
3129

3230
namespace Test {
3331

34-
class P4CArchitecture : public P4CTest { };
32+
class P4CArchitecture : public P4CTest {};
3533

3634
TEST_F(P4CArchitecture, packet_out) {
3735
std::string program = P4_SOURCE(R"(
@@ -57,10 +55,8 @@ TEST_F(P4CArchitecture, packet_out) {
5755
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
5856

5957
ReferenceMap refMap;
60-
TypeMap typeMap;
61-
PassManager passes({
62-
new TypeChecking(&refMap, &typeMap)
63-
});
58+
TypeMap typeMap;
59+
PassManager passes({new TypeChecking(&refMap, &typeMap)});
6460

6561
pgm = pgm->apply(passes);
6662
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
@@ -92,10 +88,8 @@ TEST_F(P4CArchitecture, duplicatedDeclarationBug) {
9288

9389
if (pgm != nullptr) {
9490
ReferenceMap refMap;
95-
TypeMap typeMap;
96-
PassManager passes({
97-
new TypeChecking(&refMap, &typeMap)
98-
});
91+
TypeMap typeMap;
92+
PassManager passes({new TypeChecking(&refMap, &typeMap)});
9993

10094
pgm = pgm->apply(passes);
10195
}
@@ -141,10 +135,8 @@ TEST_F(P4CArchitecture, instantiation) {
141135
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
142136

143137
ReferenceMap refMap;
144-
TypeMap typeMap;
145-
PassManager passes({
146-
new TypeChecking(&refMap, &typeMap)
147-
});
138+
TypeMap typeMap;
139+
PassManager passes({new TypeChecking(&refMap, &typeMap)});
148140

149141
pgm = pgm->apply(passes);
150142
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
@@ -173,10 +165,8 @@ TEST_F(P4CArchitecture, psa_package_with_body) {
173165

174166
if (pgm != nullptr) {
175167
ReferenceMap refMap;
176-
TypeMap typeMap;
177-
PassManager passes({
178-
new TypeChecking(&refMap, &typeMap)
179-
});
168+
TypeMap typeMap;
169+
PassManager passes({new TypeChecking(&refMap, &typeMap)});
180170
pgm = pgm->apply(passes);
181171
}
182172
ASSERT_GT(::errorCount(), 0U);
@@ -211,10 +201,8 @@ TEST_F(P4CArchitecture, psa_control_in_control) {
211201
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
212202

213203
ReferenceMap refMap;
214-
TypeMap typeMap;
215-
PassManager passes({
216-
new TypeChecking(&refMap, &typeMap)
217-
});
204+
TypeMap typeMap;
205+
PassManager passes({new TypeChecking(&refMap, &typeMap)});
218206
pgm = pgm->apply(passes);
219207
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
220208
}
@@ -237,10 +225,8 @@ TEST_F(P4CArchitecture, psa_clone_as_param_to_package) {
237225
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
238226

239227
ReferenceMap refMap;
240-
TypeMap typeMap;
241-
PassManager passes({
242-
new TypeChecking(&refMap, &typeMap)
243-
});
228+
TypeMap typeMap;
229+
PassManager passes({new TypeChecking(&refMap, &typeMap)});
244230
pgm = pgm->apply(passes);
245231
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
246232
}
@@ -272,10 +258,8 @@ TEST_F(P4CArchitecture, psa_clone_as_param_to_control) {
272258
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
273259

274260
ReferenceMap refMap;
275-
TypeMap typeMap;
276-
PassManager passes({
277-
new TypeChecking(&refMap, &typeMap)
278-
});
261+
TypeMap typeMap;
262+
PassManager passes({new TypeChecking(&refMap, &typeMap)});
279263
pgm = pgm->apply(passes);
280264
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
281265
}
@@ -315,10 +299,8 @@ TEST_F(P4CArchitecture, psa_clone_as_param_to_extern) {
315299
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
316300

317301
ReferenceMap refMap;
318-
TypeMap typeMap;
319-
PassManager passes({
320-
new TypeChecking(&refMap, &typeMap)
321-
});
302+
TypeMap typeMap;
303+
PassManager passes({new TypeChecking(&refMap, &typeMap)});
322304
pgm = pgm->apply(passes);
323305
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
324306
}
@@ -347,10 +329,8 @@ TEST_F(P4CArchitecture, clone_as_extern_method) {
347329
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
348330

349331
ReferenceMap refMap;
350-
TypeMap typeMap;
351-
PassManager passes({
352-
new TypeChecking(&refMap, &typeMap)
353-
});
332+
TypeMap typeMap;
333+
PassManager passes({new TypeChecking(&refMap, &typeMap)});
354334
pgm = pgm->apply(passes);
355335
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
356336
}

test/gtest/bitvec_test.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
1717

18+
#include "lib/bitvec.h"
1819

1920
#include "gtest/gtest.h"
20-
#include "lib/bitvec.h"
2121

2222
namespace Test {
2323

@@ -31,7 +31,7 @@ TEST(Bitvec, Shift) {
3131

3232
#ifdef __SIZEOF_INT128__
3333
TEST(Bitvec, bigval) {
34-
__int128_t val[2] = { 0, 1 };
34+
__int128_t val[2] = {0, 1};
3535
val[1] <<= 100;
3636
bitvec bv(val[1]);
3737
EXPECT_EQ(bv.getbit(100), true);
@@ -45,12 +45,12 @@ TEST(Bitvec, bigval) {
4545
(defined(__clang__) && (__clang_major__ >= 3) && (__clang_minor__ > 8))
4646
bv.setraw(val, 2);
4747
EXPECT_EQ(bv.getbit(238), true);
48-
#endif // (defined(__GNUC__) && !defined(__clang__)) ||
49-
// (defined(__clang__) && (__clang_major__ >= 3) && (__clang_minor__ > 8))
48+
#endif // (defined(__GNUC__) && !defined(__clang__)) ||
49+
// (defined(__clang__) && (__clang_major__ >= 3) && (__clang_minor__ > 8))
5050
}
5151
#else
5252
TEST(Bitvec, bigval) {
53-
int64_t val[2] = { 0, 1 };
53+
int64_t val[2] = {0, 1};
5454
val[1] <<= 60;
5555
bitvec bv(val[1]);
5656
EXPECT_EQ(bv.getbit(60), true);

test/gtest/call_graph_test.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2013-present Barefoot Networks, Inc.
2+
Copyright 2013-present Barefoot Networks, Inc.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -16,23 +16,21 @@ limitations under the License.
1616

1717
#include <vector>
1818

19-
#include "gtest/gtest.h"
2019
#include "frontends/p4/callGraph.h"
20+
#include "gtest/gtest.h"
2121

2222
namespace Test {
2323

2424
template <class T>
2525
static void sameSet(std::unordered_set<T> &set, std::vector<T> vector) {
2626
EXPECT_EQ(vector.size(), set.size());
27-
for (T v : vector)
28-
EXPECT_NEQ(set.end(), set.find(v));
27+
for (T v : vector) EXPECT_NEQ(set.end(), set.find(v));
2928
}
3029

3130
template <class T>
3231
static void sameSet(std::set<T> &set, std::vector<T> vector) {
3332
EXPECT_EQ(vector.size(), set.size());
34-
for (T v : vector)
35-
EXPECT_NEQ(set.end(), set.find(v));
33+
for (T v : vector) EXPECT_NEQ(set.end(), set.find(v));
3634
}
3735

3836
TEST(CallGraph, Acyclic) {

test/gtest/complex_bitwise.cpp

+20-34
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
#include <boost/algorithm/string/replace.hpp>
21
#include <optional>
32

4-
#include "gtest/gtest.h"
5-
#include "ir/ir.h"
6-
#include "helpers.h"
7-
#include "lib/log.h"
8-
#include "lib/sourceCodeBuilder.h"
3+
#include <boost/algorithm/string/replace.hpp>
94

105
#include "frontends/common/parseInput.h"
116
#include "frontends/common/resolveReferences/referenceMap.h"
127
#include "frontends/p4/toP4/toP4.h"
138
#include "frontends/p4/typeChecking/typeChecker.h"
149
#include "frontends/p4/typeMap.h"
10+
#include "gtest/gtest.h"
11+
#include "helpers.h"
12+
#include "ir/ir.h"
13+
#include "lib/log.h"
14+
#include "lib/sourceCodeBuilder.h"
1515
#include "midend/simplifyBitwise.h"
1616

1717
using namespace P4;
1818

19-
2019
namespace Test {
2120

2221
namespace {
2322

24-
std::optional<FrontendTestCase>
25-
createSimplifyBitwiseTestCase(const std::string &ingressSource) {
23+
std::optional<FrontendTestCase> createSimplifyBitwiseTestCase(const std::string &ingressSource) {
2624
std::string source = P4_SOURCE(P4Headers::V1MODEL, R"(
2725
header H
2826
{
@@ -80,7 +78,7 @@ class CountAssignmentStatements : public Inspector {
8078

8179
} // namespace
8280

83-
class SimplifyBitwiseTest : public P4CTest { };
81+
class SimplifyBitwiseTest : public P4CTest {};
8482

8583
TEST_F(SimplifyBitwiseTest, SimpleSplit) {
8684
auto test = createSimplifyBitwiseTestCase(P4_SOURCE(R"(
@@ -94,12 +92,8 @@ TEST_F(SimplifyBitwiseTest, SimpleSplit) {
9492
Util::SourceCodeBuilder builder;
9593
ToP4 dump(builder, false);
9694

97-
PassManager quick_midend = {
98-
new TypeChecking(&refMap, &typeMap, true),
99-
new SimplifyBitwise,
100-
&cas,
101-
&dump
102-
};
95+
PassManager quick_midend = {new TypeChecking(&refMap, &typeMap, true), new SimplifyBitwise,
96+
&cas, &dump};
10397

10498
test->program->apply(quick_midend);
10599
EXPECT_EQ(2, cas.as_total());
@@ -123,23 +117,19 @@ TEST_F(SimplifyBitwiseTest, ManySplit) {
123117
Util::SourceCodeBuilder builder;
124118
ToP4 dump(builder, false);
125119

126-
PassManager quick_midend = {
127-
new TypeChecking(&refMap, &typeMap, true),
128-
new SimplifyBitwise,
129-
&cas,
130-
&dump
131-
};
120+
PassManager quick_midend = {new TypeChecking(&refMap, &typeMap, true), new SimplifyBitwise,
121+
&cas, &dump};
132122

133123
test->program->apply(quick_midend);
134124
EXPECT_EQ(32, cas.as_total());
135125
std::string program_string = builder.toString();
136126
for (int i = 0; i < 32; i += 2) {
137-
std::string value1 = "headers.h.f1[" + std::to_string(i) + ":" + std::to_string(i)
138-
+ "] = headers.h.f2[" + std::to_string(i) + ":"
139-
+ std::to_string(i) + "]";
140-
std::string value2 = "headers.h.f1[" + std::to_string(i+1) + ":" + std::to_string(i+1)
141-
+ "] = headers.h.f1[" + std::to_string(i+1) + ":"
142-
+ std::to_string(i+1) + "]";
127+
std::string value1 = "headers.h.f1[" + std::to_string(i) + ":" + std::to_string(i) +
128+
"] = headers.h.f2[" + std::to_string(i) + ":" + std::to_string(i) +
129+
"]";
130+
std::string value2 = "headers.h.f1[" + std::to_string(i + 1) + ":" + std::to_string(i + 1) +
131+
"] = headers.h.f1[" + std::to_string(i + 1) + ":" +
132+
std::to_string(i + 1) + "]";
143133
EXPECT_FALSE(program_string.find(value1) == std::string::npos);
144134
EXPECT_FALSE(program_string.find(value2) == std::string::npos);
145135
}
@@ -156,12 +146,8 @@ TEST_F(SimplifyBitwiseTest, SplitWithZero) {
156146

157147
Util::SourceCodeBuilder builder;
158148
ToP4 dump(builder, false);
159-
PassManager quick_midend = {
160-
new TypeChecking(&refMap, &typeMap, true),
161-
new SimplifyBitwise,
162-
&cas,
163-
&dump
164-
};
149+
PassManager quick_midend = {new TypeChecking(&refMap, &typeMap, true), new SimplifyBitwise,
150+
&cas, &dump};
165151

166152
test->program->apply(quick_midend);
167153
EXPECT_EQ(3, cas.as_total());

test/gtest/constant_expr_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
namespace Test {
2222

23-
class ConstantExpr : public P4CTest { };
23+
class ConstantExpr : public P4CTest {};
2424

2525
TEST_F(ConstantExpr, TestInt) {
2626
int val = 0x1;

0 commit comments

Comments
 (0)