Jiri Simsa | 1023a34 | 2014-08-20 18:01:22 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Test the build server daemon. |
| 4 | # |
| 5 | # This test starts a build server daemon and uses the build client to |
| 6 | # verify that <build>.Build() works as expected. |
| 7 | |
Asim Shankar | ca821a4 | 2014-08-27 01:05:27 -0700 | [diff] [blame] | 8 | # shell_test.sh must be sourced *last* Because it has a "trap" statement that |
| 9 | # cleans up processes on exit and we want to avoid this trap statement being |
| 10 | # overridden by other scripts. For example, go.sh sources a script which sets |
| 11 | # up a different trap handler and thus, if go.sh is sourced second, then it |
| 12 | # overrides the trap handler setup in shell_test.sh. |
| 13 | # TODO(jsimsa,ashankar): Figure out a way to execute all trap handlers instead |
| 14 | # of having to worry about ordering the imports and/or skipping some trap |
| 15 | # handlers. |
Jiri Simsa | 701cdc6 | 2014-08-21 16:52:10 -0700 | [diff] [blame] | 16 | source "${VEYRON_ROOT}/environment/scripts/lib/go.sh" |
Asim Shankar | ca821a4 | 2014-08-27 01:05:27 -0700 | [diff] [blame] | 17 | source "${VEYRON_ROOT}/environment/scripts/lib/shell_test.sh" |
Jiri Simsa | 1023a34 | 2014-08-20 18:01:22 -0700 | [diff] [blame] | 18 | |
| 19 | build() { |
| 20 | local -r GO="${REPO_ROOT}/scripts/build/go" |
| 21 | "${GO}" build veyron/services/mgmt/build/buildd || shell_test::fail "line ${LINENO}: failed to build 'buildd'" |
| 22 | "${GO}" build veyron/tools/build || shell_test::fail "line ${LINENO}: failed to build 'build'" |
| 23 | } |
| 24 | |
| 25 | main() { |
| 26 | cd "${TMPDIR}" |
| 27 | build |
| 28 | |
| 29 | shell_test::setup_server_test |
| 30 | |
| 31 | # Start the binary repository daemon. |
| 32 | local -r SERVER="buildd-test-server" |
Jiri Simsa | 701cdc6 | 2014-08-21 16:52:10 -0700 | [diff] [blame] | 33 | local GO_BIN=$(which go) |
| 34 | if [[ -n "${GO_BIN}" ]] && go::usable_release "${GO_BIN}"; then |
| 35 | local -r GO_ROOT=$(go env GOROOT) |
| 36 | else |
Jiri Simsa | e396502 | 2014-08-22 09:07:29 -0700 | [diff] [blame] | 37 | local -r GO_ROOT="${VEYRON_ROOT}/environment/go/$(go::os)/$(go::architecture)/go" |
Jiri Simsa | 701cdc6 | 2014-08-21 16:52:10 -0700 | [diff] [blame] | 38 | GO_BIN="${GO_ROOT}/bin/go" |
| 39 | fi |
| 40 | shell_test::start_server ./buildd --name="${SERVER}" --gobin="${GO_BIN}" --goroot="${GO_ROOT}" --address=127.0.0.1:0 |
Jiri Simsa | 1023a34 | 2014-08-20 18:01:22 -0700 | [diff] [blame] | 41 | |
| 42 | # Create and build a test source file. |
Jiri Simsa | e396502 | 2014-08-22 09:07:29 -0700 | [diff] [blame] | 43 | local -r GO_PATH=$(shell::tmp_dir) |
| 44 | local -r BIN_DIR="${GO_PATH}/bin" |
Jiri Simsa | 1023a34 | 2014-08-20 18:01:22 -0700 | [diff] [blame] | 45 | mkdir -p "${BIN_DIR}" |
Jiri Simsa | e396502 | 2014-08-22 09:07:29 -0700 | [diff] [blame] | 46 | local -r SRC_DIR="${GO_PATH}/src/test" |
Jiri Simsa | 1023a34 | 2014-08-20 18:01:22 -0700 | [diff] [blame] | 47 | mkdir -p "${SRC_DIR}" |
| 48 | local -r SRC_FILE="${SRC_DIR}/test.go" |
| 49 | cat > "${SRC_FILE}" <<EOF |
| 50 | package main |
| 51 | |
| 52 | import "fmt" |
| 53 | |
| 54 | func main() { |
| 55 | fmt.Printf("Hello World!\n") |
| 56 | } |
| 57 | EOF |
Jiri Simsa | e396502 | 2014-08-22 09:07:29 -0700 | [diff] [blame] | 58 | GOPATH="${GO_PATH}" GOROOT="${GO_ROOT}" TMPDIR="${BIN_DIR}" ./build build "${SERVER}" "test" || shell_test::fail "line ${LINENO}: 'build' failed" |
Jiri Simsa | 1023a34 | 2014-08-20 18:01:22 -0700 | [diff] [blame] | 59 | if [[ ! -e "${BIN_DIR}/test" ]]; then |
| 60 | shell_test::fail "test binary not found" |
| 61 | fi |
| 62 | local -r GOT=$("${BIN_DIR}/test") |
| 63 | local -r WANT="Hello World!" |
| 64 | if [[ "${GOT}" != "${WANT}" ]]; then |
| 65 | shell_test::fail "unexpected result: want '${WANT}', got '${GOT}'" |
| 66 | fi |
| 67 | |
| 68 | shell_test::pass |
| 69 | } |
| 70 | |
| 71 | main "$@" |