blob: 0cfce9b09b8a8a85f64299aa0b0bf5958ca5b7a8 [file] [log] [blame]
Jiri Simsa1023a342014-08-20 18:01:22 -07001#!/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 Shankarca821a42014-08-27 01:05:27 -07008# 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 Simsa701cdc62014-08-21 16:52:10 -070016source "${VEYRON_ROOT}/environment/scripts/lib/go.sh"
Asim Shankarca821a42014-08-27 01:05:27 -070017source "${VEYRON_ROOT}/environment/scripts/lib/shell_test.sh"
Jiri Simsa1023a342014-08-20 18:01:22 -070018
19build() {
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
25main() {
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 Simsa701cdc62014-08-21 16:52:10 -070033 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 Simsae3965022014-08-22 09:07:29 -070037 local -r GO_ROOT="${VEYRON_ROOT}/environment/go/$(go::os)/$(go::architecture)/go"
Jiri Simsa701cdc62014-08-21 16:52:10 -070038 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 Simsa1023a342014-08-20 18:01:22 -070041
42 # Create and build a test source file.
Jiri Simsae3965022014-08-22 09:07:29 -070043 local -r GO_PATH=$(shell::tmp_dir)
44 local -r BIN_DIR="${GO_PATH}/bin"
Jiri Simsa1023a342014-08-20 18:01:22 -070045 mkdir -p "${BIN_DIR}"
Jiri Simsae3965022014-08-22 09:07:29 -070046 local -r SRC_DIR="${GO_PATH}/src/test"
Jiri Simsa1023a342014-08-20 18:01:22 -070047 mkdir -p "${SRC_DIR}"
48 local -r SRC_FILE="${SRC_DIR}/test.go"
49 cat > "${SRC_FILE}" <<EOF
50package main
51
52import "fmt"
53
54func main() {
55 fmt.Printf("Hello World!\n")
56}
57EOF
Jiri Simsae3965022014-08-22 09:07:29 -070058 GOPATH="${GO_PATH}" GOROOT="${GO_ROOT}" TMPDIR="${BIN_DIR}" ./build build "${SERVER}" "test" || shell_test::fail "line ${LINENO}: 'build' failed"
Jiri Simsa1023a342014-08-20 18:01:22 -070059 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
71main "$@"