Commit eb0e516f authored by Kirill Smelkov's avatar Kirill Smelkov

X check hash result and error if mismatch (zhash.* part); neotest part pending

parent 2928fd63
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
set -o pipefail set -o pipefail
# FIXME warn if/when thermal throttling activates - XXX how?
# ---- deploy NEO for tests/benchmarks at a node ---- # ---- deploy NEO for tests/benchmarks at a node ----
die() { die() {
...@@ -787,9 +789,9 @@ bench() { ...@@ -787,9 +789,9 @@ bench() {
url=$2 url=$2
# nrun time demo-zbigarray read $url # nrun time demo-zbigarray read $url
nrun ./zhash.py --bench=$topic/%s --$hashfunc $url nrun ./zhash.py --check=XXX --bench=$topic/%s --$hashfunc $url
echo -e "\n# ${Npar} clients in parallel" echo -e "\n# ${Npar} clients in parallel"
nrunpar ./zhash.py --bench=$topic/%s-P$Npar --$hashfunc $url nrunpar ./zhash.py --check=XXX --bench=$topic/%s-P$Npar --$hashfunc $url
if [[ $url == zeo://* ]]; then if [[ $url == zeo://* ]]; then
echo "(skipping zhash.go on ZEO -- Cgo does not support zeo:// protocol)" echo "(skipping zhash.go on ZEO -- Cgo does not support zeo:// protocol)"
...@@ -803,11 +805,11 @@ bench() { ...@@ -803,11 +805,11 @@ bench() {
bench_go() { bench_go() {
topic=$1 topic=$1
url=$2 url=$2
nrun ./zhash_go --bench=$topic/%s --log_dir=$log -$hashfunc $url nrun ./zhash_go -check=XXX --bench=$topic/%s --log_dir=$log -$hashfunc $url
nrun ./zhash_go --bench=$topic/%s --log_dir=$log -$hashfunc -useprefetch $url nrun ./zhash_go -check=XXX --bench=$topic/%s --log_dir=$log -$hashfunc -useprefetch $url
echo -e "\n# ${Npar} clients in parallel" echo -e "\n# ${Npar} clients in parallel"
nrunpar ./zhash_go --bench=$topic/%s-P$Npar --log_dir=$log -$hashfunc $url nrunpar ./zhash_go -check=XXX --bench=$topic/%s-P$Npar --log_dir=$log -$hashfunc $url
} }
......
...@@ -69,6 +69,7 @@ func main() { ...@@ -69,6 +69,7 @@ func main() {
fsha1 := flag.Bool("sha1", false, "compute SHA1 cryptographic hash") fsha1 := flag.Bool("sha1", false, "compute SHA1 cryptographic hash")
fsha256 := flag.Bool("sha256", false, "compute SHA256 cryptographic hash") fsha256 := flag.Bool("sha256", false, "compute SHA256 cryptographic hash")
fsha512 := flag.Bool("sha512", false, "compute SHA512 cryptographic hash") fsha512 := flag.Bool("sha512", false, "compute SHA512 cryptographic hash")
fcheck := flag.String("check", "", "verify resulting hash to be = expected")
fbench := flag.String("bench", "", "use benchmarking format for output") fbench := flag.String("bench", "", "use benchmarking format for output")
useprefetch := flag.Bool("useprefetch", false, "prefetch loaded objects") useprefetch := flag.Bool("useprefetch", false, "prefetch loaded objects")
flag.Parse() flag.Parse()
...@@ -105,13 +106,13 @@ func main() { ...@@ -105,13 +106,13 @@ func main() {
log.Fatal(ctx, "no hash function specified") log.Fatal(ctx, "no hash function specified")
} }
err := zhash(ctx, url, h, *useprefetch, *fbench) err := zhash(ctx, url, h, *useprefetch, *fbench, *fcheck)
if err != nil { if err != nil {
log.Fatal(ctx, err) log.Fatal(ctx, err)
} }
} }
func zhash(ctx context.Context, url string, h hasher, useprefetch bool, bench string) (err error) { func zhash(ctx context.Context, url string, h hasher, useprefetch bool, bench, check string) (err error) {
defer task.Running(&ctx, "zhash")(&err) defer task.Running(&ctx, "zhash")(&err)
stor, err := zodb.OpenStorageURL(ctx, url) stor, err := zodb.OpenStorageURL(ctx, url)
...@@ -221,14 +222,19 @@ loop: ...@@ -221,14 +222,19 @@ loop:
if useprefetch { if useprefetch {
x += fmt.Sprintf("+prefetch%d", nprefetch) x += fmt.Sprintf("+prefetch%d", nprefetch)
} }
hresult := fmt.Sprintf("%s:%x", h.name, h.Sum(nil))
if bench == "" { if bench == "" {
fmt.Printf("%s:%x ; oid=0..%d nread=%d t=%s (%s / object) x=%s\n", fmt.Printf("%s ; oid=0..%d nread=%d t=%s (%s / object) x=%s\n",
h.name, h.Sum(nil), oid-1, nread, δt, δt / time.Duration(oid), x) // XXX /oid cast ? hresult, oid-1, nread, δt, δt / time.Duration(oid), x) // XXX /oid cast ?
} else { } else {
topic := fmt.Sprintf(bench, x) // XXX -> better text/template topic := fmt.Sprintf(bench, x) // XXX -> better text/template
fmt.Printf("Benchmark%s 1 %.1f µs/object\t# %s:%x oid=0..%d nread=%d t=%s\n", fmt.Printf("Benchmark%s 1 %.1f µs/object\t# %s oid=0..%d nread=%d t=%s\n",
topic, float64(δt) / float64(oid) / float64(time.Microsecond), topic, float64(δt) / float64(oid) / float64(time.Microsecond),
h.name, h.Sum(nil), oid-1, nread, δt) hresult, oid-1, nread, δt)
}
if check != "" && hresult != check {
return fmt.Errof("%s: hash mismatch: expected %s ; got %s\t# x=%s", url, check, hresult, x)
} }
return nil return nil
......
...@@ -84,25 +84,28 @@ def usage(w): ...@@ -84,25 +84,28 @@ def usage(w):
options: options:
--null don't compute hash - just read data --null don't compute hash - just read data
--adler32 compute Adler32 checksum --adler32 compute Adler32 checksum
--crc32 compute CRC32 checksum --crc32 compute CRC32 checksum
--sha1 compute SHA1 cryptographic hash --sha1 compute SHA1 cryptographic hash
--sha256 compute SHA256 cryptographic hash --sha256 compute SHA256 cryptographic hash
--sha512 compute SHA512 cryptographic hash --sha512 compute SHA512 cryptographic hash
--bench=<topic> use benchmarking format for output --check=<expected> verify resulting hash to be = expected
--bench=<topic> use benchmarking format for output
""", file=w) """, file=w)
def main(): def main():
try: try:
optv, argv = getopt(sys.argv[1:], "h", ["help", "bench="] + hashRegistry.keys()) optv, argv = getopt(sys.argv[1:], "h", ["help", "check=", "bench="] + hashRegistry.keys())
except GetoptError as e: except GetoptError as e:
print("E: %s" % e, file=sys.stderr) print("E: %s" % e, file=sys.stderr)
usage(sys.stderr) usage(sys.stderr)
exit(1) exit(1)
bench=None bench=None
check=None
for opt, arg in optv: for opt, arg in optv:
if opt in ("-h", "--help"): if opt in ("-h", "--help"):
print(__doc__) print(__doc__)
...@@ -113,6 +116,10 @@ def main(): ...@@ -113,6 +116,10 @@ def main():
bench=arg bench=arg
continue continue
if opt in ("--check"):
check=arg
continue
opt = opt.lstrip("-") opt = opt.lstrip("-")
hctor = hashRegistry[opt] hctor = hashRegistry[opt]
h = hctor() h = hctor()
...@@ -150,13 +157,18 @@ def main(): ...@@ -150,13 +157,18 @@ def main():
dt = tend - tstart dt = tend - tstart
x = "zhash.py" x = "zhash.py"
hresult = "%s:%s" % (h.name, h.hexdigest())
if bench is None: if bench is None:
print('%s:%s ; oid=0..%d nread=%d t=%.3fs (%.1fμs / object) x=%s' % \ print('%s ; oid=0..%d nread=%d t=%.3fs (%.1fμs / object) x=%s' % \
(h.name, h.hexdigest(), oid-1, nread, dt, dt * 1E6 / oid, x)) (hresult, oid-1, nread, dt, dt * 1E6 / oid, x))
else: else:
topic = bench % x topic = bench % x
print('Benchmark%s 1 %.1f µs/object\t# %s:%s oid=0..%d nread=%d t=%.3fs' % \ print('Benchmark%s 1 %.1f µs/object\t# %s:%s oid=0..%d nread=%d t=%.3fs' % \
(topic, dt * 1E6 / oid, h.name, h.hexdigest(), oid-1, nread, dt)) (topic, dt * 1E6 / oid, hresult, oid-1, nread, dt))
if check != None and hresult != check:
print("%s: hash mismatch: expected %s ; got %s\t# x=%s" % (url, check, hresult, x), file=sys.stderr)
sys.exit(1)
if __name__ == '__main__': if __name__ == '__main__':
main() main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment