Skip to content

Commit

Permalink
Adding MockRNG to the Google Test Mock (#668)
Browse files Browse the repository at this point in the history
# Preface

Please ensure you have read the [contribution
docs](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md) prior
to submitting the pull request. In particular,
[pull request
guidelines](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md#pull-request-best-practices).

## Description

Adds MockRNG to the Google Test Mock

For each item, place an "x" in between `[` and `]` if true. Example:
`[x]`.
_(you can also check items in the GitHub UI)_

- [ ] Impacts functionality?
  - **Functionality** - No
- [ ] Impacts security?
  - **Security** - No
- [ ] Breaking change?
  - **Breaking change** - No
- [ ] Includes tests?
  - **Tests** - No
- [ ] Includes documentation?
  - **Documentation** - No
  
## How This Was Tested

Local Tests

## Integration Instructions

N/A
  • Loading branch information
Flickdm authored Jan 9, 2024
1 parent 7fdfe17 commit c3db959
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
47 changes: 47 additions & 0 deletions MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockRng.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/** @file
This file declares a mock of Rng Protocol.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_RNG_H
#define MOCK_RNG_H

#include <Library/GoogleTestLib.h>
#include <Library/FunctionMockLib.h>

extern "C" {
#include <Uefi.h>
#include <Protocol\Rng.h>
}

struct MockRng {
MOCK_INTERFACE_DECLARATION (MockRng);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS
GetInfo (
IN EFI_RNG_PROTOCOL *This,
IN OUT UINTN *RNGAlgorithmListSize,
OUT EFI_RNG_ALGORITHM *RNGAlgorithmList
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS
GetRNG (
IN EFI_RNG_PROTOCOL *This,
IN EFI_RNG_ALGORITHM *RNGAlgorithmList,
IN UINTN RNGAlgorithmListSize,
IN OUT UINT8 *RandomNumber,
IN UINTN RandomNumberLength
)
);
};

extern "C" {
extern EFI_RNG_PROTOCOL *gRngProtocol;
}

#endif // MOCK_RNG_H
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,7 @@ static EFI_BOOT_SERVICES LocalBs = {
};

extern "C" {
EFI_BOOT_SERVICES *gBS = &LocalBs;
EFI_BOOT_SERVICES *gBS = &LocalBs;
EFI_HANDLE gImageHandle = NULL;
EFI_SYSTEM_TABLE *gST = NULL;
}
21 changes: 21 additions & 0 deletions MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockRng.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** @file MockRng.cpp
Google Test mock for Rng Protocol
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <GoogleTest/Protocol/MockRng.h>

MOCK_INTERFACE_DEFINITION (MockRng);
MOCK_FUNCTION_DEFINITION (MockRng, GetInfo, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockRng, GetRng, 5, EFIAPI);

EFI_RNG_PROTOCOL RNG_PROTOCOL_INSTANCE = {
GetInfo, // EFI_RNG_GET_INFO
GetRng // EFI_RNG_GET_RNG
};

extern "C" {
EFI_RNG_PROTOCOL *gRngProtocol = &RNG_PROTOCOL_INSTANCE;
}

0 comments on commit c3db959

Please sign in to comment.