Beispiel #1
0
def DumpScreenOnOffLogs(WS):
    """ Dump screen on and off logs i.e display on off

    :param WS: Workspace object
    :return: True on sccess and False on failure
    """
    try:
        f_power_logs_buf = open(WS.file_power_logs, 'w+')
    except IOError as err:
        error = 'failed to create power log file : ' + str(err)
        util.PLOGE(TAG, error)

    try:
        f_event_logs_buf = open(WS.file_event_logs, 'r')
    except IOError as err:
        error = 'failed to read event log file : ' + str(err)
        util.PLOGE(TAG, error)

    util.PrintLogFileTitle(f_power_logs_buf, 'Power logs')
    f_power_logs_buf.write('--- Screen ON and OFF ---')
    f_power_logs_buf.write(util.get_empty_line())
    f_power_logs_buf.write(util.get_empty_line())

    for line in f_event_logs_buf:
        if pattr.screen_on.search(line) or \
                pattr.screen_off.search(line) :
            f_power_logs_buf.write(line)
    f_power_logs_buf.write(util.get_empty_line())

    f_power_logs_buf.close()
    f_event_logs_buf.close()
def ExtractLogs(WS):
    """Extract data files
    """
    try:
        f_bug_rpt = open(WS.file_bugreport, 'rU')
    except IOError as err:
        err_str = 'failed to open file : ' + \
                  WS.file_bugreport + '\n' + str(err)
        util.PLOGE(TAG, err_str)
        return False

    if not DumpBuildDetails(WS, f_bug_rpt):
        util.PLOGE(TAG, 'Failed to get build details')
    if not DumpUptime(WS, f_bug_rpt):
        util.PLOGE(TAG, 'Failed to get uptime logs')
    if not DumpKernelLogs(WS, f_bug_rpt):
        util.PLOGE(TAG, 'Failed to get kernel logs')
    if not DumpSystemLogs(WS, f_bug_rpt):
        util.PLOGE(TAG, 'Failed to get system logs')
    if not DumpEventLogs(WS, f_bug_rpt):
        util.PLOGE(TAG, 'Failed to get events logs')
    if not DumpRadioLogs(WS, f_bug_rpt):
        util.PLOGE(TAG, 'Failed to get radio logs')
    if not DumpVMtracesForNow(WS, f_bug_rpt):
        util.PLOGE(TAG, 'Failed to get VM traces for anr logs')
    if not DumpSysProp(WS, f_bug_rpt):
        util.PLOGE(TAG, 'Failed to get sys prop')
    if not DumpAccounts(WS, f_bug_rpt):
        util.PLOGE(TAG, 'failed to get account details')
    return True
Beispiel #3
0
def PrepareBugreportRawData():
    """Extract bugreport.zip if bugreport is in zip format
    """
    if not SetupWs():
        util.PLOGE(TAG, 'failed to setup ws', exit=False)
        return False

    is_unzip_required, error = util.IsUnzipRequired(OPT.zip_file)

    if error:
        util.PLOGE(
            TAG, 'bugreport file type wrong, expected TEXT or ZIP ', exit=False)
        return False

    if is_unzip_required:
        util.PLOGV(TAG, 'Extracting ... : ' + OPT.file_name)
        with zipfile.ZipFile(OPT.zip_file, 'r') as bug_zip:
            try:
                bug_zip.extractall(WS.dir_ws)
            except zipfile.BadZipfile:
                util.PLOGE(TAG, 'Badzipfile', exit=False)
                return False
            except zipfile.LargeZipFile:
                util.PLOGE(TAG, 'LargeZipFile', exit=False)
                return False
    return True
Beispiel #4
0
def DumpPowerLogs(WS):
    """Dump power logs

    :param WS: WorkSpace object
    :return: True on Success and False on Failure
    """
    try:
        f_power_logs_buf = open(WS.file_power_logs, 'a+')
    except IOError as err:
        error = 'failed to create power log file : ' + str(err)
        util.PLOGE(TAG, error)
        return False

    try:
        f_sys_logs_buf = open(WS.file_system_logs, 'r')
    except IOError as err:
        error = 'failed to read event log file : ' + str(err)
        util.PLOGE(TAG, error)
        return False

    try:
        f_kernel_logs_buf = open(WS.file_kernel_logs, 'r')
    except IOError as err:
        error = 'failed to read event log file : ' + str(err)
        util.PLOGE(TAG, error)
        return False

    f_power_logs_buf.write('--- PowerManager ---')
    f_power_logs_buf.write(util.get_empty_line())
    f_power_logs_buf.write(util.get_empty_line())

    for line in f_sys_logs_buf:
        if pattr.device_sys_sleep_power_button.search(line) or \
                pattr.device_sys_sleep_screen_timeout.search(line) or \
                pattr.device_sys_wake_up.search(line):
            f_power_logs_buf.write(line)
    f_power_logs_buf.write(util.get_empty_line())

    f_power_logs_buf.write('--- Kernel ---')
    f_power_logs_buf.write(util.get_empty_line())
    f_power_logs_buf.write(util.get_empty_line())

    for line in f_kernel_logs_buf:
        if pattr.device_kernel_sleep.search(line) or \
                pattr.device_sys_sleep_screen_timeout.search(line) or \
                pattr.device_kernel_wakeup.search(line):
            f_power_logs_buf.write(line)
    f_power_logs_buf.write(util.get_empty_line())

    f_power_logs_buf.close()
    f_sys_logs_buf.close()
    f_kernel_logs_buf.close()
    return True
Beispiel #5
0
def StartAnalysis():
    """Check prerequisites, extract required logs and start
    analysis"""

    # check cmd line args
    if not CheckPrerequisite():
        Usage()
        util.PLOGE(TAG, 'check prerequitsite failed', exit=True)
    if not PrepareBugreportRawData():
        util.PLOGE(TAG, 'Prepare bugreport data failed', exit=True)
    if not SetFilesPath():
        util.PLOGE(TAG, 'failed to set file path', exit=True)
    if not AnalyzeBugreport():
        util.PLOGE(TAG, 'Failed to analyze bugreport', exit=True)
def DumpAccounts(WS, file_buf):
    """Dump Account information
    """
    bool_start_dump = False
    try:
        f_accounts = open(WS.file_accounts, 'w+')
    except IOError as err:
        err_str = 'failed to create file : ' + WS.file_accounts + \
                  '\n' + str(err)
        util.PLOGE(TAG, err_str)
        return False

    f_accounts.write(util.get_line())
    f_accounts.write('--- Accounts ---\n')
    f_accounts.write(util.get_line())

    for line in file_buf:
        if bool_start_dump:
            f_accounts.write(line)
        if patt.start_accounts.search(line):
            bool_start_dump = True
        if patt.end_accounts.search(line):
            bool_start_dump = False
            break

    f_accounts.write(util.get_empty_line())
    f_accounts.close()
    return True
def DumpUptime(WS, file_buf):
    """Dump uptime
    """
    bool_start_dump = False
    try:
        f_other = open(WS.file_other, 'w+')
    except IOError as err:
        err_str = 'failed to create file : ' + WS.file_accounts + \
                  '\n' + str(err)
        util.PLOGE(TAG, err_str)
        return False

    f_other.write(util.get_line())
    f_other.write('--- Other ---\n')
    f_other.write(util.get_line())
    f_other.write(util.get_empty_line())

    for line in file_buf:
        if bool_start_dump:
            f_other.write(line)
        if patt.start_uptime.search(line):
            f_other.write(line)
            bool_start_dump = True
        if patt.end_uptime.search(line):
            bool_start_dump = False
            break

    f_other.write(util.get_empty_line())
    f_other.close()
    return True
def DumpKernelLogs(WS, file_buf):
    """Dump kernel logs
    """
    bool_start_dump = False
    try:
        f_kernel_logs = open(WS.file_kernel_logs, 'w+')
    except IOError as err:
        err_str = 'failed to create file : ' + WS.file_kernel_logs + \
                  '\n' + str(err)
        util.PLOGE(TAG, err_str)
        return False

    f_kernel_logs.write(util.get_line())
    f_kernel_logs.write('--- Kernel logs (dmesg) ---\n')
    f_kernel_logs.write(util.get_line())

    for line in file_buf:
        # print line,
        if bool_start_dump:
            f_kernel_logs.write(line)
        if patt.start_kernel_log.search(line):
            bool_start_dump = True
        if patt.end_kernel_log.search(line):
            bool_start_dump = False
            break

    f_kernel_logs.write(util.get_empty_line())
    f_kernel_logs.close()
    return True
def DumpVMtracesForNow(WS, file_buf):
    """Dump VM TRACES FOR NOW for anr
    """
    bool_start_dump = False
    try:
        f_other = open(WS.file_anr_logs, 'w+')
    except IOError as err:
        err_str = 'failed to create file : ' + WS.file_anr_logs + \
                  '\n' + str(err)
        util.PLOGE(TAG, err_str)
        return False

    f_other.write(util.get_line())
    f_other.write('--- VM TRACES FOR NOW for anr ---\n')
    f_other.write(util.get_line())
    f_other.write(util.get_empty_line())

    for line in file_buf:
        if bool_start_dump:
            f_other.write(line)
        if patt.start_anr_all.search(line):
            f_other.write(line)
            bool_start_dump = True
        if patt.end_anr_all.search(line):
            bool_start_dump = False
            break

    f_other.write(util.get_empty_line())
    f_other.close()
    return True
def DumpSystemLogs(WS, file_buf):
    """ Dump system logs
    """
    bool_start_dump = False
    try:
        f_sys_log_buf = open(WS.file_system_logs, 'w+')
    except IOError as err:
        err_str = 'failed to create file : ' \
                  + WS.file_system_logs + '\n' + str(err)
        util.PLOGE(TAG, err_str)
        return False
    f_sys_log_buf.write(util.get_line())
    f_sys_log_buf.write('--- System logs ---\n')
    f_sys_log_buf.write(util.get_line())

    for line in file_buf:
        if bool_start_dump:
            f_sys_log_buf.write(line)
        if patt.start_system_log.search(line):
            bool_start_dump = True
        if patt.end_system_log.search(line):
            bool_start_dump = False
            break
        # if bool_start_dump:
        #     f_sys_log_buf.write(line)

    f_sys_log_buf.write(util.get_line())
    f_sys_log_buf.close()
    return True
def DumpBuildDetails(WS, file_buf):
    """Dump build details
    """
    try:
        f_build_details = open(WS.file_build_details, 'w+')
    except IOError as err:
        err_str = 'failed to create file : ' + \
                  WS.file_build_details + '\n' + str(err)
        util.PLOGE(TAG, err_str)
        return False

    f_build_details.write(util.get_line())
    f_build_details.write('--- Build details ---\n')
    f_build_details.write(util.get_line())

    for line in file_buf:
        if patt.start_of_file.match(line):
            continue
        if patt.start_dumpsys_meminfo.search(line):
            break
        f_build_details.write(line)

    f_build_details.write(util.get_empty_line())
    f_build_details.close()
    return True
def DumpRadioLogs(WS, file_buf):
    """ Dump radio logs
    """
    bool_start_dump = False
    try:
        f_radio_logs = open(WS.file_radio_logs, 'w+')
    except IOError as err:
        err_str = 'failed to create file : ' + WS.file_radio_logs + \
                  '\n' + str(err)
        util.PLOGE(TAG, err_str)
        return False

    f_radio_logs.write(util.get_line())
    f_radio_logs.write('--- Radio logs ---\n')
    f_radio_logs.write(util.get_line())

    for line in file_buf:
        if bool_start_dump:
            f_radio_logs.write(line)
        if patt.start_radio_log.search(line):
            bool_start_dump = True
        if patt.end_radio_log.search(line):
            bool_start_dump = False
            break

    f_radio_logs.write(util.get_empty_line())
    f_radio_logs.close()
    return True
    def AvcLogs(WS):
        """FilterAvcLogs :
            filter avc denied
        """
        try:
            sys_log_buf = open(WS.file_event_logs, 'rU')
        except IOError as err:
            err_string = 'failed to read : ' + WS.file_system_logs + \
                         'error : ' + err
            util.PLOGE(TAG, err_string)
            return False

        try:
            f_tmp_avc = open(temp_avc_file, 'w+')
        except IOError:
            util.PLOGE(TAG, 'failed to create : ' + temp_avc_file)
            return False

        for line in sys_log_buf:
            if not AVC_PATTERN in line:
                continue
            if not DENIED_PATTERN in line:
                continue
            if COMM_PATTERN in line or NAME_PATTERN in line:
                f_tmp_avc.write(line)
                split_list = line.split()
                for word in split_list:
                    data = []
                    if 'comm=' in word or 'name=' in word:
                        data = word.split('=')
                        data[1] = data[1].strip('"')
                        if data[0] == 'comm':
                            if data[1] not in comm_list:
                                comm_list.append(data[1])
                        elif data[0] == 'name':
                            if data[1] not in name_list:
                                name_list.append(data[1])

                    if 'scontext=' in word:
                        data = word.split(':')
                        if data[2] not in scontext_list:
                            scontext_list.append(data[2])

        sys_log_buf.close()
        f_tmp_avc.close()
        return comm_list, scontext_list
Beispiel #14
0
def GetAppCrashes(WS):
    """Dump application crash logs

    :param WS: WorkSpace object
    :return: True on Success and False on Failure
    """
    try:
        f_system_log_buf = open(WS.file_system_logs, 'r')
    except IOError as err:
        errorString = "failed to read system logs " + \
                      str(err)
        util.PLOGE(errorString)
        return False

    try:
        f_app_crash_buf = open(WS.file_ws_system_app_crash, 'w+')
    except IOError as err:
        errorString = 'failed to create application crash log file ' + \
                      str(err)
        util.PLOGE(errorString)
        return False

    f_app_crash_buf.write(util.get_line())
    f_app_crash_buf.write("--- Application crash ---")
    f_app_crash_buf.write(util.get_empty_line())
    f_app_crash_buf.write(util.get_line())
    f_app_crash_buf.write(util.get_empty_line())
    found_crash = False
    for line in f_system_log_buf:
        if pattr.start_crash_application.search(line):
            found_crash = True
            f_app_crash_buf.write(util.get_empty_line())
            f_app_crash_buf.write(util.get_line())
        if pattr.end_crash_application.search(line):
            f_app_crash_buf.write(line)

    f_system_log_buf.close()
    f_app_crash_buf.close()

    if not found_crash:
        os.remove(WS.file_ws_system_app_crash)
        util.PLOGV(TAG, "Opps, No application crash")

    return True
Beispiel #15
0
def GetTempFile():
    """Create temp file and open it and return fd.
    """
    try:
        file_tmp = tmp.NamedTemporaryFile(delete=False)
    except IOError as err:
        util.PLOGE(TAG, "failed to create tmp file : " + err)
        return False
    util.PLOGV(TAG, str(file_tmp.name))
    return file_tmp.name
Beispiel #16
0
def SetupWs():
    """Setup workspace class object
    """
    WS.dir_out              = OPT.out
    WS.dir_ws               = OPT.out + '/' + util.dir_ws
    WS.dir_ws_analysis      = OPT.out + '/' + util.dir_ws_analysis
    WS.file_build_details   = OPT.out + '/' + util.file_ws_analysis_build_details
    WS.file_kernel_logs     = OPT.out + '/' + util.file_ws_analysis_kernel_logs
    WS.file_system_logs     = OPT.out + '/' + util.file_ws_analysis_sys_logs
    WS.file_event_logs      = OPT.out + '/' + util.file_ws_analysis_event_logs
    WS.file_radio_logs      = OPT.out + '/' + util.file_ws_analysis_radio_logs
    WS.file_sys_prop        = OPT.out + '/' + util.file_ws_analysis_sys_prop
    WS.file_devinfo         = OPT.out + '/' + util.file_ws_analysis_devinfo
    WS.file_avc_logs        = OPT.out + '/' + util.file_ws_analysis_avc_logs
    WS.file_power_logs      = OPT.out + '/' + util.file_ws_analysis_power_logs
    WS.file_accounts        = OPT.out + '/' + util.file_ws_analysis_accounts_logs
    WS.file_other           = OPT.out + '/' + util.file_ws_analysis_other_logs

    # anr logs
    WS.dir_FS_data_anr      = OPT.out + '/' + util.dir_ws_FS_data_anr
    WS.dir_analysis_anr     = OPT.out + '/' + util.dir_ws_analysis_anr
    WS.file_anr_logs        = OPT.out + '/' + util.file_ws_analysis_anr_logs


    # events logs
    WS.dir_ws_analysis_events           = OPT.out + '/' + util.dir_ws_analysis_events
    WS.file_ws_events_JP_data           = OPT.out + '/' + util.file_ws_events_JP_data
    WS.file_ws_events_am_proc_start     = OPT.out + '/' + util.file_ws_events_am_proc_start
    WS.file_ws_events_am_proc_bound     = OPT.out + '/' + util.file_ws_events_am_proc_bound
    WS.file_ws_events_am_proc_died      = OPT.out + '/' + util.file_ws_events_am_proc_died
    WS.dir_ws_analysis_bypid            = OPT.out + '/' + util.dir_ws_analysis_bypid

    # system logs
    WS.file_ws_system_native_crash      = OPT.out + '/' + util.file_ws_system_native_crash
    WS.file_ws_system_app_crash         = OPT.out + '/' + util.file_ws_system_app_crash
    WS.file_ws_system_anr               = OPT.out + '/' + util.file_ws_system_anr

    # report
    WS.file_analysis_rpt                = OPT.out + '/' + util.file_ws_analysis_rpt

    try:
        if os.path.exists(WS.dir_out):
            shutil.rmtree(WS.dir_out)
        os.makedirs(WS.dir_out)
        os.makedirs(WS.dir_ws)
        os.makedirs(WS.dir_ws_analysis)
        os.makedirs(WS.dir_ws_analysis_events)
        os.makedirs(WS.dir_ws_analysis_bypid)
        os.makedirs(WS.dir_analysis_anr)

    except os.error as err:
        util.PLOGE(TAG, str(err), exit=False)
        return False
    return True
