llvm/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp

//===--- OrcCAPITest.cpp - Unit tests for the OrcJIT v2 C API ---*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "llvm-c/Core.h"
#include "llvm-c/Error.h"
#include "llvm-c/LLJIT.h"
#include "llvm-c/LLJITUtils.h"
#include "llvm-c/Orc.h"
#include "gtest/gtest.h"

#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/Testing/Support/Error.h"
#include <string>

usingnamespacellvm;
usingnamespacellvm::orc;

DEFINE_SIMPLE_CONVERSION_FUNCTIONS()
DEFINE_SIMPLE_CONVERSION_FUNCTIONS()

// OrcCAPITestBase contains several helper methods and pointers for unit tests
// written for the LLVM-C API. It provides the following helpers:
//
// 1. Jit: an LLVMOrcLLJIT instance which is freed upon test exit
// 2. ExecutionSession: the LLVMOrcExecutionSession for the JIT
// 3. MainDylib: the main JITDylib for the LLJIT instance
// 4. materializationUnitFn: function pointer to an empty function, used for
//                           materialization unit testing
// 5. definitionGeneratorFn: function pointer for a basic
//                           LLVMOrcCAPIDefinitionGeneratorTryToGenerateFunction
// 6. createTestModule: helper method for creating a basic thread-safe-module
class OrcCAPITestBase : public testing::Test {};

std::string OrcCAPITestBase::TargetTriple;
bool OrcCAPITestBase::TargetSupported =;

namespace {

constexpr StringRef SumExample =;

constexpr StringRef SumDebugExample =;

} // end anonymous namespace.

// Consumes the given error ref and returns the string error message.
static std::string toString(LLVMErrorRef E) {}

TEST_F(OrcCAPITestBase, SymbolStringPoolUniquing) {}

TEST_F(OrcCAPITestBase, JITDylibLookup) {}

TEST_F(OrcCAPITestBase, MaterializationUnitCreation) {}

struct ExecutionSessionLookupHelper {};

static void executionSessionLookupHandlerCallback(LLVMErrorRef Err,
                                                  LLVMOrcCSymbolMapPairs Result,
                                                  size_t NumPairs,
                                                  void *RawCtx) {}

TEST_F(OrcCAPITestBase, ExecutionSessionLookup_Success) {}

TEST_F(OrcCAPITestBase, ExecutionSessionLookup_Failure) {}

TEST_F(OrcCAPITestBase, DefinitionGenerators) {}

#if defined(_AIX)
TEST_F(OrcCAPITestBase, DISABLED_ResourceTrackerDefinitionLifetime) {
#else
TEST_F(OrcCAPITestBase, ResourceTrackerDefinitionLifetime) {}

#if defined(_AIX)
TEST_F(OrcCAPITestBase, DISABLED_ResourceTrackerTransfer) {
#else
TEST_F(OrcCAPITestBase, ResourceTrackerTransfer) {}

#if defined(_AIX)
TEST_F(OrcCAPITestBase, DISABLED_AddObjectBuffer) {
#else
TEST_F(OrcCAPITestBase, AddObjectBuffer) {}

// JITLink debug support plugins put information about JITed code in this GDB
// JIT Interface global from OrcTargetProcess.
extern "C" struct jit_descriptor __jit_debug_descriptor;

static void *findLastDebugDescriptorEntryPtr() {}

#if defined(_AIX) or not(defined(__ELF__) or defined(__MACH__))
TEST_F(OrcCAPITestBase, DISABLED_EnableDebugSupport) {
#else
static LLVM_ATTRIBUTE_USED void linkComponents() {}
TEST_F(OrcCAPITestBase, EnableDebugSupport) {}

#if defined(_AIX)
TEST_F(OrcCAPITestBase, DISABLED_ExecutionTest) {
#else
TEST_F(OrcCAPITestBase, ExecutionTest) {}

void Destroy(void *Ctx) {}

void TargetFn() {}

void Materialize(void *Ctx, LLVMOrcMaterializationResponsibilityRef MR) {}

TEST_F(OrcCAPITestBase, MaterializationResponsibility) {}

struct SuspendedLookupContext {};

static LLVMErrorRef TryToGenerateWithSuspendedLookup(
    LLVMOrcDefinitionGeneratorRef GeneratorObj, void *RawCtx,
    LLVMOrcLookupStateRef *LookupState, LLVMOrcLookupKind Kind,
    LLVMOrcJITDylibRef JD, LLVMOrcJITDylibLookupFlags JDLookupFlags,
    LLVMOrcCLookupSet LookupSet, size_t LookupSetSize) {}

static void DisposeSuspendedLookupContext(void *Ctx) {}

static void
suspendLookupTestLookupHandlerCallback(LLVMErrorRef Err,
                                       LLVMOrcCSymbolMapPairs Result,
                                       size_t NumPairs, void *RawCtx) {}

TEST_F(OrcCAPITestBase, SuspendedLookup) {}