summary refs log tree commit diff
path: root/msg_socket/tests/struct.rs
blob: 5efc3696014b7cf96488a408d5874030e96aabb3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use sys_util::EventFd;

use msg_socket::*;

#[derive(MsgOnSocket)]
struct Request {
    field0: u8,
    field1: EventFd,
    field2: u32,
    field3: bool,
}

#[derive(MsgOnSocket)]
struct DummyResponse {}

#[test]
fn sock_send_recv_struct() {
    let (req, res) = pair::<Request, DummyResponse>().unwrap();
    let e0 = EventFd::new().unwrap();
    let e1 = e0.try_clone().unwrap();
    req.send(&Request {
        field0: 2,
        field1: e0,
        field2: 0xf0f0,
        field3: true,
    })
    .unwrap();
    let r = res.recv().unwrap();
    assert_eq!(r.field0, 2);
    assert_eq!(r.field2, 0xf0f0);
    assert_eq!(r.field3, true);
    r.field1.write(0x0f0f).unwrap();
    assert_eq!(e1.read().unwrap(), 0x0f0f);
}