• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15# ==============================================================================
16#
17# Bash unit tests for TensorFlow Debugger (tfdbg) Python examples that do not
18# involve downloading data. Also tests the binary offline_analyzer.
19#
20# Command-line flags:
21#   --virtualenv: (optional) If set, will test the examples and binaries
22#     against pip install of TensorFlow in a virtualenv.
23
24set -e
25
26# Filter out LOG(INFO)
27export TF_CPP_MIN_LOG_LEVEL=1
28
29IS_VIRTUALENV=0
30PYTHON_BIN_PATH=""
31while true; do
32  if [[ -z "$1" ]]; then
33    break
34  elif [[ "$1" == "--virtualenv" ]]; then
35    IS_VIRTUALENV=1
36    PYTHON_BIN_PATH=$(which python)
37    echo
38    echo "IS_VIRTUALENV = ${IS_VIRTUALENV}"
39    echo "PYTHON_BIN_PATH = ${PYTHON_BIN_PATH}"
40    echo "Will test tfdbg examples and binaries against virtualenv pip install."
41    echo
42  fi
43  shift 1
44done
45
46if [[ -z "${PYTHON_BIN_PATH}" ]]; then
47  DEBUG_FIBONACCI_BIN="$TEST_SRCDIR/org_tensorflow/tensorflow/python/debug/examples/v2/debug_fibonacci_v2"
48  DEBUG_MNIST_BIN="$TEST_SRCDIR/org_tensorflow/tensorflow/python/debug/examples/v2/debug_mnist_v2"
49else
50  DEBUG_FIBONACCI_BIN="${PYTHON_BIN_PATH} -m tensorflow.python.debug.examples.v2.debug_fibonacci"
51  DEBUG_MNIST_BIN="${PYTHON_BIN_PATH} -m tensorflow.python.debug.examples.v2.debug_mnist"
52fi
53
54# Verify fibonacci runs normally without additional flags
55${DEBUG_FIBONACCI_BIN} --tensor_size=2
56
57# Verify mnist runs normally without additional flags
58${DEBUG_MNIST_BIN} --max_steps=4 --fake_data
59
60# Verify mnist does not break with check_numerics enabled on first iteration
61# check_numerics should not cause non-zero exit code on a single train step
62${DEBUG_MNIST_BIN} --max_steps=1 --fake_data --check_numerics
63
64# Verify check_numerics exits with non-zero exit code
65! ${DEBUG_MNIST_BIN} --max_steps=4 --fake_data --check_numerics
66
67# Verify that dumping works properly.
68TMP_DIR="$(mktemp -d)"
69${DEBUG_MNIST_BIN} --max_steps=4 --fake_data --dump_dir="${TMP_DIR}"
70
71# Check that the .execution and .graph_execution_traces are not empty,
72# i.e., the content of the circular buffer have been written to the disk.
73EXECUTION_FILE="$(ls ${TMP_DIR}/*.execution)"
74EXECUTION_FILE_SIZE=$(du -b "${EXECUTION_FILE}" | awk '{print $1}')
75echo "Size of ${EXECUTION_FILE}: ${EXECUTION_FILE_SIZE}"
76if [[ "${EXECUTION_FILE_SIZE}" == "0" ]]; then
77  echo "ERROR: ${EXECUTION_FILE} is unexpectedly empty."
78  exit 1
79fi
80
81GRAPH_TRACES_FILE="$(ls ${TMP_DIR}/*.graph_execution_traces)"
82GRAPH_TRACES_FILE_SIZE=$(du -b "${EXECUTION_FILE}" | awk '{print $1}')
83echo "Size of ${GRAPH_TRACES_FILE}: ${GRAPH_TRACES_FILE_SIZE}"
84if [[ "${GRAPH_TRACES_FILE_SIZE}" == "0" ]]; then
85  echo "ERROR: ${GRAPH_TRACES_FILE} is unexpectedly empty."
86  exit 1
87fi
88
89rm -rf "${TMP_DIR}"
90
91echo "SUCCESS: tfdbg examples and binaries test PASSED"
92