1 // Copyright 2019 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 use sys_util::EventFd;
6
7 use msg_socket::*;
8
9 #[derive(MsgOnSocket)]
10 struct Request {
11 field0: u8,
12 field1: EventFd,
13 field2: u32,
14 field3: bool,
15 }
16
17 #[derive(MsgOnSocket)]
18 struct DummyResponse {}
19
20 #[test]
sock_send_recv_struct()21 fn sock_send_recv_struct() {
22 let (req, res) = pair::<Request, DummyResponse>().unwrap();
23 let e0 = EventFd::new().unwrap();
24 let e1 = e0.try_clone().unwrap();
25 req.send(&Request {
26 field0: 2,
27 field1: e0,
28 field2: 0xf0f0,
29 field3: true,
30 })
31 .unwrap();
32 let r = res.recv().unwrap();
33 assert_eq!(r.field0, 2);
34 assert_eq!(r.field2, 0xf0f0);
35 assert_eq!(r.field3, true);
36 r.field1.write(0x0f0f).unwrap();
37 assert_eq!(e1.read().unwrap(), 0x0f0f);
38 }
39