Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
c7088da5
A
apollo
项目概览
Pinoxchio
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c7088da5
编写于
12月 29, 2020
作者:
S
storypku
提交者:
Liu Jiaming
1月 06, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cyber: add unit tests for shared_library
上级
6ebdd0de
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
150 addition
and
2 deletion
+150
-2
cyber/class_loader/shared_library/BUILD
cyber/class_loader/shared_library/BUILD
+34
-1
cyber/class_loader/shared_library/sample.cc
cyber/class_loader/shared_library/sample.cc
+22
-0
cyber/class_loader/shared_library/sample.h
cyber/class_loader/shared_library/sample.h
+22
-0
cyber/class_loader/shared_library/shared_library.cc
cyber/class_loader/shared_library/shared_library.cc
+1
-1
cyber/class_loader/shared_library/shared_library_test.cc
cyber/class_loader/shared_library/shared_library_test.cc
+71
-0
未找到文件。
cyber/class_loader/shared_library/BUILD
浏览文件 @
c7088da5
load
(
"@rules_cc//cc:defs.bzl"
,
"cc_
library
"
)
load
(
"@rules_cc//cc:defs.bzl"
,
"cc_
binary"
,
"cc_library"
,
"cc_test
"
)
load
(
"//tools:cpplint.bzl"
,
"cpplint"
)
package
(
default_visibility
=
[
"//visibility:public"
])
...
...
@@ -18,4 +18,37 @@ cc_library(
hdrs
=
[
"exceptions.h"
],
)
cc_binary
(
name
=
"libsample.so"
,
testonly
=
True
,
linkshared
=
True
,
linkstatic
=
False
,
visibility
=
[
"//visibility:private"
],
deps
=
[
":sample_lib"
,
],
)
cc_library
(
name
=
"sample_lib"
,
testonly
=
True
,
srcs
=
[
"sample.cc"
],
hdrs
=
[
"sample.h"
],
linkopts
=
[
"-lm"
],
visibility
=
[
"//visibility:private"
],
)
cc_test
(
name
=
"shared_library_test"
,
size
=
"small"
,
srcs
=
[
"shared_library_test.cc"
],
data
=
[
":libsample.so"
,
],
deps
=
[
":shared_library"
,
"@com_google_googletest//:gtest_main"
,
],
)
cpplint
()
cyber/class_loader/shared_library/sample.cc
0 → 100644
浏览文件 @
c7088da5
/******************************************************************************
* Copyright 2020 The Apollo Authors. All Rights Reserved.
*
* 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 "cyber/class_loader/shared_library/sample.h"
#include <cmath>
int
sample_add
(
int
x
,
int
y
)
{
return
x
+
y
;
}
double
sample_sin
(
double
x
)
{
return
std
::
sin
(
x
);
}
cyber/class_loader/shared_library/sample.h
0 → 100644
浏览文件 @
c7088da5
/******************************************************************************
* Copyright 2020 The Apollo Authors. All Rights Reserved.
*
* 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.
*****************************************************************************/
#ifndef CYBER_CLASS_LOADER_SHARED_LIBRARY_SAMPLE_H_
#define CYBER_CLASS_LOADER_SHARED_LIBRARY_SAMPLE_H_
extern
"C"
int
sample_add
(
int
a
,
int
b
);
extern
"C"
double
sample_sin
(
double
x
);
#endif // CYBER_CLASS_LOADER_SHARED_LIBRARY_SAMPLE_H_
cyber/class_loader/shared_library/shared_library.cc
浏览文件 @
c7088da5
...
...
@@ -19,7 +19,7 @@
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier:
BSL-1.0
// SPDX-License-Identifier:
BSL-1.0
//
#include "cyber/class_loader/shared_library/shared_library.h"
...
...
cyber/class_loader/shared_library/shared_library_test.cc
0 → 100644
浏览文件 @
c7088da5
/******************************************************************************
* Copyright 2020 The Apollo Authors. All Rights Reserved.
*
* 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 "cyber/class_loader/shared_library/shared_library.h"
#include <cmath>
#include "gtest/gtest.h"
namespace
{
const
std
::
string
&
SAMPLE_LIB
=
"/apollo/bazel-bin/cyber/class_loader/shared_library/libsample.so"
;
constexpr
double
epsilon
=
1.0e-8
;
}
// namespace
namespace
apollo
{
namespace
cyber
{
namespace
class_loader
{
TEST
(
SharedLibraryTest
,
symbol_test_1
)
{
auto
shared_lib
=
std
::
make_shared
<
SharedLibrary
>
();
EXPECT_TRUE
(
shared_lib
->
GetPath
().
empty
());
EXPECT_FALSE
(
shared_lib
->
IsLoaded
());
EXPECT_NO_THROW
(
shared_lib
->
Load
(
SAMPLE_LIB
));
EXPECT_TRUE
(
shared_lib
->
IsLoaded
());
EXPECT_THROW
(
shared_lib
->
Load
(
SAMPLE_LIB
),
LibraryAlreadyLoadedException
);
EXPECT_TRUE
(
shared_lib
->
HasSymbol
(
"sample_add"
));
auto
symbol
=
shared_lib
->
GetSymbol
(
"sample_add"
);
EXPECT_TRUE
(
symbol
!=
nullptr
);
typedef
int
(
*
BinaryFunc
)(
int
,
int
);
auto
pf
=
reinterpret_cast
<
BinaryFunc
>
(
symbol
);
EXPECT_EQ
(
pf
(
3
,
5
),
8
);
shared_lib
->
Unload
();
}
TEST
(
SharedLibraryTest
,
symbol_test_2
)
{
auto
shared_lib
=
std
::
make_shared
<
SharedLibrary
>
(
SAMPLE_LIB
);
EXPECT_TRUE
(
shared_lib
->
IsLoaded
());
typedef
double
(
*
UnaryFunc
)(
double
);
auto
symbol
=
shared_lib
->
GetSymbol
(
"sample_sin"
);
EXPECT_TRUE
(
symbol
!=
nullptr
);
auto
sample_sin
=
reinterpret_cast
<
UnaryFunc
>
(
symbol
);
EXPECT_NEAR
(
sample_sin
(
M_PI
/
2
),
1.0
,
epsilon
);
shared_lib
->
Unload
();
}
}
// namespace class_loader
}
// namespace cyber
}
// namespace apollo
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录