Skip to content

Commit

Permalink
Run linters across test folder. (#3982)
Browse files Browse the repository at this point in the history
* Also lint test.

* Run the linter.

* Ignore revs for Python.
  • Loading branch information
fruffy authored Apr 28, 2023
1 parent f20d87a commit 30d953b
Show file tree
Hide file tree
Showing 31 changed files with 688 additions and 783 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ e26a49dbf5749ee92585cec9e95ca781d377ebfd
7a722a3fb8205c57d7e9554fc7c62c2629720d5a
# Switched from left to right pointer alignment.
f1181a071844f759b618ed3c894cf56e2df1dd05
# Added a Python formatter.
8947d5ec2c12157d29a2d07ad25cf0245a5792a5
3 changes: 2 additions & 1 deletion cmake/Linters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ file(
lib/*.h
midend/*.cpp
midend/*.h
test/*.cpp
test/*.h
tools/*.cpp
tools/*.h
)
Expand Down Expand Up @@ -92,7 +94,6 @@ file(
tools/*.py
)
list(FILTER P4C_PYTHON_LINT_LIST EXCLUDE REGEX "backends/p4tools/submodules")
list(FILTER P4C_PYTHON_LINT_LIST EXCLUDE REGEX "control-plane/p4runtime")
list(FILTER P4C_PYTHON_LINT_LIST EXCLUDE REGEX "tools/cpplint.py")

add_black_files(${P4C_SOURCE_DIR} "${P4C_PYTHON_LINT_LIST}")
Expand Down
66 changes: 23 additions & 43 deletions test/gtest/arch_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,22 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#include "gtest/gtest.h"
#include "ir/ir.h"
#include "helpers.h"
#include "lib/log.h"

#include "frontends/common/parseInput.h"
#include "frontends/common/resolveReferences/referenceMap.h"
#include "frontends/common/resolveReferences/resolveReferences.h"
#include "frontends/p4/createBuiltins.h"
#include "frontends/p4/typeChecking/typeChecker.h"
#include "frontends/p4/typeMap.h"

#include "gtest/gtest.h"
#include "helpers.h"
#include "ir/ir.h"
#include "lib/log.h"

using namespace P4;

namespace Test {

class P4CArchitecture : public P4CTest { };
class P4CArchitecture : public P4CTest {};

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

ReferenceMap refMap;
TypeMap typeMap;
PassManager passes({
new TypeChecking(&refMap, &typeMap)
});
TypeMap typeMap;
PassManager passes({new TypeChecking(&refMap, &typeMap)});

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

if (pgm != nullptr) {
ReferenceMap refMap;
TypeMap typeMap;
PassManager passes({
new TypeChecking(&refMap, &typeMap)
});
TypeMap typeMap;
PassManager passes({new TypeChecking(&refMap, &typeMap)});

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

ReferenceMap refMap;
TypeMap typeMap;
PassManager passes({
new TypeChecking(&refMap, &typeMap)
});
TypeMap typeMap;
PassManager passes({new TypeChecking(&refMap, &typeMap)});

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

if (pgm != nullptr) {
ReferenceMap refMap;
TypeMap typeMap;
PassManager passes({
new TypeChecking(&refMap, &typeMap)
});
TypeMap typeMap;
PassManager passes({new TypeChecking(&refMap, &typeMap)});
pgm = pgm->apply(passes);
}
ASSERT_GT(::errorCount(), 0U);
Expand Down Expand Up @@ -211,10 +201,8 @@ TEST_F(P4CArchitecture, psa_control_in_control) {
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);

ReferenceMap refMap;
TypeMap typeMap;
PassManager passes({
new TypeChecking(&refMap, &typeMap)
});
TypeMap typeMap;
PassManager passes({new TypeChecking(&refMap, &typeMap)});
pgm = pgm->apply(passes);
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
}
Expand All @@ -237,10 +225,8 @@ TEST_F(P4CArchitecture, psa_clone_as_param_to_package) {
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);

ReferenceMap refMap;
TypeMap typeMap;
PassManager passes({
new TypeChecking(&refMap, &typeMap)
});
TypeMap typeMap;
PassManager passes({new TypeChecking(&refMap, &typeMap)});
pgm = pgm->apply(passes);
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
}
Expand Down Expand Up @@ -272,10 +258,8 @@ TEST_F(P4CArchitecture, psa_clone_as_param_to_control) {
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);

ReferenceMap refMap;
TypeMap typeMap;
PassManager passes({
new TypeChecking(&refMap, &typeMap)
});
TypeMap typeMap;
PassManager passes({new TypeChecking(&refMap, &typeMap)});
pgm = pgm->apply(passes);
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
}
Expand Down Expand Up @@ -315,10 +299,8 @@ TEST_F(P4CArchitecture, psa_clone_as_param_to_extern) {
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);

ReferenceMap refMap;
TypeMap typeMap;
PassManager passes({
new TypeChecking(&refMap, &typeMap)
});
TypeMap typeMap;
PassManager passes({new TypeChecking(&refMap, &typeMap)});
pgm = pgm->apply(passes);
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
}
Expand Down Expand Up @@ -347,10 +329,8 @@ TEST_F(P4CArchitecture, clone_as_extern_method) {
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);

ReferenceMap refMap;
TypeMap typeMap;
PassManager passes({
new TypeChecking(&refMap, &typeMap)
});
TypeMap typeMap;
PassManager passes({new TypeChecking(&refMap, &typeMap)});
pgm = pgm->apply(passes);
ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0);
}
Expand Down
10 changes: 5 additions & 5 deletions test/gtest/bitvec_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#include "lib/bitvec.h"

#include "gtest/gtest.h"
#include "lib/bitvec.h"

namespace Test {

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

#ifdef __SIZEOF_INT128__
TEST(Bitvec, bigval) {
__int128_t val[2] = { 0, 1 };
__int128_t val[2] = {0, 1};
val[1] <<= 100;
bitvec bv(val[1]);
EXPECT_EQ(bv.getbit(100), true);
Expand All @@ -45,12 +45,12 @@ TEST(Bitvec, bigval) {
(defined(__clang__) && (__clang_major__ >= 3) && (__clang_minor__ > 8))
bv.setraw(val, 2);
EXPECT_EQ(bv.getbit(238), true);
#endif // (defined(__GNUC__) && !defined(__clang__)) ||
// (defined(__clang__) && (__clang_major__ >= 3) && (__clang_minor__ > 8))
#endif // (defined(__GNUC__) && !defined(__clang__)) ||
// (defined(__clang__) && (__clang_major__ >= 3) && (__clang_minor__ > 8))
}
#else
TEST(Bitvec, bigval) {
int64_t val[2] = { 0, 1 };
int64_t val[2] = {0, 1};
val[1] <<= 60;
bitvec bv(val[1]);
EXPECT_EQ(bv.getbit(60), true);
Expand Down
10 changes: 4 additions & 6 deletions test/gtest/call_graph_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2013-present Barefoot Networks, Inc.
Copyright 2013-present Barefoot Networks, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -16,23 +16,21 @@ limitations under the License.

#include <vector>

#include "gtest/gtest.h"
#include "frontends/p4/callGraph.h"
#include "gtest/gtest.h"

namespace Test {

template <class T>
static void sameSet(std::unordered_set<T> &set, std::vector<T> vector) {
EXPECT_EQ(vector.size(), set.size());
for (T v : vector)
EXPECT_NEQ(set.end(), set.find(v));
for (T v : vector) EXPECT_NEQ(set.end(), set.find(v));
}

template <class T>
static void sameSet(std::set<T> &set, std::vector<T> vector) {
EXPECT_EQ(vector.size(), set.size());
for (T v : vector)
EXPECT_NEQ(set.end(), set.find(v));
for (T v : vector) EXPECT_NEQ(set.end(), set.find(v));
}

TEST(CallGraph, Acyclic) {
Expand Down
54 changes: 20 additions & 34 deletions test/gtest/complex_bitwise.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
#include <boost/algorithm/string/replace.hpp>
#include <optional>

#include "gtest/gtest.h"
#include "ir/ir.h"
#include "helpers.h"
#include "lib/log.h"
#include "lib/sourceCodeBuilder.h"
#include <boost/algorithm/string/replace.hpp>

#include "frontends/common/parseInput.h"
#include "frontends/common/resolveReferences/referenceMap.h"
#include "frontends/p4/toP4/toP4.h"
#include "frontends/p4/typeChecking/typeChecker.h"
#include "frontends/p4/typeMap.h"
#include "gtest/gtest.h"
#include "helpers.h"
#include "ir/ir.h"
#include "lib/log.h"
#include "lib/sourceCodeBuilder.h"
#include "midend/simplifyBitwise.h"

using namespace P4;


namespace Test {

namespace {

std::optional<FrontendTestCase>
createSimplifyBitwiseTestCase(const std::string &ingressSource) {
std::optional<FrontendTestCase> createSimplifyBitwiseTestCase(const std::string &ingressSource) {
std::string source = P4_SOURCE(P4Headers::V1MODEL, R"(
header H
{
Expand Down Expand Up @@ -80,7 +78,7 @@ class CountAssignmentStatements : public Inspector {

} // namespace

class SimplifyBitwiseTest : public P4CTest { };
class SimplifyBitwiseTest : public P4CTest {};

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

PassManager quick_midend = {
new TypeChecking(&refMap, &typeMap, true),
new SimplifyBitwise,
&cas,
&dump
};
PassManager quick_midend = {new TypeChecking(&refMap, &typeMap, true), new SimplifyBitwise,
&cas, &dump};

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

PassManager quick_midend = {
new TypeChecking(&refMap, &typeMap, true),
new SimplifyBitwise,
&cas,
&dump
};
PassManager quick_midend = {new TypeChecking(&refMap, &typeMap, true), new SimplifyBitwise,
&cas, &dump};

test->program->apply(quick_midend);
EXPECT_EQ(32, cas.as_total());
std::string program_string = builder.toString();
for (int i = 0; i < 32; i += 2) {
std::string value1 = "headers.h.f1[" + std::to_string(i) + ":" + std::to_string(i)
+ "] = headers.h.f2[" + std::to_string(i) + ":"
+ std::to_string(i) + "]";
std::string value2 = "headers.h.f1[" + std::to_string(i+1) + ":" + std::to_string(i+1)
+ "] = headers.h.f1[" + std::to_string(i+1) + ":"
+ std::to_string(i+1) + "]";
std::string value1 = "headers.h.f1[" + std::to_string(i) + ":" + std::to_string(i) +
"] = headers.h.f2[" + std::to_string(i) + ":" + std::to_string(i) +
"]";
std::string value2 = "headers.h.f1[" + std::to_string(i + 1) + ":" + std::to_string(i + 1) +
"] = headers.h.f1[" + std::to_string(i + 1) + ":" +
std::to_string(i + 1) + "]";
EXPECT_FALSE(program_string.find(value1) == std::string::npos);
EXPECT_FALSE(program_string.find(value2) == std::string::npos);
}
Expand All @@ -156,12 +146,8 @@ TEST_F(SimplifyBitwiseTest, SplitWithZero) {

Util::SourceCodeBuilder builder;
ToP4 dump(builder, false);
PassManager quick_midend = {
new TypeChecking(&refMap, &typeMap, true),
new SimplifyBitwise,
&cas,
&dump
};
PassManager quick_midend = {new TypeChecking(&refMap, &typeMap, true), new SimplifyBitwise,
&cas, &dump};

test->program->apply(quick_midend);
EXPECT_EQ(3, cas.as_total());
Expand Down
2 changes: 1 addition & 1 deletion test/gtest/constant_expr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.

namespace Test {

class ConstantExpr : public P4CTest { };
class ConstantExpr : public P4CTest {};

TEST_F(ConstantExpr, TestInt) {
int val = 0x1;
Expand Down
Loading

0 comments on commit 30d953b

Please sign in to comment.