1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-11-13 11:04:27 -05:00
libkernaux/tests/test_multiboot2_info_helpers.c

399 lines
12 KiB
C
Raw Normal View History

2020-12-06 23:47:53 -05:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <kernaux/multiboot2.h>
#include <assert.h>
2022-01-12 23:05:34 -05:00
#include "multiboot2_info_example1.h"
#include "multiboot2_info_example2.h"
static const struct {
2022-01-12 22:59:52 -05:00
struct KernAux_Multiboot2_Info multiboot2_info;
2022-01-12 22:38:51 -05:00
struct KernAux_Multiboot2_ITag_None tag_none;
} multiboot2_without_boot_cmd_line = {
2022-01-12 22:59:52 -05:00
.multiboot2_info = {
.total_size = sizeof(multiboot2_without_boot_cmd_line),
.reserved1 = 0,
},
.tag_none = {
.base = {
2022-01-12 21:49:25 -05:00
.type = KERNAUX_MULTIBOOT2_ITAG_NONE,
.size = sizeof(multiboot2_without_boot_cmd_line.tag_none),
},
},
};
static const struct {
2022-01-12 22:59:52 -05:00
struct KernAux_Multiboot2_Info multiboot2_info;
struct {
2022-01-12 22:38:51 -05:00
struct KernAux_Multiboot2_ITag_BootCmdLine tag;
char cmdline[14];
} tag_boot_cmd_line;
unsigned char _align1[2];
2022-01-12 22:38:51 -05:00
struct KernAux_Multiboot2_ITag_None tag_none;
} multiboot2_with_some_boot_cmd_line = {
2022-01-12 22:59:52 -05:00
.multiboot2_info = {
.total_size = sizeof(multiboot2_with_some_boot_cmd_line),
.reserved1 = 0,
},
.tag_boot_cmd_line = {
.tag = {
.base = {
2022-01-12 21:49:25 -05:00
.type = KERNAUX_MULTIBOOT2_ITAG_BOOT_CMD_LINE,
.size = sizeof(
multiboot2_with_some_boot_cmd_line.tag_boot_cmd_line
),
},
},
.cmdline = "Hello, World!\0",
},
.tag_none = {
.base = {
2022-01-12 21:49:25 -05:00
.type = KERNAUX_MULTIBOOT2_ITAG_NONE,
.size = sizeof(multiboot2_with_some_boot_cmd_line.tag_none),
},
},
};
static const struct {
2022-01-12 22:59:52 -05:00
struct KernAux_Multiboot2_Info multiboot2_info;
struct {
2022-01-12 22:38:51 -05:00
struct KernAux_Multiboot2_ITag_BootCmdLine tag;
char cmdline[14];
} tag_boot_cmd_line1;
unsigned char _align1[2];
struct {
2022-01-12 22:38:51 -05:00
struct KernAux_Multiboot2_ITag_BootCmdLine tag;
char cmdline[13];
} tag_boot_cmd_line2;
unsigned char _align2[3];
2022-01-12 22:38:51 -05:00
struct KernAux_Multiboot2_ITag_None tag_none;
} multiboot2_with_two_boot_cmd_lines = {
2022-01-12 22:59:52 -05:00
.multiboot2_info = {
.total_size = sizeof(multiboot2_with_two_boot_cmd_lines),
.reserved1 = 0,
},
.tag_boot_cmd_line1 = {
.tag = {
.base = {
2022-01-12 21:49:25 -05:00
.type = KERNAUX_MULTIBOOT2_ITAG_BOOT_CMD_LINE,
.size = sizeof(
multiboot2_with_two_boot_cmd_lines.tag_boot_cmd_line1
),
},
},
.cmdline = "Hello, World!\0",
},
.tag_boot_cmd_line2 = {
.tag = {
.base = {
2022-01-12 21:49:25 -05:00
.type = KERNAUX_MULTIBOOT2_ITAG_BOOT_CMD_LINE,
.size = sizeof(
multiboot2_with_two_boot_cmd_lines.tag_boot_cmd_line2
),
},
},
.cmdline = "Hello again!\0",
},
.tag_none = {
.base = {
2022-01-12 21:49:25 -05:00
.type = KERNAUX_MULTIBOOT2_ITAG_NONE,
.size = sizeof(multiboot2_with_two_boot_cmd_lines.tag_none),
},
},
};
int main()
{
2022-01-12 22:59:52 -05:00
assert(KernAux_Multiboot2_Info_is_valid(
2022-01-12 23:05:34 -05:00
(struct KernAux_Multiboot2_Info*)multiboot2_info_example1
));
2022-01-12 22:59:52 -05:00
assert(KernAux_Multiboot2_Info_is_valid(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info
));
2022-01-12 22:59:52 -05:00
assert(KernAux_Multiboot2_Info_is_valid(
&multiboot2_without_boot_cmd_line.multiboot2_info
));
2022-01-12 22:59:52 -05:00
assert(KernAux_Multiboot2_Info_is_valid(
&multiboot2_with_some_boot_cmd_line.multiboot2_info
));
2022-01-12 22:59:52 -05:00
assert(KernAux_Multiboot2_Info_is_valid(
&multiboot2_with_two_boot_cmd_lines.multiboot2_info
));
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_boot_cmd_line(
&multiboot2_without_boot_cmd_line.multiboot2_info
) == 0
);
2022-01-12 22:59:52 -05:00
// KernAux_Multiboot2_Info_first_tag_with_type
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
(struct KernAux_Multiboot2_Info*)multiboot2_info_example1,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_EFI_32BIT_SYSTEM_TABLE_PTR
) == 0
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
(struct KernAux_Multiboot2_Info*)multiboot2_info_example1,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_EFI_64BIT_SYSTEM_TABLE_PTR
) == 0
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
(struct KernAux_Multiboot2_Info*)multiboot2_info_example1,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_SMBIOS_TABLES
) == 0
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
(struct KernAux_Multiboot2_Info*)multiboot2_info_example1,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_ACPI_NEW_RSDP
) == 0
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
(struct KernAux_Multiboot2_Info*)multiboot2_info_example1,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_NETWORKING_INFO
) == 0
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
(struct KernAux_Multiboot2_Info*)multiboot2_info_example1,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_EFI_MEMORY_MAP
) == 0
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
(struct KernAux_Multiboot2_Info*)multiboot2_info_example1,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_EFI_BOOT_SERVICES_NOT_TERMINATED
) == 0
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
(struct KernAux_Multiboot2_Info*)multiboot2_info_example1,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_EFI_32BIT_IMAGE_HANDLE_PTR
) == 0
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
(struct KernAux_Multiboot2_Info*)multiboot2_info_example1,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_EFI_64BIT_IMAGE_HANDLE_PTR
) == 0
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_NONE
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_none.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_BOOT_CMD_LINE
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_boot_cmd_line.tag.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_BOOT_LOADER_NAME
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_boot_loader_name.tag.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_MODULE
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_module1.tag.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_BASIC_MEMORY_INFO
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_basic_memory_info.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_FRAMEBUFFER_INFO
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_framebuffer_info.tag.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_ELF_SYMBOLS
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_elf_symbols.tag.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_APM_TABLE
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_apm_table.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_EFI_32BIT_SYSTEM_TABLE_PTR
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_efi_32bit_system_table_ptr.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_EFI_64BIT_SYSTEM_TABLE_PTR
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_efi_64bit_system_table_ptr.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_SMBIOS_TABLES
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_smbios_tables.tag.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_ACPI_OLD_RSDP
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_acpi_old_rsdp.tag.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_ACPI_NEW_RSDP
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_acpi_new_rsdp.tag.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_NETWORKING_INFO
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_networking_info.tag.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_EFI_MEMORY_MAP
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_efi_memory_map.tag.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_EFI_BOOT_SERVICES_NOT_TERMINATED
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_efi_boot_services_not_terminated.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_EFI_32BIT_IMAGE_HANDLE_PTR
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_efi_32bit_image_handle_ptr.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_EFI_64BIT_IMAGE_HANDLE_PTR
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_efi_64bit_image_handle_ptr.base
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_IMAGE_LOAD_BASE_PHYS_ADDR
2022-01-12 23:05:34 -05:00
) == &multiboot2_info_example2.tag_image_load_base_phys_addr.base
);
2022-01-12 22:59:52 -05:00
// KernAux_Multiboot2_Info_tag_with_type_after
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_tag_with_type_after(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_MODULE,
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_MODULE
) - 1
2022-01-12 22:03:15 -05:00
) == (struct KernAux_Multiboot2_ITagBase*)
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.tag_module1
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_tag_with_type_after(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_MODULE,
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_MODULE
)
2022-01-12 22:03:15 -05:00
) == (struct KernAux_Multiboot2_ITagBase*)
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.tag_module2
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_tag_with_type_after(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_MODULE,
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_tag_with_type_after(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_MODULE,
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_first_tag_with_type(
2022-01-12 23:05:34 -05:00
&multiboot2_info_example2.multiboot2_info,
2022-01-12 21:49:25 -05:00
KERNAUX_MULTIBOOT2_ITAG_MODULE
)
)
) == 0
);
2022-01-12 22:59:52 -05:00
// KernAux_Multiboot2_Info_boot_cmd_line
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_boot_cmd_line(
&multiboot2_with_some_boot_cmd_line.multiboot2_info
) == multiboot2_with_some_boot_cmd_line.tag_boot_cmd_line.cmdline
);
assert(
2022-01-12 22:59:52 -05:00
KernAux_Multiboot2_Info_boot_cmd_line(
&multiboot2_with_two_boot_cmd_lines.multiboot2_info
) == multiboot2_with_two_boot_cmd_lines.tag_boot_cmd_line1.cmdline
);
return 0;
}