Beispiel #17
0
def GetFileWithFilterData(src_file, pattr):
    """ Filter file data with given pattern
    :param src_file: file to be filter
    :param pattr: filter pattern
    :return: filtered content in file format
    """
    temp_file = GetTempFile()
    if not temp_file:
        util.PLOGE(TAG, 'failed to get tmp file ')
        return False
    try:
        f_outfile = open(temp_file, 'w+')
    except Exception as err:
        util.PLOGE(TAG, "failed to create file :  " + str(err))
        return False
    with open(src_file, 'rU') as f_event_log:
        for line in f_event_log:
            if not pattr.search(line):
                continue
            f_outfile.write(line)
        f_event_log.close()
    f_outfile.close()
    return temp_file
Beispiel #18
0
    def WriteToFile(file, buf):
        """Write given buffer to given file

        :param file: File name
        :param buf: data to be write
        :return: True on Success and False on Failure
        """
        try:
            f_buf = open(file, 'a+')
        except IOError as err:
            util.PLOGE(TAG, 'failed write file : ' + str(err))
            return False
        f_buf.write(buf)
        f_buf.close()
        return True
Beispiel #19
0
def main():
    # Parse args
    if not ParseArgument(sys.argv):
        util.PLOGE(TAG, 'parse argument failed', exit=True)

    # start analysis
    StartAnalysis()

    # Generate report
    GenReport()

    # Dump file links to terminal
    DumpAnalysisPaths()

    time_str = "--- %s seconds ---" % (time.time() - start_time)
    util.PLOGD(TAG,time_str)
Beispiel #20
0
def DumpAnrForPid(WS, pid, pid_name):
    """Dump VM TRACES for given pid and pid_name

    :param WS: Workspace object
    :param pid: pid number
    :param pid_name: process name
    :return: True on Success and False on Failure
    """
    filename = WS.dir_analysis_anr + '/' + pid + '_' + pid_name
    try:
        f_pid_anr = open(filename, 'w+')
    except IOError as err:
        errorString = 'failed to create anr log file ' + \
                     filename + ' ' + str(err)
        util.PLOGE(errorString)
        return False

    patt_start = re.compile("----- pid " + pid)
    patt_end = re.compile("----- end " + pid)
    isTraceFound = False
    with open(WS.file_anr_logs, 'r') as anr_logs:
        bool_start_dump = None
        for line in anr_logs:
            if bool_start_dump:
                f_pid_anr.write(line)
            if patt_start.search(line):
                f_pid_anr.write(line)
                isTraceFound = True
                bool_start_dump = True
            if patt_end.search(line):
                bool_start_dump = False
                break
        anr_logs.close()
    f_pid_anr.close()

    if not isTraceFound:
        os.remove(filename)
        return False

    return True
def DumpDevinfo(WS, dict_devinfo):
    """Dump device information
    """
    try:
        f_devinfo = open(WS.file_devinfo, 'w+')
    except IOError as err:
        err_str = 'failed to create file : ' + WS.file_devinfo + \
                  str(err)
        util.PLOGE(TAG, err_str)
        return False

    f_devinfo.write(util.get_line())
    f_devinfo.write('--- devinfo ---\n')
    f_devinfo.write(util.get_line())

    for item in dict_devinfo:
        f_devinfo.write(util.get_empty_line())
        f_devinfo.write(dict_devinfo[item])

    f_devinfo.write(util.get_empty_line())
    f_devinfo.close()
    return True
Beispiel #22
0
def CheckPrerequisite():
    """Validate commandline args and check prerequisite
    """
    if not OPT.file_name:
        util.PLOGE(TAG,'bug report file not given in termial command line ')
        return False

    if not OPT.out:
        util.PLOGE(TAG,'out dir not givent in terminal command line')
        return False

    patt_out = re.compile(r'^[.]')
    if patt_out.search(OPT.out):
        util.PLOGE(TAG,'out dir is a current or previous dir. please give name for dir')
        return False

    file_path = os.path.dirname(os.path.realpath(OPT.file_name))
    util.PLOGV(TAG,'file : ' + file_path )
    util.PLOGV(TAG,'out  : ' + os.path.realpath(OPT.out))

    if file_path == os.path.realpath(OPT.out):
        util.PLOGE(TAG,'out dir and file is in same dir. please give different dir')
        return False


    OPT.zip_file = os.path.abspath(OPT.file_name)
    if not os.path.isfile(OPT.zip_file):
        util.PLOGE(TAG, 'File not found or is not a file : ',
                   OPT.zip_file, exit=False)
        return False

    is_unzip_required, error = util.IsUnzipRequired(OPT.zip_file)

    if error:
        util.PLOGE(
            TAG, 'bugreport file type wrong, expected TEXT or ZIP ', exit=False)
        return False
    else:
        util.PLOGV(TAG,'bugreport zip file found : ' + str(is_unzip_required))

    return True
