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 | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 8 | source "${VEYRON_ROOT}/scripts/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) |
Cosmos Nicolaou | f17b602 | 2014-10-14 10:04:20 -0700 | [diff] [blame] | 33 | shell_test::setup_server_test || shell_test::fail "setup_server_test failed" |
| 34 | local -r EP="${NAMESPACE_ROOT}" |
| 35 | unset NAMESPACE_ROOT |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 36 | |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 37 | # Test top level glob. |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 38 | local -r DBGLOG="${WORKDIR}/debug.log" |
Matt Rosencrantz | be1a8b5 | 2014-11-21 15:14:06 -0800 | [diff] [blame] | 39 | GOT=$("${DEBUG_BIN}" "${DEBUG_FLAGS}" glob "${EP}/__debug/*" 2> "${DBGLOG}") \ |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 40 | || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug") |
| 41 | WANT="${EP}/__debug/logs |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 42 | ${EP}/__debug/pprof |
Matt Rosencrantz | b30286b | 2014-11-10 14:52:17 -0800 | [diff] [blame] | 43 | ${EP}/__debug/stats |
| 44 | ${EP}/__debug/vtrace" |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 45 | shell_test::assert_eq "${GOT}" "${WANT}" "${LINENO}" |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 46 | |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 47 | # Test logs glob. |
Matt Rosencrantz | be1a8b5 | 2014-11-21 15:14:06 -0800 | [diff] [blame] | 48 | 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] | 49 | || (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 Presotto | cb8a614 | 2014-12-02 14:27:49 -0800 | [diff] [blame^] | 51 | |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 52 | # Test logs size. |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 53 | echo "This is a log file" > "${TMPDIR}/my-test-log-file" |
Matt Rosencrantz | be1a8b5 | 2014-11-21 15:14:06 -0800 | [diff] [blame] | 54 | 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] | 55 | || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug") |
Cosmos Nicolaou | 9348da6 | 2014-10-03 14:21:19 -0700 | [diff] [blame] | 56 | WANT=$(echo "This is a log file" | wc -c | tr -d ' ') |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 57 | shell_test::assert_eq "${GOT}" "${WANT}" "${LINENO}" |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 58 | |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 59 | # Test logs read. |
Matt Rosencrantz | be1a8b5 | 2014-11-21 15:14:06 -0800 | [diff] [blame] | 60 | 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] | 61 | || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug") |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 62 | WANT="This is a log file" |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 63 | shell_test::assert_eq "${GOT}" "${WANT}" "${LINENO}" |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 64 | |
Robin Thellend | faa083a | 2014-10-22 13:41:18 -0700 | [diff] [blame] | 65 | # Test stats read. |
Matt Rosencrantz | be1a8b5 | 2014-11-21 15:14:06 -0800 | [diff] [blame] | 66 | 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] | 67 | || (dumplogs "${DBGLOG}"; shell_test::fail "line ${LINENO}: failed to run debug") |
| 68 | shell_test::assert_gt "${GOT}" "0" "${LINENO}" |
| 69 | |
Matt Rosencrantz | be1a8b5 | 2014-11-21 15:14:06 -0800 | [diff] [blame] | 70 | # 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 Thellend | faa083a | 2014-10-22 13:41:18 -0700 | [diff] [blame] | 81 | # Test stats watch. |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 82 | local TMP=$(shell::tmp_file) |
| 83 | touch "${TMP}" |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 84 | 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] | 85 | "${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] | 86 | shell::timed_wait_for "${shell_test_DEFAULT_MESSAGE_TIMEOUT}" "${TMP}" "ReadLog/latency-ms" |
| 87 | kill "${DEBUG_PID}" |
Jungho Ahn | 58e85b8 | 2014-12-01 10:01:02 -0800 | [diff] [blame] | 88 | 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] | 89 | |
Jiri Simsa | 85aea7b | 2014-10-15 15:48:36 -0700 | [diff] [blame] | 90 | # Test pprof. |
Jing Jin | 89312ff | 2014-10-24 10:42:08 -0700 | [diff] [blame] | 91 | if ! "${DEBUG_BIN}" pprof run "${EP}/__debug/pprof" heap --text &> "${DBGLOG}"; then |
Cosmos Nicolaou | f17b602 | 2014-10-14 10:04:20 -0700 | [diff] [blame] | 92 | dumplogs "${DBGLOG}" |
Robin Thellend | 663bf48 | 2014-10-01 10:27:10 -0700 | [diff] [blame] | 93 | shell_test::fail "line ${LINENO}: unexpected failure." |
| 94 | fi |
| 95 | |
| 96 | shell_test::pass |
| 97 | } |
| 98 | |
| 99 | main "$@" |