1abb37c58SSriram Melkote#!/bin/bash
2abb37c58SSriram Melkote
3abb37c58SSriram Melkotesource ~/.cienv
4abb37c58SSriram Melkote
5abb37c58SSriram Melkoteecho '</pre><h3>Testing</h3><pre>'
6abb37c58SSriram Melkote
7abb37c58SSriram Melkoteif [ "$WORKSPACE" = "" ]; then
8abb37c58SSriram Melkote  echo 'WORKSPACE not set'
9abb37c58SSriram Melkote  exit 2
10abb37c58SSriram Melkotefi
11abb37c58SSriram Melkote
12abb37c58SSriram Melkoteif [ "$MODE" = "" ]; then
13abb37c58SSriram Melkote  echo 'MODE not set'
14abb37c58SSriram Melkote  exit 2
15abb37c58SSriram Melkotefi
16abb37c58SSriram Melkote
17abb37c58SSriram Melkoteif [ "$TS" = "" ]; then
18abb37c58SSriram Melkote  TS="adhoc"
19abb37c58SSriram Melkotefi
20abb37c58SSriram Melkote
21abb37c58SSriram Melkotestart_cluster() {
22abb37c58SSriram Melkote  echo "Starting server"
23abb37c58SSriram Melkote  for a in {1..3}; do
24abb37c58SSriram Melkote    echo "Starting server: attempt $a"
25abb37c58SSriram Melkote    stop_cluster
26abb37c58SSriram Melkote    cd $WORKSPACE/ns_server
27abb37c58SSriram Melkote    ./cluster_run -n4 1>$WORKSPACE/run.log 2>&1 &
28abb37c58SSriram Melkote    disown
29abb37c58SSriram Melkote    for i in {1..120}; do
30abb37c58SSriram Melkote      grep -qs 'Couchbase Server has started' logs/n_0/info.log && \
31abb37c58SSriram Melkote        grep -qs 'Couchbase Server has started' logs/n_1/info.log && \
32abb37c58SSriram Melkote          wget -qO- http://localhost:9000/ &>/dev/null &&
33abb37c58SSriram Melkote            wget -qO- http://localhost:9001/ &>/dev/null &&
34abb37c58SSriram Melkote              ok_run=1 && break
35abb37c58SSriram Melkote      sleep 3
36abb37c58SSriram Melkote    done
37abb37c58SSriram Melkote    sleep 30
38abb37c58SSriram Melkote    test "$ok_run" && break
39abb37c58SSriram Melkote  done
40abb37c58SSriram Melkote  test "$ok_run" || error_exit "Server startup failed even after 3 tries"
41abb37c58SSriram Melkote}
42abb37c58SSriram Melkote
43abb37c58SSriram Melkotestop_cluster() {
44abb37c58SSriram Melkote  pkill -f cluster_
45abb37c58SSriram Melkote  pkill -f $WORKSPACE/install/bin
46abb37c58SSriram Melkote  pkill -f testrunner
47abb37c58SSriram Melkote  pkill -f $WORKSPACE/install
48abb37c58SSriram Melkote  pkill -f testrunner
49abb37c58SSriram Melkote  killall beam.smp epmd memcached eventing-producer eventing-consumer python memcached.json 1>/dev/null 2>&1
50abb37c58SSriram Melkote  sleep 10
51abb37c58SSriram Melkote  killall -9 beam.smp epmd memcached eventing-producer eventing-consumer python memcached.json 1>/dev/null 2>&1
52abb37c58SSriram Melkote  cd $WORKSPACE/ns_server
53abb37c58SSriram Melkote  make dataclean 1>/dev/null 2>&1
54abb37c58SSriram Melkote  sudo rm -f /tmp/core*
55abb37c58SSriram Melkote  sleep 10
56abb37c58SSriram Melkote}
57abb37c58SSriram Melkote
58abb37c58SSriram Melkotecollect_logs() {
59abb37c58SSriram Melkote  if [ "$phase" = "" ]; then phase=unknown; fi
60abb37c58SSriram Melkote  tar -C $WORKSPACE --transform "s/^/logs-$phase-/" -uf $WORKSPACE/logs.tar ns_server/logs 1>/dev/null 2>&1
61abb37c58SSriram Melkote  tar -C $WORKSPACE --transform "s/^/logs-$phase-/" -uf $WORKSPACE/logs.tar testrunner/logs 1>/dev/null 2>&1
62abb37c58SSriram Melkote  tar -C $WORKSPACE --transform "s/^/logs-$phase-/" -uf $WORKSPACE/logs.tar test.log 1>/dev/null 2>&1
63abb37c58SSriram Melkote  tar -C $WORKSPACE --transform "s/^/logs-$phase-/" -uf $WORKSPACE/logs.tar run.log 1>/dev/null 2>&1
64abb37c58SSriram Melkote}
65abb37c58SSriram Melkote
66abb37c58SSriram Melkoteerror_email() {
67abb37c58SSriram Melkote  if [ ! -f ~/.cigreen ]; then return; fi
68abb37c58SSriram Melkote  rm ~/.cigreen
69abb37c58SSriram Melkote
70abb37c58SSriram Melkote  if test "`find ~ -maxdepth 1 -name .cinotify -mmin -1440`"; then return; fi
71abb37c58SSriram Melkote  touch ~/.cinotify
72abb37c58SSriram Melkote
73abb37c58SSriram Melkote  if [ "$WATCHERS" = "" ]; then return; fi
74abb37c58SSriram Melkote  cat /var/www/views-current.html | \
75abb37c58SSriram Melkote     sendemail -q \
76abb37c58SSriram Melkote       -s west.smtp.mx.exch029.serverdata.net:25 \
774713a04dSSriram Melkote       -f 'Views CI <community_admin@couchbase.com>' \
78abb37c58SSriram Melkote       -t $WATCHERS \
7980992523SSriram Melkote       -u "Views CI $CINAME broke"
80abb37c58SSriram Melkote}
81abb37c58SSriram Melkote
82abb37c58SSriram Melkoteerror_exit() {
83abb37c58SSriram Melkote  echo "</pre><h4>Testing Failed: $1</h4><pre>"
84abb37c58SSriram Melkote  echo "$2"
85abb37c58SSriram Melkote  collect_logs
86abb37c58SSriram Melkote  stop_cluster
87abb37c58SSriram Melkote  error_email
88abb37c58SSriram Melkote  exit 2
89abb37c58SSriram Melkote}
90abb37c58SSriram Melkote
91abb37c58SSriram Melkote# Setup workspace
92abb37c58SSriram Melkoteecho "Testing mode: $MODE"
93abb37c58SSriram Melkotestop_cluster
94abb37c58SSriram Melkoterm -f $WORKSPACE/logs.tar.* $WORKSPACE/test.log $WORKSPACE/run.log /tmp/core-*
95abb37c58SSriram Melkote> $WORKSPACE/test.log
96abb37c58SSriram Melkote
97abb37c58SSriram Melkote# Test the base
98abb37c58SSriram Melkoteecho "</pre><h4>Simple Test</h4><pre>"
99abb37c58SSriram Melkoteexport phase=sanity
100abb37c58SSriram Melkotecd $WORKSPACE/testrunner
101abb37c58SSriram Melkote(timeout 1h make simple-test 2>&1 | ts) | tee -a $WORKSPACE/test.log | egrep 'pass|fail|summary|ok$'
102abb37c58SSriram Melkote
103fd676668Sharsha# Unit tests
10492255397Sharshaecho "</pre><h4>Unit Tests with dialyzer</h4><pre>"
105fd676668Sharshaexport phase=sanity
106fd676668Sharshacd $WORKSPACE/build/couchdb
10792255397Sharsha(timeout 2h make check 2>&1 | ts) | tee -a $WORKSPACE/test.log | egrep 'pass|fail|summary|ok$'
108fd676668Sharsha
109fd676668Sharsha# Test the premerge tests
110fd676668Sharshaecho "</pre><h4>Views Pre merge test without createdelete views</h4><pre>"
111fd676668Sharshaexport phase=sanity
112fd676668Sharshacd $WORKSPACE/testrunner
113fd676668Sharsha(timeout 1h make test-views-pre-merge-viewci 2>&1 | ts) | tee -a $WORKSPACE/test.log | egrep 'pass|fail|summary|ok$'
114fd676668Sharsha
115fd676668Sharsha# Test the viewmerge tests
116fd676668Sharshaecho "</pre><h4>Viewmerge tests without devview test</h4><pre>"
117fd676668Sharshaexport phase=sanity
118fd676668Sharshacd $WORKSPACE/testrunner
119fd676668Sharsha(timeout 1h make test-viewmerge-viewci 2>&1 | ts) | tee -a $WORKSPACE/test.log | egrep 'pass|fail|summary|ok$'
120fd676668Sharsha
121abb37c58SSriram Melkote# Functional tests
122abb37c58SSriram Melkoteexport phase=functional
123abb37c58SSriram Melkotestart_cluster
124abb37c58SSriram Melkoteulimit -c 2097152
125abb37c58SSriram Melkotesudo bash -c "echo /tmp/core-%e.$TS.%p > /proc/sys/kernel/core_pattern"
126abb37c58SSriram Melkoteperl -pi -e 's/num_files, 10/num_files, 50/' $WORKSPACE/install/etc/couchbase/static_config
127abb37c58SSriram Melkote(timeout 1h echo "No functional tests defined" 2>&1 | ts) | tee -a $WORKSPACE/test.log | egrep 'pass|fail|summary|ok$'
128abb37c58SSriram Melkotecollect_logs
129abb37c58SSriram Melkotestop_cluster
130abb37c58SSriram Melkote
131abb37c58SSriram Melkote# Integration tests
13280992523SSriram Melkote#echo "</pre><h4>Integration tests</h4><pre>"
13380992523SSriram Melkote#export phase=integration
13480992523SSriram Melkote#cd $WORKSPACE/testrunner
13580992523SSriram Melkote#(timeout 2h "No integration tests defined" 2>&1 | ts) | tee -a $WORKSPACE/test.log
13680992523SSriram Melkote#collect_logs
137abb37c58SSriram Melkote
138abb37c58SSriram Melkote# Verify results
139abb37c58SSriram Melkote> /tmp/fail.log
140abb37c58SSriram Melkotecd $WORKSPACE/couchdb
141abb37c58SSriram Melkotegrep 'make:\s\*\*\*\s\[test-view.*\]\s' $WORKSPACE/test.log >> /tmp/fail.log
14280992523SSriram Melkotegrep 'recipe for target .* failed' $WORKSPACE/test.log >> /tmp/fail.log
143abb37c58SSriram Melkotegrep '\sfail\s*$' $WORKSPACE/test.log >> /tmp/fail.log
144abb37c58SSriram Melkotegrep 'FAIL\s*github.com/couchbase' $WORKSPACE/test.log >> /tmp/fail.log
145abb37c58SSriram Melkotegrep -- '--- FAIL:' $WORKSPACE/test.log >> /tmp/fail.log
146abb37c58SSriram Melkotegrep '^\s*2i' $WORKSPACE/test.log | grep 'fail\s*$' >> /tmp/fail.log
147abb37c58SSriram Melkoteskiplist="`cat test/ci/skip.txt`"
148abb37c58SSriram Melkotefor tst in $skiplist; do
149abb37c58SSriram Melkote  echo "$tst" | grep -qs '^\s*#' && continue
150abb37c58SSriram Melkote  echo "$tst" | grep -qs '^\s*$' && continue
151abb37c58SSriram Melkote  grep -v "$tst" /tmp/fail.log > /tmp/fail-out.log
152abb37c58SSriram Melkote  mv /tmp/fail-out.log /tmp/fail.log
153abb37c58SSriram Melkotedone
154abb37c58SSriram Melkotefaillog="`cat /tmp/fail.log`"
155abb37c58SSriram Melkoteif [ "$faillog" != "" ]; then error_exit "Required test failed" "$faillog"; fi
156abb37c58SSriram Melkoteecho "</pre><h4>Testing Succeeded</h4><pre>"
157abb37c58SSriram Melkoteif [ "$skiplist" != "" ]; then
158abb37c58SSriram Melkote  echo "But we ignored these tests:"
159abb37c58SSriram Melkote  echo "$skiplist"
160abb37c58SSriram Melkotefi
161abb37c58SSriram Melkoteecho
162abb37c58SSriram Melkote
163abb37c58SSriram Melkote# Note versions
164abb37c58SSriram Melkotecd $WORKSPACE/goproj/src/github.com/couchbase/eventing
165abb37c58SSriram Melkotegit rev-parse HEAD > ~/eventing.good
166abb37c58SSriram Melkotecd $WORKSPACE/goproj/src/github.com/couchbase/indexing
167abb37c58SSriram Melkotegit rev-parse HEAD > ~/indexing.good
168abb37c58SSriram Melkotecd $WORKSPACE/goproj/src/github.com/couchbase/query
169abb37c58SSriram Melkotegit rev-parse HEAD > ~/query.good
170abb37c58SSriram Melkotecd $WORKSPACE/goproj/src/github.com/couchbase/gometa
171abb37c58SSriram Melkotegit rev-parse HEAD > ~/gometa.good
172abb37c58SSriram Melkotecd $WORKSPACE/forestdb
173abb37c58SSriram Melkotegit rev-parse HEAD > ~/forestdb.good
174abb37c58SSriram Melkotecd $WORKSPACE/ns_server
175abb37c58SSriram Melkotegit rev-parse HEAD > ~/ns_server.good
176abb37c58SSriram Melkotecd $WORKSPACE/couchdb
17780992523SSriram Melkotegit rev-parse couchbase/$BRANCH > ~/couchdb.good
178abb37c58SSriram Melkotecd $WORKSPACE/couchstore
179abb37c58SSriram Melkotegit rev-parse HEAD > ~/couchstore.good
180abb37c58SSriram Melkotecd $WORKSPACE/goproj/src/github.com/couchbase/plasma
181abb37c58SSriram Melkotegit rev-parse HEAD > ~/plasma.good
182abb37c58SSriram Melkotecd $WORKSPACE/goproj/src/github.com/couchbase/nitro
183abb37c58SSriram Melkotegit rev-parse HEAD > ~/nitro.good
184abb37c58SSriram Melkotecd $WORKSPACE/testrunner
185abb37c58SSriram Melkotegit rev-parse HEAD > ~/testrunner.good
186abb37c58SSriram Melkotecd $WORKSPACE/kv_engine
187abb37c58SSriram Melkotegit rev-parse HEAD > ~/kv_engine.good
18880992523SSriram Melkotecd $WORKSPACE/geocouch
18980992523SSriram Melkotegit rev-parse HEAD > ~/geocouch.good
190abb37c58SSriram Melkote
191abb37c58SSriram Melkotetouch ~/.cigreen
192abb37c58SSriram Melkoteexit 0
193abb37c58SSriram Melkote
194