Beispiel #23
0
def GetAppAnr(WS):
    """Dump application ANR logs

    :param WS: WorkSpace object
    :return: True on Success and False on Failure
    """
    anr_pid_dict = {}
    try:
        f_system_log_buf = open(WS.file_system_logs, 'r')
    except IOError as err:
        errorString = "failed to read system logs " + \
                      str(err)
        util.PLOGE(errorString)
        return False

    try:
        f_app_anr_buf = open(WS.file_ws_system_anr, 'w+')
    except IOError as err:
        errorString = 'failed to create application anr log file ' + \
                      str(err)
        util.PLOGE(errorString)
        return False

    f_app_anr_buf.write(util.get_line())
    f_app_anr_buf.write("--- Application ANR ---")
    f_app_anr_buf.write(util.get_empty_line())
    f_app_anr_buf.write(util.get_line())
    f_app_anr_buf.write(util.get_empty_line())
    found_crash = False

    pid_number = None
    process_name = None
    for line in f_system_log_buf:
        if pattr.start_anr_application.search(line):
            process_words = line.split(' E ')
            process_name = process_words[1].split().pop(3)
            found_crash = True
            f_app_anr_buf.write(util.get_empty_line())
            f_app_anr_buf.write(util.get_line())
        if found_crash and pattr.end_anr_application.search(line):
            if re.compile(r'ActivityManager: PID:').search(line):
                word_list = line.split()
                pid_number = word_list[len(word_list) - 1]
                anr_pid_dict[pid_number] = process_name
                pid_number = None
                process_name = None
            f_app_anr_buf.write(line)

    f_system_log_buf.close()
    f_app_anr_buf.close()

    if not found_crash:
        os.remove(WS.file_ws_system_anr)
        util.PLOGV(TAG, "Opps, No application ANR")

    for pid, pid_name in anr_pid_dict.iteritems():
        if (pid and pid_name) is None:
            continue

        if not DumpAnrForPid(WS, pid, pid_name):
            util.PLOGE(TAG,"Failed to get or not found ANR traces for : " + \
                       str(pid) + ' - ' + str(pid_name))

    return True
def GenReport(WS):
    """Create text report

    :param WS: WorkSpace object
    :return: True on Success and False on Failure
    """
    try:
        mFile_rpt_buf = open(WS.file_analysis_rpt, 'w+')
    except IOError as err:
        errstring = 'failed to create file ' + WS.file_analysis_rpt \
                    + ' Err: ' + str(err)
        util.PLOGE(errstring)
        return False

    def WriteReportTitle():
        mFile_rpt_buf.write(util.get_line())
        mFile_rpt_buf.write('BUGREPORT ANALYSIS')
        mFile_rpt_buf.write(util.get_empty_line())
        mFile_rpt_buf.write(util.get_line())
        mFile_rpt_buf.write(util.get_empty_line())
        mFile_rpt_buf.write(util.get_empty_line())

    def PreapreTitle(title):
        return title + ' ' * (30 - len(title)) + ': '

    def WriteTitleAndValue(title, value):
        mFile_rpt_buf.write(str(PreapreTitle(title)))
        mFile_rpt_buf.write(str(value))
        mFile_rpt_buf.write(util.get_empty_line())

    def WriteBugID():
        WriteTitleAndValue('Bug ID', util.OPT.bug_num)

    def WriteBugTitle():
        WriteTitleAndValue('Bug title', util.OPT.bug_title)

    def WriteDevEngineer():
        WriteTitleAndValue('Dev Enginner', util.OPT.dev_name)

    def WriteTestEngineer():
        WriteTitleAndValue('Test Enginner', util.OPT.tester_name)

    def WriteBuildDetails():
        build_id = None
        with open(WS.file_build_details, 'r') as build:
            for line in build:
                if re.compile(r'Build:').search(line):
                    build_id = line.split(':').pop(1)
                    break
        build.close()
        WriteTitleAndValue('Build ID', build_id[1:])

    def WriteDeviceDetails():
        WriteTitleAndValue('Device info', '--->>>')
        with open(WS.file_devinfo, 'r') as device:
            for line in device:
                if re.compile(r'Device ').search(line):
                    keyValue = line.split(': ')
                    mFile_rpt_buf.write(keyValue[0].strip())
                    mFile_rpt_buf.write(
                        str(' ' * (30 - len(keyValue[0].strip()))))
                    mFile_rpt_buf.write(': ')
                    mFile_rpt_buf.write(keyValue[1])
        device.close()

    def WriteDeviceOwnerAndAccount():
        user = None
        acc_list = []
        with open(WS.file_accounts, 'r') as system:
            for line in system:
                email_match = re.search(r'([\w.-]+)@([\w.-]+)', line)
                if email_match:
                    if email_match.group() not in acc_list:
                        acc_list.append(email_match.group())
                if re.compile(r'UserInfo').search(line):
                    user = line.split(':')[1]
        WriteTitleAndValue('Device owner', user)
        WriteTitleAndValue('Device Accounts', '--->>>')
        for account in acc_list:
            mFile_rpt_buf.write((' ' * 32) + account)
            mFile_rpt_buf.write(util.get_empty_line())

        system.close()

    def WriteUptime():
        uptime = None
        uptime_found = False
        with open(WS.file_other, 'r') as other:
            for line in other:
                if uptime_found:
                    uptime = line.split(',').pop(0).strip()
                    break
                if pattr.start_uptime.search(line):
                    uptime_found = True

        WriteTitleAndValue('Up time', uptime)
        other.close()

    def WriteNetwork():
        network = None
        with open(WS.file_build_details, 'r') as build:
            for line in build:
                if re.compile(r'Network:').search(line):
                    network = line.split(':').pop(1)
                    break
        build.close()
        WriteTitleAndValue('Network', network[1:])

    def WriteNativeCrash():
        native_crash = False
        native_crash_list = []
        cont = False
        if os.path.exists(WS.file_ws_system_native_crash):
            with open(WS.file_ws_system_native_crash) as native_crash_buf:
                for line in native_crash_buf:
                    if cont or re.compile('F DEBUG   : pid:').search(line):
                        native_crash = True
                        cont = True
                        native_crash_list.append(line)
                    if re.compile('F DEBUG   : Abort message:').search(line):
                        native_crash_list.append('#')
                        cont = False
                WriteTitleAndValue('Native crash', '--->>>')
                mFile_rpt_buf.write(util.get_line())

                for item in native_crash_list:
                    if item == '#':
                        mFile_rpt_buf.write(util.get_empty_line())
                        continue
                    mFile_rpt_buf.write(item)

                native_crash_buf.close()

        if not native_crash:
            WriteTitleAndValue('Native crash', 'None')
            mFile_rpt_buf.write(util.get_line())
            return

    def WriteApplicationCrash():
        app_crash = None
        app_crash_list = []
        cont = False
        if os.path.exists(WS.file_ws_system_app_crash):
            with open(WS.file_ws_system_app_crash) as app_crash_buf:
                for line in app_crash_buf:
                    if cont or re.compile(
                            'E AndroidRuntime: FATAL EXCEPTION:').search(line):
                        app_crash = True
                        cont = True
                        app_crash_list.append(line)
                    if re.compile('E AndroidRuntime: android.os.').search(line) or \
                            re.compile('E AndroidRuntime: java.lang.').search(line):
                        app_crash_list.append('#')
                        cont = False

            WriteTitleAndValue('Application crash', '--->>>')
            mFile_rpt_buf.write(util.get_line())

            if app_crash is not None:
                for item in app_crash_list:
                    if item == '#':
                        mFile_rpt_buf.write(util.get_empty_line())
                        continue
                    mFile_rpt_buf.write(item)

            app_crash_buf.close()

        if app_crash is None:
            WriteTitleAndValue('Application crash', app_crash)
            mFile_rpt_buf.write(util.get_line())
            return

    def WriteApplicationAnr():
        app_anr = None
        app_anr_list = []
        cont = False
        if os.path.exists(WS.file_ws_system_anr):
            with open(WS.file_ws_system_anr) as app_anr_buf:
                for line in app_anr_buf:
                    if cont or re.compile('E ActivityManager: ANR in ').search(
                            line):
                        app_anr = True
                        cont = True
                        app_anr_list.append(line)
                    if re.compile('E ActivityManager: Reason: ').search(line):
                        app_anr_list.append('#')
                        cont = False

            WriteTitleAndValue('Application ANR', '--->>>')
            mFile_rpt_buf.write(util.get_line())

            if app_anr is not None:
                for item in app_anr_list:
                    if item == '#':
                        mFile_rpt_buf.write(util.get_empty_line())
                        continue
                    mFile_rpt_buf.write(item)

            app_anr_buf.close()

        if app_anr is None:
            WriteTitleAndValue('Application ANR', app_anr)
            mFile_rpt_buf.write(util.get_line())
            return

    # Create report
    WriteReportTitle()
    # WriteBugID()
    WriteBugTitle()
    WriteDevEngineer()
    WriteTestEngineer()
    WriteBuildDetails()
    WriteDeviceDetails()
    WriteDeviceOwnerAndAccount()
    WriteUptime()
    WriteNetwork()
    WriteNativeCrash()
    WriteApplicationCrash()
    WriteApplicationAnr()
    return True
Beispiel #25
0
def FilterByTagInFilesList(WS):
    """Extract the event log tags and create file of each tag
    with filtered data by that tag

    :param WS: workspace object
    :return: List of tags in event log
    """
    def GetTag(tag, line):
        """ Fill tag object from line content

        :param tag: Tag class object
        :param line: event log line
        :return: None
        """
        if not line:
            return False
        list_raw_words = str(line).split(': ')
        list_words = list_raw_words[0].split()
        tag.date = list_words[0]
        tag.time = list_words[1]
        tag.log_uid = list_words[2]
        tag.log_pid = list_words[3]
        tag.log_tid = list_words[4]
        tag.log_level = list_words[5]
        tag.tag_name = list_words[6]
        return True

    def WriteToFile(file, buf):
        """Write given buffer to given file

        :param file: File name
        :param buf: data to be write
        :return: True on Success and False on Failure
        """
        try:
            f_buf = open(file, 'a+')
        except IOError as err:
            util.PLOGE(TAG, 'failed write file : ' + str(err))
            return False
        f_buf.write(buf)
        f_buf.close()
        return True

    # Get list tag from event log
    list_tag = []
    list_tag_files = []
    try:
        f_buf = open(WS.file_event_logs, 'rU')
    except IOError as err:
        util.PLOGE(TAG, 'failed read file : ' + str(err))
        return False

    # skip title lines
    for each in [1, 2, 3]:
        f_buf.readline()

    for line in f_buf:
        if pattr.end_event_log.search(line):
            break
        mTag = bugClasses.Tag()
        # get the tag
        if not GetTag(mTag, line):
            util.PLOGE(TAG, 'failed to get tag', exit=False)
            return False

        if not mTag.tag_name in list_tag:
            list_tag.append(str(mTag.tag_name))

        if not mTag.tag_name in list_tag:
            continue

        # Create file with tag name
        file_name = os.path.abspath(WS.dir_ws_analysis_events + '/' +
                                    str(mTag.tag_name))
        if not file_name in list_tag_files:
            list_tag_files.append(file_name)

        if not WriteToFile(file_name, line):
            continue

    f_buf.close()
    return list_tag_files
