2020-11-27 16:48:50 -05:00
|
|
|
#include <kernaux/multiboot2.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
static const struct KernAux_Multiboot2_Tag_None tag_none_valid = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_NONE,
|
|
|
|
.size = 8,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct KernAux_Multiboot2_Tag_None tag_none_invalid_type = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_CMD_LINE,
|
|
|
|
.size = 8,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct KernAux_Multiboot2_Tag_None tag_none_invalid_size = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_NONE,
|
|
|
|
.size = 9,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_BootCmdLine tag;
|
|
|
|
char cmdline[1];
|
|
|
|
} tag_boot_cmd_line_with_empty_cmdline_valid = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_CMD_LINE,
|
|
|
|
.size = 9,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.cmdline = "\0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_BootCmdLine tag;
|
|
|
|
char cmdline[14];
|
|
|
|
} tag_boot_cmd_line_with_some_cmdline_valid = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_CMD_LINE,
|
|
|
|
.size = 22,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.cmdline = "Hello, World!\0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_BootCmdLine tag;
|
|
|
|
char cmdline[1];
|
|
|
|
} tag_boot_cmd_line_invalid_type = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_NONE,
|
|
|
|
.size = 9,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.cmdline = "\0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_BootCmdLine tag;
|
|
|
|
char cmdline[1];
|
|
|
|
} tag_boot_cmd_line_with_empty_cmdline_invalid_size = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_CMD_LINE,
|
|
|
|
.size = 10,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.cmdline = "\0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_BootCmdLine tag;
|
|
|
|
char cmdline[14];
|
|
|
|
} tag_boot_cmd_line_with_some_cmdline_invalid_size = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_CMD_LINE,
|
|
|
|
.size = 23,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.cmdline = "Hello, World!\0",
|
|
|
|
};
|
|
|
|
|
2020-11-27 17:01:49 -05:00
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_BootLoaderName tag;
|
|
|
|
char cmdline[1];
|
|
|
|
} tag_boot_loader_name_with_empty_name_valid = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_LOADER_NAME,
|
|
|
|
.size = 9,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.cmdline = "\0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_BootLoaderName tag;
|
|
|
|
char cmdline[14];
|
|
|
|
} tag_boot_loader_name_with_some_name_valid = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_LOADER_NAME,
|
|
|
|
.size = 22,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.cmdline = "Hello, World!\0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_BootLoaderName tag;
|
|
|
|
char cmdline[1];
|
|
|
|
} tag_boot_loader_name_invalid_type = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_NONE,
|
|
|
|
.size = 9,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.cmdline = "\0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_BootLoaderName tag;
|
|
|
|
char cmdline[1];
|
|
|
|
} tag_boot_loader_name_with_empty_name_invalid_size = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_LOADER_NAME,
|
|
|
|
.size = 10,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.cmdline = "\0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_BootLoaderName tag;
|
|
|
|
char cmdline[14];
|
|
|
|
} tag_boot_loader_name_with_some_name_invalid_size = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_BOOT_LOADER_NAME,
|
|
|
|
.size = 23,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.cmdline = "Hello, World!\0",
|
|
|
|
};
|
|
|
|
|
2020-11-27 17:11:01 -05:00
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_Module tag;
|
|
|
|
char cmdline[1];
|
|
|
|
} tag_module_with_empty_name_valid = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_MODULE,
|
|
|
|
.size = 17,
|
|
|
|
},
|
|
|
|
.mod_start = 123,
|
|
|
|
.mod_end = 456,
|
|
|
|
},
|
|
|
|
.cmdline = "\0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_Module tag;
|
|
|
|
char cmdline[14];
|
|
|
|
} tag_module_with_some_name_valid = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_MODULE,
|
|
|
|
.size = 30,
|
|
|
|
},
|
|
|
|
.mod_start = 123,
|
|
|
|
.mod_end = 456,
|
|
|
|
},
|
|
|
|
.cmdline = "Hello, World!\0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_Module tag;
|
|
|
|
char cmdline[1];
|
|
|
|
} tag_module_invalid_type = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_NONE,
|
|
|
|
.size = 17,
|
|
|
|
},
|
|
|
|
.mod_start = 123,
|
|
|
|
.mod_end = 456,
|
|
|
|
},
|
|
|
|
.cmdline = "\0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_Module tag;
|
|
|
|
char cmdline[1];
|
|
|
|
} tag_module_with_empty_name_invalid_size = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_MODULE,
|
|
|
|
.size = 18,
|
|
|
|
},
|
|
|
|
.mod_start = 123,
|
|
|
|
.mod_end = 456,
|
|
|
|
},
|
|
|
|
.cmdline = "\0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_Module tag;
|
|
|
|
char cmdline[14];
|
|
|
|
} tag_module_with_some_name_invalid_size = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_MODULE,
|
|
|
|
.size = 31,
|
|
|
|
},
|
|
|
|
.mod_start = 123,
|
|
|
|
.mod_end = 456,
|
|
|
|
},
|
|
|
|
.cmdline = "Hello, World!\0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_Module tag;
|
|
|
|
char cmdline[14];
|
|
|
|
} tag_module_with_equal_start_end_invalid = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_MODULE,
|
|
|
|
.size = 31,
|
|
|
|
},
|
|
|
|
.mod_start = 123,
|
|
|
|
.mod_end = 123,
|
|
|
|
},
|
|
|
|
.cmdline = "Hello, World!\0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
struct KernAux_Multiboot2_Tag_Module tag;
|
|
|
|
char cmdline[14];
|
|
|
|
} tag_module_with_reversed_start_end_invalid = {
|
|
|
|
.tag = {
|
|
|
|
.base = {
|
|
|
|
.type = KERNAUX_MULTIBOOT2_TAGTYPE_MODULE,
|
|
|
|
.size = 31,
|
|
|
|
},
|
|
|
|
.mod_start = 456,
|
|
|
|
.mod_end = 123,
|
|
|
|
},
|
|
|
|
.cmdline = "Hello, World!\0",
|
|
|
|
};
|
|
|
|
|
2020-11-27 16:48:50 -05:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
assert(KernAux_Multiboot2_Tag_None_is_valid(&tag_none_valid));
|
|
|
|
assert(!KernAux_Multiboot2_Tag_None_is_valid(&tag_none_invalid_type));
|
|
|
|
assert(!KernAux_Multiboot2_Tag_None_is_valid(&tag_none_invalid_size));
|
|
|
|
|
|
|
|
assert(KernAux_Multiboot2_Tag_BootCmdLine_is_valid(
|
|
|
|
&tag_boot_cmd_line_with_empty_cmdline_valid.tag
|
|
|
|
));
|
|
|
|
|
|
|
|
assert(KernAux_Multiboot2_Tag_BootCmdLine_is_valid(
|
|
|
|
&tag_boot_cmd_line_with_some_cmdline_valid.tag
|
|
|
|
));
|
|
|
|
|
|
|
|
assert(!KernAux_Multiboot2_Tag_BootCmdLine_is_valid(
|
|
|
|
&tag_boot_cmd_line_invalid_type.tag
|
|
|
|
));
|
|
|
|
|
|
|
|
assert(!KernAux_Multiboot2_Tag_BootCmdLine_is_valid(
|
|
|
|
&tag_boot_cmd_line_with_empty_cmdline_invalid_size.tag
|
|
|
|
));
|
|
|
|
|
|
|
|
assert(!KernAux_Multiboot2_Tag_BootCmdLine_is_valid(
|
|
|
|
&tag_boot_cmd_line_with_some_cmdline_invalid_size.tag
|
|
|
|
));
|
|
|
|
|
2020-11-27 17:01:49 -05:00
|
|
|
assert(KernAux_Multiboot2_Tag_BootLoaderName_is_valid(
|
|
|
|
&tag_boot_loader_name_with_empty_name_valid.tag
|
|
|
|
));
|
|
|
|
|
|
|
|
assert(KernAux_Multiboot2_Tag_BootLoaderName_is_valid(
|
|
|
|
&tag_boot_loader_name_with_some_name_valid.tag
|
|
|
|
));
|
|
|
|
|
|
|
|
assert(!KernAux_Multiboot2_Tag_BootLoaderName_is_valid(
|
|
|
|
&tag_boot_loader_name_invalid_type.tag
|
|
|
|
));
|
|
|
|
|
|
|
|
assert(!KernAux_Multiboot2_Tag_BootLoaderName_is_valid(
|
|
|
|
&tag_boot_loader_name_with_empty_name_invalid_size.tag
|
|
|
|
));
|
|
|
|
|
|
|
|
assert(!KernAux_Multiboot2_Tag_BootLoaderName_is_valid(
|
|
|
|
&tag_boot_loader_name_with_some_name_invalid_size.tag
|
|
|
|
));
|
|
|
|
|
2020-11-27 17:11:01 -05:00
|
|
|
assert(KernAux_Multiboot2_Tag_Module_is_valid(
|
|
|
|
&tag_module_with_empty_name_valid.tag
|
|
|
|
));
|
|
|
|
|
|
|
|
assert(KernAux_Multiboot2_Tag_Module_is_valid(
|
|
|
|
&tag_module_with_some_name_valid.tag
|
|
|
|
));
|
|
|
|
|
|
|
|
assert(!KernAux_Multiboot2_Tag_Module_is_valid(
|
|
|
|
&tag_module_invalid_type.tag
|
|
|
|
));
|
|
|
|
|
|
|
|
assert(!KernAux_Multiboot2_Tag_Module_is_valid(
|
|
|
|
&tag_module_with_empty_name_invalid_size.tag
|
|
|
|
));
|
|
|
|
|
|
|
|
assert(!KernAux_Multiboot2_Tag_Module_is_valid(
|
|
|
|
&tag_module_with_some_name_invalid_size.tag
|
|
|
|
));
|
|
|
|
|
|
|
|
assert(!KernAux_Multiboot2_Tag_Module_is_valid(
|
|
|
|
&tag_module_with_equal_start_end_invalid.tag
|
|
|
|
));
|
|
|
|
|
|
|
|
assert(!KernAux_Multiboot2_Tag_Module_is_valid(
|
|
|
|
&tag_module_with_reversed_start_end_invalid.tag
|
|
|
|
));
|
|
|
|
|
2020-11-27 16:48:50 -05:00
|
|
|
return 0;
|
|
|
|
}
|