#include "t.h" #include "nm.h" static char *parse(uint8_t *b, size_t n) { tobi_rd r; tobi_rd_init(&r, b, n, 0); char *s = NULL; if (!tobi_nm_namestring(&r, &s)) { return NULL; } return s; } int t_nm(void) { uint8_t simple[] = {'A','B','C','0'}; uint8_t root[] = {'\\','_','S','B','_'}; uint8_t parent[] = {'^','^','P','C','I','0'}; uint8_t dual[] = {0x2e,'A','A','A','0','B','B','B','0'}; uint8_t multi[] = {0x2f,3,'A','A','A','0','B','B','B','0','C','C','C','0'}; char *s = parse(simple, sizeof(simple)); T_CHECK(s && strcmp(s, "ABC0") == 0); free(s); s = parse(root, sizeof(root)); T_CHECK(s && strcmp(s, "\\_SB_") == 0); free(s); s = parse(parent, sizeof(parent)); T_CHECK(s && strcmp(s, "^^PCI0") == 0); free(s); s = parse(dual, sizeof(dual)); T_CHECK(s && strcmp(s, "AAA0.BBB0") == 0); free(s); s = parse(multi, sizeof(multi)); T_CHECK(s && strcmp(s, "AAA0.BBB0.CCC0") == 0); free(s); uint8_t bad[] = {'1','B','C','D'}; T_CHECK(parse(bad, sizeof(bad)) == NULL); uint8_t trunc[] = {0x2f,2,'A','A','A','0','B'}; T_CHECK(parse(trunc, sizeof(trunc)) == NULL); s = tobi_nm_resolve("\\_SB_.PCI0", "^DEV0"); T_CHECK(strcmp(s, "\\_SB_.DEV0") == 0); free(s); tobi_ns ns; tobi_ns_init(&ns); int dup = 0; tobi_ns_ent *e = tobi_ns_add(&ns, TOBI_NS_METHOD, "\\CALX", "\\", 4, 1, 0x08, 1, NULL, &dup); T_CHECK(e != NULL && dup == 0); T_CHECK(e->external && e->args == 1); T_CHECK(tobi_ns_find_method(&ns, "CALX") == e); e = tobi_ns_add(&ns, TOBI_NS_METHOD, "\\CALX", "\\", 20, 2, 0x02, 0, NULL, &dup); T_CHECK(e != NULL && dup == 0); T_CHECK(!e->external && e->off == 20 && e->args == 2); (void)tobi_ns_add(&ns, TOBI_NS_METHOD, "\\CALX", "\\", 40, 2, 0x02, 0, NULL, &dup); T_CHECK(dup == 1); e = tobi_ns_add(&ns, TOBI_NS_ALIAS, "\\ALX0", "\\", 44, 0, 0, 0, "\\CALX", &dup); T_CHECK(e != NULL && dup == 0 && e->target != NULL); T_CHECK(strcmp(e->target, "\\CALX") == 0); (void)tobi_ns_add(&ns, TOBI_NS_METHOD, "\\_SB_.MTH0", "\\_SB_", 52, 3, 0, 0, NULL, &dup); (void)tobi_ns_add(&ns, TOBI_NS_METHOD, "\\MTH0", "\\", 56, 1, 0, 0, NULL, &dup); const tobi_ns_ent *found = tobi_ns_lookup(&ns, "\\_SB_.PCI0.DEV0", "MTH0"); T_CHECK(found != NULL && strcmp(found->path, "\\_SB_.MTH0") == 0 && found->args == 3); (void)tobi_ns_add(&ns, TOBI_NS_ALIAS, "\\_SB_.PCI0.DEV0.AMTH", "\\_SB_.PCI0.DEV0", 60, 0, 0, 0, "\\_SB_.MTH0", &dup); found = tobi_ns_lookup(&ns, "\\_SB_.PCI0.DEV0", "AMTH"); T_CHECK(found != NULL && strcmp(found->path, "\\_SB_.MTH0") == 0); char *rp = tobi_ns_resolve_path(&ns, "\\_SB_.PCI0.DEV0", "^MTH0"); T_CHECK(strcmp(rp, "\\_SB_.PCI0.MTH0") == 0); free(rp); tobi_ns_free(&ns); return 0; }