Beispiel #26
0
def FilterByPid(WS):
    """ Filter event logs by PID from am_start_proc filter

    :param WS: WorkSpace object
    :return:True on success and False on Failure
    """
    tmpfile = filter.GetFileWithFilterData(WS.file_event_logs,
                                           pattr.am_proc_start)
    if (not tmpfile) or not (os.path.isfile(tmpfile)):
        util.PLOGE(TAG, 'failed to set filter')
        return False

    try:
        f_buf = open(tmpfile, 'r')
    except IOError as err:
        util.PLOGE(TAG, 'failed to read file : ' + str(err))
        return False

    try:
        f_event_aps_buf = open(WS.file_ws_events_am_proc_start, 'w+')
    except IOError as err:
        util.PLOGE(TAG, 'failed to read file : ' + str(err))
        return False

    process_data_aps_title = '##log_timestamp user pid uid name p_typ component data_aps'
    f_event_aps_buf.write(process_data_aps_title)
    f_event_aps_buf.write(util.get_empty_line())

    # get all pid list from am_proc_start
    unwanted = re.compile(r'^[[]+')
    unwanted_1 = re.compile(r'[]\n]+$')
    list_jp_pid = []

    for line_am_proc_start in f_buf:
        JP = util.JavaProcess()
        list_am_proc_start = str(line_am_proc_start).split(': ')
        list_aps_process_data = str(list_am_proc_start[1]).split(',')
        list_aps_time_data = str(list_am_proc_start[0]).split()

        for idx, item in enumerate(list_aps_process_data):
            if unwanted.search(item):
                list_aps_process_data[idx] = str(item).strip('[')
            if unwanted_1.search(item):
                list_aps_process_data[idx] = str(item).strip(']\n')

        JP.log_timestamp = str(list_aps_time_data[0]) + '_' + str(
            list_aps_time_data[1])
        JP.user = list_aps_process_data[0]
        JP.pid = list_aps_process_data[1]
        JP.uid = list_aps_process_data[2]
        JP.name = list_aps_process_data[3]
        JP.p_type = list_aps_process_data[4]
        JP.component = list_aps_process_data[5]

        process_data_aps =  str(JP.log_timestamp) +  ' ' + \
                            str(JP.user) + ' ' + \
                            str(JP.pid) + ' ' + \
                            str(JP.uid) + ' ' + \
                            ' '* (6 - len(JP.uid)) + \
                            str(JP.name) + ' ' + \
                            ' '* (50 - len(JP.name)) + \
                            str(JP.p_type) + ' ' + \
                            ' '* (20 - len(JP.p_type)) + \
                            str(JP.component)
        # print process_data_aps
        f_event_aps_buf.write(process_data_aps)
        f_event_aps_buf.write(util.get_empty_line())

        set_warning = None
        if not JP.pid in list_jp_pid:
            list_jp_pid.append(JP.pid)
        else:
            util.PLOGV(TAG, "The duplicate pid found : " + str(JP.pid))
            set_warning = True
            list_jp_pid.append(JP.pid)

        pid_dir_name = WS.dir_ws_analysis_bypid + '/' + JP.pid
        file_jp_pid_events = pid_dir_name + '/' + 'events_' + JP.pid + '.txt'

        if not os.path.exists(pid_dir_name):
            os.makedirs(pid_dir_name)

        #Open main events file and check for current JP.pid
        util.PLOGV(TAG, " dump event data for : " + pid_dir_name)
        try:
            f_event_buf = open(WS.file_event_logs, 'rU')
        except IOError as err:
            error_str = 'failed to read event file for pid : ' + \
                        JP.pid  + '\n' + str(err)
            util.PLOGE(TAG, error_str)
            return False

        try:
            f_jp_pid_events = open(file_jp_pid_events, 'a+')
        except IOError as err:
            error_str = 'failed to create file_jp_pid_events file for pid : ' + \
                        JP.pid  + '\n' + str(err)
            util.PLOGE(TAG, error_str)
            return False
        if set_warning:
            msg_warn_L1 = "Warning *********************************************************** \n"
            msg_warn_L2 = "Warning ** The " + JP.pid + " might be dumplicate please check *** \n"
            msg_warn_L3 = "Warning *********************************************************** \n"
            util.PLOGV(TAG, msg_warn_L1)
            util.PLOGV(TAG, msg_warn_L2)
            util.PLOGV(TAG, msg_warn_L3)

            f_jp_pid_events.write(msg_warn_L1 + msg_warn_L2 + msg_warn_L3)
            set_warning = None
            msg_warn_L1 = None
            msg_warn_L2 = None
            msg_warn_L3 = None

        #skip title lines
        for each in [1, 2, 3]:
            f_event_buf.readline()

        for event_line in f_event_buf:
            if pattr.end_event_log.search(event_line):
                break
            mTag = evntClasses.Tag()
            if not GetEventTag(mTag, event_line):
                continue
            if not IsLineContainPid(JP.pid, event_line):
                continue
            f_jp_pid_events.write(event_line)
        f_event_buf.close()

    f_buf.close()
    f_event_aps_buf.close()
    util.clean_me(tmpfile)
