Skip to content

Commit

Permalink
fix: removed duplicate file (#920)
Browse files Browse the repository at this point in the history
* fix: removed duplicate file

Signed-off-by: James Chapman <[email protected]>

* fix: might fix BAZEL build

Signed-off-by: James Chapman <[email protected]>

* Initial draft for separate util library

Signed-off-by: aw <[email protected]>

* clang-format

Signed-off-by: aw <[email protected]>

* added @hikinggrass comments

Signed-off-by: aw <[email protected]>

* fix bazel

Signed-off-by: Dima Dorezyuk <[email protected]>

* more consistent directory structure

Signed-off-by: aw <[email protected]>

* fix: fixed missing header when building MBED TLS version of V2G

Signed-off-by: James Chapman <[email protected]>

---------

Signed-off-by: James Chapman <[email protected]>
Signed-off-by: aw <[email protected]>
Signed-off-by: Dima Dorezyuk <[email protected]>
Co-authored-by: aw <[email protected]>
Co-authored-by: Dima Dorezyuk <[email protected]>
Co-authored-by: Piet Gömpel <[email protected]>
  • Loading branch information
4 people authored Nov 6, 2024
1 parent 1a162cc commit 2ec32d8
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 110 deletions.
5 changes: 5 additions & 0 deletions lib/staging/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
add_subdirectory(can_dpm1000)
add_subdirectory(util)

if(EVEREST_DEPENDENCY_ENABLED_LIBEVSE_SECURITY)
add_subdirectory(evse_security)
add_subdirectory(tls)
endif()

if(EVEREST_DEPENDENCY_ENABLED_LIBSLAC AND EVEREST_DEPENDENCY_ENABLED_LIBFSM)
add_subdirectory(slac)
endif()

if(EVEREST_DEPENDENCY_ENABLED_EVEREST_GPIO)
add_subdirectory(gpio)
endif()

if(EVEREST_DEPENDENCY_ENABLED_LIBOCPP)
add_subdirectory(ocpp)
endif()
4 changes: 3 additions & 1 deletion lib/staging/tls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ target_compile_definitions(tls PRIVATE
target_include_directories(tls
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../util>
)

# FIXME (aw): check whether all of this needs to be publicly exposed
target_link_libraries(tls
PUBLIC
OpenSSL::SSL
OpenSSL::Crypto
everest::evse_security
everest::staging::util
PRIVATE
everest::framework
)

Expand Down
4 changes: 2 additions & 2 deletions lib/staging/tls/extensions/tls_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <cstdint>

#include <EnumFlags.hpp>
#include <everest/staging/util/EnumFlags.hpp>

struct ocsp_response_st;
struct ssl_ctx_st;
Expand All @@ -26,7 +26,7 @@ class StatusFlags {
last = trusted_ca_keys,
};

util::AtomicEnumFlags<flags_t, std::uint8_t> flags;
everest::staging::util::AtomicEnumFlags<flags_t, std::uint8_t> flags;

public:
void status_request_received() {
Expand Down
47 changes: 27 additions & 20 deletions lib/staging/tls/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ add_executable(${TLS_GTEST_NAME})
add_dependencies(${TLS_GTEST_NAME} tls_test_files_target)

target_include_directories(${TLS_GTEST_NAME} PRIVATE
. .. ../../util
)
..)

target_compile_definitions(${TLS_GTEST_NAME} PRIVATE
-DUNIT_TEST
Expand All @@ -46,19 +45,21 @@ target_sources(${TLS_GTEST_NAME} PRIVATE
../tls.cpp
)

target_link_libraries(${TLS_GTEST_NAME} PRIVATE
GTest::gtest
OpenSSL::SSL
OpenSSL::Crypto
everest::evse_security
target_link_libraries(${TLS_GTEST_NAME}
PRIVATE
GTest::gtest
OpenSSL::SSL
OpenSSL::Crypto
everest::evse_security
everest::staging::util
)

set(TLS_MAIN_NAME tls_server)
add_executable(${TLS_MAIN_NAME})
add_dependencies(${TLS_MAIN_NAME} tls_test_files_target)

target_include_directories(${TLS_MAIN_NAME} PRIVATE
. .. ../../util
..
)

target_compile_definitions(${TLS_MAIN_NAME} PRIVATE
Expand All @@ -74,17 +75,19 @@ target_sources(${TLS_MAIN_NAME} PRIVATE
../tls.cpp
)

target_link_libraries(${TLS_MAIN_NAME} PRIVATE
OpenSSL::SSL
OpenSSL::Crypto
target_link_libraries(${TLS_MAIN_NAME}
PRIVATE
OpenSSL::SSL
OpenSSL::Crypto
everest::staging::util
)

set(TLS_CLIENT_NAME tls_client)
add_executable(${TLS_CLIENT_NAME})
add_dependencies(${TLS_CLIENT_NAME} tls_test_files_target)

target_include_directories(${TLS_CLIENT_NAME} PRIVATE
. .. ../../util
..
)

target_compile_definitions(${TLS_CLIENT_NAME} PRIVATE
Expand All @@ -100,17 +103,19 @@ target_sources(${TLS_CLIENT_NAME} PRIVATE
../tls.cpp
)

target_link_libraries(${TLS_CLIENT_NAME} PRIVATE
OpenSSL::SSL
OpenSSL::Crypto
target_link_libraries(${TLS_CLIENT_NAME}
PRIVATE
OpenSSL::SSL
OpenSSL::Crypto
everest::staging::util
)

set(TLS_PATCH_NAME patched_test)
add_executable(${TLS_PATCH_NAME})
add_dependencies(${TLS_PATCH_NAME} tls_test_files_target)

target_include_directories(${TLS_PATCH_NAME} PRIVATE
. .. ../../util
..
)

target_compile_definitions(${TLS_PATCH_NAME} PRIVATE
Expand All @@ -126,10 +131,12 @@ target_sources(${TLS_PATCH_NAME} PRIVATE
../tls.cpp
)

target_link_libraries(${TLS_PATCH_NAME} PRIVATE
GTest::gtest_main
OpenSSL::SSL
OpenSSL::Crypto
target_link_libraries(${TLS_PATCH_NAME}
PRIVATE
GTest::gtest_main
OpenSSL::SSL
OpenSSL::Crypto
everest::staging::util
)

add_test(${TLS_GTEST_NAME} ${TLS_GTEST_NAME})
10 changes: 6 additions & 4 deletions lib/staging/tls/tests/tls_connection_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <extensions/helpers.hpp>
#include <openssl_util.hpp>

#include <EnumFlags.hpp>
#include <array>
#include <chrono>
#include <csignal>
Expand All @@ -18,6 +17,8 @@
#include <tls.hpp>
#include <unistd.h>

#include <everest/staging/util/EnumFlags.hpp>

using namespace std::chrono_literals;

namespace {
Expand All @@ -35,10 +36,11 @@ struct ClientStatusRequestV2Test : public ClientStatusRequestV2 {
last = connected,
};

util::AtomicEnumFlags<flags_t, std::uint8_t>& flags;
everest::staging::util::AtomicEnumFlags<flags_t, std::uint8_t>& flags;

ClientStatusRequestV2Test() = delete;
explicit ClientStatusRequestV2Test(util::AtomicEnumFlags<flags_t, std::uint8_t>& flag_ref) : flags(flag_ref) {
explicit ClientStatusRequestV2Test(everest::staging::util::AtomicEnumFlags<flags_t, std::uint8_t>& flag_ref) :
flags(flag_ref) {
}

int status_request_cb(tls::Ssl* ctx) override {
Expand Down Expand Up @@ -96,7 +98,7 @@ struct ClientStatusRequestV2Test : public ClientStatusRequestV2 {

struct ClientTest : public tls::Client {
using flags_t = ClientStatusRequestV2Test::flags_t;
util::AtomicEnumFlags<flags_t, std::uint8_t> flags;
everest::staging::util::AtomicEnumFlags<flags_t, std::uint8_t> flags;

ClientTest() : tls::Client(std::unique_ptr<ClientStatusRequestV2>(new ClientStatusRequestV2Test(flags))) {
}
Expand Down
6 changes: 6 additions & 0 deletions lib/staging/util/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cc_library(
name = "util",
hdrs = ["include/*.hpp"],
visibility = ["//visibility:public"],
includes = ["include"],
)
11 changes: 11 additions & 0 deletions lib/staging/util/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_library(everest_staging_util INTERFACE)
add_library(everest::staging::util ALIAS everest_staging_util)

target_include_directories(everest_staging_util
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

if (BUILD_TESTING)
add_subdirectory(tests)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <atomic>
#include <type_traits>

namespace util {
namespace everest::staging::util {

template <typename T, typename B> class AtomicEnumFlags {
static_assert(std::is_enum<T>(), "Not enum");
Expand Down Expand Up @@ -53,5 +53,5 @@ template <typename T, typename B> class AtomicEnumFlags {
}
};

} // namespace util
} // namespace everest::staging::util
#endif
12 changes: 12 additions & 0 deletions lib/staging/util/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
add_executable(EnumFlagsTest
EnumFlagsTest.cpp
)

target_link_libraries(EnumFlagsTest
PRIVATE
GTest::gtest_main
everest::staging::util
)

include(GoogleTest)
gtest_discover_tests(EnumFlagsTest)
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include <EnumFlags.hpp>
#include <gtest/gtest.h>

#include <atomic>

namespace {
#include <everest/staging/util/EnumFlags.hpp>

enum class ErrorHandlingFlags : std::uint8_t {
prevent_charging,
prevent_charging_welded,
all_errors_cleared,
last = AllErrorCleared
last = all_errors_cleared
};

enum class BspErrors : std::uint8_t {
Expand Down Expand Up @@ -39,52 +36,52 @@ enum class BspErrors : std::uint8_t {
last = VendorError
};

using namespace everest::staging::util;

TEST(AtomicEnumFlagsTest, init) {
module::AtomicEnumFlags<ErrorHandlingFlags, std::uint8_t> flags;
AtomicEnumFlags<ErrorHandlingFlags, std::uint8_t> flags;
EXPECT_TRUE(flags.all_reset());
}

TEST(AtomicEnumFlagsTest, init_large) {
module::AtomicEnumFlags<BspErrors, std::uint32_t> flags;
AtomicEnumFlags<BspErrors, std::uint32_t> flags;
EXPECT_TRUE(flags.all_reset());
}

TEST(AtomicEnumFlagsTest, set_reset_one) {
module::AtomicEnumFlags<ErrorHandlingFlags, std::uint8_t> flags;
AtomicEnumFlags<ErrorHandlingFlags, std::uint8_t> flags;
EXPECT_TRUE(flags.all_reset());

flags.set(ErrorHandlingFlags::AllErrorCleared);
flags.set(ErrorHandlingFlags::all_errors_cleared);
EXPECT_FALSE(flags.all_reset());
flags.reset(ErrorHandlingFlags::AllErrorCleared);
flags.reset(ErrorHandlingFlags::all_errors_cleared);
EXPECT_TRUE(flags.all_reset());
}

TEST(AtomicEnumFlagsTest, set_reset_two) {
module::AtomicEnumFlags<ErrorHandlingFlags, std::uint8_t> flags;
AtomicEnumFlags<ErrorHandlingFlags, std::uint8_t> flags;
EXPECT_TRUE(flags.all_reset());

flags.set(ErrorHandlingFlags::AllErrorCleared);
flags.set(ErrorHandlingFlags::all_errors_cleared);
EXPECT_FALSE(flags.all_reset());
flags.set(ErrorHandlingFlags::PreventCharging);
flags.set(ErrorHandlingFlags::prevent_charging);
EXPECT_FALSE(flags.all_reset());
flags.reset(ErrorHandlingFlags::AllErrorCleared);
flags.reset(ErrorHandlingFlags::all_errors_cleared);
EXPECT_FALSE(flags.all_reset());
flags.reset(ErrorHandlingFlags::PreventCharging);
flags.reset(ErrorHandlingFlags::prevent_charging);
EXPECT_TRUE(flags.all_reset());
}

TEST(AtomicEnumFlagsTest, set_reset_three) {
module::AtomicEnumFlags<ErrorHandlingFlags, std::uint8_t> flags;
AtomicEnumFlags<ErrorHandlingFlags, std::uint8_t> flags;
EXPECT_TRUE(flags.all_reset());

flags.set(ErrorHandlingFlags::AllErrorCleared);
flags.set(ErrorHandlingFlags::all_errors_cleared);
EXPECT_FALSE(flags.all_reset());
flags.set(ErrorHandlingFlags::PreventCharging);
flags.set(ErrorHandlingFlags::prevent_charging);
EXPECT_FALSE(flags.all_reset());
flags.set(ErrorHandlingFlags::prevent_charging_welded);
EXPECT_FALSE(flags.all_reset());
flags.reset();
EXPECT_TRUE(flags.all_reset());
}

} // namespace
56 changes: 0 additions & 56 deletions modules/EvseManager/EnumFlags.hpp

This file was deleted.

Loading

0 comments on commit 2ec32d8

Please sign in to comment.