Skip to content

Conversation

@vineelko
Copy link
Contributor

@vineelko vineelko commented Nov 20, 2025

Description

Since Patina relies on the log::* API for logging, not configuring a default
logger can cause log::* calls to appear completely uncovered in llvm-cov
reports, slightly reducing overall coverage. Adding a simple environment based
logger avoids this issue. Although this change enables coverage for log::*,
there are still cases that cannot be covered. For example, in the function
below, there is no way to get coverage for lines 6 and 7.

1   1   fn print() {
2   1       let mut i = 0;
3   11      for _ in 0..10 {
4   10          log::info!(
5   10              "This will be covered {} {}",
6                   i,
7                   "This and the above line will not be covered."
8               );
9   10          i = i + 1;
10          }
11  1   }

The environment logger can be enabled as shown below:
To enable logging, set the RUST_LOG environment variable to the desired
log level (e.g., debug, info, warn, error) before running the tests.

$ RUST_LOG=debug cargo test -p patina_dxe_core allocator::usage_tests::uefi_memory_map -- --nocapture
or
PS:> $env:RUST_LOG="debug"; cargo test -p patina_dxe_core allocator::usage_tests::uefi_memory_map -- --nocapture

For cargo make coverage a corresponding Makefile.toml change will be added
from patina-devops

[tasks.test]
description = "Run tests and collect coverage data without generating reports."
env = { "RUST_LOG" = "info" }  <---
...

How This Was Tested

cargo make all

Integration Instructions

NA

@github-actions github-actions bot added the impact:non-functional Does not have a functional impact label Nov 20, 2025
@codecov
Copy link

codecov bot commented Nov 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@os-d os-d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default this won't log anything, right? Only if you pass --no-capture will the log have it? I'm worried about cluttering the log and slowing down tests if we do actual logging.

@Javagedes
Copy link
Collaborator

Javagedes commented Nov 20, 2025

Are you sure we actually need a real logger here? I think we just need to make sure the level conditions are correct so that the if statement in the expanded macro does not bail out. I kind of think that just involves setting the max_level() correctly maybe? This is what the expanded log macros come out to:

{
    let lvl = ::log::Level::Error;
    if lvl <= ::log::STATIC_MAX_LEVEL
        && lvl <= ::log::max_level()
    {
        ::log::__private_api::log(
            { ::log::__private_api::GlobalLogger },
            format_args!(
                "Error freeing previous MAT pointer: {0:#X?}",
                err,
            ),
            lvl,
            &(
                "patina_dxe_core::config_tables::memory_attributes_table",
                "patina_dxe_core::config_tables::memory_attributes_table",
                ::log::__private_api::loc(),
            ),
            (),
        );
    }
}

Overall, I'm not against having a real logger, but realistically it should be unnecessary with the debugger on a host based system.

@vineelko vineelko requested a review from Javagedes November 20, 2025 17:34
@vineelko
Copy link
Contributor Author

By default this won't log anything, right? Only if you pass --no-capture will the log have it? I'm worried about cluttering the log and slowing down tests if we do actual logging.

That's correct. No logs without --nocapture

@vineelko vineelko force-pushed the users/vineelko/add_logger_to_patina_dxe_core_1119 branch from 0179dd3 to 6c6ffd0 Compare November 20, 2025 19:04
@vineelko
Copy link
Contributor Author

Are you sure we actually need a real logger here? I think we just need to make sure the level conditions are correct so that the if statement in the expanded macro does not bail out. I kind of think that just involves setting the max_level() correctly maybe? This is what the expanded log macros come out to:

{
    let lvl = ::log::Level::Error;
    if lvl <= ::log::STATIC_MAX_LEVEL
        && lvl <= ::log::max_level()
    {
        ::log::__private_api::log(
            { ::log::__private_api::GlobalLogger },
            format_args!(
                "Error freeing previous MAT pointer: {0:#X?}",
                err,
            ),
            lvl,
            &(
                "patina_dxe_core::config_tables::memory_attributes_table",
                "patina_dxe_core::config_tables::memory_attributes_table",
                ::log::__private_api::loc(),
            ),
            (),
        );
    }
}

Overall, I'm not against having a real logger, but realistically it should be unnecessary with the debugger on a host based system.

I still think there is value in have a real logger because it helps diagnose individual tests using --nocapture and especially since during normal test execution this does not make any different wrt to the output. For more granular control on the log level may be we can switch the real logger to be based on env_logger. That way we can set the var appropriately along with --nocapture

@vineelko vineelko force-pushed the users/vineelko/add_logger_to_patina_dxe_core_1119 branch from 6c6ffd0 to 6d4cd51 Compare December 22, 2025 19:53
@vineelko vineelko changed the title Patina Dxe Core: Tests: Add a console logger Patina Dxe Core: Add a default environment based test logger Dec 22, 2025
@vineelko vineelko force-pushed the users/vineelko/add_logger_to_patina_dxe_core_1119 branch from 6d4cd51 to 7882bba Compare December 22, 2025 19:56
Since Patina relies on the `log::*` API for logging, not configuring a default
logger can cause `log::*` calls to appear completely uncovered in llvm-cov
reports, slightly reducing overall coverage. Adding a simple environment based
logger avoids this issue. Although this change enables coverage for `log::*`,
there are still cases that cannot be covered. For example, in the function
below, there is no way to get coverage for lines 6 and 7.

```
1   1   fn print() {
2   1       let mut i = 0;
3   11      for _ in 0..10 {
4   10          log::info!(
5   10              "This will be covered {} {}",
6                   i,
7                   "This and the above line will not be covered."
8               );
9   10          i = i + 1;
10          }
11  1   }
```

The environment logger can be enabled as shown below:
To enable logging, set the `RUST_LOG` environment variable to the desired
log level (e.g., `debug`, `info`, `warn`, `error`) before running the tests.

```bash
$ RUST_LOG=debug cargo test -p patina_dxe_core allocator::usage_tests::uefi_memory_map -- --nocapture
or
PS:> $env:RUST_LOG="debug"; cargo test -p patina_dxe_core allocator::usage_tests::uefi_memory_map -- --nocapture
```

For `cargo make coverage` a corresponding `Makefile.toml` change will be added
from patina-devops
```
[tasks.test]
description = "Run tests and collect coverage data without generating reports."
env = { "RUST_LOG" = "info" }  <---
...
```

Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
@vineelko vineelko force-pushed the users/vineelko/add_logger_to_patina_dxe_core_1119 branch from 7882bba to 3e601b5 Compare January 5, 2026 20:00
@vineelko vineelko merged commit 19b22bf into OpenDevicePartnership:main Jan 5, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:non-functional Does not have a functional impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants