diff options
author | Tiancong Wang <tcwang@google.com> | 2020-02-13 21:08:49 +0000 |
---|---|---|
committer | Tiancong Wang <tcwang@google.com> | 2020-02-13 21:08:49 +0000 |
commit | b75f321fc8978b92ce3db6886ccb966768f0c7a8 (patch) | |
tree | 35fa0fbaeaaddd9cc2a126a05eee3527b51e83a8 /deprecated/test_gdb_dejagnu.py | |
parent | cddd960b0ba2eb62c372c0d3176c75f0bd05d5e8 (diff) | |
parent | e617e3393dd24003aa976ece5050bb291070041c (diff) | |
download | toolchain-utils-android11-mainline-documentsui-release.tar.gz |
Merging 18 commit(s) from Chromium's toolchain-utils am: 0ae38c8498 am: 2a19d36a82 am: e617e3393dr_aml_301500702android-mainline-12.0.0_r55android-mainline-11.0.0_r9android-mainline-11.0.0_r8android-mainline-11.0.0_r7android-mainline-11.0.0_r6android-mainline-11.0.0_r5android-mainline-11.0.0_r45android-mainline-11.0.0_r44android-mainline-11.0.0_r43android-mainline-11.0.0_r42android-mainline-11.0.0_r41android-mainline-11.0.0_r40android-mainline-11.0.0_r4android-mainline-11.0.0_r39android-mainline-11.0.0_r38android-mainline-11.0.0_r37android-mainline-11.0.0_r36android-mainline-11.0.0_r35android-mainline-11.0.0_r34android-mainline-11.0.0_r33android-mainline-11.0.0_r32android-mainline-11.0.0_r31android-mainline-11.0.0_r30android-mainline-11.0.0_r3android-mainline-11.0.0_r29android-mainline-11.0.0_r28android-mainline-11.0.0_r27android-mainline-11.0.0_r26android-mainline-11.0.0_r25android-mainline-11.0.0_r24android-mainline-11.0.0_r23android-mainline-11.0.0_r22android-mainline-11.0.0_r21android-mainline-11.0.0_r20android-mainline-11.0.0_r2android-mainline-11.0.0_r19android-mainline-11.0.0_r18android-mainline-11.0.0_r17android-mainline-11.0.0_r16android-mainline-11.0.0_r15android-mainline-11.0.0_r14android-mainline-11.0.0_r13android-mainline-11.0.0_r12android-mainline-11.0.0_r10android-mainline-11.0.0_r1android-11.0.0_r48android-11.0.0_r47android-11.0.0_r46android-11.0.0_r45android-11.0.0_r44android-11.0.0_r43android-11.0.0_r42android-11.0.0_r41android-11.0.0_r40android-11.0.0_r39android-11.0.0_r38android-11.0.0_r37android-11.0.0_r36android-11.0.0_r35android-11.0.0_r34android-11.0.0_r33android-11.0.0_r32android-11.0.0_r31android-11.0.0_r30android-11.0.0_r29android-11.0.0_r28android-11.0.0_r27android-11.0.0_r26android-11.0.0_r24android-11.0.0_r23android-11.0.0_r22android-11.0.0_r21android-11.0.0_r20android-11.0.0_r19android-11.0.0_r18android-11.0.0_r16android11-qpr3-s1-releaseandroid11-qpr3-releaseandroid11-qpr2-releaseandroid11-qpr1-s2-releaseandroid11-qpr1-s1-releaseandroid11-qpr1-releaseandroid11-qpr1-d-s1-releaseandroid11-qpr1-d-releaseandroid11-qpr1-c-releaseandroid11-mainline-tethering-releaseandroid11-mainline-sparse-2021-jan-releaseandroid11-mainline-sparse-2020-dec-releaseandroid11-mainline-releaseandroid11-mainline-permission-releaseandroid11-mainline-os-statsd-releaseandroid11-mainline-networkstack-releaseandroid11-mainline-media-swcodec-releaseandroid11-mainline-media-releaseandroid11-mainline-extservices-releaseandroid11-mainline-documentsui-releaseandroid11-mainline-conscrypt-releaseandroid11-mainline-cellbroadcast-releaseandroid11-mainline-captiveportallogin-releaseandroid11-devandroid11-d2-releaseandroid11-d1-b-release
Change-Id: I3f25c7ee034b2e20e37ed941b8eae24eec7043eb
Diffstat (limited to 'deprecated/test_gdb_dejagnu.py')
-rwxr-xr-x | deprecated/test_gdb_dejagnu.py | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/deprecated/test_gdb_dejagnu.py b/deprecated/test_gdb_dejagnu.py new file mode 100755 index 00000000..6f37a4c9 --- /dev/null +++ b/deprecated/test_gdb_dejagnu.py @@ -0,0 +1,170 @@ +#!/usr/bin/env python2 +"""Script adapter used by automation client for testing dejagnu. + + This is not intended to be run on command line. + To kick off a single dejagnu run, use ./dejagnu/run_dejagnu.py +""" + +from __future__ import print_function + +import argparse +import sys +import setup_chromeos + +from dejagnu import gdb_dejagnu +from cros_utils import command_executer +from cros_utils import email_sender + + +class DejagnuAdapter(object): + """Dejagnu Adapter class.""" + + def __init__(self, board, remote, gdb_dir, chromeos_root, cleanup): + self._board = board + self._remote = remote + self._gdb_dir = gdb_dir + self._chromeos_root = chromeos_root + self._cleanup = cleanup + self._cmd_exec = command_executer.GetCommandExecuter() + + def SetupChromeOS(self): + cmd = [ + setup_chromeos.__file__, '--dir=' + self._chromeos_root, '--minilayout', + '--jobs=8' + ] + ret = setup_chromeos.Main(cmd) + if ret: + raise RuntimeError('Failed to checkout chromeos') + ## Do cros_sdk and setup_board, otherwise build_tc in next step will fail. + cmd = 'cd {0} && cros_sdk --download'.format(self._chromeos_root) + ret = self._cmd_exec.RunCommand(cmd, terminated_timeout=9000) + if ret: + raise RuntimeError('Failed to create chroot.') + + def SetupBoard(self): + cmd = 'setup_board --board=' + self._board + ret = self._cmd_exec.ChrootRunCommand( + self._chromeos_root, cmd, terminated_timeout=4000) + if ret: + raise RuntimeError('Failed to setup board.') + + def CheckGDB(self): + args = [ + gdb_dejagnu.__file__, '--board=' + self._board, + '--chromeos_root=' + self._chromeos_root, '--mount=' + self._gdb_dir, + '--remote=' + self._remote + ] + if self._cleanup: + args.append('--cleanup=' + self._cleanup) + return gdb_dejagnu.Main(args) + + +# Parse the output log to determine how many failures we have. +# Return -1 if parse output log failed. +def GetNumNewFailures(result): + if not result: + return 0 + return len(result) + + +# Do not throw any exception in this function! +def EmailResult(result): + email_to = ['yunlian@google.com'] + if len(result) == 4: + subject = 'Job failed: dejagnu test didn\'t finish' + email_text = ( + 'Job failed prematurely, check exception below.\n' + result[3]) + elif result[0]: + subject = 'Job finished: dejagnu test failed' + num_new_failures = GetNumNewFailures(result[1]) + if num_new_failures >= 0: + summary = '{0} new fail(s), check log below.'.format(num_new_failures) + else: + summary = 'At least 1 new fail found, check log below.' + email_text = (summary + ('\nStdout ====\n' + '{0}\n' + '\nStderr ===\n' + '{1}\n').format(result[1], result[2])) + else: + subject = 'Job finished: dejagnu test passed' + email_text = ('Cool! No new fail found.\n' + '\nStdout ====\n' + '{0}\n' + '\nStderr ====\n' + '{1}\n').format(result[1], result[2]) + + try: + email_sender.EmailSender().SendEmail(email_to, subject, email_text) + print('Email sent.') + except Exception as e: + # Do not propagate this email sending exception, you want to email an + # email exception? Just log it on console. + print('Sending email failed - {0}' + 'Subject: {1}' + 'Text: {2}').format(str(e), subject, email_text) + + +def ProcessArguments(argv): + """Processing script arguments.""" + parser = argparse.ArgumentParser( + description=('This script is used by nightly client to test gdb. ' + 'DO NOT run it unless you know what you are doing.'), + usage='test_gdb_dejagnu.py options') + parser.add_argument( + '-b', + '--board', + dest='board', + help=('Required. Specify board type. For example ' + '\'lumpy\' and \'daisy\'')) + parser.add_argument( + '-r', + '--remote', + dest='remote', + help=('Required. Specify remote board address')) + parser.add_argument( + '-g', + '--gdb_dir', + dest='gdb_dir', + default='', + help=('Optional. Specify gdb checkout directory.')) + parser.add_argument( + '-c', + '--chromeos_root', + dest='chromeos_root', + default='chromeos.live', + help=('Optional. Specify chromeos checkout directory.')) + parser.add_argument( + '--cleanup', + dest='cleanup', + default=None, + help=('Optional. Do cleanup after the test.')) + + options = parser.parse_args(argv) + + if not options.board or not options.remote: + raise SyntaxError('--board and --remote are mandatory options.') + + return options + + +def Main(argv): + opt = ProcessArguments(argv) + print(opt) + adapter = DejagnuAdapter(opt.board, opt.remote, opt.gdb_dir, + opt.chromeos_root, opt.cleanup) + try: + adapter.SetupChromeOS() + adapter.SetupBoard() + ret = adapter.CheckGDB() + except Exception as e: + print(e) + ret = (1, '', '', str(e)) + finally: + EmailResult(ret) + + return ret + + +if __name__ == '__main__': + retval = Main(sys.argv[1:]) + sys.exit(retval[0]) |