Skip to content

Commit

Permalink
Create Google mock for ReadOnlyVariable2 (#579)
Browse files Browse the repository at this point in the history
## Description

Create Google mock for ReadOnlyVariable2
Created a new PR for cleaner single-commit (also this one works)
Old PR: #530

- [ ] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
- Examples: Add a new library, publish a new PPI, update an algorithm,
...
- [ ] Impacts security?
- **Security** - Does the change have a direct security impact on an
application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
- **Breaking change** - Will anyone consuming this change experience a
break
    in build or boot behavior?
- Examples: Add a new library class, move a module to a different repo,
call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
- **Documentation** - Does the change contain explicit documentation
additions
    outside direct code modifications (and comments)?
- Examples: Update readme file, add feature readme file, link to
documentation
    on an a separate Web page, ...

## How This Was Tested

Tested with ConfigKnobShimLib GoogleTest

## Integration Instructions

N/A
  • Loading branch information
VivianNK authored and kenlautner committed Oct 23, 2023
1 parent 8f0e0c4 commit 1e2aab9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
49 changes: 49 additions & 0 deletions MdePkg/Test/Mock/Include/GoogleTest/Ppi/MockReadOnlyVariable2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/** @file MockReadOnlyVariable2.h
This file declares a mock of Read-only Variable Service2 PPI.
This PPI permits read-only access to the UEFI variable store during the PEI phase.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_PEI_READ_ONLY_VARIABLE2_PPI_H
#define MOCK_PEI_READ_ONLY_VARIABLE2_PPI_H

#include <Library/GoogleTestLib.h>
#include <Library/FunctionMockLib.h>
extern "C" {
#include <Uefi.h>
#include <Pi/PiPeiCis.h>
#include <Ppi/ReadOnlyVariable2.h>
}

struct MockReadOnlyVariable2 {
MOCK_INTERFACE_DECLARATION (MockReadOnlyVariable2);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
GetVariable,
(IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
IN CONST CHAR16 *VariableName,
IN CONST EFI_GUID *VariableGuid,
OUT UINT32 *Attributes,
IN OUT UINTN *DataSize,
OUT VOID *Data OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
NextVariableName,
(IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
IN OUT UINTN *VariableNameSize,
IN OUT CHAR16 *VariableName,
IN OUT EFI_GUID *VariableGuid)
);
};

extern "C" {
extern EFI_PEI_READ_ONLY_VARIABLE2_PPI *PpiReadOnlyVariableServices;
}

#endif
23 changes: 23 additions & 0 deletions MdePkg/Test/Mock/Library/GoogleTest/Ppi/MockReadOnlyVariable2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/** @file MockReadOnlyVariable2.cpp
Google Test mock for ReadOnlyVariable2
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <GoogleTest/Ppi/MockReadOnlyVariable2.h>

MOCK_INTERFACE_DEFINITION (MockReadOnlyVariable2);
MOCK_FUNCTION_DEFINITION (MockReadOnlyVariable2, GetVariable, 6, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockReadOnlyVariable2, NextVariableName, 4, EFIAPI);

// Normally PpiVariableServices is "found"
// This will be defined INSIDE the test, with its definition pointing to the mock function GetVariable
EFI_PEI_READ_ONLY_VARIABLE2_PPI PeiReadOnlyVariablePpi = {
GetVariable, // EFI_PEI_GET_VARIABLE2
NextVariableName // EFI_PEI_GET_NEXT_VARIABLE_NAME2
};

extern "C" {
EFI_PEI_READ_ONLY_VARIABLE2_PPI *PpiReadOnlyVariableServices = &PeiReadOnlyVariablePpi;
}

0 comments on commit 1e2aab9

Please sign in to comment.