Skip to content
Snippets Groups Projects
Commit ad72d70d authored by Austin Anderson's avatar Austin Anderson
Browse files

Fix libtensorflow script and start prelim check

parent 118219df
No related branches found
No related tags found
No related merge requests found
# Suite of verification tests for the SINGLE TensorFlow wheel in /tf/pkg changed_files() {
# or whatever path is set as $TF_WHEEL. git diff --name-only origin/master
# get all changed targets...
bazel query $(git diff --name-only origin/master | sed ':a; N; $!ba; s/\n/ union /g') --keep_going
}
setup_file() { setup_file() {
cd /tf/pkg cd /tf/tensorflow
if [[ -z "$TF_WHEEL" ]]; then bazel version # Start the bazel server
export TF_WHEEL=$(find /tf/pkg -iname "*.whl")
fi
} }
teardown_file() { @test "Validate BUILD files" {
rm -rf /tf/venv changed_files | xargs bazel query | xargs bazel query "attr('srcs', '{}'
bazel build --jobs=auto --nobuild -- //tensorflow/... -//tensorflow/lite/...
bazel query --noimplicit_deps -- 'deps(//tensorflow/...) - kind("android_*", //tensorflow/...)' > /dev/null
} }
@test "Wheel is manylinux2010 (manylinux_2_12) compliant" { @test "Check formatting for C++ files" {
python3 -m auditwheel show "$TF_WHEEL" > audit.txt changed_files | grep -e '\.h$' -e '\.cc$' | xargs -I'{}' -n1 -P $(nproc --all) bash -c 'clang-format {} | diff - {} >/dev/null|| echo {}' | tee needs_help.txt
grep --quiet 'This constrains the platform tag to "manylinux_2_12_x86_64"' audit.txt test ! -s needs_help.txt
} }
@test "Wheel conforms to upstream size limitations" { @test "Check formatting for Python files" {
WHEEL_MEGABYTES=$(stat --format %s "$TF_WHEEL" | awk '{print int($1/(1024*1024))}') skip
# Ref. cs/test_tf_whl_size (internal only) pylint --rcfile=tensorflow/tools/ci_build/pylintrc -j $(nproc --all) $(git ls-files '*.py') --disable=all --enable=E,W0311,W0312,C0330,C0301,C0326,W0611,W0622
case "$TF_WHEEL" in
# CPU:
*cpu*manylinux*) LARGEST_OK_SIZE=200 ;;
*cpu*win*) LARGEST_OK_SIZE=170 ;;
*macos*) LARGEST_OK_SIZE=225 ;;
# GPU:
*manylinux*) LARGEST_OK_SIZE=500 ;;
*win*) LARGEST_OK_SIZE=345 ;;
# Unknown:
*)
echo "The wheel's name is in an unknown format."
exit 1
;;
esac
# >&3 forces output in bats even if the test passes. See
# https://bats-core.readthedocs.io/en/stable/writing-tests.html#printing-to-the-terminal
echo "# Size of $TF_WHEEL is $WHEEL_MEGABYTES / $LARGEST_OK_SIZE megabytes." >&3
test "$WHEEL_MEGABYTES" -le "$LARGEST_OK_SIZE"
} }
# Note: this runs before the tests further down the file, so TF is installed in @test "All tensorflow.org/code links point to real files" {
# the venv and the venv is active when those tests run. The venv gets cleaned for i in `grep -onI 'https://www.tensorflow.org/code/[a-zA-Z0-9/._-]\+' -r tensorflow`; do
# up in teardown_file() above. target=$(echo $i | sed 's!.*https://www.tensorflow.org/code/!!g')
@test "Wheel is installable" {
python3 -m venv /tf/venv
source /tf/venv/bin/activate
python3 -m pip install "$TF_WHEEL"
}
@test "TensorFlow is importable" { if [[ ! -f $target ]] && [[ ! -d $target ]]; then
source /tf/venv/bin/activate echo "$i" >> errors.txt
python3 -c 'import tensorflow as tf; t1=tf.constant([1,2,3,4]); t2=tf.constant([5,6,7,8]); print(tf.add(t1,t2).shape)' fi
} if [[ -e errors.txt ]]; then
echo "Broken links found:"
# Is this still useful? cat errors.txt
@test "TensorFlow has Keras" { rm errors.txt
source /tf/venv/bin/activate false
python3 -c 'import sys; import tensorflow as tf; sys.exit(0 if "_v2.keras" in tf.keras.__name__ else 1)' fi
done
} }
# Is this still useful? teardown_file() {
@test "TensorFlow has Estimator" { bazel shutdown
source /tf/venv/bin/activate
python3 -c 'import sys; import tensorflow as tf; sys.exit(0 if "_v2.estimator" in tf.estimator.__name__ else 1)'
} }
...@@ -25,7 +25,7 @@ function cp_normalized_srcjar() { ...@@ -25,7 +25,7 @@ function cp_normalized_srcjar() {
src_jar="$1" src_jar="$1"
dest_jar="$2" dest_jar="$2"
tmp_dir=$(mktemp -d) tmp_dir=$(mktemp -d)
cp "${SRC}" "${tmp_dir}/orig.jar" cp "${src_jar}" "${tmp_dir}/orig.jar"
pushd "${tmp_dir}" pushd "${tmp_dir}"
# Extract any src/ files # Extract any src/ files
jar -xf "${tmp_dir}/orig.jar" src/ jar -xf "${tmp_dir}/orig.jar" src/
...@@ -45,4 +45,4 @@ cp bazel-bin/tensorflow/tools/lib_package/libtensorflow_jni.tar.gz "${DIR}/libte ...@@ -45,4 +45,4 @@ cp bazel-bin/tensorflow/tools/lib_package/libtensorflow_jni.tar.gz "${DIR}/libte
cp bazel-bin/tensorflow/java/libtensorflow.jar "${DIR}" cp bazel-bin/tensorflow/java/libtensorflow.jar "${DIR}"
cp_normalized_srcjar bazel-bin/tensorflow/java/libtensorflow-src.jar "${DIR}/libtensorflow-src.jar" cp_normalized_srcjar bazel-bin/tensorflow/java/libtensorflow-src.jar "${DIR}/libtensorflow-src.jar"
cp bazel-bin/tensorflow/tools/lib_package/libtensorflow_proto.zip "${DIR}" cp bazel-bin/tensorflow/tools/lib_package/libtensorflow_proto.zip "${DIR}"
chmod -x "${DIR}/*" chmod -R -x "${DIR}"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment