generated from limine-bootloader/limine-c-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
142 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# A simple cheat-sheet to provide a quick reference for the most common commands and operations. | ||
|
||
## Table of Contents | ||
|
||
### Code coverage | ||
|
||
To generate a code coverage report, run the following command: | ||
|
||
```shell | ||
bazel coverage -c dbg --nocache_test_results --combined_report=lcov //... | ||
``` | ||
|
||
To view the report | ||
|
||
```shell | ||
genhtml --branch-coverage --output genhtml "$(bazel info output_path)/_coverage/_coverage_report.dat" | ||
``` | ||
|
||
references [bazel.build/configure/coverage](https://bazel.build/configure/coverage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include <RuntimeLib.h> | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
|
||
TEST_CASE ("AllocatePages", "[BumpAllocator]") { | ||
BUMP_ALLOCATOR allocator { }; | ||
|
||
RtlBumpAllocatorInitialize (&allocator); | ||
|
||
// Setup code | ||
allocator.bumpers[0].heap_start = (UINTN) new UINT8[PAGE_SIZE_4K]; | ||
allocator.bumpers[0].heap_end = allocator.bumpers[0].heap_start + PAGE_SIZE_4K; | ||
allocator.bumpers[0].next = allocator.bumpers[0].heap_start; | ||
|
||
allocator.bumpers[1].heap_start = (UINTN) new UINT8[PAGE_SIZE_4K * 2]; | ||
allocator.bumpers[1].heap_end = allocator.bumpers[1].heap_start + PAGE_SIZE_4K * 2; | ||
allocator.bumpers[1].next = allocator.bumpers[1].heap_start; | ||
|
||
SECTION ("Allocates 4K page") { | ||
VOID* address = NULL; | ||
STATUS status = PA_ALLOCATE (&allocator, &address, 1, PAGE_SIZE_4K); | ||
|
||
REQUIRE (status == STATUS_SUCCESS); | ||
REQUIRE (allocator.bumpers[0].next == allocator.bumpers[0].heap_end); | ||
REQUIRE (address != NULL); | ||
REQUIRE (address == (VOID*)allocator.bumpers[0].heap_start); | ||
} | ||
|
||
SECTION ("Allocate multiple pages") { | ||
VOID* address = NULL; | ||
STATUS status = PA_ALLOCATE (&allocator, &address, 2, PAGE_SIZE_4K); | ||
|
||
REQUIRE (status == STATUS_SUCCESS); | ||
REQUIRE (allocator.bumpers[1].next == allocator.bumpers[1].heap_end); | ||
REQUIRE (address != NULL); | ||
REQUIRE (address == (VOID*)allocator.bumpers[1].heap_start); | ||
} | ||
|
||
SECTION ("Making sure we cannot over-allocate") { | ||
VOID* address = NULL; | ||
STATUS status = PA_ALLOCATE (&allocator, &address, PAGE_SIZE_4K, PAGE_SIZE_4K); | ||
|
||
REQUIRE (status == STATUS_OUT_OF_MEMORY); | ||
REQUIRE (address == NULL); | ||
} | ||
|
||
SECTION ("Try unaligned pages") { | ||
VOID* address = NULL; | ||
STATUS status = PA_ALLOCATE (&allocator, &address, 1, 1025); | ||
|
||
REQUIRE (status == STATUS_INVALID_ALIGNMENT); | ||
REQUIRE (address == NULL); | ||
} | ||
|
||
SECTION ("Make sure zero pages are not allocated") { | ||
VOID* address = NULL; | ||
STATUS status = PA_ALLOCATE (&allocator, &address, 0, PAGE_SIZE_4K); | ||
|
||
REQUIRE (status == STATUS_INVALID_PARAMETER); | ||
REQUIRE (address == NULL); | ||
} | ||
|
||
SECTION ("Make sure NULL Address is not allocated") { | ||
STATUS status = PA_ALLOCATE (&allocator, NULL, 1, PAGE_SIZE_4K); | ||
|
||
REQUIRE (status == STATUS_INVALID_PARAMETER); | ||
} | ||
|
||
SECTION ("Allocate multiple pages, multiple times") { | ||
VOID* address = NULL; | ||
STATUS status; | ||
|
||
// First allocation, this is guaranteed to succeed | ||
status = PA_ALLOCATE (&allocator, &address, 1, PAGE_SIZE_4K); | ||
|
||
REQUIRE (status == STATUS_SUCCESS); | ||
REQUIRE (address != NULL); | ||
REQUIRE (address == (VOID*)allocator.bumpers[0].heap_start); | ||
REQUIRE (allocator.bumpers[0].next == allocator.bumpers[0].heap_end); | ||
|
||
// Second allocation, this is also guaranteed, but we must be on the second bumper | ||
status = PA_ALLOCATE (&allocator, &address, 1, PAGE_SIZE_4K); | ||
|
||
REQUIRE (status == STATUS_SUCCESS); | ||
REQUIRE (address != NULL); | ||
REQUIRE (address == (VOID*)allocator.bumpers[1].heap_start); | ||
|
||
// Same as above, but we should reach the end of the second bumper | ||
status = PA_ALLOCATE (&allocator, &address, 1, PAGE_SIZE_4K); | ||
|
||
REQUIRE (status == STATUS_SUCCESS); | ||
REQUIRE (address != NULL); | ||
REQUIRE (address == (VOID*)(allocator.bumpers[1].heap_start + PAGE_SIZE_4K)); | ||
REQUIRE (allocator.bumpers[1].next == allocator.bumpers[1].heap_end); | ||
|
||
// Third allocation, this should fail as we have no more bumpers available. | ||
status = PA_ALLOCATE (&allocator, &address, 1, PAGE_SIZE_4K); | ||
|
||
REQUIRE (status == STATUS_OUT_OF_MEMORY); | ||
REQUIRE (address == NULL); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <RuntimeLib.h> | ||
|
||
#include <catch2/catch_test_macros.hpp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters