Browse Source

更改测试代码的组织方式

3.0.0
tearshark 2 years ago
parent
commit
0d2af93ceb

+ 9
- 0
CMakeLists.txt View File

@@ -139,6 +139,15 @@ endif()
if(CMAKE_ENABLE_UNIT_TEST)
add_subdirectory(tutorial)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/tutorial ALL_TUTORIAL_FILES)
add_executable(test_librf
${CMAKE_CURRENT_SOURCE_DIR}/test_librf.cpp
${CMAKE_CURRENT_SOURCE_DIR}/benchmark/benchmark_async_mem.cpp
${CMAKE_CURRENT_SOURCE_DIR}/benchmark/benchmark_channel_passing_next.cpp
${ALL_TUTORIAL_FILES})
target_link_libraries(test_librf PUBLIC librf)
#add_subdirectory(benchmark)
endif()

+ 3
- 0
benchmark/CMakeLists.txt View File

@@ -7,4 +7,7 @@ foreach(BENCHMARK_FILE_PATH ${BENCHMARK_FILES})

add_executable(${BENCHMARK_FILE_NAME} ${BENCHMARK_FILE_PATH})
target_link_libraries(${BENCHMARK_FILE_NAME} PUBLIC librf)
target_compile_definitions(${TUTORIAL_FILE_NAME}
PRIVATE LIBRF_TUTORIAL_STAND_ALONE=1
)
endforeach(BENCHMARK_FILE_PATH)

+ 1
- 1
benchmark/benchmark_asio_echo.cpp View File

@@ -1,7 +1,7 @@

#include <iostream>
#include "librf.h"
#include "librf/librf.h"
#include <asio.hpp>
#include "../asio/asio_task.h"

+ 3
- 1
benchmark/benchmark_async_mem.cpp View File

@@ -4,7 +4,7 @@
#include <string>
#include <thread>
#include "librf.h"
#include "librf/librf.h"
const size_t N = 5000000;
const size_t LOOP_COUNT = 50;
@@ -39,8 +39,10 @@ void resumable_main_benchmark_mem(bool wait_key)
//clang : 平均 210字节
//msvc : 平均600字节
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_benchmark_mem(false);
return 0;
}
#endif

+ 3
- 1
benchmark/benchmark_channel_passing_next.cpp View File

@@ -6,7 +6,7 @@
#include <deque>
#include <mutex>

#include "librf.h"
#include "librf/librf.h"

using namespace librf;
using namespace std::chrono;
@@ -74,8 +74,10 @@ void benchmark_main_channel_passing_next()
this_scheduler()->run_until_notask();
}

#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
benchmark_main_channel_passing_next();
return 0;
}
#endif

+ 1
- 1
benchmark/test_async_cinatra_client.cpp View File

@@ -4,7 +4,7 @@

#include <iostream>
#include "../../cinatra/include/cinatra.hpp"
#include "librf.h"
#include "librf/librf.h"
#include "use_librf.h"

using namespace librf;

+ 4
- 4
include/librf/src/scheduler.h View File

@@ -93,11 +93,11 @@ namespace librf
}

#ifndef DOXYGEN_SKIP_PROPERTY
LIBRF_API void add_generator(state_base_t* sptr);
LIBRF_API void del_final(state_base_t* sptr);
void add_generator(state_base_t* sptr);
void del_final(state_base_t* sptr);
LIBRF_API std::unique_ptr<task_t> del_switch(state_base_t* sptr);
LIBRF_API void add_switch(std::unique_ptr<task_t> task);
LIBRF_API task_t* find_task(state_base_t* sptr) const noexcept;
void add_switch(std::unique_ptr<task_t> task);
task_t* find_task(state_base_t* sptr) const noexcept;

friend struct local_scheduler_t;
protected:

+ 1
- 1
include/librf/src/state.h View File

@@ -60,7 +60,7 @@ namespace librf
}
scheduler_t* get_scheduler() const
{
return get_root()->_scheduler;
return _scheduler ? _scheduler : get_root()->_scheduler;
}
};

+ 1
- 1
modern_cb

@@ -1 +1 @@
Subproject commit 678558b0339e490b7c9624d22afca1ab0367fb3e
Subproject commit afe1a6bd4e98ccbb4177ecf90b6335520c85ddff

+ 3
- 0
tutorial/CMakeLists.txt View File

@@ -7,4 +7,7 @@ foreach(TUTORIAL_FILE_PATH ${TUTORIAL_FILES})

add_executable(${TUTORIAL_FILE_NAME} ${TUTORIAL_FILE_PATH})
target_link_libraries(${TUTORIAL_FILE_NAME} PUBLIC librf)
target_compile_definitions(${TUTORIAL_FILE_NAME}
PRIVATE LIBRF_TUTORIAL_STAND_ALONE=1
)
endforeach(TUTORIAL_FILE_PATH)

+ 2
- 0
tutorial/test_async_cb.cpp View File

@@ -105,8 +105,10 @@ void resumable_main_cb()
this_scheduler()->run_until_notask();
}
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_cb();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_channel.cpp View File

@@ -182,8 +182,10 @@ void resumable_main_channel()
test_channel_performance_double_thread(1000);
}
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_channel();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_channel_mult_thread.cpp View File

@@ -113,8 +113,10 @@ void resumable_main_channel_mult_thread()
std::cout << "OK: counter = " << gcounter.load() << std::endl;
}
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_channel_mult_thread();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_dynamic_go.cpp View File

@@ -60,8 +60,10 @@ void resumable_main_dynamic_go()
test_dynamic_go();
}
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_dynamic_go();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_event.cpp View File

@@ -195,8 +195,10 @@ void resumable_main_event()
std::cout << std::endl;
}
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_event();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_event_timeout.cpp View File

@@ -183,8 +183,10 @@ void resumable_main_event_timeout()
std::cout << std::endl;
}
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_event_timeout();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_event_v2.cpp View File

@@ -112,8 +112,10 @@ void resumable_main_event_v2()
std::cout << std::endl;
}

#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_event_v2();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_exception.cpp View File

@@ -90,8 +90,10 @@ void resumable_main_exception(bool bomb)
}
}
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_exception(true);
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_memory_layout.cpp View File

@@ -141,8 +141,10 @@ void resumable_main_layout()
std::cout << __FUNCTION__ << " - end" << std::endl;
}

#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_layout();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_modern_cb.cpp View File

@@ -175,8 +175,10 @@ void resumable_main_modern_cb()
example_librf();
}

#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_modern_cb();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_multi_thread.cpp View File

@@ -87,8 +87,10 @@ void resumable_main_multi_thread()
scheduler_t::g_scheduler.run_until_notask();
}
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_multi_thread();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_mutex.cpp View File

@@ -215,8 +215,10 @@ void resumable_main_mutex()
resumable_mutex_lock_range();
}
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_mutex();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_resumable.cpp View File

@@ -78,8 +78,10 @@ void resumable_main_resumable()
*/
}
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_resumable();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_routine.cpp View File

@@ -44,8 +44,10 @@ void resumable_main_routine()
this_scheduler()->run_until_notask();
}
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_routine();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_sleep.cpp View File

@@ -74,8 +74,10 @@ void resumable_main_sleep()
std::cout << std::endl;
}
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_sleep();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_stop_token.cpp View File

@@ -96,8 +96,10 @@ void resumable_main_stop_token()
std::cout << "OK - stop_token!" << std::endl;
}

#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_stop_token();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_suspend_always.cpp View File

@@ -93,8 +93,10 @@ test_loop_sleep<6> -> 0000016B847726C0
test_loop_sleep<7> -> 0000016B847726C0
*/
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_suspend_always();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_switch_scheduler.cpp View File

@@ -133,8 +133,10 @@ void resumable_main_switch_scheduler()
other.join();
}

#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_switch_scheduler();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_timer.cpp View File

@@ -34,8 +34,10 @@ void resumable_main_timer()
th2.stop(); //but th2 is invalid
}
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_timer();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_when_all.cpp View File

@@ -240,8 +240,10 @@ void resumable_main_when_all()
#endif
}
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_when_all();
return 0;
}
#endif

+ 2
- 0
tutorial/test_async_yield_return.cpp View File

@@ -89,8 +89,10 @@ void resumable_main_yield_return()
this_scheduler()->run_until_notask();
}
#if LIBRF_TUTORIAL_STAND_ALONE
int main()
{
resumable_main_yield_return();
return 0;
}
#endif

Loading…
Cancel
Save