Skip to content

Commit

Permalink
snapshots seg: library target (#1807)
Browse files Browse the repository at this point in the history
  • Loading branch information
battlmonstr authored Feb 12, 2024
1 parent ae94cff commit 60f0b46
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 88 deletions.
1 change: 1 addition & 0 deletions cmake/common/targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function(silkworm_library TARGET)

file(GLOB_RECURSE SRC CONFIGURE_DEPENDS "*.cpp" "*.hpp")
list(FILTER SRC EXCLUDE REGEX "_test\\.cpp$")
list(FILTER SRC EXCLUDE REGEX "_benchmark\\.cpp$")
list_filter(SRC ARG_EXCLUDE_REGEX)
add_library(${TARGET} ${SRC})

Expand Down
5 changes: 0 additions & 5 deletions cmd/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ endif()
if(NOT SILKWORM_CORE_ONLY)
find_package(GTest REQUIRED)

# Silkworm Node Tests
file(GLOB_RECURSE SILKWORM_NODE_TESTS CONFIGURE_DEPENDS "${SILKWORM_MAIN_SRC_DIR}/node/*_test.cpp")
add_executable(node_test unit_test.cpp ${SILKWORM_NODE_TESTS})
target_link_libraries(node_test silkworm_node Catch2::Catch2)

# Silkworm RpcDaemon Tests
file(GLOB_RECURSE SILKWORM_RPCDAEMON_TESTS CONFIGURE_DEPENDS "${SILKWORM_MAIN_SRC_DIR}/rpc/*_test.cpp")
add_executable(rpcdaemon_test unit_test.cpp ${SILKWORM_RPCDAEMON_TESTS})
Expand Down
File renamed without changes.
26 changes: 7 additions & 19 deletions silkworm/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
limitations under the License.
]]

include("${SILKWORM_MAIN_DIR}/cmake/common/targets.cmake")

add_subdirectory(snapshots/seg)

find_package(absl REQUIRED)
find_package(asio-grpc REQUIRED)
find_package(Boost REQUIRED headers container)
Expand All @@ -23,23 +27,6 @@ find_package(magic_enum REQUIRED)
find_package(Protobuf REQUIRED)
find_package(roaring REQUIRED)

file(
GLOB_RECURSE
SILKWORM_NODE_SRC
CONFIGURE_DEPENDS
"*.cpp"
"*.hpp"
"*.c"
"*.h"
"*.cc"
)
list(FILTER SILKWORM_NODE_SRC EXCLUDE REGEX "_test\\.cpp$")
list(FILTER SILKWORM_NODE_SRC EXCLUDE REGEX "_benchmark\\.cpp$")

add_library(silkworm_node "${SILKWORM_NODE_SRC}")

target_include_directories(silkworm_node PUBLIC "${SILKWORM_MAIN_DIR}")

