Skip to content

Commit

Permalink
Lrpc 9 use pylint (#17)
Browse files Browse the repository at this point in the history
* Fixed MyPy issues and PyLint issues
* Added pyproject.toml with black, mypy and pylint config
* Applied black to python files
* Update setup.py
* Added github action for mypy and pylint with reviewdog
* Using Python 3.9 to make sure everything works with old version of Python
* Removed base_type_is_struct and base_type_is_enum from LrpcVar. If a custom type is an enum or struct, the type field of LrpcVar is prepended with `enum@` or `struct@` by LrpcDef
* Enable build with MSVC
* C++ version to 14 for now
* Compiler warnings as errors off for now
* MSVC code analysis configuration
* Fix some SonarCloud issues
* Added logging to report definition warnings and errors
* Normalized loading LrpcDef from various sources

---------

Co-authored-by: tzijnge <[email protected]>
Co-authored-by: Timon Zijnge <[email protected]>
  • Loading branch information
3 people authored Oct 12, 2024
1 parent 07b0767 commit 3510950
Show file tree
Hide file tree
Showing 76 changed files with 3,272 additions and 2,573 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Checkout
uses: actions/[email protected]
with:
submodules: "true"

- name: Install Python requirements
run: pip install -r requirements.txt
run: |
pip install -r requirements/package.txt
pip install -r requirements/dev.txt
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/msvc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ jobs:
with:
submodules: "true"

- name: Install Python requirements
run: |
pip install -r requirements/package.txt
pip install -r requirements/dev.txt
- name: Configure CMake
run: cmake -B ${{ env.build }}

Expand All @@ -53,6 +58,8 @@ jobs:
cmakeBuildDirectory: ${{ env.build }}
# Ruleset file that will determine what checks will be run
ruleset: NativeRecommendedRules.ruleset
ignoredIncludePaths: external
ignoreSystemHeaders: true

# Upload SARIF file to GitHub Code Scanning Alerts
- name: Upload SARIF to GitHub
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Reviewdog
on: [pull_request]
jobs:
Reviewdog:
name: Reviewdog
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install mypy
run: pip install mypy
- name: Install requirements
run: pip install -r requirements/dev.txt
- name: Run MyPy
uses: tsuyoshicho/action-mypy@v4
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
level: error
fail_on_error: false
- name: Run PyLint
uses: dciborow/[email protected]
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
level: error
glob_pattern: "package"
fail_on_error: false
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

[![Quality gate](https://sonarcloud.io/api/project_badges/quality_gate?project=tzijnge_LotusRpc)](https://sonarcloud.io/summary/new_code?id=tzijnge_LotusRpc)

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

# LotusRpc
RPC framework for embedded systems based on [ETL](https://github.com/ETLCPP/etl). Generates C++ code with no dynamic memory allocations, no exceptions, no RTTI, etc.

Expand Down
12 changes: 9 additions & 3 deletions language/cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project(UnitTests VERSION 0.1.0)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
set(BUILD_GMOCK ON)
set(gtest_force_shared_crt on)

Expand Down Expand Up @@ -54,9 +54,15 @@ add_executable(UnitTests

target_include_directories(UnitTests PRIVATE .)
target_include_directories(UnitTests PRIVATE ../include)
target_include_directories(UnitTests PRIVATE ../../../external/etl/include)
target_include_directories(UnitTests SYSTEM PRIVATE ../../../external/etl/include)

target_compile_options(UnitTests PRIVATE -Werror -Wall -Wextra)
if(MSVC)
target_compile_options(UnitTests PRIVATE /W4)
else()
target_compile_options(UnitTests PRIVATE -Wall -Wextra)
endif()

set_property(TARGET UnitTests PROPERTY COMPILE_WARNING_AS_ERROR OFF)

target_link_libraries(
UnitTests
Expand Down
16 changes: 8 additions & 8 deletions language/cpp/tests/TestEtlRwExtensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TEST(TestEtlRwExtensions, readArithmetic)
EXPECT_TRUE(lrpc::read_unchecked<bool>(reader));
EXPECT_EQ(0x02, lrpc::read_unchecked<uint8_t>(reader));
EXPECT_EQ(0x0403, lrpc::read_unchecked<uint16_t>(reader));
EXPECT_FLOAT_EQ(123.456, lrpc::read_unchecked<float>(reader));
EXPECT_FLOAT_EQ(123.456F, lrpc::read_unchecked<float>(reader));
}

TEST(TestEtlRwExtensions, readAutoString)
Expand Down Expand Up @@ -160,7 +160,7 @@ TEST(TestEtlRwExtensions, copyString)

TEST(TestEtlRwExtensions, copyArrayOfString)
{
etl::array<etl::string_view, 2> source {"T1", "T2"};
etl::array<etl::string_view, 2> source{"T1", "T2"};
etl::array<etl::string<2>, 2> dest;
lrpc::copy<etl::array<etl::string<2>, 2>>(source, dest);
EXPECT_EQ("T1", dest[0]);
Expand All @@ -169,13 +169,13 @@ TEST(TestEtlRwExtensions, copyArrayOfString)

TEST(TestEtlRwExtensions, copyOptionalString)
{
etl::optional<etl::string_view> source1 {"T1"};
etl::optional<etl::string_view> source1{"T1"};
etl::optional<etl::string<2>> dest1;
lrpc::copy<etl::optional<etl::string<2>>>(source1, dest1);
ASSERT_TRUE(dest1.has_value());
EXPECT_EQ("T1", dest1.value());

etl::optional<etl::string<2>> dest2 {"~~"};
etl::optional<etl::string<2>> dest2{"~~"};
lrpc::copy<etl::optional<etl::string<2>>>(source1, dest2);
ASSERT_TRUE(dest2.has_value());
EXPECT_EQ("T1", dest2.value());
Expand All @@ -194,7 +194,7 @@ TEST(TestEtlRwExtensions, writeArithmetic)
lrpc::write_unchecked<bool>(writer, true);
lrpc::write_unchecked<uint8_t>(writer, 0x02);
lrpc::write_unchecked<uint16_t>(writer, 0x0403);
lrpc::write_unchecked<float>(writer, 123.456);
lrpc::write_unchecked<float>(writer, 123.456F);

auto written = writer.used_data();
ASSERT_EQ(9, written.size());
Expand Down Expand Up @@ -248,11 +248,11 @@ TEST(TestEtlRwExtensions, writeArray)
etl::array<uint8_t, 10> storage;
etl::byte_stream_writer writer(storage.begin(), storage.end(), etl::endian::little);

etl::array<uint8_t, 2> t2 {0x01, 0x02};
etl::array<uint8_t, 2> t2{0x01, 0x02};
lrpc::write_unchecked<etl::array<uint8_t, 2>>(writer, t2);

auto written = writer.used_data();
ASSERT_EQ(2, written.size());
ASSERT_EQ(2, written.size());
EXPECT_EQ(0x01, written[0]);
EXPECT_EQ(0x02, written[1]);
}
Expand All @@ -262,7 +262,7 @@ TEST(TestEtlRwExtensions, writeArrayOfString)
etl::array<uint8_t, 10> storage;
etl::byte_stream_writer writer(storage.begin(), storage.end(), etl::endian::little);

etl::array<etl::string<2>, 2> a {"T1", "T2"};
etl::array<etl::string<2>, 2> a{"T1", "T2"};
lrpc::write_unchecked<etl::array<etl::string<2>, 2>>(writer, a);

auto written = writer.used_data();
Expand Down
27 changes: 20 additions & 7 deletions language/cpp/tests/TestServer1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ class TestServer1 : public ::testing::Test
const etl::span<const uint8_t> s(bytes.begin(), bytes.end());

lrpc::Service::Reader reader(s.begin(), s.end(), etl::endian::little);
lrpc::Service::Writer writer(response.begin(), response.end(), etl::endian::little);
lrpc::Service::Writer writer(responseBuffer.begin(), responseBuffer.end(), etl::endian::little);
s0Service.invoke(reader, writer);

return { response.begin(), writer.size_bytes()};
return {responseBuffer.begin(), writer.size_bytes()};
}

void EXPECT_RESPONSE(const std::vector<uint8_t> &expected, const etl::span<uint8_t> actual)
{
std::vector<uint8_t> actualVec {actual.begin(), actual.end()};
std::vector<uint8_t> actualVec{actual.begin(), actual.end()};
EXPECT_EQ(expected, actualVec);
}

private:
etl::array<uint8_t, 256> response;
etl::array<uint8_t, 256> responseBuffer;
};

static_assert(std::is_same<ts1::Server1, lrpc::Server<0, 100, 200>>::value, "RX and/or TX buffer size are unequal to the definition file");
Expand Down Expand Up @@ -117,15 +117,15 @@ TEST_F(TestServer1, decodeF3)
// Decode function f4 with float arg
TEST_F(TestServer1, decodeF4)
{
EXPECT_CALL(s0Service, f4(123.456));
EXPECT_CALL(s0Service, f4(123.456F));
auto response = receive({4, 0x79, 0xE9, 0xF6, 0x42});
EXPECT_RESPONSE({4}, response);
}

// Decode function f5 with array of uint16_t arg
TEST_F(TestServer1, decodeF5)
{
std::vector<uint16_t> expected {0xBBAA, 0xDDCC};
std::vector<uint16_t> expected{0xBBAA, 0xDDCC};
EXPECT_CALL(s0Service, f5(SPAN_EQ(expected)));
auto response = receive({5, 0xAA, 0xBB, 0xCC, 0xDD});
EXPECT_RESPONSE({5}, response);
Expand Down Expand Up @@ -278,7 +278,20 @@ TEST_F(TestServer1, decodef22)

EXPECT_CALL(s0Service, f22(arg1, arg2)).WillOnce(Return(std::tuple<etl::string<4>, etl::string<4>>{ret1, ret2}));
auto response = receive({22, 'a', 'r', 'g', '1', '\0', 'a', 'r', 'g', '2', '\0'});
EXPECT_RESPONSE({22, 'r','e','t','1','\0','r','e','t','2','\0',}, response);
EXPECT_RESPONSE({
22,
'r',
'e',
't',
'1',
'\0',
'r',
'e',
't',
'2',
'\0',
},
response);
}

// Decode function f6 with string arg
Expand Down
8 changes: 4 additions & 4 deletions language/cpp/tests/TestServer2_s0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ class TestServer2 : public ::testing::Test
const etl::span<const uint8_t> s(bytes.begin(), bytes.end());

lrpc::Service::Reader reader(s.begin(), s.end(), etl::endian::little);
lrpc::Service::Writer writer(response.begin(), response.end(), etl::endian::little);
lrpc::Service::Writer writer(responseBuffer.begin(), responseBuffer.end(), etl::endian::little);
service.invoke(reader, writer);

return { response.begin(), writer.size_bytes()};
return {responseBuffer.begin(), writer.size_bytes()};
}

void EXPECT_RESPONSE(const std::vector<uint8_t> &expected, const etl::span<uint8_t> actual)
{
std::vector<uint8_t> actualVec {actual.begin(), actual.end()};
std::vector<uint8_t> actualVec{actual.begin(), actual.end()};
EXPECT_EQ(expected, actualVec);
}

private:
etl::array<uint8_t, 256> response;
etl::array<uint8_t, 256> responseBuffer;
};

static_assert(std::is_same<Server2, lrpc::Server<1, 100, 256>>::value, "RX and/or TX buffer size are unequal to the definition file");
Expand Down
15 changes: 7 additions & 8 deletions language/cpp/tests/TestServer2_s1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ MATCHER_P(SPAN_EQ, e, "Equality matcher for etl::span")
}
}
return true;

}

