Skip to content

Commit

Permalink
[tests] Devide ScMemoryTest and ScSingleThreadedMemoryTest
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaZotov committed Apr 17, 2023
1 parent a0bab2e commit 53baf4b
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 37 deletions.
4 changes: 2 additions & 2 deletions sc-kpm/tests/sc-agents/sc-threaded-core-agents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ sc_bool test_agent_has_result(sc_memory_context * context, sc_addr const questio
return result;
}

TEST_F(ScMemoryTest, agents_parallel_work1)
TEST_F(ScSingleThreadedMemoryTest, agents_parallel_work1)
{
sc_memory_context * context = sc_memory_context_new(sc_access_lvl_make_min);

Expand Down Expand Up @@ -196,7 +196,7 @@ TEST_F(ScMemoryTest, agents_parallel_work1)
sc_module_shutdown();
}

TEST_F(ScMemoryTest, agents_parallel_work2)
TEST_F(ScSingleThreadedMemoryTest, agents_parallel_work2)
{
sc_memory_context * context = sc_memory_context_new(sc_access_lvl_make_min);

Expand Down
4 changes: 2 additions & 2 deletions sc-memory/sc-core/sc-store/sc_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,15 @@ void sc_event_unlock(sc_event * evt)
}

// --------
sc_bool sc_events_initialize_ext(sc_int32 const max_events_and_agents_threads)
sc_bool sc_events_initialize_ext(sc_uint32 const max_events_and_agents_threads)
{
event_queue = sc_event_queue_new_ext(max_events_and_agents_threads);
return SC_TRUE;
}

sc_bool sc_events_initialize()
{
return sc_events_initialize_ext((sc_int32)g_get_num_processors());
return sc_events_initialize_ext(g_get_num_processors());
}

void sc_events_shutdown()
Expand Down
2 changes: 1 addition & 1 deletion sc-memory/sc-core/sc-store/sc_event/sc_event_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct _sc_event
};

//! Function to initialize sc-events module with user processors number
sc_bool sc_events_initialize_ext(sc_int32 max_events_and_agents_threads);
sc_bool sc_events_initialize_ext(sc_uint32 max_events_and_agents_threads);

//! Function to initialize sc-events module
sc_bool sc_events_initialize();
Expand Down
8 changes: 4 additions & 4 deletions sc-memory/sc-core/sc-store/sc_event/sc_event_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,27 @@ void sc_event_pool_worker(gpointer data, gpointer user_data)
sc_event_pool_worker_data_destroy(work_data);
}

sc_event_queue * sc_event_queue_new_ext(sc_int32 max_events_and_agents_threads)
sc_event_queue * sc_event_queue_new_ext(sc_uint32 max_events_and_agents_threads)
{
sc_event_queue * queue = sc_mem_new(sc_event_queue, 1);
queue->running = SC_TRUE;
g_mutex_init(&queue->mutex);

max_events_and_agents_threads = sc_max(1, sc_min(max_events_and_agents_threads, (sc_int32)g_get_num_processors()));
max_events_and_agents_threads = sc_max(1, sc_min(max_events_and_agents_threads, g_get_num_processors()));
{
sc_message("[sc-events] Configuration:");
sc_message("\tMax events and agents threads: %d", max_events_and_agents_threads);
}

queue->thread_pool =
g_thread_pool_new(sc_event_pool_worker, null_ptr, max_events_and_agents_threads, SC_FALSE, null_ptr);
g_thread_pool_new(sc_event_pool_worker, null_ptr, (sc_int32)max_events_and_agents_threads, SC_FALSE, null_ptr);

return queue;
}

sc_event_queue * sc_event_queue_new()
{
return sc_event_queue_new_ext((sc_int32)g_get_num_processors());
return sc_event_queue_new_ext(g_get_num_processors());
}

void sc_event_queue_stop_processing(sc_event_queue * queue)
Expand Down
2 changes: 1 addition & 1 deletion sc-memory/sc-core/sc-store/sc_event/sc_event_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct _sc_event_queue
typedef struct _sc_event_queue sc_event_queue;

//! Create new sc-event queue with user processors number
sc_event_queue * sc_event_queue_new_ext(sc_int32 max_events_and_agents_threads);
sc_event_queue * sc_event_queue_new_ext(sc_uint32 max_events_and_agents_threads);

//! Create new sc-event queue
sc_event_queue * sc_event_queue_new();
Expand Down
2 changes: 1 addition & 1 deletion sc-memory/sc-core/sc_memory_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void sc_memory_params_clear(sc_memory_params * params)

params->max_loaded_segments = DEFAULT_MAX_LOADED_SEGMENTS;
params->max_threads = DEFAULT_MAX_THREADS;
params->max_events_and_agents_threads = DEFAULT_EVENTS_PROCESSORS;
params->max_events_and_agents_threads = DEFAULT_MAX_EVENTS_AND_AGENTS_THREADS;