set(SILKWORM_NODE_PUBLIC_LIBS
silkworm_core
silkworm_infra
Expand All @@ -63,13 +50,14 @@ set(SILKWORM_NODE_PRIVATE_LIBS
cborcpp
evmone
magic_enum::magic_enum
sais_lite
silkworm_interfaces
silkworm_snapshots_seg
)
# cmake-format: on

target_link_libraries(
silkworm_library(
silkworm_node
PUBLIC ${SILKWORM_NODE_PUBLIC_LIBS}
PRIVATE ${SILKWORM_NODE_PRIVATE_LIBS}
EXCLUDE_REGEX "snapshots/seg"
)
2 changes: 1 addition & 1 deletion silkworm/node/snapshots/rec_split/common/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#include <memory>

#include <silkworm/core/common/assert.hpp>
#include <silkworm/node/common/bit_count.hpp>
#include <silkworm/core/common/bit_count.hpp>

// Explicit branch predictions
#define likely(x) __builtin_expect(!!(x), 1)
Expand Down
26 changes: 26 additions & 0 deletions silkworm/node/snapshots/seg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#[[
Copyright 2024 The Silkworm Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]

include("${SILKWORM_MAIN_DIR}/cmake/common/targets.cmake")

# circular_buffer
find_package(Boost REQUIRED headers)

silkworm_library(
silkworm_snapshots_seg
PUBLIC silkworm_core silkworm_infra
PRIVATE Boost::headers sais_lite
)
2 changes: 1 addition & 1 deletion silkworm/node/snapshots/seg/compressor/patricia_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#include <utility>
#include <vector>

#include <silkworm/core/common/bit_count.hpp>
#include <silkworm/core/common/bytes.hpp>
#include <silkworm/node/common/bit_count.hpp>

#include "lcp_kasai.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "patricia_tree.hpp"

#include <catch2/catch.hpp>
Expand Down
2 changes: 0 additions & 2 deletions silkworm/node/snapshots/seg/compressor/pattern_extractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

#include <silkworm/core/common/bytes.hpp>

#include "intx/intx.hpp"

namespace silkworm::snapshots::seg {

/**
Expand Down
2 changes: 0 additions & 2 deletions silkworm/node/snapshots/seg/decompressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@

#include <absl/functional/function_ref.h>

#include <silkworm/core/common/base.hpp>
#include <silkworm/core/common/bytes.hpp>
#include <silkworm/infra/common/log.hpp>
#include <silkworm/infra/common/memory_mapped_file.hpp>

namespace silkworm::snapshots::seg {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
limitations under the License.
*/

#include "decompressor.hpp"

#include <algorithm>
#include <filesystem>
#include <map>
Expand All @@ -34,14 +32,16 @@
#include <silkworm/infra/test_util/log.hpp>
#include <silkworm/node/snapshots/test_util/common.hpp>

using Catch::Matchers::Message;
#include "seg/decompressor.hpp"

namespace silkworm::snapshots::seg {
namespace silkworm::snapshots {

using Catch::Matchers::Message;
namespace test = test_util;
using silkworm::test_util::null_stream;
using silkworm::test_util::SetLogVerbosityGuard;
using silkworm::test_util::TemporaryFile;
using namespace snapshots::seg;

//! DecodingTable exposed for white-box testing
class DecodingTable_ForTest : public DecodingTable {
Expand Down Expand Up @@ -547,4 +547,4 @@ TEST_CASE("Decompressor: lorem ipsum has_prefix", "[silkworm][node][seg][decompr
CHECK(test_function(it));
}

} // namespace silkworm::snapshots::seg
} // namespace silkworm::snapshots
18 changes: 7 additions & 11 deletions tests/unit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ It works with multiple compilers and build configurations.
$cd tests/unit
$./run_unit_test_loop.py
Usage: ./run_unit_test_loop.py [-h] [-i iterations] [-m modules] [-t test] builddir
Usage: ./run_unit_test_loop.py [-h] [-i iterations] [-t test] modules
Launch an automated unit test sequence on target build configuration
builddir
the path of the target build folder
modules
comma-separated list of unit test executables to launch
-h print this help
-i iterations
the number of iterations for each configuration (default: 1000)
-m modules
the list of unit test modules to launch (default: ['core_test', 'node_test', 'rpcdaemon_test', 'sentry_test', 'sync_test'])
-o options
the Catch2 options to pass to the launcher enclosed in string (default: "" i.e. none)
-t test
Expand All @@ -29,11 +27,9 @@ builddir
## Examples

```
$cd tests/unit
$./run_unit_test_loop.py -i 100 -m node_test ../../cmake-build-clang-release
$./run_unit_test_loop.py -i 100 build/silkworm/node/silkworm_node_test
$./run_unit_test_loop.py -i 100 -m node_test -o "-d yes" ../../cmake-build-clang-release
$./run_unit_test_loop.py -i 100 -o "-d yes" build/silkworm/node/silkworm_node_test
$./run_unit_test_loop.py -i 100 -m node_test -t "MemoryMutationCursor: to_next" ../../cmake-build-clang-release
```
$./run_unit_test_loop.py -i 100 -t "MemoryMutationCursor: to_next" build/silkworm/node/silkworm_node_test
```
53 changes: 11 additions & 42 deletions tests/unit/run_unit_test_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,46 @@
from typing import List


class UnitTestModule(str, Enum):
""" The unit test modules"""
core_test = 'core_test'
node_test = 'node_test'
rpcdaemon_test = 'rpcdaemon_test'
sentry_test = 'sentry_test'
sync_test = 'sync_test'

@classmethod
def item_names(cls) -> List[str]:
""" Return the list of enumeration item names """
return [member_name for member_name in UnitTestModule.__members__.keys()]

@classmethod
def has_item(cls, name: str) -> bool:
""" Return true if name is a valid enumeration item, false otherwise """
return name in cls.item_names()


class UnitTest:
""" The unit test executable """

def __init__(self, module: UnitTestModule, build_dir: str):
def __init__(self, module: str):
""" Create a new unit test execution """
self.module = module
self.build_dir = build_dir

def execute(self, num_iterations: int, test_name: str = None, test_options: str = "") -> None:
""" Execute the unit tests `num_iterations` times """
cmd = self.build_dir + "/cmd/test/" + self.module.name.lower()
cmd = self.module
if test_name is not None and test_name != '':
cmd = cmd + " \"" + test_name + "\""
cmd = cmd + " " + test_options
print("Unit test runner: " + cmd + "\n")

print("Unit test stress for " + self.module.name.lower() + " STARTED")
print("Unit test stress for " + self.module + " STARTED")
for i in range(num_iterations):
print("Unit test stress for " + self.module.name.lower() + " RUN [i=" + str(i) + "]")
print("Unit test stress for " + self.module + " RUN [i=" + str(i) + "]")
status = os.system(cmd)
if status != 0:
print("Unit test stress for " + self.module.name.lower() + " FAILED [i=" + str(i) + "]")
print("Unit test stress for " + self.module + " FAILED [i=" + str(i) + "]")
sys.exit(-1)
print("Unit test stress for " + self.module.name.lower() + " COMPLETED [" + str(num_iterations) + "]")
print("Unit test stress for " + self.module + " COMPLETED [" + str(num_iterations) + "]")


DEFAULT_NUM_ITERATIONS: int = 1000
DEFAULT_MODULES: List[str] = UnitTestModule.item_names()


def usage(argv):
""" Print usage """
print("Usage: " + argv[0] + " [-h] [-i iterations] [-m modules] [-t test] builddir")
print("Usage: " + argv[0] + " [-h] [-i iterations] [-t test] modules")
print("")
print("Launch an automated unit test sequence on target build configuration")
print("")
print("builddir")
print(" \tthe path of the target build folder")
print("modules")
print(" \tcomma-separated list of unit test executables to launch")
print("")
print("-h\tprint this help")
print("-i\titerations")
print(" \tthe number of iterations for each configuration (default: " + str(DEFAULT_NUM_ITERATIONS) + ")")
print("-m\tmodules")
print(" \tthe list of unit test modules to launch (default: " + str(DEFAULT_MODULES) + ")")
print("-o\toptions")
print(" \tthe Catch2 options to pass to the launcher enclosed in string (default: \"\" i.e. none)")
print("-t\ttest")
Expand All @@ -87,32 +64,24 @@ def main(argv) -> int:
usage(argv)
return 1

build_dir = args[0]
modules = args[0].split(",")
test_name = None
test_options = ""
iterations = DEFAULT_NUM_ITERATIONS
modules = DEFAULT_MODULES

for option, option_arg in opts:
if option in ("-h", "--help"):
usage(argv)
elif option == "-i":
iterations = int(option_arg)
elif option == "-m":
modules = str(option_arg).split(",")
elif option == "-o":
test_options = option_arg
print("test_options=" + test_options)
elif option == "-t":
test_name = option_arg

for module_name in modules:
module_name = module_name.lower()
if not UnitTestModule.has_item(module_name):
print("Invalid test module name [" + module_name + "], ignored")
continue
unit_test_module = UnitTestModule(module_name)
unit_test = UnitTest(unit_test_module, build_dir)
unit_test = UnitTest(module_name)
unit_test.execute(iterations, test_name, test_options)

return 0
Expand Down

0 comments on commit 60f0b46

Please sign in to comment.