summaryrefslogtreecommitdiff
path: root/kythe/release/release_test.sh
blob: 40a07222aee89e3ddaf472d816482803f952944c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
set -eo pipefail

# Copyright 2015 The Kythe Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Test the Kythe release package for basic functionality.

export TMPDIR=${TEST_TMPDIR:?}
SHASUM_TOOL="$PWD/$1"
shift

JAVA_LANGTOOLS="$PWD/$(ls third_party/javac/javac*.jar)"

TEST_PORT=9898
ADDR=localhost:$TEST_PORT
TEST_REPOSRCDIR="$PWD"

jq() { "$TEST_REPOSRCDIR/external/com_github_stedolan_jq/jq" "$@"; }

if ! command -v curl >/dev/null; then
  echo "Test requires curl command" >&2
  exit 1
fi

cd kythe/release

EXPECTED_SUM=$(cat kythe-*.tar.gz.sha256)
SUM=$("$SHASUM_TOOL" kythe-*.tar.gz)
if [[ "$SUM" != "$EXPECTED_SUM" ]]; then
  echo "Expected digest \"$EXPECTED_SUM\" but got \"$SUM\"."
  exit 1
fi

rm -rf "$TMPDIR/release"
mkdir "$TMPDIR/release"
tar xzf kythe-*.tar.gz -C "$TMPDIR/release"
cd "$TMPDIR/release"

cd kythe-*

# Ensure the various tools work on test inputs
tools/kzip view "$TEST_REPOSRCDIR/kythe/testdata/test.kzip" | \
  jq . >/dev/null
tools/entrystream < "$TEST_REPOSRCDIR/kythe/testdata/test.entries" | \
  tools/entrystream --write_format=json | \
  tools/entrystream --read_format=json --entrysets >/dev/null
tools/triples < "$TEST_REPOSRCDIR/kythe/testdata/test.entries" >/dev/null

# TODO(zarko): add cxx extractor tests

rm -rf "$TMPDIR/java_compilation"
export KYTHE_OUTPUT_FILE="$TMPDIR/java_compilation/util.kzip"
if (java -version |& head -1 | grep 1.8 >/dev/null);
then
  export KYTHE_JAVA_RUNTIME_OPTIONS="-Xbootclasspath/p:$JAVA_LANGTOOLS"
else
  export KYTHE_JAVA_RUNTIME_OPTIONS="-Xbootclasspath/a:$JAVA_LANGTOOLS"
fi
JAVAC_EXTRACTOR_JAR=$PWD/extractors/javac_extractor.jar \
  KYTHE_ROOT_DIRECTORY="$TEST_REPOSRCDIR" \
  KYTHE_EXTRACT_ONLY=1 \
  extractors/javac-wrapper.sh \
  "$TEST_REPOSRCDIR/kythe/java/com/google/devtools/kythe/util"/*.java
test -r "$KYTHE_OUTPUT_FILE"
java "${KYTHE_JAVA_RUNTIME_OPTIONS[@]}" \
  -jar indexers/java_indexer.jar "$KYTHE_OUTPUT_FILE" | \
  tools/entrystream --count

# Ensure the Java indexer works on a curated test compilation
java "${KYTHE_JAVA_RUNTIME_OPTIONS[@]}"  \
  -jar indexers/java_indexer.jar "$TEST_REPOSRCDIR/kythe/testdata/test.kzip" > entries
# TODO(zarko): add C++ test kindex entries

# Ensure basic Kythe pipeline toolset works
tools/dedup_stream < entries | \
  tools/write_entries --graphstore gs
tools/write_tables --graphstore gs --out srv

tools/read_entries --graphstore gs | \
  tools/entrystream --sort >/dev/null

# Smoke test the verifier
echo "//- _ childof _" > any_childof_any2
tools/verifier --nofile_vnames --ignore_dups --show_goals any_childof_any2 \
    < entries
echo "//- _ noSuchEdge _" > any_nosuchedge_any2
if tools/verifier --nofile_vnames --ignore_dups any_nosuchedge_any2 < entries;\
    then
  echo "ERROR: verifier found a non-existent edge" >&2
  exit 1
fi

# Ensure kythe tool is functional
tools/kythe --api srv nodes 'kythe:?lang=java#pkg.Names'
tools/http_server \
  --serving_table srv \
  --listen $ADDR &
pid=$!
trap "kill $pid; kill -9 $pid" EXIT ERR INT

while ! curl -s $ADDR >/dev/null; do
  echo "Waiting for http_server..."
  sleep 0.5
done

# Ensure basic HTTP handlers work
curl -sf $ADDR/corpusRoots | jq . >/dev/null
curl -sf $ADDR/dir | jq . >/dev/null
curl -sf $ADDR/decorations -d '{"location": {"ticket": "kythe://kythe?path=kythe/javatests/com/google/devtools/kythe/analyzers/java/testdata/pkg/Names.java"}, "source_text": true, "references": true}' | \
  jq -e '(.reference | length) > 0
     and (.nodes | length) == 0
     and (.source_text | type) == "string"
     and (.source_text | length) > 0'
curl -sf $ADDR/decorations -d '{"location": {"ticket": "kythe://kythe?path=kythe/javatests/com/google/devtools/kythe/analyzers/java/testdata/pkg/Names.java"}, "references": true, "filter": ["**"]}' | \
  jq -e '(.reference | length) > 0
     and (.nodes | length) > 0
     and (.source_text | length) == 0'