1 /*
2  * Copyright (c) 2020 Friedt Professional Engineering Services, Inc
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "_main.h"
8 
9 #include <zephyr/logging/log.h>
10 #include <zephyr/net/socket.h>
11 #include <zephyr/ztest.h>
12 
13 static ZTEST_DMEM struct net_socketpair_fixture fixture;
setup(void)14 static void *setup(void)
15 {
16 	k_thread_system_pool_assign(k_current_get());
17 
18 	return &fixture;
19 }
20 
before(void * arg)21 static void before(void *arg)
22 {
23 	struct net_socketpair_fixture *fixture = arg;
24 
25 	for (int i = 0; i < 2; ++i) {
26 		if (fixture->sv[i] >= 0) {
27 			fixture->sv[i] = -1;
28 		}
29 	}
30 	zassert_ok(socketpair(AF_UNIX, SOCK_STREAM, 0, fixture->sv));
31 }
32 
after(void * arg)33 static void after(void *arg)
34 {
35 	struct net_socketpair_fixture *fixture = arg;
36 
37 	for (int i = 0; i < 2; ++i) {
38 		if (fixture->sv[i] >= 0) {
39 			zassert_ok(close(fixture->sv[i]));
40 			fixture->sv[i] = -1;
41 		}
42 	}
43 }
44 
45 ZTEST_SUITE(net_socketpair, NULL, setup, before, after, NULL);
46