Make test more lenient for custom clang version strings
[llvm-project.git] / libc / test / src / __support / freelist_test.cpp
blobbd5ecec45d921b3b5df529f920bcfdbb6bf47fdd
1 //===-- Unittests for a freelist --------------------------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 #include <stddef.h>
11 #include "src/__support/freelist.h"
12 #include "test/UnitTest/Test.h"
14 using LIBC_NAMESPACE::Block;
15 using LIBC_NAMESPACE::FreeList;
16 using LIBC_NAMESPACE::cpp::byte;
17 using LIBC_NAMESPACE::cpp::optional;
19 TEST(LlvmLibcFreeList, FreeList) {
20 byte mem[1024];
21 optional<Block *> maybeBlock = Block::init(mem);
22 ASSERT_TRUE(maybeBlock.has_value());
23 Block *block1 = *maybeBlock;
25 maybeBlock = block1->split(128);
26 ASSERT_TRUE(maybeBlock.has_value());
27 Block *block2 = *maybeBlock;
29 maybeBlock = block2->split(128);
30 ASSERT_TRUE(maybeBlock.has_value());
32 FreeList list;
33 list.push(block1);
34 ASSERT_FALSE(list.empty());
35 EXPECT_EQ(list.front(), block1);
37 list.push(block2);
38 EXPECT_EQ(list.front(), block1);
40 list.pop();
41 ASSERT_FALSE(list.empty());
42 EXPECT_EQ(list.front(), block2);
44 list.pop();
45 ASSERT_TRUE(list.empty());
47 list.push(block1);
48 list.push(block2);
49 list.remove(reinterpret_cast<FreeList::Node *>(block2->usable_space()));
50 EXPECT_EQ(list.front(), block1);
51 list.pop();
52 ASSERT_TRUE(list.empty());