xref: /llvm-project/libc/test/src/unistd/getentropy_test.cpp (revision defd0d966d5ebae37787e76b86f2f2ff2a5cfd59)
1 //===-- Unittests for getentropy ------------------------------------------===//
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 
9 #include "hdr/errno_macros.h"
10 #include "src/unistd/getentropy.h"
11 #include "test/UnitTest/ErrnoSetterMatcher.h"
12 #include "test/UnitTest/Test.h"
13 
14 using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
15 
16 TEST(LlvmLibcUnistdGetEntropyTest, LengthTooLong) {
17   char buf[1024];
18   ASSERT_THAT(LIBC_NAMESPACE::getentropy(buf, 257), Fails(EIO));
19 }
20 
21 TEST(LlvmLibcUnistdGetEntropyTest, SmokeTest) {
22   char buf[256];
23   ASSERT_THAT(LIBC_NAMESPACE::getentropy(buf, 256), Succeeds());
24 }
25 
26 TEST(LlvmLibcUnistdGetEntropyTest, OtherError) {
27   ASSERT_THAT(LIBC_NAMESPACE::getentropy(nullptr, 1), Fails(EIO));
28 }
29