Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
49a92da2
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
694
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
49a92da2
编写于
9月 09, 2016
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add unittest to CustomStackTrace.
上级
b384af58
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
149 addition
and
0 deletion
+149
-0
paddle/utils/tests/CMakeLists.txt
paddle/utils/tests/CMakeLists.txt
+10
-0
paddle/utils/tests/test_CustomStackTrace.cpp
paddle/utils/tests/test_CustomStackTrace.cpp
+95
-0
paddle/utils/tests/test_CustomStackTracePrint.cpp
paddle/utils/tests/test_CustomStackTracePrint.cpp
+29
-0
paddle/utils/tests/test_CustomStackTracePrint.sh
paddle/utils/tests/test_CustomStackTracePrint.sh
+15
-0
未找到文件。
paddle/utils/tests/CMakeLists.txt
浏览文件 @
49a92da2
...
...
@@ -2,3 +2,13 @@ add_simple_unittest(test_CommandLineParser)
add_simple_unittest
(
test_Logging
)
add_simple_unittest
(
test_Thread
)
add_simple_unittest
(
test_StringUtils
)
add_simple_unittest
(
test_CustomStackTrace
)
add_executable
(
test_CustomStackTracePrint
test_CustomStackTracePrint.cpp
)
link_paddle_exe
(
test_CustomStackTracePrint
)
add_test
(
NAME test_CustomStackTracePrint
COMMAND
${
PROJ_ROOT
}
/paddle/utils/tests/test_CustomStackTracePrint.sh
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
)
paddle/utils/tests/test_CustomStackTrace.cpp
0 → 100644
浏览文件 @
49a92da2
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <gtest/gtest.h>
#include <chrono>
#include "paddle/utils/CustomStackTrace.h"
#include "paddle/utils/CommandLineParser.h"
#include "paddle/utils/Util.h"
#include "paddle/utils/Locks.h"
P_DEFINE_int32
(
test_thread_num
,
10
,
"testing thread number"
);
void
testNormalImpl
(
const
std
::
function
<
void
(
paddle
::
CustomStackTrace
<
std
::
string
>&
,
size_t
,
size_t
,
paddle
::
ThreadBarrier
&
,
paddle
::
ThreadBarrier
&
)
>&
callback
)
{
paddle
::
CustomStackTrace
<
std
::
string
>
tracer
;
paddle
::
ThreadBarrier
doneBarrier
(
FLAGS_test_thread_num
+
1
);
paddle
::
ThreadBarrier
startBarrier
(
FLAGS_test_thread_num
+
1
);
constexpr
size_t
countDown
=
10
;
constexpr
size_t
layerSize
=
1000
;
std
::
vector
<
std
::
unique_ptr
<
std
::
thread
>>
threads
;
threads
.
reserve
(
FLAGS_test_thread_num
);
for
(
int32_t
i
=
0
;
i
<
FLAGS_test_thread_num
;
++
i
)
{
threads
.
emplace_back
(
new
std
::
thread
([
&
tracer
,
&
countDown
,
&
layerSize
,
&
startBarrier
,
&
doneBarrier
,
&
callback
]{
callback
(
tracer
,
countDown
,
layerSize
,
startBarrier
,
doneBarrier
);
}));
}
size_t
cntDown
=
countDown
;
while
(
cntDown
--
>
0
)
{
startBarrier
.
wait
();
doneBarrier
.
wait
();
ASSERT_TRUE
(
tracer
.
empty
());
}
for
(
auto
&
thread
:
threads
)
{
thread
->
join
();
}
}
TEST
(
CustomStackTrace
,
normalTrain
)
{
testNormalImpl
([](
paddle
::
CustomStackTrace
<
std
::
string
>&
tracer
,
size_t
countDown
,
size_t
layerSize
,
paddle
::
ThreadBarrier
&
start
,
paddle
::
ThreadBarrier
&
finish
){
while
(
countDown
--
>
0
)
{
start
.
wait
();
for
(
size_t
i
=
0
;
i
<
layerSize
;
++
i
)
{
tracer
.
push
(
"layer_"
+
std
::
to_string
(
i
));
}
tracer
.
pop
(
""
);
for
(
size_t
i
=
0
;
i
<
layerSize
;
++
i
)
{
tracer
.
pop
(
"layer_"
+
std
::
to_string
(
layerSize
-
1
-
i
));
}
finish
.
wait
();
}
});
}
TEST
(
CustomStackTrace
,
normalTest
)
{
testNormalImpl
([]
(
paddle
::
CustomStackTrace
<
std
::
string
>&
tracer
,
size_t
countDown
,
size_t
layerSize
,
paddle
::
ThreadBarrier
&
start
,
paddle
::
ThreadBarrier
&
finish
){
while
(
countDown
--
>
0
)
{
start
.
wait
();
for
(
size_t
i
=
0
;
i
<
layerSize
;
++
i
)
{
tracer
.
push
(
"layer_"
+
std
::
to_string
(
i
));
}
tracer
.
clear
();
// in forward test, tracer will clear after forward.
finish
.
wait
();
}
});
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
paddle
::
initMain
(
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
paddle/utils/tests/test_CustomStackTracePrint.cpp
0 → 100644
浏览文件 @
49a92da2
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/utils/Util.h"
#include "paddle/utils/CustomStackTrace.h"
int
main
(
int
argc
,
char
**
argv
)
{
paddle
::
initMain
(
argc
,
argv
);
for
(
size_t
i
=
0
;
i
<
1000
;
++
i
)
{
paddle
::
gLayerStackTrace
.
push
(
"layer_"
+
std
::
to_string
(
i
));
if
(
i
==
998
)
{
throw
"Unhandle exception"
;
}
}
return
0
;
}
paddle/utils/tests/test_CustomStackTracePrint.sh
0 → 100755
浏览文件 @
49a92da2
#!/bin/bash
echo
"Test Custom Stack Trace print correct result when fail"
./test_CustomStackTracePrint
>
customStackTraceLog 2>&1
if
[
$?
-eq
0
]
;
then
exit
1
else
set
-e
TEXT
=
""
for
((
i
=
0
;
i<
=
998
;
i++
))
do
TEXT
=
"layer_
$i
, "
$TEXT
done
TEXT
=
"Forwarding "
$TEXT
grep
-q
"
$TEXT
"
customStackTraceLog
fi
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录