blob: dc5bdd026eb06d7a92d401d6d864cafeaaccb8c9 [file] [log] [blame]
Robin Thellend663bf482014-10-01 10:27:10 -07001#!/bin/bash
2
3# Test the debug binary
4#
5# This test starts a mounttable server and then runs the debug command against
6# it.
7
Jiri Simsa85aea7b2014-10-15 15:48:36 -07008source "${VEYRON_ROOT}/scripts/lib/shell_test.sh"
Robin Thellend663bf482014-10-01 10:27:10 -07009
Jing Jin89312ff2014-10-24 10:42:08 -070010readonly WORKDIR="${shell_test_WORK_DIR}"
Matt Rosencrantzbe1a8b52014-11-21 15:14:06 -080011readonly DEBUG_FLAGS="--veyron.vtrace.sample_rate=1"
Robin Thellend663bf482014-10-01 10:27:10 -070012
13build() {
Jing Jin89312ff2014-10-24 10:42:08 -070014 DEBUG_BIN="$(shell_test::build_go_binary 'veyron.io/veyron/veyron/tools/debug')"
Robin Thellend663bf482014-10-01 10:27:10 -070015}
16
17dumplogs() {
18 for x in $*; do
19 echo "-- $(basename "${x}") --"
20 cat "${x}"
21 done
22}
23
24main() {
Jiri Simsa85aea7b2014-10-15 15:48:36 -070025 local GOT WANT
26
Robin Thellend663bf482014-10-01 10:27:10 -070027 cd "${WORKDIR}"
Jing Jin89312ff2014-10-24 10:42:08 -070028 build
Robin Thellendfaa083a2014-10-22 13:41:18 -070029 mkdir "tmp"
30 export TMPDIR="${WORKDIR}/tmp"
Robin Thellend663bf482014-10-01 10:27:10 -070031
Asim Shankarf30b2df2014-10-11 18:51:45 -070032 export VEYRON_CREDENTIALS=$(shell::tmp_dir)
Cosmos Nicolaouf17b6022014-10-14 10:04:20 -070033 shell_test::setup_server_test || shell_test::fail "setup_server_test failed"
34 local -r EP="${NAMESPACE_ROOT}"
35 unset NAMESPACE_ROOT
Robin Thellend663bf482014-10-01 10:27:10 -070036
Jiri Simsa85aea7b2014-10-15 15:48:36 -070037 # Test top level glob.
Robin Thellend663bf482014-10-01 10:27:10 -070038 local -r DBGLOG="${WORKDIR}/debug.log"
Matt Rosencrantzbe1a8b52014-11-21 15:14:06 -080039 GOT=$("${DEBUG_BIN}" "${DEBUG_FLAGS}" glob "${EP}/__debug/*" 2> "${DBGLOG}") \
Jiri Simsa85aea7b2014-10-15 15:48:36 -070040 || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug")
41 WANT="${EP}/__debug/logs
Robin Thellend663bf482014-10-01 10:27:10 -070042${EP}/__debug/pprof
Matt Rosencrantzb30286b2014-11-10 14:52:17 -080043${EP}/__debug/stats
44${EP}/__debug/vtrace"
Jiri Simsa85aea7b2014-10-15 15:48:36 -070045 shell_test::assert_eq "${GOT}" "${WANT}" "${LINENO}"
Robin Thellend663bf482014-10-01 10:27:10 -070046
Jiri Simsa85aea7b2014-10-15 15:48:36 -070047 # Test logs glob.
Matt Rosencrantzbe1a8b52014-11-21 15:14:06 -080048 GOT=$("${DEBUG_BIN}" "${DEBUG_FLAGS}" glob "${EP}/__debug/logs/*" 2> "${DBGLOG}" | wc -l) \
Jiri Simsa85aea7b2014-10-15 15:48:36 -070049 || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug")
50 shell_test::assert_gt "${GOT}" "0" "${LINENO}"
David Why Use Two When One Will Do Presottocb8a6142014-12-02 14:27:49 -080051
Jiri Simsa85aea7b2014-10-15 15:48:36 -070052 # Test logs size.
Robin Thellend663bf482014-10-01 10:27:10 -070053 echo "This is a log file" > "${TMPDIR}/my-test-log-file"
Matt Rosencrantzbe1a8b52014-11-21 15:14:06 -080054 GOT=$("${DEBUG_BIN}" "${DEBUG_FLAGS}" logs size "${EP}/__debug/logs/my-test-log-file" 2> "${DBGLOG}") \
Jiri Simsa85aea7b2014-10-15 15:48:36 -070055 || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug")
Cosmos Nicolaou9348da62014-10-03 14:21:19 -070056 WANT=$(echo "This is a log file" | wc -c | tr -d ' ')
Jiri Simsa85aea7b2014-10-15 15:48:36 -070057 shell_test::assert_eq "${GOT}" "${WANT}" "${LINENO}"
Robin Thellend663bf482014-10-01 10:27:10 -070058
Jiri Simsa85aea7b2014-10-15 15:48:36 -070059 # Test logs read.
Matt Rosencrantzbe1a8b52014-11-21 15:14:06 -080060 GOT=$("${DEBUG_BIN}" "${DEBUG_FLAGS}" logs read "${EP}/__debug/logs/my-test-log-file" 2> "${DBGLOG}") \
Jiri Simsa85aea7b2014-10-15 15:48:36 -070061 || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug")
Robin Thellend663bf482014-10-01 10:27:10 -070062 WANT="This is a log file"
Jiri Simsa85aea7b2014-10-15 15:48:36 -070063 shell_test::assert_eq "${GOT}" "${WANT}" "${LINENO}"
Robin Thellend663bf482014-10-01 10:27:10 -070064
Robin Thellendfaa083a2014-10-22 13:41:18 -070065 # Test stats read.
Matt Rosencrantzbe1a8b52014-11-21 15:14:06 -080066 GOT=$("${DEBUG_BIN}" "${DEBUG_FLAGS}" stats read "${EP}/__debug/stats/ipc/server/routing-id/*/methods/ReadLog/latency-ms" 2> "${DBGLOG}" | wc -l) \
Robin Thellendfaa083a2014-10-22 13:41:18 -070067 || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug")
68 shell_test::assert_gt "${GOT}" "0" "${LINENO}"
69
Matt Rosencrantzbe1a8b52014-11-21 15:14:06 -080070 # Test fetching all vtrace traces.
71 GOT=$("${DEBUG_BIN}" "${DEBUG_FLAGS}" vtrace "${EP}/__debug/vtrace" 2> "${DBGLOG}" | egrep -o "^Trace - ([^ ]+)" | cut -b 9- | sort) \
72 || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug")
73 shell_test::assert_eq $(echo "${GOT}" | wc -l | tr -d ' ') "6" "${LINENO}"
74
75 # Test fetching individual traces.
76 IDS=$(echo "$GOT" | tr '\n' ' ')
77 GOT2=$("${DEBUG_BIN}" "${DEBUG_FLAGS}" vtrace "${EP}/__debug/vtrace" ${IDS} 2> "${DBGLOG}" | egrep -o "^Trace - ([^ ]+)" | cut -b 9- | sort) \
78 || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug")
79 shell_test::assert_eq "${GOT2}" "${GOT}" "${LINENO}"
80
Robin Thellendfaa083a2014-10-22 13:41:18 -070081 # Test stats watch.
Robin Thellend663bf482014-10-01 10:27:10 -070082 local TMP=$(shell::tmp_file)
83 touch "${TMP}"
Jiri Simsa85aea7b2014-10-15 15:48:36 -070084 local -r DEBUG_PID=$(shell::run_server "${shell_test_DEFAULT_SERVER_TIMEOUT}" "${TMP}" "${DBGLOG}" \
Bogdan Capritae7376312014-11-10 13:13:17 -080085 "${DEBUG_BIN}" stats watch -raw "${EP}/__debug/stats/ipc/server/routing-id/*/methods/ReadLog/latency-ms")
Cosmos Nicolaouf17b6022014-10-14 10:04:20 -070086 shell::timed_wait_for "${shell_test_DEFAULT_MESSAGE_TIMEOUT}" "${TMP}" "ReadLog/latency-ms"
87 kill "${DEBUG_PID}"
Jungho Ahn58e85b82014-12-01 10:01:02 -080088 grep -q "Count: 1 " "${TMP}" || (dumplogs "${TMP}"; shell_test::fail "line ${LINENO}: failed to find expected output")
Robin Thellend663bf482014-10-01 10:27:10 -070089
Jiri Simsa85aea7b2014-10-15 15:48:36 -070090 # Test pprof.
Jing Jin89312ff2014-10-24 10:42:08 -070091 if ! "${DEBUG_BIN}" pprof run "${EP}/__debug/pprof" heap --text &> "${DBGLOG}"; then
Cosmos Nicolaouf17b6022014-10-14 10:04:20 -070092 dumplogs "${DBGLOG}"
Robin Thellend663bf482014-10-01 10:27:10 -070093 shell_test::fail "line ${LINENO}: unexpected failure."
94 fi
95
96 shell_test::pass
97}
98
99main "$@"