params->init_memory_generated_structure = (sc_char const *)null_ptr;
params->init_memory_generated_upload = SC_FALSE;
Expand Down
5 changes: 3 additions & 2 deletions sc-memory/sc-core/sc_memory_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#define DEFAULT_SAVE_PERIOD 32000
#define DEFAULT_UPDATE_PERIOD 16000
#define DEFAULT_MAX_THREADS 32
#define DEFAULT_EVENTS_PROCESSORS 32
#define DEFAULT_MAX_EVENTS_AND_AGENTS_THREADS 32
#define DEFAULT_MIN_EVENTS_AND_AGENTS_THREADS 1
#define DEFAULT_MAX_LOADED_SEGMENTS 1000
#define DEFAULT_MAX_SEARCHABLE_STRING_SIZE 1000
#define DEFAULT_LOG_TYPE "Console"
Expand All @@ -36,7 +37,7 @@ typedef struct _sc_memory_params
sc_uint32 max_loaded_segments;
sc_uint32 max_searchable_string_size;
sc_uint8 max_threads;
sc_int32 max_events_and_agents_threads;
sc_uint32 max_events_and_agents_threads;

const sc_char * init_memory_generated_structure;
sc_bool init_memory_generated_upload;
Expand Down
33 changes: 12 additions & 21 deletions sc-memory/tests/sc-memory/_test/sc_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "sc-memory/sc_memory.hpp"

#include <memory>

class ScMemoryTest : public testing::Test
{
protected:
Expand All @@ -23,7 +21,7 @@ class ScMemoryTest : public testing::Test
ScMemoryTest::Shutdown();
}

void Initialize()
void Initialize(sc_uint32 max_events_and_agents_threads = DEFAULT_MAX_EVENTS_AND_AGENTS_THREADS, std::string const & result_structure = "")
{
sc_memory_params params;
sc_memory_params_clear(&params);
Expand All @@ -32,7 +30,10 @@ class ScMemoryTest : public testing::Test
params.repo_path = "repo";
params.log_level = "Debug";

params.max_events_and_agents_threads = 1;
params.max_events_and_agents_threads = max_events_and_agents_threads;

params.init_memory_generated_upload = !result_structure.empty();
params.init_memory_generated_structure = result_structure.c_str();

ScMemory::LogMute();
ScMemory::Initialize(params);
Expand All @@ -54,26 +55,16 @@ class ScMemoryTestWithInitMemoryGeneratedStructure : public ScMemoryTest
{
virtual void SetUp()
{
ScMemoryTestWithInitMemoryGeneratedStructure::Initialize();
ScMemoryTestWithInitMemoryGeneratedStructure::Initialize(DEFAULT_MAX_EVENTS_AND_AGENTS_THREADS, "result_structure");
m_ctx = std::make_unique<ScMemoryContext>(sc_access_lvl_make_min, "test");
}
};

void Initialize()
class ScSingleThreadedMemoryTest : public ScMemoryTest
{
virtual void SetUp()
{
sc_memory_params params;
sc_memory_params_clear(&params);

params.clear = SC_TRUE;
params.repo_path = "repo";
params.log_level = "Debug";

params.max_events_and_agents_threads = 1;

params.init_memory_generated_upload = SC_TRUE;
params.init_memory_generated_structure = "result_structure";

ScMemory::LogMute();
ScMemory::Initialize(params);
ScMemory::LogUnmute();
ScSingleThreadedMemoryTest::Initialize(DEFAULT_MIN_EVENTS_AND_AGENTS_THREADS);
m_ctx = std::make_unique<ScMemoryContext>(sc_access_lvl_make_min, "test");
}
};
2 changes: 0 additions & 2 deletions sc-memory/tests/sc-memory/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ make_tests_from_folder(${CMAKE_CURRENT_LIST_DIR}/common
INCLUDES ${SC_MEMORY_SRC} ${CMAKE_CURRENT_LIST_DIR}/_test
)

sc_codegen(sc-memory-common-tests ${CMAKE_CURRENT_LIST_DIR}/common)

make_tests_from_folder(${CMAKE_CURRENT_LIST_DIR}/containers
NAME sc-memory-containers-tests
DEPENDS sc-memory sc-core ${GLIB2_LIBRARIES}
Expand Down
2 changes: 1 addition & 1 deletion sc-tools/sc-config-utils/sc_memory_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ScMemoryConfig
m_memoryParams.max_loaded_segments = GetIntByKey("max_loaded_segments", DEFAULT_MAX_LOADED_SEGMENTS);
m_memoryParams.max_threads = GetIntByKey("max_threads", DEFAULT_MAX_THREADS);
m_memoryParams.max_events_and_agents_threads =
GetIntByKey("max_events_and_agents_threads", DEFAULT_EVENTS_PROCESSORS);
GetIntByKey("max_events_and_agents_threads", DEFAULT_MAX_EVENTS_AND_AGENTS_THREADS);
m_memoryParams.max_searchable_string_size =
GetIntByKey("max_searchable_string_size", DEFAULT_MAX_SEARCHABLE_STRING_SIZE);

Expand Down

0 comments on commit 53baf4b

Please sign in to comment.