1//===-- Unittests for pipe2 -----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#include "src/unistd/close.h"
9#include "src/unistd/pipe2.h"
10
11#include "test/UnitTest/ErrnoCheckingTest.h"
12#include "test/UnitTest/ErrnoSetterMatcher.h"
13#include "test/UnitTest/Test.h"
14
15using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
16using LlvmLibcPipe2Test = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
17
18TEST_F(LlvmLibcPipe2Test, SucceedsSmokeTest) {
19 int pipefd[2];
20 ASSERT_THAT(LIBC_NAMESPACE::pipe2(pipefd, 0), Succeeds());
21 ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[0]), Succeeds());
22 ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[1]), Succeeds());
23}
24
25TEST_F(LlvmLibcPipe2Test, FailsSmokeTest) {
26 int pipefd[2];
27 ASSERT_THAT(LIBC_NAMESPACE::pipe2(pipefd, -1), Fails(EINVAL));
28 ASSERT_THAT(LIBC_NAMESPACE::pipe2(nullptr, 0), Fails(EFAULT));
29}
30

source code of libc/test/src/unistd/pipe2_test.cpp