class MockS01Service : public s01ServiceShim
Expand All @@ -44,20 +43,20 @@ class TestServer2_s1 : public ::testing::Test
const etl::span<const uint8_t> s(bytes.begin(), bytes.end());

lrpc::Service::Reader reader(s.begin(), s.end(), etl::endian::little);
lrpc::Service::Writer writer(response.begin(), response.end(), etl::endian::little);
lrpc::Service::Writer writer(responseBuffer.begin(), responseBuffer.end(), etl::endian::little);
service.invoke(reader, writer);

return { response.begin(), writer.size_bytes()};
return {responseBuffer.begin(), writer.size_bytes()};
}

void EXPECT_RESPONSE(const std::vector<uint8_t> &expected, const etl::span<uint8_t> actual)
{
std::vector<uint8_t> actualVec {actual.begin(), actual.end()};
std::vector<uint8_t> actualVec{actual.begin(), actual.end()};
EXPECT_EQ(expected, actualVec);
}

private:
etl::array<uint8_t, 256> response;
etl::array<uint8_t, 256> responseBuffer;
};

// Decode void function with array of strings param
Expand All @@ -82,7 +81,7 @@ TEST_F(TestServer2_s1, decodeF0WithStringShorterThanMax)
// Decode function that returns array of strings
TEST_F(TestServer2_s1, decodeF1)
{
etl::array<etl::string<2>, 2> retVal {"T1", "T2"};
etl::array<etl::string<2>, 2> retVal{"T1", "T2"};
EXPECT_CALL(service, f1()).WillOnce(Return(retVal));
auto response = receive({1});
EXPECT_RESPONSE({1, 'T', '1', '\0', 'T', '2', '\0'}, response);
Expand Down Expand Up @@ -144,8 +143,8 @@ TEST_F(TestServer2_s1, decodeF6)
// Decode function that takes auto string argument and returns fixed size string
TEST_F(TestServer2_s1, decodeF7)
{
etl::string<5> retVal {"T1234"};
etl::string_view expected {"T0"};
etl::string<5> retVal{"T1234"};
etl::string_view expected{"T0"};
EXPECT_CALL(service, f7(expected)).WillOnce(Return(retVal));
auto response = receive({7, 'T', '0', '\0'});
EXPECT_RESPONSE({7, 'T', '1', '2', '3', '4', '\0'}, response);
Expand Down
5 changes: 5 additions & 0 deletions language/cpp/tests/etl_profile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#ifdef _MSC_VER
#define ETL_ENDIAN_NATIVE 0
#endif
Empty file.
Loading

0 comments on commit 3510950

Please sign in to comment.