kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/serving/tools/testdata/write_tables_test.sh (about) 1 #!/bin/bash 2 set -eo pipefail 3 # Copyright 2016 The Kythe Authors. All rights reserved. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 readonly TABLE="$TEST_TMPDIR/serving_table" 18 19 scan() { 20 local out="$TABLE.${1%:}.json" 21 echo -n "$out: " >&2 22 "$scan_leveldb" --prefix $1 --proto_value $2 --json "$TABLE" | \ 23 tee >(wc -l >&2) | \ 24 "$jq" -S . > "$out" 25 } 26 27 entries2tables() { 28 local ENTRIES="$1" 29 local OUT="$2" 30 31 gunzip -c "$ENTRIES" | \ 32 "$entrystream" --unique | \ 33 "$write_tables" --max_page_size 75 --entries - --out "$OUT" 34 } 35 36 echo "Building new serving table" 37 entries2tables kythe/testdata/entries.gz "$TABLE" 38 39 echo "Splitting serving data in JSON" 40 scan edgeSets: kythe.proto.serving.PagedEdgeSet 41 scan edgePages: kythe.proto.serving.EdgePage 42 scan xrefs: kythe.proto.serving.PagedCrossReferences 43 scan xrefPages: kythe.proto.serving.PagedCrossReferences.Page 44 scan decor: kythe.proto.serving.FileDecorations 45 46 check_diff() { 47 local table="serving_table.$1.json" 48 local gold="kythe/testdata/$table" 49 local new="$TEST_TMPDIR/$table" 50 gzip -kdf "$gold.gz" 51 52 echo 53 if ! diff -q "$gold" "$new"; then 54 $jq .key "$gold" > "$TEST_TMPDIR/gold.keys" 55 $jq .key "$new" > "$TEST_TMPDIR/new.keys" 56 57 if ! diff -u "$TEST_TMPDIR/"{gold,new}.keys | diffstat -qm; then 58 echo " Key samples:" 59 echo " Unique to gold:" 60 comm -23 "$TEST_TMPDIR/"{gold,new}.keys | sort -R | head -n3 61 echo " Unique to new:" 62 comm -13 "$TEST_TMPDIR/"{gold,new}.keys | sort -R | head -n3 63 fi 64 65 echo " Key-value samples:" 66 echo " Unique to gold:" 67 comm -23 <($jq -S -c . "$gold") <($jq -S -c . "$new") | \ 68 sort -R | head -n1 | $jq . 69 echo " Unique to new:" 70 comm -13 <($jq -S -c . "$gold") <($jq -S -c . "$new") | \ 71 sort -R | head -n1 | $jq . 72 73 return 1 74 fi 75 } 76 77 fail= 78 79 echo "Testing for differences" 80 check_diff decor || fail=1 81 check_diff xrefs || fail=1 82 check_diff xrefPages || fail=1 83 check_diff edgeSets || fail=1 84 check_diff edgePages || fail=1 85 86 if [[ -n "$fail" ]]; then 87 exit 1 88 fi