kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/release/release_test.sh (about)

     1  #!/bin/bash
     2  set -eo pipefail
     3  
     4  # Copyright 2015 The Kythe Authors. All rights reserved.
     5  #
     6  # Licensed under the Apache License, Version 2.0 (the "License");
     7  # you may not use this file except in compliance with the License.
     8  # You may obtain a copy of the License at
     9  #
    10  #   http://www.apache.org/licenses/LICENSE-2.0
    11  #
    12  # Unless required by applicable law or agreed to in writing, software
    13  # distributed under the License is distributed on an "AS IS" BASIS,
    14  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  # See the License for the specific language governing permissions and
    16  # limitations under the License.
    17  #
    18  # Test the Kythe release package for basic functionality.
    19  
    20  export TMPDIR=${TEST_TMPDIR:?}
    21  SHASUM_TOOL="$PWD/$1"
    22  shift
    23  
    24  TEST_PORT=9898
    25  ADDR=localhost:$TEST_PORT
    26  TEST_REPOSRCDIR="$PWD"
    27  
    28  # The Java extractor and indexer need access to various packages in the jdk.compiler module.
    29  JAVA_EXPORTS=(
    30    --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
    31    --add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
    32    --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
    33    --add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
    34    --add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
    35    --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
    36    --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
    37    --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
    38  )
    39  
    40  export KYTHE_JAVA_RUNTIME_OPTIONS="${JAVA_EXPORTS[*]}"
    41  
    42  jq() { "$TEST_REPOSRCDIR/external/com_github_stedolan_jq/jq" "$@"; }
    43  
    44  if ! command -v curl > /dev/null; then
    45    echo "Test requires curl command" >&2
    46    exit 1
    47  fi
    48  
    49  cd kythe/release
    50  
    51  EXPECTED_SUM=$(cat kythe-*.tar.gz.sha256)
    52  SUM=$("$SHASUM_TOOL" kythe-*.tar.gz)
    53  if [[ "$SUM" != "$EXPECTED_SUM" ]]; then
    54    echo "Expected digest \"$EXPECTED_SUM\" but got \"$SUM\"."
    55    exit 1
    56  fi
    57  
    58  rm -rf "$TMPDIR/release"
    59  mkdir "$TMPDIR/release"
    60  tar xzf kythe-*.tar.gz -C "$TMPDIR/release"
    61  cd "$TMPDIR/release"
    62  
    63  cd kythe-*
    64  
    65  # Ensure the various tools work on test inputs
    66  tools/kzip view "$TEST_REPOSRCDIR/kythe/testdata/test.kzip" |
    67    jq . > /dev/null
    68  tools/entrystream < "$TEST_REPOSRCDIR/kythe/testdata/test.entries" |
    69    tools/entrystream --write_format=json |
    70    tools/entrystream --read_format=json --entrysets > /dev/null
    71  tools/triples < "$TEST_REPOSRCDIR/kythe/testdata/test.entries" > /dev/null
    72  
    73  # TODO(zarko): add cxx extractor tests
    74  
    75  rm -rf "$TMPDIR/java_compilation"
    76  export KYTHE_OUTPUT_FILE="$TMPDIR/java_compilation/util.kzip"
    77  JAVAC_EXTRACTOR_JAR=$PWD/extractors/javac_extractor.jar \
    78    KYTHE_ROOT_DIRECTORY="$TEST_REPOSRCDIR" \
    79    KYTHE_EXTRACT_ONLY=1 \
    80    extractors/javac-wrapper.sh \
    81    "$TEST_REPOSRCDIR/kythe/java/com/google/devtools/kythe/util"/*.java
    82  test -r "$KYTHE_OUTPUT_FILE"
    83  # We do not want to inhibit word splitting here.
    84  # shellcheck disable=SC2086
    85  java $KYTHE_JAVA_RUNTIME_OPTIONS \
    86    -jar indexers/java_indexer.jar "$KYTHE_OUTPUT_FILE" |
    87    tools/entrystream --count
    88  
    89  # Ensure the Java indexer works on a curated test compilation
    90  # We do not want to inhibit word splitting here.
    91  # shellcheck disable=SC2086
    92  java $KYTHE_JAVA_RUNTIME_OPTIONS \
    93    -jar indexers/java_indexer.jar "$TEST_REPOSRCDIR/kythe/testdata/test.kzip" > entries
    94  # TODO(zarko): add C++ test kzip entries
    95  
    96  # Ensure basic Kythe pipeline toolset works
    97  tools/dedup_stream < entries |
    98    tools/write_entries --graphstore gs
    99  tools/write_tables --graphstore gs --out srv
   100  
   101  tools/read_entries --graphstore gs |
   102    tools/entrystream --sort > /dev/null
   103  
   104  # Smoke test the verifier
   105  echo "//- _ childof _" > any_childof_any2
   106  tools/verifier --nofile_vnames --ignore_dups --show_goals any_childof_any2 \
   107    < entries
   108  echo "//- _ noSuchEdge _" > any_nosuchedge_any2
   109  if tools/verifier --nofile_vnames --ignore_dups any_nosuchedge_any2 < entries; then
   110    echo "ERROR: verifier found a non-existent edge" >&2
   111    exit 1
   112  fi
   113  
   114  # Ensure kythe tool is functional
   115  tools/kythe --api srv nodes 'kythe:?lang=java#pkg.Names'
   116  tools/http_server \
   117    --serving_table srv \
   118    --listen $ADDR &
   119  pid=$!
   120  trap "kill $pid; kill -9 $pid" EXIT ERR INT
   121  
   122  while ! curl -s $ADDR > /dev/null; do
   123    echo "Waiting for http_server..."
   124    sleep 0.5
   125  done
   126  
   127  # Ensure basic HTTP handlers work
   128  curl -sf $ADDR/corpusRoots | jq . > /dev/null
   129  curl -sf $ADDR/dir | jq . > /dev/null
   130  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}' |
   131    jq -e '(.reference | length) > 0
   132       and (.nodes | length) == 0
   133       and (.source_text | type) == "string"
   134       and (.source_text | length) > 0'
   135  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": ["**"]}' |
   136    jq -e '(.reference | length) > 0
   137       and (.nodes | length) > 0
   138       and (.source_text | length) == 0'