Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 1 | #!/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 Simsa | 7d1b28d | 2014-12-12 22:39:37 -0800 | [diff] [blame] | 8 | source "$(go list -f {{.Dir}} veyron.io/veyron/shell/lib)/shell_test.sh" |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 9 | |
Jing Jin | 89312ff | 2014-10-24 10:42:08 -0700 | [diff] [blame] | 10 | readonly WORKDIR="${shell_test_WORK_DIR}" |
Matt Rosencrantz | be1a8b5 | 2014-11-21 15:14:06 -0800 | [diff] [blame] | 11 | readonly DEBUG_FLAGS="--veyron.vtrace.sample_rate=1" |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 12 | |
| 13 | build() { |
Jing Jin | 89312ff | 2014-10-24 10:42:08 -0700 | [diff] [blame] | 14 | DEBUG_BIN="$(shell_test::build_go_binary 'veyron.io/veyron/veyron/tools/debug')" |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | dumplogs() { |
| 18 | for x in $*; do |
| 19 | echo "-- $(basename "${x}") --" |
| 20 | cat "${x}" |
| 21 | done |
| 22 | } |
| 23 | |
| 24 | main() { |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 25 | local GOT WANT |
| 26 | |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 27 | cd "${WORKDIR}" |
Jing Jin | 89312ff | 2014-10-24 10:42:08 -0700 | [diff] [blame] | 28 | build |
Robin Thellend | faa083a | 2014-10-22 13:41:18 -0700 | [diff] [blame] | 29 | mkdir "tmp" |
| 30 | export TMPDIR="${WORKDIR}/tmp" |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 31 | |
Asim Shankar | f30b2df | 2014-10-11 18:51:45 -0700 | [diff] [blame] | 32 | export VEYRON_CREDENTIALS=$(shell::tmp_dir) |
Ankur | d876269 | 2014-12-12 10:50:12 -0800 | [diff] [blame] | 33 | # Create specific VeyronCredentials for the debug command forked from the environment's |
| 34 | # VeyronCredentials. |
| 35 | export DEBUG_CREDENTIALS=$(shell_test::forkcredentials "${VEYRON_CREDENTIALS}" debug) |
| 36 | |
Cosmos Nicolaou | f17b602 | 2014-10-14 10:04:20 -0700 | [diff] [blame] | 37 | shell_test::setup_server_test || shell_test::fail "setup_server_test failed" |
| 38 | local -r EP="${NAMESPACE_ROOT}" |
| 39 | unset NAMESPACE_ROOT |
Ankur | d876269 | 2014-12-12 10:50:12 -0800 | [diff] [blame] | 40 | export VEYRON_CREDENTIALS="${DEBUG_CREDENTIALS}" |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 41 | |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 42 | # Test top level glob. |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 43 | local -r DBGLOG="${WORKDIR}/debug.log" |
Matt Rosencrantz | be1a8b5 | 2014-11-21 15:14:06 -0800 | [diff] [blame] | 44 | GOT=$("${DEBUG_BIN}" "${DEBUG_FLAGS}" glob "${EP}/__debug/*" 2> "${DBGLOG}") \ |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 45 | || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug") |
| 46 | WANT="${EP}/__debug/logs |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 47 | ${EP}/__debug/pprof |
Matt Rosencrantz | b30286b | 2014-11-10 14:52:17 -0800 | [diff] [blame] | 48 | ${EP}/__debug/stats |
| 49 | ${EP}/__debug/vtrace" |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 50 | shell_test::assert_eq "${GOT}" "${WANT}" "${LINENO}" |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 51 | |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 52 | # Test logs glob. |
Matt Rosencrantz | be1a8b5 | 2014-11-21 15:14:06 -0800 | [diff] [blame] | 53 | GOT=$("${DEBUG_BIN}" "${DEBUG_FLAGS}" glob "${EP}/__debug/logs/*" 2> "${DBGLOG}" | wc -l) \ |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 54 | || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug") |
| 55 | shell_test::assert_gt "${GOT}" "0" "${LINENO}" |
David Why Use Two When One Will Do Presotto | cb8a614 | 2014-12-02 14:27:49 -0800 | [diff] [blame] | 56 | |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 57 | # Test logs size. |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 58 | echo "This is a log file" > "${TMPDIR}/my-test-log-file" |
Matt Rosencrantz | be1a8b5 | 2014-11-21 15:14:06 -0800 | [diff] [blame] | 59 | GOT=$("${DEBUG_BIN}" "${DEBUG_FLAGS}" logs size "${EP}/__debug/logs/my-test-log-file" 2> "${DBGLOG}") \ |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 60 | || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug") |
Cosmos Nicolaou | 9348da6 | 2014-10-03 14:21:19 -0700 | [diff] [blame] | 61 | WANT=$(echo "This is a log file" | wc -c | tr -d ' ') |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 62 | shell_test::assert_eq "${GOT}" "${WANT}" "${LINENO}" |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 63 | |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 64 | # Test logs read. |
Matt Rosencrantz | be1a8b5 | 2014-11-21 15:14:06 -0800 | [diff] [blame] | 65 | GOT=$("${DEBUG_BIN}" "${DEBUG_FLAGS}" logs read "${EP}/__debug/logs/my-test-log-file" 2> "${DBGLOG}") \ |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 66 | || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug") |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 67 | WANT="This is a log file" |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 68 | shell_test::assert_eq "${GOT}" "${WANT}" "${LINENO}" |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 69 | |
Robin Thellend | faa083a | 2014-10-22 13:41:18 -0700 | [diff] [blame] | 70 | # Test stats read. |
Matt Rosencrantz | be1a8b5 | 2014-11-21 15:14:06 -0800 | [diff] [blame] | 71 | GOT=$("${DEBUG_BIN}" "${DEBUG_FLAGS}" stats read "${EP}/__debug/stats/ipc/server/routing-id/*/methods/ReadLog/latency-ms" 2> "${DBGLOG}" | wc -l) \ |
Robin Thellend | faa083a | 2014-10-22 13:41:18 -0700 | [diff] [blame] | 72 | || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug") |
| 73 | shell_test::assert_gt "${GOT}" "0" "${LINENO}" |
| 74 | |
Matt Rosencrantz | be1a8b5 | 2014-11-21 15:14:06 -0800 | [diff] [blame] | 75 | # Test fetching all vtrace traces. |
| 76 | GOT=$("${DEBUG_BIN}" "${DEBUG_FLAGS}" vtrace "${EP}/__debug/vtrace" 2> "${DBGLOG}" | egrep -o "^Trace - ([^ ]+)" | cut -b 9- | sort) \ |
| 77 | || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug") |
| 78 | shell_test::assert_eq $(echo "${GOT}" | wc -l | tr -d ' ') "6" "${LINENO}" |
| 79 | |
| 80 | # Test fetching individual traces. |
| 81 | IDS=$(echo "$GOT" | tr '\n' ' ') |
| 82 | GOT2=$("${DEBUG_BIN}" "${DEBUG_FLAGS}" vtrace "${EP}/__debug/vtrace" ${IDS} 2> "${DBGLOG}" | egrep -o "^Trace - ([^ ]+)" | cut -b 9- | sort) \ |
| 83 | || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug") |
| 84 | shell_test::assert_eq "${GOT2}" "${GOT}" "${LINENO}" |
| 85 | |
Robin Thellend | faa083a | 2014-10-22 13:41:18 -0700 | [diff] [blame] | 86 | # Test stats watch. |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 87 | local TMP=$(shell::tmp_file) |
| 88 | touch "${TMP}" |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 89 | local -r DEBUG_PID=$(shell::run_server "${shell_test_DEFAULT_SERVER_TIMEOUT}" "${TMP}" "${DBGLOG}" \ |
Bogdan Caprita | e737631 | 2014-11-10 13:13:17 -0800 | [diff] [blame] | 90 | "${DEBUG_BIN}" stats watch -raw "${EP}/__debug/stats/ipc/server/routing-id/*/methods/ReadLog/latency-ms") |
Cosmos Nicolaou | f17b602 | 2014-10-14 10:04:20 -0700 | [diff] [blame] | 91 | shell::timed_wait_for "${shell_test_DEFAULT_MESSAGE_TIMEOUT}" "${TMP}" "ReadLog/latency-ms" |
| 92 | kill "${DEBUG_PID}" |
Jungho Ahn | 58e85b8 | 2014-12-01 10:01:02 -0800 | [diff] [blame] | 93 | grep -q "Count: 1 " "${TMP}" || (dumplogs "${TMP}"; shell_test::fail "line ${LINENO}: failed to find expected output") |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 94 | |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 95 | # Test pprof. |
Jing Jin | 89312ff | 2014-10-24 10:42:08 -0700 | [diff] [blame] | 96 | if ! "${DEBUG_BIN}" pprof run "${EP}/__debug/pprof" heap --text &> "${DBGLOG}"; then |
Cosmos Nicolaou | f17b602 | 2014-10-14 10:04:20 -0700 | [diff] [blame] | 97 | dumplogs "${DBGLOG}" |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 98 | shell_test::fail "line ${LINENO}: unexpected failure." |
| 99 | fi |
| 100 | |
| 101 | shell_test::pass |
| 102 | } |
| 103 | |
| 104 | main "$@" |