static void compare_mem_rsv(void *fdt1, void *fdt2) { int i; uint64_t addr1, size1, addr2, size2; int err; if (fdt_num_mem_rsv(fdt1) != fdt_num_mem_rsv(fdt2)) MISMATCH("Trees have different number of reserve entries"); qsort((char *)fdt1 + fdt_off_mem_rsvmap(fdt1), fdt_num_mem_rsv(fdt1), sizeof(struct fdt_reserve_entry), mem_rsv_cmp); qsort((char *)fdt2 + fdt_off_mem_rsvmap(fdt2), fdt_num_mem_rsv(fdt2), sizeof(struct fdt_reserve_entry), mem_rsv_cmp); for (i = 0; i < fdt_num_mem_rsv(fdt1); i++) { CHECK(fdt_get_mem_rsv(fdt1, i, &addr1, &size1)); CHECK(fdt_get_mem_rsv(fdt2, i, &addr2, &size2)); if ((addr1 != addr2) || (size1 != size2)) MISMATCH("Mismatch in reserve entry %d: " "(0x%llx, 0x%llx) != (0x%llx, 0x%llx)", i, (unsigned long long)addr1, (unsigned long long)size1, (unsigned long long)addr2, (unsigned long long)size2); } }
int main(int argc, char *argv[]) { void *fdt1, *fdt2; uint32_t cpuid1, cpuid2; test_init(argc, argv); if ((argc != 3) && ((argc != 4) || !streq(argv[1], "-n"))) CONFIG("Usage: %s [-n] <dtb file> <dtb file>", argv[0]); if (argc == 4) notequal = 1; fdt1 = load_blob(argv[argc-2]); fdt2 = load_blob(argv[argc-1]); compare_mem_rsv(fdt1, fdt2); compare_structure(fdt1, fdt2); cpuid1 = fdt_boot_cpuid_phys(fdt1); cpuid2 = fdt_boot_cpuid_phys(fdt2); if (cpuid1 != cpuid2) MISMATCH("boot_cpuid_phys mismatch 0x%x != 0x%x", cpuid1, cpuid2); MATCH(); }
static void compare_properties(const void *fdt1, int offset1, const void *fdt2, int offset2) { int offset = offset1; /* Check the properties */ for (offset = fdt_first_property_offset(fdt1, offset1); offset >= 0; offset = fdt_next_property_offset(fdt1, offset)) { const char *name; int len1, len2; const void *data1, *data2; int i; data1 = fdt_getprop_by_offset(fdt1, offset, &name, &len1); if (!data1) FAIL("fdt_getprop_by_offset(): %s\n", fdt_strerror(len1)); verbose_printf("Property '%s'\n", name); data2 = fdt_getprop(fdt2, offset2, name, &len2); if (!data2) { if (len2 == -FDT_ERR_NOTFOUND) MISMATCH("Property '%s' missing\n", name); else FAIL("fdt_get_property(): %s\n", fdt_strerror(len2)); } verbose_printf("len1=%d data1=", len1); for (i = 0; i < len1; i++) verbose_printf(" %02x", ((const char *)data1)[i]); verbose_printf("\nlen2=%d data2=", len2); for (i = 0; i < len1; i++) verbose_printf(" %02x", ((const char *)data2)[i]); verbose_printf("\n"); if (len1 != len2) MISMATCH("Property '%s' mismatched length %d vs. %d\n", name, len1, len2); else if (memcmp(data1, data2, len1) != 0) MISMATCH("Property '%s' mismatched value\n", name); } }
static void compare_mem_rsv(const void *fdt1, const void *fdt2) { int i; uint64_t addr1, size1, addr2, size2; int err; if (fdt_num_mem_rsv(fdt1) != fdt_num_mem_rsv(fdt2)) MISMATCH("Trees have different number of reserve entries"); for (i = 0; i < fdt_num_mem_rsv(fdt1); i++) { CHECK(fdt_get_mem_rsv(fdt1, i, &addr1, &size1)); CHECK(fdt_get_mem_rsv(fdt2, i, &addr2, &size2)); if ((addr1 != addr2) || (size1 != size2)) MISMATCH("Mismatch in reserve entry %d: " "(0x%llx, 0x%llx) != (0x%llx, 0x%llx)", i, (unsigned long long)addr1, (unsigned long long)size1, (unsigned long long)addr2, (unsigned long long)size2); } }
/* * CompleteLine - do command completion on the entire command line * (which may have trailing newline). * Return value: * 0: No command matched or failure * 1: One command matched * 2: Several commands matched */ static int CompleteLine(void) { int endflag, tmatch; Char *argptr, *OldCursor, *OldLastChar; OldLastChar = LastChar; OldCursor = Cursor; argptr = InputBuf; endflag = 1; do { while (ismetahash(*argptr) || iscmdmeta(*argptr)) argptr++; for (Cursor = argptr; *Cursor != '\0' && ((Cursor != argptr && Cursor[-1] == '\\') || (!ismetahash(*Cursor) && !iscmdmeta(*Cursor))); Cursor++) continue; if (*Cursor == '\0') { Cursor = LastChar; if (LastChar[-1] == '\n') Cursor--; endflag = 0; } if (!MISMATCH(*argptr) && starting_a_command(argptr, InputBuf)) { tmatch = tenematch(InputBuf, Cursor - InputBuf, RECOGNIZE); if (tmatch <= 0) { return 0; } else if (tmatch > 1) { return 2; } if (LastChar != OldLastChar) { if (argptr < OldCursor) OldCursor += (LastChar - OldLastChar); OldLastChar = LastChar; } } argptr = Cursor; } while (endflag); Cursor = OldCursor; return 1; }
int main(int argc, char *argv[]) { void *fdt1, *fdt2; uint32_t cpuid1, cpuid2; char **args; int argsleft; test_init(argc, argv); args = &argv[1]; argsleft = argc - 1; while (argsleft > 2) { if (streq(args[0], "-n")) notequal = 1; else if (streq(args[0], "-m")) ignore_memrsv = 1; else badargs(argv); args++; argsleft--; } if (argsleft != 2) badargs(argv); fdt1 = load_blob(args[0]); fdt2 = load_blob(args[1]); if (!ignore_memrsv) compare_mem_rsv(fdt1, fdt2); compare_node(fdt1, 0, fdt2, 0); cpuid1 = fdt_boot_cpuid_phys(fdt1); cpuid2 = fdt_boot_cpuid_phys(fdt2); if (cpuid1 != cpuid2) MISMATCH("boot_cpuid_phys mismatch 0x%x != 0x%x", cpuid1, cpuid2); MATCH(); }
static void compare_subnodes(const void *fdt1, int offset1, const void *fdt2, int offset2, int recurse) { int coffset1, coffset2, depth; for (depth = 0, coffset1 = offset1; (coffset1 >= 0) && (depth >= 0); coffset1 = fdt_next_node(fdt1, coffset1, &depth)) if (depth == 1) { const char *name = fdt_get_name(fdt1, coffset1, NULL); verbose_printf("Subnode %s\n", name); coffset2 = fdt_subnode_offset(fdt2, offset2, name); if (coffset2 == -FDT_ERR_NOTFOUND) MISMATCH("Subnode %s missing\n", name); else if (coffset2 < 0) FAIL("fdt_subnode_offset(): %s\n", fdt_strerror(coffset2)); if (recurse) compare_node(fdt1, coffset1, fdt2, coffset2); } }
/* * SpellLine - do spelling correction on the entire command line * (which may have trailing newline). * If cmdonly is set, only check spelling of command words. * Return value: * -1: Something was incorrectible, and nothing was corrected * 0: Everything was correct * 1: Something was corrected */ static int SpellLine(int cmdonly) { int endflag, matchval; Char *argptr, *OldCursor, *OldLastChar; OldLastChar = LastChar; OldCursor = Cursor; argptr = InputBuf; endflag = 1; matchval = 0; do { while (ismetahash(*argptr) || iscmdmeta(*argptr)) argptr++; for (Cursor = argptr; *Cursor != '\0' && ((Cursor != argptr && Cursor[-1] == '\\') || (!ismetahash(*Cursor) && !iscmdmeta(*Cursor))); Cursor++) continue; if (*Cursor == '\0') { Cursor = LastChar; if (LastChar[-1] == '\n') Cursor--; endflag = 0; } if (!MISMATCH(*argptr) && (!cmdonly || starting_a_command(argptr, InputBuf))) { #ifdef WINNT_NATIVE /* * This hack avoids correcting drive letter changes */ if((Cursor - InputBuf) != 2 || (char)InputBuf[1] != ':') #endif /* WINNT_NATIVE */ { #ifdef HASH_SPELL_CHECK Char save; size_t len = Cursor - InputBuf; save = InputBuf[len]; InputBuf[len] = '\0'; if (find_cmd(InputBuf, 0) != 0) { InputBuf[len] = save; argptr = Cursor; continue; } InputBuf[len] = save; #endif /* HASH_SPELL_CHECK */ switch (tenematch(InputBuf, Cursor - InputBuf, SPELL)) { case 1: /* corrected */ matchval = 1; break; case -1: /* couldn't be corrected */ if (!matchval) matchval = -1; break; default: /* was correct */ break; } } if (LastChar != OldLastChar) { if (argptr < OldCursor) OldCursor += (LastChar - OldLastChar); OldLastChar = LastChar; } } argptr = Cursor; } while (endflag); Cursor = OldCursor; return matchval; }
static void compare_structure(const void *fdt1, const void *fdt2) { int nextoffset1 = 0, nextoffset2 = 0; int offset1, offset2; uint32_t tag1, tag2; const char *name1, *name2; int err; const struct fdt_property *prop1, *prop2; int len1, len2; while (1) { do { offset1 = nextoffset1; tag1 = fdt_next_tag(fdt1, offset1, &nextoffset1); } while (tag1 == FDT_NOP); do { offset2 = nextoffset2; tag2 = fdt_next_tag(fdt2, offset2, &nextoffset2); } while (tag2 == FDT_NOP); if (tag1 != tag2) MISMATCH("Tag mismatch (%d != %d) at (%d, %d)", tag1, tag2, offset1, offset2); switch (tag1) { case FDT_BEGIN_NODE: name1 = fdt_get_name(fdt1, offset1, &err); if (!name1) FAIL("fdt_get_name(fdt1, %d, ..): %s", offset1, fdt_strerror(err)); name2 = fdt_get_name(fdt2, offset2, NULL); if (!name2) FAIL("fdt_get_name(fdt2, %d, ..): %s", offset2, fdt_strerror(err)); if (!streq(name1, name2)) MISMATCH("Name mismatch (\"%s\" != \"%s\") at (%d, %d)", name1, name2, offset1, offset2); break; case FDT_PROP: prop1 = fdt_offset_ptr(fdt1, offset1, sizeof(*prop1)); if (!prop1) FAIL("Could get fdt1 property at %d", offset1); prop2 = fdt_offset_ptr(fdt2, offset2, sizeof(*prop2)); if (!prop2) FAIL("Could get fdt2 property at %d", offset2); name1 = fdt_string(fdt1, fdt32_to_cpu(prop1->nameoff)); name2 = fdt_string(fdt2, fdt32_to_cpu(prop2->nameoff)); if (!streq(name1, name2)) MISMATCH("Property name mismatch \"%s\" != \"%s\" " "at (%d, %d)", name1, name2, offset1, offset2); len1 = fdt32_to_cpu(prop1->len); len2 = fdt32_to_cpu(prop2->len); if (len1 != len2) MISMATCH("Property length mismatch %u != %u " "at (%d, %d)", len1, len2, offset1, offset2); if (memcmp(prop1->data, prop2->data, len1) != 0) MISMATCH("Property value mismatch at (%d, %d)", offset1, offset2); break; case FDT_END: return; } } }
bool virCPUDefIsEqual(virCPUDefPtr src, virCPUDefPtr dst, bool reportError) { bool identical = false; size_t i; if (!src && !dst) return true; #define MISMATCH(fmt, ...) \ if (reportError) \ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, fmt, __VA_ARGS__) if ((src && !dst) || (!src && dst)) { MISMATCH("%s", _("Target CPU does not match source")); goto cleanup; } if (src->type != dst->type) { MISMATCH(_("Target CPU type %s does not match source %s"), virCPUTypeToString(dst->type), virCPUTypeToString(src->type)); goto cleanup; } if (src->mode != dst->mode) { MISMATCH(_("Target CPU mode %s does not match source %s"), virCPUModeTypeToString(dst->mode), virCPUModeTypeToString(src->mode)); goto cleanup; } if (src->check != dst->check) { MISMATCH(_("Target CPU check %s does not match source %s"), virCPUCheckTypeToString(dst->check), virCPUCheckTypeToString(src->check)); goto cleanup; } if (src->arch != dst->arch) { MISMATCH(_("Target CPU arch %s does not match source %s"), virArchToString(dst->arch), virArchToString(src->arch)); goto cleanup; } if (STRNEQ_NULLABLE(src->model, dst->model)) { MISMATCH(_("Target CPU model %s does not match source %s"), NULLSTR(dst->model), NULLSTR(src->model)); goto cleanup; } if (STRNEQ_NULLABLE(src->vendor, dst->vendor)) { MISMATCH(_("Target CPU vendor %s does not match source %s"), NULLSTR(dst->vendor), NULLSTR(src->vendor)); goto cleanup; } if (STRNEQ_NULLABLE(src->vendor_id, dst->vendor_id)) { MISMATCH(_("Target CPU vendor id %s does not match source %s"), NULLSTR(dst->vendor_id), NULLSTR(src->vendor_id)); goto cleanup; } if (src->sockets != dst->sockets) { MISMATCH(_("Target CPU sockets %d does not match source %d"), dst->sockets, src->sockets); goto cleanup; } if (src->cores != dst->cores) { MISMATCH(_("Target CPU cores %d does not match source %d"), dst->cores, src->cores); goto cleanup; } if (src->threads != dst->threads) { MISMATCH(_("Target CPU threads %d does not match source %d"), dst->threads, src->threads); goto cleanup; } if (src->nfeatures != dst->nfeatures) { MISMATCH(_("Target CPU feature count %zu does not match source %zu"), dst->nfeatures, src->nfeatures); goto cleanup; } for (i = 0; i < src->nfeatures; i++) { if (STRNEQ(src->features[i].name, dst->features[i].name)) { MISMATCH(_("Target CPU feature %s does not match source %s"), dst->features[i].name, src->features[i].name); goto cleanup; } if (src->features[i].policy != dst->features[i].policy) { MISMATCH(_("Target CPU feature policy %s does not match source %s"), virCPUFeaturePolicyTypeToString(dst->features[i].policy), virCPUFeaturePolicyTypeToString(src->features[i].policy)); goto cleanup; } } if ((src->cache && !dst->cache) || (!src->cache && dst->cache) || (src->cache && dst->cache && (src->cache->level != dst->cache->level || src->cache->mode != dst->cache->mode))) { MISMATCH("%s", _("Target CPU cache does not match source")); goto cleanup; } #undef MISMATCH identical = true; cleanup: return identical; }