Skip to content

Commit

Permalink
单测打印 crash 堆栈
Browse files Browse the repository at this point in the history
  • Loading branch information
zxffffffff committed Aug 12, 2024
1 parent 757da91 commit 1ce4e86
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
5 changes: 5 additions & 0 deletions sample-net-test/http_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "common.h"
#include "platform.h"
#include "hardware.h"
#include "log.h"

#include "http_client.h"
#include "impl/curl_http_client.h"
Expand All @@ -34,6 +35,8 @@ TEST(HttpClientTest, curl_version)

TEST(HttpClientTest, TestBaidu)
{
Log::InitCrashReport();

TestHttpClient http(4);
TestHttpClient http2(4);
http.SetProxy(false);
Expand Down Expand Up @@ -61,6 +64,8 @@ TEST(HttpClientTest, TestBaidu)

TEST(HttpClientTest, URLEncode)
{
Log::InitCrashReport();

TestHttpClient http(4);

/* 低端设备更容易复现问题 */
Expand Down
3 changes: 3 additions & 0 deletions sample-net-test/http_server_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "common.h"
#include "platform.h"
#include "hardware.h"
#include "log.h"

#include "http_server.h"
#include "impl/boost_http_parser.h"
Expand All @@ -33,6 +34,8 @@ using TestHttpClient = HttpClient<HttpClientImpl, ThreadPoolImpl>;
/* 警告:Google Test 仅在 *nix 上线程安全,Windows 或其他平台不支持多线程断言 */
TEST(HttpServerTest, GetPost)
{
Log::InitCrashReport();

for (int i = 0; i < 100; ++i)
{
/* 随机端口,减少端口被占用概率 */
Expand Down
16 changes: 10 additions & 6 deletions sample-net-test/tcp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "common.h"
#include "platform.h"
#include "hardware.h"
#include "log.h"

#include "tcp_server.h"
#include "tcp_client.h"
Expand Down Expand Up @@ -47,8 +48,9 @@ struct Data
TEST(TcpCS, pingpong)
{
/* 低端设备无法准确计时 */
if (Hardware::GetCPUs() < 8)
return;
// if (Hardware::GetCPUs() < 8)
// return;
Log::InitCrashReport();

int sleep_ms = 1000 / Hardware::GetCPUs();
sleep_ms = std::min(std::max(100, sleep_ms), 1000);
Expand Down Expand Up @@ -131,8 +133,9 @@ TEST(TcpCS, pingpong)
TEST(TcpCS, monkeytest)
{
/* 低端设备无法准确计时 */
if (Hardware::GetCPUs() < 8)
return;
// if (Hardware::GetCPUs() < 8)
// return;
Log::InitCrashReport();

int sleep_ms = 1000 / Hardware::GetCPUs();
sleep_ms = std::min(std::max(100, sleep_ms), 1000);
Expand Down Expand Up @@ -248,8 +251,9 @@ TEST(TcpCS, monkeytest)
TEST(TcpCS, monkeytest2)
{
/* 低端设备无法准确计时 */
if (Hardware::GetCPUs() < 8)
return;
// if (Hardware::GetCPUs() < 8)
// return;
Log::InitCrashReport();

int sleep_ms = 1000 / Hardware::GetCPUs();
sleep_ms = std::min(std::max(100, sleep_ms), 1000);
Expand Down
8 changes: 4 additions & 4 deletions sample-tools/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#endif

/* TODO 最好再封装一层glog参数 */
DEFINE_int32(logCleaner, 15, "自动删除旧日志");
// DEFINE_int32(logCleaner, 15, "自动删除旧日志");

#define LOG_HEAD (__func__)

Expand Down Expand Up @@ -88,9 +88,9 @@ class Log
/* 自动删除旧日志
* 然后每次执行flush时glog都会检查是否有过期的日志。
*/
int logCleaner = FLAGS_logCleaner;
if (logCleaner > 0)
google::EnableLogCleaner(logCleaner); // days
// int logCleaner = FLAGS_logCleaner;
// if (logCleaner > 0)
// google::EnableLogCleaner(logCleaner); // days

/* 消息同时输出 stderr
* Set whether log messages go to stderr in addition to logfiles.
Expand Down

0 comments on commit 1ce4e86

Please sign in to comment.