Skip to content

Commit

Permalink
Remove warnings from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamos82 committed Aug 2, 2024
1 parent d91e8b6 commit 8e60712
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
6 changes: 3 additions & 3 deletions tests/include/test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#include <stddef.h>
#include <stdbool.h>

/*#define pretty_assert(msg, expected_value, returned_value) \
( \
#define pretty_assert(msg, expected_value, returned_value) \
({ \
printf("\t[%s] %s Returned value: %d should be: %d\n", __FUNCTION__, msg, expected_value, returned_value); \
assert(expected_value == returned_value); \
)*/
})

typedef enum {
Debug = 0,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <bitmap.h>

void _printStringAndNumber(char *string, unsigned long number){
printf("%s0x%X\n", string, number);
printf("%s0x%lX\n", string, number);
}

void _printStr(const char *string){
Expand Down
12 changes: 6 additions & 6 deletions tests/test_kheap.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ int main(){
kernel_heap_start->size = 8 * PAGE_SIZE;
kernel_heap_start->next = NULL;
kernel_heap_start->prev = NULL;
printf("\t [test_kheap] (Init) Initialized heap of size: %d\n", kernel_heap_start->size);
printf("\t [test_kheap] (Init) Initialized heap of size: %lu\n", kernel_heap_start->size);
printf("\t [test_kheap] (Init) Address of kheap: 0x%X\n", kernel_heap_start);
kernel_heap_end = kernel_heap_start;
end_of_mapped_memory = (uint64_t) kernel_heap_end + 0x15000;
printf("\t [test_kheap] (Init) Initializing sizeof heap structure: ... %d\n", sizeof(KHeapMemoryNode));
printf("\t [test_kheap] (Init) Initializing sizeof heap structure: ... %lu\n", sizeof(KHeapMemoryNode));
printf("\t [test_kheap] (Init) Address of kheap: 0x%X\n", kernel_heap_end);
printf("\t [test_kheap] (Init) Kheap size: %d\n", get_kheap_size(kernel_heap_start));
test_kmalloc();
Expand All @@ -60,24 +60,24 @@ void test_kmalloc(){
printf("\t [test_kheap] (kmalloc) test_ptr value: 0x%x\n", test_ptr);
assert(kernel_heap_start == (test_ptr - sizeof(KHeapMemoryNode)));
assert((uint64_t)test_ptr == (((uint64_t)initial_end) + sizeof(KHeapMemoryNode)));
printf("\t [test_kheap] (kmalloc) testing kheap size after kmalloc: 0x%X\n", kernel_heap_end->size);
printf("\t [test_kheap] (kmalloc) testing kheap size after kmalloc: 0x%lX\n", kernel_heap_end->size);
assert(kernel_heap_end->size == (kheap_size - (0x30 + sizeof(KHeapMemoryNode))));
printf("Finished\n");
}

void test_kfree(){
printf("Test kfree\n");
KHeapMemoryNode *original_end = kernel_heap_end;
printf("\t [test_kheap] (kfree) Kernel heap end size: 0x%x\n", kernel_heap_end->size);
printf("\t [test_kheap] (kfree) KHeapMemoryNode size: 0x%x\n", sizeof(KHeapMemoryNode));
printf("\t [test_kheap] (kfree) Kernel heap end size: 0x%lx\n", kernel_heap_end->size);
printf("\t [test_kheap] (kfree) KHeapMemoryNode size: 0x%lx\n", sizeof(KHeapMemoryNode));
kfree(NULL);
assert(original_end == kernel_heap_end);
printf("\t [test_kheap] (kfree) Testing kfree right after a malloc\n");
printf("\t [test_kheap] (kfree) Kheap size: %d\n", get_kheap_size(kernel_heap_start));
char *test_ptr = (char *) kmalloc(10);
uint8_t heap_length = get_kheap_size(kernel_heap_start);
printf("\t [test_kheap] (kfree) Kheap size: %d\n", heap_length);
printf("\t [test_kheap] (kfree) Kernel heap end size: 0x%x\n", kernel_heap_end->size);
printf("\t [test_kheap] (kfree) Kernel heap end size: 0x%lx\n", kernel_heap_end->size);
printf("\t [test_kheap] (kfree) test_ptr: 0x%x\n", test_ptr);
kfree(test_ptr);
uint8_t new_heap_length = get_kheap_size(kernel_heap_start);
Expand Down
34 changes: 17 additions & 17 deletions tests/test_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void test_pmm(){
printf("\t [test_mem] (bitmap): Used frames: %x\n", used_frames);
assert(used_frames==0x2);
printf("\t [test_mem] (bitmap): Testing memory_map initial value\n");
printf("\t [test_mem] (bitmap): memory_map[0] = %X\n", memory_map[0]);
printf("\t [test_mem] (bitmap): memory_map[0] = %lX\n", memory_map[0]);
assert(memory_map[0]==0x3);
printf("\t [test_mem] (bitmap):Testing value of first call to _bitmap_request_frame()\n");
uint64_t frame_value = _bitmap_request_frame();
Expand All @@ -101,8 +101,8 @@ void test_pmm(){
uint64_t frame = (uint64_t) pmm_alloc_frame();
printf("\t [test_mem] (bitmap): used_frames: %x\n", used_frames);
assert(used_frames == 0x3);
printf("\t [test_mem] (bitmap): Checking that returned address is: 0x%x\n", frame);
assert(frame == (void*)0x400000);
printf("\t [test_mem] (bitmap): Checking that returned address is: 0x%lx\n", frame);
assert((void *)frame == (void*)0x400000);
assert(memory_map[0] == 0x7);
printf("\t [test_mem] (bitmap): Test setting a frame at row 1 column 3\n");
_bitmap_set_bit(67);
Expand All @@ -115,8 +115,8 @@ void test_pmm(){
assert(memory_map[1] == 0x40);
printf("\t [test_mem] (bitmap): Trying allocating another frame\n");
frame = (uint64_t)pmm_alloc_frame();
printf("\t [test_mem] (bitmap): Checking that returned address is: 0x%x\n", frame);
assert(frame == (void*)0x600000);
printf("\t [test_mem] (bitmap): Checking that returned address is: 0x%lx\n", frame);
assert((void *)frame == (void*)0x600000);
assert(used_frames == 0x4);
assert(memory_map[0] == 0xF);
printf("\t [test_mem] (bitmap): Testing test_bit on frame 67 should be 0\n");
Expand All @@ -130,28 +130,28 @@ void test_pmm(){
assert(bit_value == true);
printf("\t [test_mem] (bitmap): Trying to free a page at address 0x400000\n");
pmm_free_frame( (uint64_t*)0x400000 );
printf("\t [test_mem] (bitmap): Memory map value: 0x%X\n", memory_map[0]);
printf("\t [test_mem] (bitmap): Memory map value: 0x%lX\n", memory_map[0]);
assert(memory_map[0] == 0xB);
assert(used_frames == 0x3);
printf("\t [test_mem] (bitmap): Trying to free another frame: 0x%x\n", frame);
printf("\t [test_mem] (bitmap): before freeing memorymap[0]: %X\n", memory_map[0]);
printf("\t [test_mem] (bitmap): Trying to free another frame: 0x%lx\n", frame);
printf("\t [test_mem] (bitmap): before freeing memorymap[0]: %lX\n", memory_map[0]);
pmm_free_frame((uint64_t *) frame);
assert(used_frames == 0x2);
assert(memory_map[0] == 3);
printf("\t [test_mem] (bitmap): used_frames == 0x2 %d\n", used_frames == 0x2);
printf("\t [test_mem] (bitmap): memorymap[0]: %x\n", memory_map[0]);
printf("\t [test_mem] (bitmap): Checking pmm_alloc_area page size: 0x%X\n", PAGE_SIZE_IN_BYTES);
printf("\t [test_mem] (bitmap): memorymap[0]: %lx\n", memory_map[0]);
printf("\t [test_mem] (bitmap): Checking pmm_alloc_area page size: 0x%lX\n", PAGE_SIZE_IN_BYTES);
uint64_t *frame_2 = pmm_alloc_area(0x250000);
printf("\t [test_mem] (bitmap): Address: 0x%x\n", frame_2);
printf("\t [test_mem] (bitmap): Address: 0x%lx\n", frame_2);
printf("\t [test_mem] (bitmap): Returned frame_2 should be 0x02 0x%x and used frames should be 0x04 0x%x\n", frame_2, used_frames);
assert(frame_2 == 0x02);
assert(frame_2 == (uint64_t *)0x02);
assert(used_frames == 0x04);
printf("\t [test_mem] (bitmap): memory_map[0]: 0x%x\n", memory_map[0]);
printf("\t [test_mem] (bitmap): memory_map[0]: 0x%lx\n", memory_map[0]);
printf("\t [test_mem] (bitmap): Changing memory_map[0] value to 75, and used frames to 4\n");
memory_map[0] = 75;
used_frames = 4;
frame_2 = pmm_alloc_area(0x500000);
printf("\t [test_mem] (bitmap): memory_map[0]=0x%x and used_frames=0x%x\n", memory_map[0], used_frames);
printf("\t [test_mem] (bitmap): memory_map[0]=0x%lx and used_frames=0x%x\n", memory_map[0], used_frames);
assert(memory_map[0] == 0x3CB);
assert(used_frames == 0x7);
printf("Finished\n");
Expand All @@ -163,13 +163,13 @@ void test_mmap(){
assert(mmap_number_of_entries == 6);
printf("\t [test_mem] (mmap): Check that mmap_entries point to mmap_root->entries\n");
assert(mmap_root->entries == mmap_entries);
printf("\t [test_mem] (mmap): Check that 0x%X address is correctly set to 1\n", mmap_entries[1].addr);
printf("\t [test_mem] (mmap): Check that 0x%llX address is correctly set to 1\n", mmap_entries[1].addr);
uint32_t bitmap_entry = ADDRESS_TO_BITMAP_ENTRY(mmap_entries[1].addr);
assert(_bitmap_test_bit(bitmap_entry) == true);
printf("\t [test_mem] (mmap): Check that 0x%X address is correctly set to 1\n", mmap_entries[2].addr);
printf("\t [test_mem] (mmap): Check that 0x%llX address is correctly set to 1\n", mmap_entries[2].addr);
bitmap_entry = ADDRESS_TO_BITMAP_ENTRY(mmap_entries[2].addr);
assert(_bitmap_test_bit(bitmap_entry) == true);
printf("\t [test_mem] (mmap): Check that 0x%X is correctly set to 1\n", mmap_entries[3].addr);
printf("\t [test_mem] (mmap): Check that 0x%llX is correctly set to 1\n", mmap_entries[3].addr);
bitmap_entry = ADDRESS_TO_BITMAP_ENTRY(mmap_entries[3].addr);
assert(_bitmap_test_bit(bitmap_entry) == true);
printf("\t [test_mem] (mmap): Check that 11th bit of bitmap should be set as 0\n");
Expand Down
8 changes: 4 additions & 4 deletions tests/test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
int main() {
printf("Testing VMM Utility function -\n");
size_t number_of_pages = get_number_of_pages_from_size(0x900);
printf("\t [test_utils] (get_number_of_pages_from_size): Testing number of pages for 0x900, should be 1: %d\n", number_of_pages);
printf("\t [test_utils] (get_number_of_pages_from_size): Testing number of pages for 0x900, should be 1: %ld\n", number_of_pages);
assert(number_of_pages == 1);
number_of_pages = get_number_of_pages_from_size(0x0);
printf("\t [test_utils] (get_number_of_pages_from_size): Testing number of pages for 0x0, should be 0: %d\n", number_of_pages);
printf("\t [test_utils] (get_number_of_pages_from_size): Testing number of pages for 0x0, should be 0: %ld\n", number_of_pages);
assert(align_value_to_page(0x100) == 0x200000);
printf("\t [test_utils] (align_value_to_page): Testing alignment for 0x100, should be 0x200000: %x\n", align_value_to_page(0x100));
printf("\t [test_utils] (align_value_to_page): Testing alignment for 0x100, should be 0x200000: %lx\n", align_value_to_page(0x100));
assert(align_value_to_page(0x200015) == 0x400000);
printf("\t [test_utils] (align_value_to_page): Testing alignment for 0x100, should be 0x200015: %x\n", align_value_to_page(0x200015));
printf("\t [test_utils] (align_value_to_page): Testing alignment for 0x100, should be 0x200015: %lx\n", align_value_to_page(0x200015));

}
12 changes: 6 additions & 6 deletions tests/test_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ int main() {
void test_ensure_address_in_higher_half() {
printf("Testing ensure_addres_in_higher_half\n");
uint64_t test_address = 0x100000;
printf("\t [test_vm](%s): Should return (0) for type not recognized and address: 0x%x\n", __FUNCTION__, test_address);
printf("\t [test_vm](%s): Should return (0) for type not recognized and address: 0x%lx\n", __FUNCTION__, test_address);
test_address = ensure_address_in_higher_half(test_address, 3);
assert(test_address == 0);
test_address = ensure_address_in_higher_half(0x100000, VM_TYPE_MMIO);
printf("\t [test_vm](%s): Should return (0x%x) for type MMIO and address=0x%x \n", __FUNCTION__, test_address, 0x100000);
printf("\t [test_vm](%s): Should return (0x%lx) for type MMIO and address=0x%x \n", __FUNCTION__, test_address, 0x100000);
assert(test_address == 0xffff800000300000);
test_address = ensure_address_in_higher_half(0x100000, VM_TYPE_MEMORY);
printf("\t [test_vm](%s): Should return (0x%lx) for type MEMORY and address=0x%x\n", __FUNCTION__, test_address, 0x100000);
Expand Down Expand Up @@ -60,12 +60,12 @@ void test_is_address_higher_half() {

void test_vm_parse_flags() {
printf("Testing test_vm_parse_flags\n");
printf("\t[test_vm](%s): Should return 0 - %d\n", __FUNCTION__, vm_parse_flags(VMM_FLAGS_ADDRESS_ONLY));
printf("\t[test_vm](%s): Should return 0 - %zu\n", __FUNCTION__, vm_parse_flags(VMM_FLAGS_ADDRESS_ONLY));
assert(0 == vm_parse_flags(VMM_FLAGS_ADDRESS_ONLY));
printf("\t[test_vm](%s): Should return 3 - %d\n", __FUNCTION__, vm_parse_flags(VMM_FLAGS_ADDRESS_ONLY | VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE));
printf("\t[test_vm](%s): Should return 3 - %zu\n", __FUNCTION__, vm_parse_flags(VMM_FLAGS_ADDRESS_ONLY | VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE));
assert(3 == vm_parse_flags(VMM_FLAGS_ADDRESS_ONLY | VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE));
printf("\t[test_vm](%s): Should return 2 - %d\n", __FUNCTION__, vm_parse_flags(VMM_FLAGS_WRITE_ENABLE));
printf("\t[test_vm](%s): Should return 2 - %zu\n", __FUNCTION__, vm_parse_flags(VMM_FLAGS_WRITE_ENABLE));
assert(2 == vm_parse_flags( VMM_FLAGS_WRITE_ENABLE));
printf("\t[test_vm](%s): Should return 3 - %d\n", __FUNCTION__, vm_parse_flags(VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE));
printf("\t[test_vm](%s): Should return 3 - %zu\n", __FUNCTION__, vm_parse_flags(VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE));
assert(3 == vm_parse_flags(VMM_FLAGS_ADDRESS_ONLY | VMM_FLAGS_PRESENT | VMM_FLAGS_WRITE_ENABLE));
}
2 changes: 1 addition & 1 deletion tests/test_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void test_get_rectangles() {
printf("\t[%s] Rectangles[0].y_orig should be: 0 - %d\n", __FUNCTION__, rectangles[0].y_orig);
assert(rectangles[0].x_orig == 0);
assert(rectangles[0].y_orig == 0);
//pretty_assert("Testing rectangles[0].x_orig", 0, rectangles[0].x_orig);
pretty_assert("Testing rectangles[0].x_orig", 0, rectangles[0].x_orig);
printf("\t[%s] Rectangles[0].width should be: 1030 - %d\n", __FUNCTION__, rectangles[0].width);
printf("\t[%s] Rectangles[0].height should be: 550 - %d\n", __FUNCTION__, rectangles[0].height);
assert(rectangles[0].width == 1030);
Expand Down

0 comments on commit 8e60712

Please sign in to comment.