Browse Source

更改测试代码的组织方式

3.0.0
tearshark 2 years ago
parent
commit
0d2af93ceb

+ 9
- 0
CMakeLists.txt View File

if(CMAKE_ENABLE_UNIT_TEST) if(CMAKE_ENABLE_UNIT_TEST)
add_subdirectory(tutorial) 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) #add_subdirectory(benchmark)
endif() endif()

+ 3
- 0
benchmark/CMakeLists.txt View File



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

+ 1
- 1
benchmark/benchmark_asio_echo.cpp View File

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

+ 3
- 1
benchmark/benchmark_async_mem.cpp View File

#include <string> #include <string>
#include <thread> #include <thread>
#include "librf.h"
#include "librf/librf.h"
const size_t N = 5000000; const size_t N = 5000000;
const size_t LOOP_COUNT = 50; const size_t LOOP_COUNT = 50;
//clang : 平均 210字节 //clang : 平均 210字节
//msvc : 平均600字节 //msvc : 平均600字节
#if LIBRF_TUTORIAL_STAND_ALONE
int main() int main()
{ {
resumable_main_benchmark_mem(false); resumable_main_benchmark_mem(false);
return 0; return 0;
} }
#endif

+ 3
- 1
benchmark/benchmark_channel_passing_next.cpp View File

#include <deque> #include <deque>
#include <mutex> #include <mutex>


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


using namespace librf; using namespace librf;
using namespace std::chrono; using namespace std::chrono;
this_scheduler()->run_until_notask(); this_scheduler()->run_until_notask();
} }


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

+ 1
- 1
benchmark/test_async_cinatra_client.cpp View File



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


using namespace librf; using namespace librf;

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

} }


#ifndef DOXYGEN_SKIP_PROPERTY #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 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; friend struct local_scheduler_t;
protected: protected:

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

} }
scheduler_t* get_scheduler() const scheduler_t* get_scheduler() const
{ {
return get_root()->_scheduler;
return _scheduler ? _scheduler : get_root()->_scheduler;
} }
}; };

+ 1
- 1
modern_cb

Subproject commit 678558b0339e490b7c9624d22afca1ab0367fb3e
Subproject commit afe1a6bd4e98ccbb4177ecf90b6335520c85ddff

+ 3
- 0
tutorial/CMakeLists.txt View File



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

+ 2
- 0
tutorial/test_async_cb.cpp View File

this_scheduler()->run_until_notask(); this_scheduler()->run_until_notask();
} }
#if LIBRF_TUTORIAL_STAND_ALONE
int main() int main()
{ {
resumable_main_cb(); resumable_main_cb();
return 0; return 0;
} }
#endif

+ 2
- 0
tutorial/test_async_channel.cpp View File

test_channel_performance_double_thread(1000); test_channel_performance_double_thread(1000);
} }
#if LIBRF_TUTORIAL_STAND_ALONE
int main() int main()
{ {
resumable_main_channel(); resumable_main_channel();
return 0; return 0;
} }
#endif

+ 2
- 0
tutorial/test_async_channel_mult_thread.cpp View File

std::cout << "OK: counter = " << gcounter.load() << std::endl; std::cout << "OK: counter = " << gcounter.load() << std::endl;
} }
#if LIBRF_TUTORIAL_STAND_ALONE
int main() int main()
{ {
resumable_main_channel_mult_thread(); resumable_main_channel_mult_thread();
return 0; return 0;
} }
#endif

+ 2
- 0
tutorial/test_async_dynamic_go.cpp View File

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

+ 2
- 0
tutorial/test_async_event.cpp View File

std::cout << std::endl; std::cout << std::endl;
} }
#if LIBRF_TUTORIAL_STAND_ALONE
int main() int main()
{ {
resumable_main_event(); resumable_main_event();
return 0; return 0;
} }
#endif

+ 2
- 0
tutorial/test_async_event_timeout.cpp View File

std::cout << std::endl; std::cout << std::endl;
} }
#if LIBRF_TUTORIAL_STAND_ALONE
int main() int main()
{ {
resumable_main_event_timeout(); resumable_main_event_timeout();
return 0; return 0;
} }
#endif

+ 2
- 0
tutorial/test_async_event_v2.cpp View File

std::cout << std::endl; std::cout << std::endl;
} }


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

+ 2
- 0
tutorial/test_async_exception.cpp View File

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

+ 2
- 0
tutorial/test_async_memory_layout.cpp View File

std::cout << __FUNCTION__ << " - end" << std::endl; std::cout << __FUNCTION__ << " - end" << std::endl;
} }


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

+ 2
- 0
tutorial/test_async_modern_cb.cpp View File

example_librf(); example_librf();
} }


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

+ 2
- 0
tutorial/test_async_multi_thread.cpp View File

scheduler_t::g_scheduler.run_until_notask(); scheduler_t::g_scheduler.run_until_notask();
} }
#if LIBRF_TUTORIAL_STAND_ALONE
int main() int main()
{ {
resumable_main_multi_thread(); resumable_main_multi_thread();
return 0; return 0;
} }
#endif

+ 2
- 0
tutorial/test_async_mutex.cpp View File

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

+ 2
- 0
tutorial/test_async_resumable.cpp View File

*/ */
} }
#if LIBRF_TUTORIAL_STAND_ALONE
int main() int main()
{ {
resumable_main_resumable(); resumable_main_resumable();
return 0; return 0;
} }
#endif

+ 2
- 0
tutorial/test_async_routine.cpp View File

this_scheduler()->run_until_notask(); this_scheduler()->run_until_notask();
} }
#if LIBRF_TUTORIAL_STAND_ALONE
int main() int main()
{ {
resumable_main_routine(); resumable_main_routine();
return 0; return 0;
} }
#endif

+ 2
- 0
tutorial/test_async_sleep.cpp View File

std::cout << std::endl; std::cout << std::endl;
} }
#if LIBRF_TUTORIAL_STAND_ALONE
int main() int main()
{ {
resumable_main_sleep(); resumable_main_sleep();
return 0; return 0;
} }
#endif

+ 2
- 0
tutorial/test_async_stop_token.cpp View File

std::cout << "OK - stop_token!" << std::endl; std::cout << "OK - stop_token!" << std::endl;
} }


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

+ 2
- 0
tutorial/test_async_suspend_always.cpp View File

test_loop_sleep<7> -> 0000016B847726C0 test_loop_sleep<7> -> 0000016B847726C0
*/ */
#if LIBRF_TUTORIAL_STAND_ALONE
int main() int main()
{ {
resumable_main_suspend_always(); resumable_main_suspend_always();
return 0; return 0;
} }
#endif

+ 2
- 0
tutorial/test_async_switch_scheduler.cpp View File

other.join(); other.join();
} }


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

+ 2
- 0
tutorial/test_async_timer.cpp View File

th2.stop(); //but th2 is invalid th2.stop(); //but th2 is invalid
} }
#if LIBRF_TUTORIAL_STAND_ALONE
int main() int main()
{ {
resumable_main_timer(); resumable_main_timer();
return 0; return 0;
} }
#endif

+ 2
- 0
tutorial/test_async_when_all.cpp View File

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

+ 2
- 0
tutorial/test_async_yield_return.cpp View File

this_scheduler()->run_until_notask(); this_scheduler()->run_until_notask();
} }
#if LIBRF_TUTORIAL_STAND_ALONE
int main() int main()
{ {
resumable_main_yield_return(); resumable_main_yield_return();
return 0; return 0;
} }
#endif

Loading…
Cancel
Save