50 lines · cpp
1//===-- SPSAllocActionTest.cpp --------------------------------------------===//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// Test SPS serialization for AllocAction APIs.10//11//===----------------------------------------------------------------------===//12 13#include "orc-rt/SPSAllocAction.h"14 15#include "SimplePackedSerializationTestUtils.h"16#include "gtest/gtest.h"17 18using namespace orc_rt;19 20static bool AAEQ(const AllocAction &LHS, const AllocAction &RHS) {21 if (LHS.Fn != RHS.Fn)22 return false;23 if (LHS.ArgData.size() != RHS.ArgData.size())24 return false;25 return memcmp(LHS.ArgData.data(), RHS.ArgData.data(), LHS.ArgData.size()) ==26 0;27}28 29static bool AAPEQ(const AllocActionPair &LHS, const AllocActionPair &RHS) {30 return AAEQ(LHS.Finalize, RHS.Finalize) && AAEQ(LHS.Dealloc, RHS.Dealloc);31}32 33static orc_rt_WrapperFunctionBuffer noopAction(const char *ArgData,34 size_t ArgSize) {35 return WrapperFunctionBuffer().release();36}37 38TEST(SPSAllocActionTest, AllocActionSerialization) {39 AllocAction AA(noopAction, WrapperFunctionBuffer::copyFrom("hello, world!"));40 blobSerializationRoundTrip<SPSAllocAction>(AA, AAEQ);41}42 43TEST(SPSAllocActionTest, AllocActionPairSerialization) {44 AllocActionPair AAP;45 AAP.Finalize = {noopAction, WrapperFunctionBuffer::copyFrom("foo")};46 AAP.Dealloc = {noopAction, WrapperFunctionBuffer::copyFrom("foo")};47 48 blobSerializationRoundTrip<SPSAllocActionPair>(AAP, AAPEQ);49}50