static void fill_area(void *p, size_t size, unsigned int cmdno) { unsigned int cpu; for_each_possible_cpu(cpu) { unsigned long v = seed_val(cmdno, cpu); unsigned long *up = per_cpu_ptr(p, cpu); size_t left = size; while (left >= sizeof(unsigned long)) { *up++ = v++; left -= sizeof(unsigned long); } } }
static void verify_area(void *p, size_t size, unsigned int cmdno) { unsigned int warns = 5; unsigned int cpu; for_each_possible_cpu(cpu) { unsigned long v = seed_val(cmdno, cpu); unsigned long *up = per_cpu_ptr(p, cpu); size_t left = size; while (left >= sizeof(unsigned long)) { if (*up != v && warns-- > 0) { printk("MISMATCH: cmdno=%u size=%zu cpu=%u off=%zu p=%p\n", cmdno, size, cpu, size - left, p); printk(" [%p]=%lx should be %lx\n", up, *up, v); } up++; v++; left -= sizeof(unsigned long); } } }
/* Compare the two different implementations using random data. */ static svn_error_t * utf_validate2(apr_pool_t *pool) { int i; seed_val(); /* We want enough iterations so that most runs get both valid and invalid strings. We also want enough iterations such that a deliberate error in one of the implementations will trigger a failure. By experiment the second requirement requires a much larger number of iterations that the first. */ for (i = 0; i < 100000; ++i) { unsigned int j; char str[64]; apr_size_t len; /* A random string; experiment shows that it's occasionally (less than 1%) valid but usually invalid. */ for (j = 0; j < sizeof(str) - 1; ++j) str[j] = (char)range_rand(0, 255); str[sizeof(str) - 1] = 0; len = strlen(str); if (svn_utf__last_valid(str, len) != svn_utf__last_valid2(str, len)) { /* Duplicate calls for easy debugging */ svn_utf__last_valid(str, len); svn_utf__last_valid2(str, len); return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "is_valid2 test %d failed", i); } } return SVN_NO_ERROR; }