A fair bit of setup / teardown code was being duplicated in many test cases in the socketpair testsuite. Take advantage of the `setup()`, `before()`, and `after()` functions in the new ZTest API. Signed-off-by: Christopher Friedt <cfriedt@meta.com>
46 lines
892 B
C
46 lines
892 B
C
/*
|
|
* Copyright (c) 2020 Friedt Professional Engineering Services, Inc
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include "_main.h"
|
|
|
|
#include <zephyr/logging/log.h>
|
|
#include <zephyr/net/socket.h>
|
|
#include <zephyr/ztest.h>
|
|
|
|
static ZTEST_DMEM struct net_socketpair_fixture fixture;
|
|
static void *setup(void)
|
|
{
|
|
k_thread_system_pool_assign(k_current_get());
|
|
|
|
return &fixture;
|
|
}
|
|
|
|
static void before(void *arg)
|
|
{
|
|
struct net_socketpair_fixture *fixture = arg;
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
if (fixture->sv[i] >= 0) {
|
|
fixture->sv[i] = -1;
|
|
}
|
|
}
|
|
zassert_ok(socketpair(AF_UNIX, SOCK_STREAM, 0, fixture->sv));
|
|
}
|
|
|
|
static void after(void *arg)
|
|
{
|
|
struct net_socketpair_fixture *fixture = arg;
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
if (fixture->sv[i] >= 0) {
|
|
zassert_ok(close(fixture->sv[i]));
|
|
fixture->sv[i] = -1;
|
|
}
|
|
}
|
|
}
|
|
|
|
ZTEST_SUITE(net_socketpair, NULL, setup, before, after, NULL);
|