blob: f88f5281f19d63e768bd85b06578e26a97ae39c1 [file] [log] [blame]
Devin Limba37cdd2018-05-07 11:41:05 -07001#!/bin/bash
2
3# Copyright 2015 Open Networking Foundation (ONF)
4#
5# Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
6# the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
7# or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
8#
9# TestON is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 2 of the License, or
12# (at your option) any later version.
13#
14# TestON is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with TestON. If not, see <http://www.gnu.org/licenses/>.
21#
22# Usage : ./findPatchScript.sh -t <testName> (optional choices : -n <# : number of run on each commit>
23# -s <# : number of commits to skip every iteration>
24
25#source $ONOS_ROOT/tools/dev/bash_profile
26
27#!/bin/bash
28usage() { echo "Usage:$0 [-t <test_name>] Optional:{ -n <number_of_running_test_on_each_commit>
29 -s <number_of_skipping_commit> }"; 1>&2; exit 1; }
30
31NUM_RUN=1
32SKIP_COMMIT=1
33LOG_FILE="/home/sdn/OnosSystemTest/TestON/logs/findCommitLog.txt"
34while getopts ":t:n:s:" ARGS; do
35 case $ARGS in
36 t)
37 TESTNAME=${OPTARG}
38 ;;
39 n)
40 NUM_RUN=${OPTARG}
41 ((NUM_RUN > 0)) || usage
42 ;;
43 s)
44 SKIP_COMMIT=${OPTARG}
45 ((SKIP_COMMIT > 0)) || usage
46 ;;
47 *)
48 usage
49 ;;
50 esac
51done
52
53if [ -z "${TESTNAME}" ]; then
54 usage
55fi
56
57exportMsg() {
58 echo "Log exported to $LOG_FILE"
59}
60runScript() {
61 echo -n > "$LOG_FILE"
62 PREVIOUS_COMMIT=""
63 while true; do
64 TEST_RESULT="1"
65 for ((i=0; i < NUM_RUN; i++))
66 do
67 cd ~/onos
68 COMMIT=$(git log -1 --pretty=fuller | grep -m1 -Po "(?<=commit\s)\w+")
69 echo "Current Commit : $COMMIT"
70 echo "Current Commit : $COMMIT" >> "$LOG_FILE"
71 echo "1" > /tmp/findPatchResult.txt
72 cd ~/OnosSystemTest/TestON/bin
73 ./cleanup.sh
74 ./cli.py run $TESTNAME
75 TEST_RESULT=$(cat /tmp/findPatchResult.txt)
76 echo $TEST_RESULT
77 if [ "$TEST_RESULT" == "0" ]; then
78 break
79 fi
80 done
81 if [ "$TEST_RESULT" == "1" ]; then
82 echo "Found the commit that has no problem : $(tput setaf 2)$COMMIT$(tput sgr 0)"
83 echo "Found the commit that has no problem : $COMMIT" >> $LOG_FILE
84 echo "Last commit that had a problem : $(tput setaf 1)$PREVIOUS_COMMIT$(tput sgr 0)"
85 echo "Last commit that had a problem : $PREVIOUS_COMMIT" >> $LOG_FILE
86 break
87 fi
88
89 cd ~/onos
90 COMMIT=$(git log -1 --skip $SKIP_COMMIT --pretty=fuller | grep -m1 -Po "(?<=commit\s)\w+")
91 echo "New commit to be tested : $COMMIT"
92 echo "New commit to be tested : $COMMIT" >> $LOG_FILE
93 PREVIOUS_COMMIT=$COMMIT
94 STASH_RESULT=$(git stash)
95 git checkout $COMMIT
96 if [ "$STASH_RESULT" != "No local changes to save" ]; then
97 git stash pop
98 fi
99 done
100}
101
102runScript
103echo >> $LOG_FILE
104echo >> $LOG_FILE
105exportMsg