def DumpSysProp(WS, file_buf):
    """Dump system properties
    """
    def get_prop_val(prop):
        list_prop_val = str(prop).split(': [')
        # print list_prop_val
        return list_prop_val[1].strip('\n').strip(']')

    bool_start_dump = False

    try:
        f_sys_prop = open(WS.file_sys_prop, 'w+')
    except IOError as err:
        err_str = 'failed to create file : ' + WS.file_sys_prop + \
                  str(err)
        util.PLOGE(TAG, err_str)
        return False

    f_sys_prop.write(util.get_line())
    f_sys_prop.write('--- system properties ---\n')
    f_sys_prop.write(util.get_line())

    for line in file_buf:
        if bool_start_dump:
            f_sys_prop.write(line)

        if patt.start_sys_properties.search(line):
            bool_start_dump = True

        if patt.end_sys_properties.search(line):
            bool_start_dump = False
            break

    f_sys_prop.write(util.get_empty_line())
    f_sys_prop.close()

    # dump device info at runtime

    try:
        f_sys_prop = open(WS.file_sys_prop, 'r')
    except IOError as err:
        err_str = 'failed to read file : ' + WS.file_sys_prop + str(err)
        util.PLOGE(TAG, err_str)
        return False
    dict_devinfo = {
        'device_product_name': '',
        'device_factory_serial_num': '',
        'device_hw_serial_num': '',
        'device_build_id': '',
        'device_build_fingerprint': '',
        'device_build_date': '',
        'device_kernel_build_date': '',
        'device_kernel_build_user': '',
        'device_mpss_baseband1_build': '',
        'device_mpss_baseband_build': '',
        'device_gms_build': '',
        'device_kernel_build_user': '',
        'device_security_patch_level': '',
        'device_slot_suffix': ''
    }

    for line in f_sys_prop:
        if patt.device_product_name.search(line):
            dict_devinfo[
                'device_product_name'] = 'Device product name                 : ' + get_prop_val(
                    line)
        elif patt.device_factory_serial_num.search(line):
            dict_devinfo[
                'device_factory_serial_num'] = 'Device factory serial number        : ' + get_prop_val(
                    line)
        elif patt.device_hw_serial_num.search(line):
            dict_devinfo[
                'device_hw_serial_num'] = 'Device hardware serial number name  : ' + get_prop_val(
                    line)
        elif patt.device_build_id.search(line):
            dict_devinfo[
                'device_build_id'] = 'Device build id                     : ' + get_prop_val(
                    line)
        elif patt.device_build_fingerprint.search(line):
            dict_devinfo[
                'device_build_fingerprint'] = 'Device build fingerprint            : ' + get_prop_val(
                    line)
        elif patt.device_build_date.search(line):
            dict_devinfo[
                'device_build_date'] = 'Device build date                   : ' + get_prop_val(
                    line)
        elif patt.device_kernel_build_date.search(line):
            dict_devinfo[
                'device_kernel_build_date'] = 'Device kernel build date            : ' + get_prop_val(
                    line)
        elif patt.device_kernel_build_user.search(line):
            dict_devinfo[
                'device_kernel_build_user'] = '******' + get_prop_val(
                    line)
        elif patt.device_mpss_baseband1_build.search(line):
            dict_devinfo[
                'device_mpss_baseband1_build'] = 'Device mpss baseband1 build         : ' + get_prop_val(
                    line)
        elif patt.device_mpss_baseband_build.search(line):
            dict_devinfo[
                'device_mpss_baseband_build'] = 'Device mpss baseband build          : ' + get_prop_val(
                    line)
        elif patt.device_gms_build.search(line):
            dict_devinfo[
                'device_gms_build'] = 'Device gms build                    : ' + get_prop_val(
                    line)
        elif patt.device_kernel_build_user.search(line):
            dict_devinfo[
                'device_kernel_build_user'] = '******' + get_prop_val(
                    line)
        elif patt.device_security_patch_level.search(line):
            dict_devinfo[
                'device_security_patch_level'] = 'Device product name                 : ' + get_prop_val(
                    line)
        elif patt.device_slot_suffix.search(line):
            dict_devinfo[
                'device_slot_suffix'] = 'Device product name                 : ' + get_prop_val(
                    line)
        else:
            continue

    f_sys_prop.close()

    util.PLOGV(TAG, dict_devinfo['device_product_name'])
    util.PLOGV(TAG, dict_devinfo['device_factory_serial_num'])
    util.PLOGV(TAG, dict_devinfo['device_hw_serial_num'])
    util.PLOGV(TAG, dict_devinfo['device_build_id'])
    util.PLOGV(TAG, dict_devinfo['device_build_fingerprint'])
    util.PLOGV(TAG, dict_devinfo['device_build_date'])
    util.PLOGV(TAG, dict_devinfo['device_kernel_build_date'])
    util.PLOGV(TAG, dict_devinfo['device_kernel_build_user'])
    util.PLOGV(TAG, dict_devinfo['device_mpss_baseband1_build'])
    util.PLOGV(TAG, dict_devinfo['device_mpss_baseband_build'])
    util.PLOGV(TAG, dict_devinfo['device_gms_build'])
    util.PLOGV(TAG, dict_devinfo['device_kernel_build_user'])
    util.PLOGV(TAG, dict_devinfo['device_security_patch_level'])
    util.PLOGV(TAG, dict_devinfo['device_slot_suffix'])

    if not DumpDevinfo(WS, dict_devinfo):
        util.PLOGE(TAG, 'Failed to dump devinfo')

    return True
Beispiel #28
0
def GenReport():
    """Generate tiny text analysis report
    """
    if not rpt.GenReport(WS):
        util.PLOGE(TAG,'failed to get report', exit=True)