From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id A84E1D804A2 for ; Fri, 29 Sep 2023 16:47:40 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=SgVgAeO/pZd3sMgGMdMmKlbxiAeK1UOab1hXQjUFqRE=; c=relaxed/simple; d=groups.io; h=Subject:To:From:User-Agent:MIME-Version:Date:References:In-Reply-To:Message-ID:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type; s=20140610; t=1696006059; v=1; b=k1l34xlXSE3htiAWOVhG76dTKLPhLcLfHBoy5Jre45uxxOnmxPnXxUBh0Ll8QXYZl6gGMKWe 71k4MiOsOKhJ57mf5VgMTjlY1EkR6KfFQ6lFLYLo0W33FVmYoAdr1tSCGUrFeTTRCJXKQSVzkjP egnVfpPJ7F1UzXAN6sBxXUcs= X-Received: by 127.0.0.2 with SMTP id wmGnYY7687511xxDiD4KeKwC; Fri, 29 Sep 2023 09:47:39 -0700 Subject: Re: [edk2-devel] Problems mocking UEFI Protocol in gMock To: CrossedCarpet ,devel@edk2.groups.io From: "CrossedCarpet" X-Originating-Location: New York, New York, US (149.88.20.215) X-Originating-Platform: Linux Chrome 116 User-Agent: GROUPS.IO Web Poster MIME-Version: 1.0 Date: Fri, 29 Sep 2023 09:47:38 -0700 References: <10445.1695395049741883261@groups.io> In-Reply-To: <10445.1695395049741883261@groups.io> Message-ID: <27529.1696006058785664800@groups.io> Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,crossedcarpet@hotmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: RkaGBcCQItMEdy5SltQCZRigx7686176AA= Content-Type: multipart/alternative; boundary="95mFQZZWhHbWD7jp5LSi" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=k1l34xlX; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=hotmail.com (policy=none) --95mFQZZWhHbWD7jp5LSi Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Greetings, A week long collaboration between me and GDB, figuring out how to reproduce= my CounterProtocol with function arguments, made me reach the conclusion t= hat mocking a UEFI protocol is indeed documented and the solution had to do= with copying the style of a global table Mock. This is the relevant piece of documentation: https://fuchsia.googlesource.c= om/third_party/edk2/+/refs/heads/main/UnitTestFrameworkPkg/#functionmocklib= -mocks-declaration And this would be my Sample Protocol: // header file struct MockCounterProtocol: CounterProtocol { MOCK_INTERFACE_DECLARATION(MockCounterProtocol); MOCK_FUNCTION_DECLARTION(INTN, CounterProtocol_Count, ()); } extern "C" { extern CounterProtocol *gCounterProtocol; } // source file MOCK_INTERFACE_DEFINITION (MockCounterProtocol) MOCK_FUNCTION_DEFINITION (MockCounterProtocol, Count, 0, EFIAPI) static CounterProtocol localCounterProtocol =3D { current_count }; extern "C" { CounterProtocol *gCounterProtocol =3D &localCounterProtocol; } Best Regards, Me & Gdb -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#109213): https://edk2.groups.io/g/devel/message/109213 Mute This Topic: https://groups.io/mt/101360319/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --95mFQZZWhHbWD7jp5LSi Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable

Greetings, 
A week long collaboration between me and GDB, figu= ring out how to reproduce my CounterProtocol with function arguments, made = me reach the conclusion that mocking a UEFI protocol is indeed documented a= nd the solution had to do with copying the style of a global table Mock.
This is the relevant piece of documentation: https://fuchsia.googlesource.com/third_party/edk2/+/refs/heads/main/Un= itTestFrameworkPkg/#functionmocklib-mocks-declaration

And th= is would be my Sample Protocol:

// header file
struct MockCounterProtocol: = CounterProtocol {
   MOCK_INTERFACE_DECLARATION(MockCounterProtocol);
=    MOCK_FUNCTION_DE= CLARTION(INTN, CounterProtocol_Count, ());
}

extern "C" {
extern CounterProt= ocol *gCounterProtocol; 
}

// source file

MOCK_INTERFACE_DEFINITION = (MockCounterProtocol)
MOCK_FUNCTION_DEFINITION (MockCounterProtocol, Count, 0, EFIAPI)
=
static CounterProtocol localCounterProtocol =3D {
    = current_count
};

extern "C" {
CounterPro= tocol *gCounterProtocol =3D &localCounterProtocol;
}

Best Regards,
Me &= ; Gdb

_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#109213) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--95mFQZZWhHbWD7jp5LSi--