• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/ErrnoCheckingTest.h"
12 #include "test/UnitTest/ErrnoSetterMatcher.h"
13 #include "test/UnitTest/Test.h"
14 
15 using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
16 using LlvmLibcUnistdGetEntropyTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
17 
TEST_F(LlvmLibcUnistdGetEntropyTest,LengthTooLong)18 TEST_F(LlvmLibcUnistdGetEntropyTest, LengthTooLong) {
19   char buf[1024];
20   ASSERT_THAT(LIBC_NAMESPACE::getentropy(buf, 257), Fails(EIO));
21 }
22 
TEST_F(LlvmLibcUnistdGetEntropyTest,SmokeTest)23 TEST_F(LlvmLibcUnistdGetEntropyTest, SmokeTest) {
24   char buf[256];
25   ASSERT_THAT(LIBC_NAMESPACE::getentropy(buf, 256), Succeeds());
26 }
27 
TEST_F(LlvmLibcUnistdGetEntropyTest,OtherError)28 TEST_F(LlvmLibcUnistdGetEntropyTest, OtherError) {
29   ASSERT_THAT(LIBC_NAMESPACE::getentropy(nullptr, 1), Fails(EIO));
30 }
31