| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# @HEADER |
| 4 |
# ***************************************************************************** |
| 5 |
# TriBITS: Tribal Build, Integrate, and Test System |
| 6 |
# |
| 7 |
# Copyright 2013-2016 NTESS and the TriBITS contributors. |
| 8 |
# SPDX-License-Identifier: BSD-3-Clause |
| 9 |
# ***************************************************************************** |
| 10 |
# @HEADER |
| 11 |
|
| 12 |
# |
| 13 |
# Imports |
| 14 |
# |
| 15 |
|
| 16 |
import os |
| 17 |
import sys |
| 18 |
import traceback |
| 19 |
from optparse import OptionParser |
| 20 |
|
| 21 |
if os.environ.get("TRIBITS_IS_CHECKIN_TESTED_COMMIT", "") == "ON": |
| 22 |
debugDump = True |
| 23 |
else: |
| 24 |
debugDump = False |
| 25 |
|
| 26 |
if debugDump: |
| 27 |
print "NOTE: TRIBITS_IS_CHECKIN_TESTED_COMMIT=ON set in env, doing debug dump ..." |
| 28 |
|
| 29 |
thisFilePath = __file__ |
| 30 |
if debugDump: print "\nthisFilePath =", thisFilePath |
| 31 |
|
| 32 |
thisFileRealAbsBasePath = os.path.dirname(os.path.abspath(os.path.realpath(thisFilePath))) |
| 33 |
if debugDump: print "\nthisFileRealAbsBasePath = '"+thisFileRealAbsBasePath+"'" |
| 34 |
|
| 35 |
sys.path = [thisFileRealAbsBasePath+"/../python_utils"] + sys.path |
| 36 |
|
| 37 |
from GeneralScriptSupport import * |
| 38 |
|
| 39 |
# |
| 40 |
# Utility classes and functions. |
| 41 |
# |
| 42 |
|
| 43 |
usageHelp = r"""is_checkin_tested_commit.py [OPTIONS] |
| 44 |
|
| 45 |
This script determines if a commit has been tested (and pushed) with the |
| 46 |
checkin-test.py script. Currently, this just looks for the string: |
| 47 |
|
| 48 |
"Build/Test Cases Summary" |
| 49 |
|
| 50 |
in the log message which is written there by the checkin-test.py script when |
| 51 |
it amends the top commit message before it pushes. |
| 52 |
|
| 53 |
This script is used with 'git bisect' to help week out commits that might not |
| 54 |
build or pass all of the tests and therefore not appropriate to bother testing |
| 55 |
when doing a 'git bisect' on to find an issue for a customer. |
| 56 |
|
| 57 |
Basically, this script should be added to the top of a 'test-commit.sh' script |
| 58 |
(as described in the 'git bisect --help' documentation) to ignore commits that |
| 59 |
are not known to be tested with the checkin-test.py script using a |
| 60 |
<test-commit> script of the form: |
| 61 |
|
| 62 |
#!/bin/bash |
| 63 |
|
| 64 |
$TRIBITS_DIR/ci_support/is_checkin_tested_commit.py |
| 65 |
IS_CHECKIN_TESTED_COMMIT_RTN=$? |
| 66 |
if [ "$IS_CHECKIN_TESTED_COMMIT_RTN" != "0" ] ; then |
| 67 |
exit 125 # Skip the commit because HEAD is was not known to be tested! |
| 68 |
fi |
| 69 |
|
| 70 |
./build_and_test_customer_code.sh # Rtn 0 "good", or [1, 124] if "bad" |
| 71 |
|
| 72 |
See 'git bisect --help' for more details and TriBITS documentation on using |
| 73 |
'git bisect' using is_checkin_tested_commit.py. |
| 74 |
""" |
| 75 |
|
| 76 |
# |
| 77 |
# A) Get command-line options |
| 78 |
# |
| 79 |
|
| 80 |
from optparse import OptionParser |
| 81 |
|
| 82 |
clp = OptionParser(usage=usageHelp) |
| 83 |
|
| 84 |
clp.add_option( |
| 85 |
"--ref", dest="gitRef", type="string", default="", |
| 86 |
help="The git reference of the commit to test (empty '' means HEAD)" ) |
| 87 |
|
| 88 |
(options, args) = clp.parse_args() |
| 89 |
|
| 90 |
# If --ref is not specified, then take HEAD |
| 91 |
if options.gitRef: |
| 92 |
gitRef = options.gitRef |
| 93 |
else: |
| 94 |
gitRef = "HEAD" |
| 95 |
|
| 96 |
# |
| 97 |
# B) Determine if the commit was tested and pushed with checkin-test.py |
| 98 |
# script. |
| 99 |
# |
| 100 |
|
| 101 |
cmnd = "git log -1 "+gitRef |
| 102 |
rawGitLogTxt = getCmndOutput(cmnd) |
| 103 |
|
| 104 |
if re.search("Build/Test Cases Summary", rawGitLogTxt): |
| 105 |
isCheckinTestedCommit = True |
| 106 |
else: |
| 107 |
isCheckinTestedCommit = False |
| 108 |
|
| 109 |
if isCheckinTestedCommit: |
| 110 |
print "The commit "+gitRef+" is checkin-test.py tested!" |
| 111 |
sys.exit(0) |
| 112 |
else: |
| 113 |
print "The commit "+gitRef+" is *NOT* checkin-test.py tested!" |
| 114 |
sys.exit(1) |