45 lines · cpp
1//===-- Integration test for the lock-free stack --------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/__support/GPU/fixedstack.h"10#include "src/__support/GPU/utils.h"11#include "test/IntegrationTest/test.h"12 13using namespace LIBC_NAMESPACE;14 15static FixedStack<uint32_t, 2048> global_stack;16 17void run() {18 // We need enough space in the stack as threads in flight can temporarily19 // consume memory before they finish comitting it back to the stack.20 ASSERT_EQ(gpu::get_num_blocks() * gpu::get_num_threads(), 512);21 22 uint32_t val;23 uint32_t num_threads = static_cast<uint32_t>(gpu::get_num_threads());24 for (int i = 0; i < 256; ++i) {25 EXPECT_TRUE(global_stack.push(UINT32_MAX))26 EXPECT_TRUE(global_stack.pop(val))27 ASSERT_TRUE(val < num_threads || val == UINT32_MAX);28 }29 30 EXPECT_TRUE(global_stack.push(static_cast<uint32_t>(gpu::get_thread_id())));31 EXPECT_TRUE(global_stack.push(static_cast<uint32_t>(gpu::get_thread_id())));32 EXPECT_TRUE(global_stack.pop(val));33 ASSERT_TRUE(val < num_threads || val == UINT32_MAX);34 35 // Fill the rest of the stack with the default value.36 while (!global_stack.push(UINT32_MAX))37 ;38}39 40TEST_MAIN(int argc, char **argv, char **envp) {41 run();42 43 return 0;44}45