1 /*
2 * Copyright (c) 2023, Google Inc. All rights reserved
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24 #include <lib/trusty/ipc.h>
25 #include <lib/unittest/unittest.h>
26 #include <lk/init.h>
27 #include <stdio.h>
28 #include <string.h>
29
TEST(list_ports,lists)30 TEST(list_ports, lists) {
31 struct ipc_port* port_list;
32 size_t len = ipc_get_port_list(&port_list);
33
34 trusty_unittest_printf("|%.64s|%.12s|%.12s|%.12s|%.12s|%.12s|\n", "NAME",
35 "TA_CONNECT", "NS_CONNECT", "STATUS", "NB_BUFFER",
36 "BUFFER_SZ");
37 for (size_t port_idx = 0; port_idx < len; ++port_idx) {
38 struct ipc_port* port = port_list + port_idx;
39
40 trusty_unittest_printf("|%.64s|", port->path);
41
42 if (port->flags & IPC_PORT_ALLOW_TA_CONNECT) {
43 trusty_unittest_printf("%.12s|", "TRUE");
44 } else {
45 trusty_unittest_printf("%.12s|", "FALSE");
46 }
47
48 if (port->flags & IPC_PORT_ALLOW_NS_CONNECT) {
49 trusty_unittest_printf("%.12s|", "TRUE");
50 } else {
51 trusty_unittest_printf("%.12s|", "FALSE");
52 }
53
54 /* Port State */
55 if (port->state == IPC_PORT_STATE_INVALID) {
56 trusty_unittest_printf("%.12s|", "INVALID");
57 } else if (port->state == IPC_PORT_STATE_LISTENING) {
58 trusty_unittest_printf("%.12s|", "LISTENING");
59 } else {
60 trusty_unittest_printf("%.12s|", "UNKNOWN");
61 }
62
63 trusty_unittest_printf("%.12u|", port->num_recv_bufs);
64 trusty_unittest_printf("%.12zu|", port->recv_buf_size);
65
66 trusty_unittest_printf("\n");
67 }
68 ipc_free_port_list(port_list);
69 }
70
71 PORT_TEST(list_ports, "com.android.kernel.list-ports");
72