Skip to content

Commit 9763f21

Browse files
Tri VoGerrit Code Review
Tri Vo
authored and
Gerrit Code Review
committed
Merge changes Id77b87bb,I56a15c80
* changes: trusty: fuzz: make utils lib use libtrusty_test trusty: Add libtrusty_test
2 parents 180b267 + 90c0e83 commit 9763f21

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

trusty/fuzz/Android.bp

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414

1515
cc_defaults {
1616
name: "trusty_fuzzer_defaults",
17-
static_libs: [
18-
"libtrusty_fuzz_utils",
19-
],
2017
shared_libs: [
18+
"libtrusty_fuzz_utils",
2119
"libbase",
2220
"liblog",
2321
],
@@ -36,6 +34,7 @@ cc_library {
3634
srcs: ["utils.cpp"],
3735
export_include_dirs: ["include"],
3836
shared_libs: [
37+
"libtrusty_test",
3938
"libbase",
4039
"liblog",
4140
],

trusty/fuzz/utils.cpp

+2-17
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@
2525
#include <linux/uio.h>
2626
#include <log/log_read.h>
2727
#include <time.h>
28+
#include <trusty/tipc.h>
2829
#include <iostream>
2930

3031
using android::base::ErrnoError;
3132
using android::base::Error;
3233
using android::base::Result;
3334
using android::base::unique_fd;
3435

35-
#define TIPC_IOC_MAGIC 'r'
36-
#define TIPC_IOC_CONNECT _IOW(TIPC_IOC_MAGIC, 0x80, char*)
37-
3836
namespace {
3937

4038
const size_t kTimeoutSeconds = 5;
@@ -80,27 +78,14 @@ TrustyApp::TrustyApp(std::string tipc_dev, std::string ta_port)
8078
: tipc_dev_(tipc_dev), ta_port_(ta_port), ta_fd_(-1) {}
8179

8280
Result<void> TrustyApp::Connect() {
83-
/*
84-
* TODO: We can't use libtrusty because (yet)
85-
* (1) cc_fuzz can't deal with vendor components (b/170753563)
86-
* (2) We need non-blocking behavior to detect Trusty going down.
87-
* (we could implement the timeout in the fuzzing code though, as
88-
* it needs to be around the call to read())
89-
*/
9081
alarm(kTimeoutSeconds);
91-
int fd = open(tipc_dev_.c_str(), O_RDWR);
82+
int fd = tipc_connect(tipc_dev_.c_str(), ta_port_.c_str());
9283
alarm(0);
9384
if (fd < 0) {
9485
return ErrnoError() << "failed to open TIPC device: ";
9586
}
9687
ta_fd_.reset(fd);
9788

98-
// This ioctl will time out in the kernel if it can't connect.
99-
int rc = TEMP_FAILURE_RETRY(ioctl(ta_fd_, TIPC_IOC_CONNECT, ta_port_.c_str()));
100-
if (rc < 0) {
101-
return ErrnoError() << "failed to connect to TIPC service: ";
102-
}
103-
10489
return {};
10590
}
10691

trusty/libtrusty/Android.bp

+15-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
cc_library {
16-
name: "libtrusty",
17-
vendor: true,
18-
15+
cc_defaults {
16+
name: "libtrusty_defaults",
1917
srcs: ["trusty.c"],
2018
export_include_dirs: ["include"],
2119
cflags: [
@@ -25,3 +23,16 @@ cc_library {
2523

2624
shared_libs: ["liblog"],
2725
}
26+
27+
cc_library {
28+
name: "libtrusty",
29+
vendor: true,
30+
defaults: ["libtrusty_defaults"],
31+
}
32+
33+
// TODO(b/170753563): cc_fuzz can't deal with vendor components. Build libtrusty
34+
// for system.
35+
cc_test_library {
36+
name: "libtrusty_test",
37+
defaults: ["libtrusty_defaults"],
38+
}

0 commit comments

Comments
 (0)