Skip to content

Commit

Permalink
wip: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abeimler committed Jul 29, 2023
1 parent 0f3929d commit 5a32ddb
Show file tree
Hide file tree
Showing 20 changed files with 378 additions and 184 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
task:
- build
# TODO: add tests and coverage tasks
#- test
- test
#- test:release
#- test:without-sanitizer
#- test:release:without-sanitizer
Expand All @@ -59,9 +59,9 @@ jobs:

# Only to test non-multiconfig builds
- os: ubuntu-22.04
compiler: gcc-11
compiler: gcc-13
CMAKE_GENERATOR: "Unix Makefiles"
GCOV: gcov-11
GCOV: gcov-13

- os: windows-2022
compiler: msvc
Expand Down
1 change: 1 addition & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tasks:
{{.PROJECT_DIR}}/reports/entities.RESULTS.md.json
{{.PROJECT_DIR}}/reports/extended.RESULTS.md.json
{{.PROJECT_DIR}}/reports/RESULTS.md.json
- "\\cp {{.PROJECT_DIR}}/reports/*.svg {{.PROJECT_DIR}}/img/."

configure:
dir: "{{.PROJECT_DIR}}"
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmarks/ECSBenchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ECSBenchmark : protected BaseECSBenchmark<EntityFactory> {
using EntityManager = typename EntityFactory::EntityManager;
using Entity = typename EntityFactory::Entity;

const float fakeTimeDelta{1.0F / 60.0F};
inline static constexpr float fakeTimeDelta{1.0F / 60.0F};

ECSBenchmark() {
benchmark::AddCustomContext("framework.name", m_name);
Expand Down
6 changes: 3 additions & 3 deletions benchmark/benchmarks/EntityBenchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ concept HasBulkDestroyFeature = requires(EntityFactory factory, EntityManager& e
template <class EntityFactory, class EntityManager = typename EntityFactory::EntityManager,
class Entity = typename EntityFactory::Entity>
concept HasGetComponentsFeature = requires(EntityFactory factory, EntityManager& entity_manager, Entity entity) {
factory.getComponentOneConst(entity_manager, entity);
factory.getComponentTwoConst(entity_manager, entity);
//factory.getComponentOneConst(entity_manager, entity);
//factory.getComponentTwoConst(entity_manager, entity);
factory.getComponentOne(entity_manager, entity);
factory.getComponentTwo(entity_manager, entity);
factory.getOptionalComponentThree(entity_manager, entity);
Expand Down Expand Up @@ -90,7 +90,7 @@ class EntityBenchmark : public BaseECSBenchmark<EntityFactory> {


void BM_CreateNoEntities(benchmark::State& state) {
const auto nentities = 0;
const size_t nentities = 0;
for (auto _ : state) {
state.PauseTiming();
EntityManager registry;
Expand Down
54 changes: 3 additions & 51 deletions fuzz_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,57 +1,9 @@
# cmake-format: off
# [[[cog
# import os, cog, glob
# path, file = os.path.split(cog.inFile)
# filepattern = os.path.join(path, '**/*.h??').lstrip('./')
# files = glob.glob(filepattern, recursive=True)
# if files:
# cog.outl("## GENERATED CODE WITH cogapp")
# cog.outl("set(${CMAKE_PROJECT_NAME}_FUZZ_TEST_HEADERS ") ###< you need to CHANGE this line (string) with your sourcecode-list cmake variable name
# for src in files:
# if "skeleton" in src: continue
# cog.outl(" ${CMAKE_CURRENT_SOURCE_DIR}/%s " % os.path.normpath(os.path.relpath(src, path)).replace("\\","/"))
# cog.outl(")")
# ]]]
# [[[end]]]
# cmake-format: on

# cmake-format: off
# [[[cog
# import os, cog, glob
# path, file = os.path.split(cog.inFile)
# filepattern = os.path.join(path, '**/*.c??').lstrip('./')
# files = glob.glob(filepattern, recursive=True)
# if files:
# cog.outl("## GENERATED CODE WITH cogapp")
# cog.outl("set(${CMAKE_PROJECT_NAME}_FUZZ_TEST_SOURCE ") ###< you need to CHANGE this line (string) with your sourcecode-list cmake variable name
# for src in files:
# if "skeleton" in src: continue
# if "catch_main.cpp" in os.path.relpath(src, path): continue
# cog.outl(" ${CMAKE_CURRENT_SOURCE_DIR}/%s " % os.path.normpath(os.path.relpath(src, path)).replace("\\","/"))
# cog.outl(")")
# ]]]
## GENERATED CODE WITH cogapp
set(${CMAKE_PROJECT_NAME}_FUZZ_TEST_SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/fuzz_tester.cpp
)
# [[[end]]]
# cmake-format: on

source_group(
TREE "${CMAKE_CURRENT_SOURCE_DIR}"
PREFIX "Test Header Files"
FILES ${${CMAKE_PROJECT_NAME}_FUZZ_TEST_HEADERS})
source_group(
TREE "${CMAKE_CURRENT_SOURCE_DIR}"
PREFIX "Test Source Files"
FILES ${${CMAKE_PROJECT_NAME}_FUZZ_TEST_SOURCE})

# A fuzz test runs until it finds an error. This particular one is going to rely on libFuzzer.
#
add_executable(${CMAKE_PROJECT_NAME}-fuzz-tester)
target_sources(${CMAKE_PROJECT_NAME}-fuzz-tester PRIVATE ${${CMAKE_PROJECT_NAME}_FUZZ_TEST_SOURCE}
add_executable(ecs-benchmark-fuzz-tester)
target_sources(ecs-benchmark-fuzz-tester PRIVATE ${${CMAKE_PROJECT_NAME}_FUZZ_TEST_SOURCE}
${${CMAKE_PROJECT_NAME}_FUZZ_TEST_HEADERS})
target_include_directories(${CMAKE_PROJECT_NAME}-fuzz-tester PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(ecs-benchmark-fuzz-tester PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

# @NOTE: add libs here
set(THREADS_PREFER_PTHREAD_FLAG ON)
Expand Down
4 changes: 2 additions & 2 deletions src/base/base/components/VelocityComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
namespace ecs::benchmarks::base::components {

struct VelocityComponent {
float x{0.0F};
float y{0.0F};
float x{1.0F};
float y{1.0F};
};

} // namespace ecs::benchmarks::base::components
Expand Down
4 changes: 4 additions & 0 deletions src/entt/entt/entities/EntityFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class EntityFactory {
static void destroy(EntityManager& registry, Entity entity);
static void destroyBulk(EntityManager& registry, std::vector<Entity>& entities);

[[nodiscard]] static inline auto getEntitiesCount(EntityManager& registry) {
return registry.storage<Entity>().size();
}


[[nodiscard]] static inline const ecs::benchmarks::base::components::PositionComponent&
getComponentOneConst(EntityManager& registry, Entity entity) {
Expand Down
22 changes: 21 additions & 1 deletion src/pico_ecs/pico_ecs/entities/EntityFactory.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
#include "EntityFactory.h"
#include "EntityFactory.h"


namespace ecs::benchmarks::pico_ecs::entities {

namespace details {

void VelocityComponent_constructor(ecs_t* ecs, ecs_id_t entity_id, void* ptr, void* args) {
(void)ecs;
(void)entity_id;
(void)args;

ecs::benchmarks::base::components::VelocityComponent* comp =
reinterpret_cast<ecs::benchmarks::base::components::VelocityComponent*>(ptr);
comp->x = 1.0F;
comp->y = 1.0F;
}

}

}
11 changes: 10 additions & 1 deletion src/pico_ecs/pico_ecs/entities/EntityFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ struct EcsDeleter {
void operator()(ecs_t* p_ecs) { ecs_free(p_ecs); }
};

void VelocityComponent_constructor(ecs_t* ecs, ecs_id_t entity_id, void* ptr, void* args);

class EntityManager {
public:
static inline constexpr int MIN_ENTITIES = 1 * 1024;
Expand All @@ -34,10 +36,14 @@ class EntityManager {
ecs_id_t VelocityComponent;
ecs_id_t DataComponent;

[[nodiscard]] inline auto valid(ecs_id_t entity_id) {
return ecs_is_ready(ecs.get(), entity_id);
}

private:
void register_components() {
PositionComponent = ecs_register_component(ecs.get(), sizeof(ecs::benchmarks::base::components::PositionComponent), nullptr, nullptr);
VelocityComponent = ecs_register_component(ecs.get(), sizeof(ecs::benchmarks::base::components::VelocityComponent), nullptr, nullptr);
VelocityComponent = ecs_register_component(ecs.get(), sizeof(ecs::benchmarks::base::components::VelocityComponent), VelocityComponent_constructor, nullptr);
DataComponent = ecs_register_component(ecs.get(), sizeof(ecs::benchmarks::base::components::DataComponent), nullptr, nullptr);
}
};
Expand Down Expand Up @@ -73,6 +79,9 @@ class EntityFactory {

void destroy(EntityManager& registry, Entity entity_id) { ecs_destroy(registry.ecs.get(), entity_id); }

/// Member access into incomplete type 'ecs_s' ... move impl. to pico_ecs.cpp
[[nodiscard]] static size_t getEntitiesCount(EntityManager& registry);

void clear(EntityManager& registry) { ecs_reset(registry.ecs.get()); }


Expand Down
10 changes: 9 additions & 1 deletion src/pico_ecs/pico_ecs/pico_ecs.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
#define PICO_ECS_IMPLEMENTATION
#include <pico_ecs.h>
#include <pico_ecs.h>

#undef PICO_ECS_IMPLEMENTATION
#include "entities/EntityFactory.h"
namespace ecs::benchmarks::pico_ecs::entities {
size_t EntityFactory::getEntitiesCount(details::EntityManager& registry) {
return registry.ecs->entity_pool.capacity-registry.ecs->entity_pool.size;
}
}
92 changes: 26 additions & 66 deletions test/constexpr_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,77 +1,37 @@
add_executable(${CMAKE_PROJECT_NAME}-constexpr-tests)
target_sources(${CMAKE_PROJECT_NAME}-constexpr-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp)
target_include_directories(${CMAKE_PROJECT_NAME}-constexpr-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${CMAKE_PROJECT_NAME}-constexpr-tests PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_include_directories(${CMAKE_PROJECT_NAME}-constexpr-tests PRIVATE ${PROJECT_BINARY_DIR}/include)
target_link_libraries(${CMAKE_PROJECT_NAME}-constexpr-tests PRIVATE project_warnings project_options)
target_compile_definitions(${CMAKE_PROJECT_NAME}-constexpr-tests PRIVATE -DCONSTEXPR_TESTING)
add_executable(ecs-benchmark-constexpr-tests)
target_sources(ecs-benchmark-constexpr-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp)
target_include_directories(ecs-benchmark-constexpr-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(ecs-benchmark-constexpr-tests PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_include_directories(ecs-benchmark-constexpr-tests PRIVATE ${PROJECT_BINARY_DIR}/include)
target_link_libraries(ecs-benchmark-constexpr-tests PRIVATE project_warnings project_options)
target_compile_definitions(ecs-benchmark-constexpr-tests PRIVATE -DCONSTEXPR_TESTING)

# @NOTE: add libs here
target_link_libraries(${CMAKE_PROJECT_NAME}-constexpr-tests PRIVATE ${CMAKE_PROJECT_NAME}::base)
target_link_system_library(${CMAKE_PROJECT_NAME}-constexpr-tests PRIVATE Catch2::Catch2)
target_link_system_library(${CMAKE_PROJECT_NAME}-constexpr-tests PRIVATE Catch2::Catch2WithMain)
target_link_libraries(ecs-benchmark-constexpr-tests PRIVATE ecs-benchmark::base)
target_link_system_libraries(ecs-benchmark-constexpr-tests PRIVATE Catch2::Catch2 Catch2::Catch2WithMain)

# automatically discover tests that are defined in catch based test files you can modify the unittests. TEST_PREFIX to whatever you want, or
# use different for different binaries
catch_discover_tests(${CMAKE_PROJECT_NAME}-constexpr-tests)
catch_discover_tests(ecs-benchmark-constexpr-tests)



# Disable the constexpr portion of the test, and build again this allows us to have an executable that we can debug when things go wrong
# with the constexpr testing
add_executable(${CMAKE_PROJECT_NAME}-relaxed-constexpr-tests)
target_sources(${CMAKE_PROJECT_NAME}-relaxed-constexpr-tests PRIVATE ${${CMAKE_PROJECT_NAME}_CONSTEXPR_TEST_SOURCE}
${${CMAKE_PROJECT_NAME}_CONSTEXPR_TEST_HEADERS})
target_include_directories(${CMAKE_PROJECT_NAME}-relaxed-constexpr-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${CMAKE_PROJECT_NAME}-relaxed-constexpr-tests PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_include_directories(${CMAKE_PROJECT_NAME}-relaxed-constexpr-tests PRIVATE ${PROJECT_BINARY_DIR}/include)
target_include_directories(${CMAKE_PROJECT_NAME}-relaxed-constexpr-tests PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include)
target_link_libraries(${CMAKE_PROJECT_NAME}-relaxed-constexpr-tests PRIVATE project_warnings project_options)
target_compile_definitions(${CMAKE_PROJECT_NAME}-relaxed-constexpr-tests PRIVATE -DRELAXED_CONSTEXPR_TESTING)
target_compile_definitions(${CMAKE_PROJECT_NAME}-relaxed-constexpr-tests PRIVATE -DCATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
add_executable(ecs-benchmark-relaxed-constexpr-tests)
target_sources(ecs-benchmark-constexpr-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests.cpp)
target_include_directories(ecs-benchmark-relaxed-constexpr-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(ecs-benchmark-relaxed-constexpr-tests PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_include_directories(ecs-benchmark-relaxed-constexpr-tests PRIVATE ${PROJECT_BINARY_DIR}/include)
target_include_directories(ecs-benchmark-relaxed-constexpr-tests PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include)
target_link_libraries(ecs-benchmark-relaxed-constexpr-tests PRIVATE project_warnings project_options)
target_compile_definitions(ecs-benchmark-relaxed-constexpr-tests PRIVATE -DRELAXED_CONSTEXPR_TESTING)
target_compile_definitions(ecs-benchmark-relaxed-constexpr-tests PRIVATE -DCATCH_CONFIG_RUNTIME_STATIC_REQUIRE)

# @NOTE: add libs here
target_link_libraries(ecs-benchmark-relaxed-constexpr-tests PRIVATE ecs-benchmark::base)
target_link_system_libraries(ecs-benchmark-relaxed-constexpr-tests PRIVATE Catch2::Catch2 Catch2::Catch2WithMain)

catch_discover_tests(
${CMAKE_PROJECT_NAME}-relaxed-constexpr-tests
TEST_PREFIX
"relaxed_constexpr."
REPORTER
xml
OUTPUT_DIR
.
OUTPUT_PREFIX
"relaxed_constexpr."
OUTPUT_SUFFIX
.xml)

if(ENABLE_COVERAGE)
setup_target_for_coverage_gcovr_html(
NAME
${CMAKE_PROJECT_NAME}-coverage-constexpr-test
EXECUTABLE
${CMAKE_PROJECT_NAME}-constexpr-tests
EXCLUDE
"${PROJECT_SOURCE_DIR}/benchmark"
"${PROJECT_SOURCE_DIR}/src/app/desktop"
"${PROJECT_SOURCE_DIR}/src/app/raspberrypi"
"${PROJECT_SOURCE_DIR}/src/core"
"${PROJECT_SOURCE_DIR}/src/persistence"
"${PROJECT_SOURCE_DIR}/test"
"${PROJECT_SOURCE_DIR}/test/tests"
"${PROJECT_SOURCE_DIR}/thirdparty"
"${CMAKE_BINARY_DIR}/_deps")

setup_target_for_coverage_gcovr_html(
NAME
${CMAKE_PROJECT_NAME}-coverage-relaxed-constexpr-test
EXECUTABLE
${CMAKE_PROJECT_NAME}-relaxed-constexpr-tests
EXCLUDE
"${PROJECT_SOURCE_DIR}/benchmark"
"${PROJECT_SOURCE_DIR}/src/app/engine"
"${PROJECT_SOURCE_DIR}/test"
"${PROJECT_SOURCE_DIR}/test/constexpr_tests"
"${PROJECT_SOURCE_DIR}/test/integrartion_tests"
"${PROJECT_SOURCE_DIR}/test/tests"
"${PROJECT_SOURCE_DIR}/thirdparty"
"${CMAKE_BINARY_DIR}/_deps")
endif()
# automatically discover tests that are defined in catch based test files you can modify the unittests. TEST_PREFIX to whatever you want, or
# use different for different binaries
catch_discover_tests(ecs-benchmark-relaxed-constexpr-tests)
File renamed without changes.
41 changes: 12 additions & 29 deletions test/integrartion_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
add_executable(${CMAKE_PROJECT_NAME}-integration-tests)
target_sources(${CMAKE_PROJECT_NAME}-integration-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests.cpp)
target_include_directories(${CMAKE_PROJECT_NAME}-integration-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${CMAKE_PROJECT_NAME}-integration-tests PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_include_directories(${CMAKE_PROJECT_NAME}-integration-tests PRIVATE ${PROJECT_BINARY_DIR}/include)
target_include_directories(${CMAKE_PROJECT_NAME}-integration-tests PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include)
target_link_libraries(${CMAKE_PROJECT_NAME}-integration-tests PRIVATE project_warnings project_options)
target_compile_definitions(${CMAKE_PROJECT_NAME}-integration-tests PUBLIC -DINTEGRATION_TESTING)
add_executable(ecs-benchmark-integration-tests)
target_sources(ecs-benchmark-integration-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests.cpp)
target_include_directories(ecs-benchmark-integration-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(ecs-benchmark-integration-tests PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_include_directories(ecs-benchmark-integration-tests PRIVATE ${PROJECT_BINARY_DIR}/include)
target_include_directories(ecs-benchmark-integration-tests PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include)
target_link_libraries(ecs-benchmark-integration-tests PRIVATE project_warnings project_options)
target_compile_definitions(ecs-benchmark-integration-tests PUBLIC -DINTEGRATION_TESTING)

# @NOTE: add libs here
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${CMAKE_PROJECT_NAME}-integration-tests PRIVATE ${CMAKE_PROJECT_NAME}::base)
target_link_system_library(${CMAKE_PROJECT_NAME}-integration-tests PRIVATE Threads::Threads)
target_link_system_library(${CMAKE_PROJECT_NAME}-integration-tests PRIVATE Catch2::Catch2)
target_link_system_library(${CMAKE_PROJECT_NAME}-integration-tests PRIVATE Catch2::Catch2 Catch2::Catch2WithMain)
target_link_libraries(ecs-benchmark-integration-tests PRIVATE ecs-benchmark::base)
target_link_system_libraries(ecs-benchmark-integration-tests PRIVATE Threads::Threads)
target_link_system_libraries(ecs-benchmark-integration-tests PRIVATE Catch2::Catch2 Catch2::Catch2WithMain)

# automatically discover tests that are defined in catch based test files you can modify the unittests. TEST_PREFIX to whatever you want, or
# use different for different binaries
catch_discover_tests(${CMAKE_PROJECT_NAME}-integration-tests

if(ENABLE_COVERAGE)
setup_target_for_coverage_gcovr_html(
NAME
${CMAKE_PROJECT_NAME}-coverage-integration-test
EXECUTABLE
${CMAKE_PROJECT_NAME}-integration-test
EXCLUDE
"${PROJECT_SOURCE_DIR}/benchmark"
"${PROJECT_SOURCE_DIR}/test"
"${PROJECT_SOURCE_DIR}/test/constexpr_tests"
"${PROJECT_SOURCE_DIR}/test/integrartion_tests"
"${PROJECT_SOURCE_DIR}/test/tests"
"${PROJECT_SOURCE_DIR}/thirdparty"
"${CMAKE_BINARY_DIR}/_deps")
endif()
catch_discover_tests(ecs-benchmark-integration-tests)
Loading

0 comments on commit 5a32ddb

Please sign in to comment.