How to use gdb_report method in autotest

Best Python code snippet using autotest_python

crash_handler.py

Source:crash_handler.py Github

copy

Full Screen

...43 f.write(data)44 finally:45 f.close()46 if report:47 gdb_report(filename)48 return filename49def get_results_dir_list(pid, core_dir_basename):50 """51 Get all valid output directories for the core file and the report. It works52 by inspecting files created by each test on /tmp and verifying if the53 PID of the process that crashed is a child or grandchild of the autotest54 test process. If it can't find any relationship (maybe a daemon that died55 during a test execution), it will write the core file to the debug dirs56 of all tests currently being executed. If there are no active autotest57 tests at a particular moment, it will return a list with ['/tmp'].58 @param pid: PID for the process that generated the core59 @param core_dir_basename: Basename for the directory that will hold both60 the core dump and the crash report.61 """62 pid_dir_dict = {}63 for debugdir_file in glob.glob("/tmp/autotest_results_dir.*"):64 a_pid = os.path.splitext(debugdir_file)[1]65 results_dir = open(debugdir_file).read().strip()66 pid_dir_dict[a_pid] = os.path.join(results_dir, core_dir_basename)67 results_dir_list = []68 # If a bug occurs and we can't grab the PID for the process that died, just69 # return all directories available and write to all of them.70 if pid is not None:71 while pid > 1:72 if pid in pid_dir_dict:73 results_dir_list.append(pid_dir_dict[pid])74 pid = get_parent_pid(pid)75 else:76 results_dir_list = pid_dir_dict.values()77 return (results_dir_list or78 pid_dir_dict.values() or79 [os.path.join("/tmp", core_dir_basename)])80def get_info_from_core(path):81 """82 Reads a core file and extracts a dictionary with useful core information.83 Right now, the only information extracted is the full executable name.84 @param path: Path to core file.85 """86 full_exe_path = None87 output = commands.getoutput('gdb -c %s batch' % path)88 path_pattern = re.compile("Core was generated by `([^\0]+)'", re.IGNORECASE)89 match = re.findall(path_pattern, output)90 for m in match:91 # Sometimes the command line args come with the core, so get rid of them92 m = m.split(" ")[0]93 if os.path.isfile(m):94 full_exe_path = m95 break96 if full_exe_path is None:97 syslog.syslog("Could not determine from which application core file %s "98 "is from" % path)99 return {'full_exe_path': full_exe_path}100def gdb_report(path):101 """102 Use GDB to produce a report with information about a given core.103 @param path: Path to core file.104 """105 # Get full command path106 exe_path = get_info_from_core(path)['full_exe_path']107 basedir = os.path.dirname(path)108 gdb_command_path = os.path.join(basedir, 'gdb_cmd')109 if exe_path is not None:110 # Write a command file for GDB111 gdb_command = 'bt full\n'112 write_to_file(gdb_command_path, gdb_command)113 # Take a backtrace from the running program114 gdb_cmd = ('gdb -e %s -c %s -x %s -n -batch -quiet' %...

Full Screen

Full Screen

whole_code.py

Source:whole_code.py Github

copy

Full Screen

1#!/usr/bin/env python2# coding: utf-83# In[88]:4import numpy as np5import pandas as pd6import json7import requests8# import sys9# import io10# ## set the http-headers11# In[89]:12ua="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36" 13headers={"User-Agent":ua} #environment setting14# 15# In[90]:16reviews=[]17scores=[]18scoresd={}19def get_review_content(baseurl,start,end):20 21 for i in range(start,end,10):22 url=baseurl + "&start={}".format(i)23 resp = requests.get(url,headers=headers)24 jsnStr=json.loads(resp.text)25 if(len(jsnStr['reviews'])==0):26 print("no more comments, stopping")27 break28 for review in jsnStr['reviews']:29 text=review['comment']['text']30 score=review["rating"]31 #print(json.dumps(review,indent=2))32 text=text.replace("&#39;","_").replace("<br>","")33 reviews.append(text)34 scores.append(score)35 if(score not in scoresd):36 scoresd[score]=037 scoresd[score]+=138 return 'crawling finished'39# In[91]:40burl="https://www.yelp.com/biz/FH978pIP1TLRuPAH-MbWIQ/review_feed?rl=en&q=&sort_by=rating_asc"41burl2="https://www.yelp.com/biz/EGS6y6WsPkNs8PZ2X6bHOA/review_feed?rl=en&q=&sort_by=relevance_desc"42get_review_content(burl2,0,1000)43# In[92]:44# # take a look on example data45example_index=046print("review: {}".format(reviews[example_index]))47print("score: {}".format(scores[example_index]))48print(scoresd) # see how the score distributed49# In[108]:50from sklearn.feature_extraction.text import CountVectorizer51from sklearn.feature_extraction.text import TfidfVectorizer52# vectorizer = CountVectorizer(max_df=0.8,min_df=0.15)53vectorizer = TfidfVectorizer(max_df=0.8,min_df=0.15)54vectorizer.fit(reviews)55X=vectorizer.transform(reviews)#result in sparse matrix56# In[94]:57y=[] # if score less or equal to 3, we will assign it to 0 which mean bad review,otherwise we will assign it to 1 which means good review58for i in range(len(scores)):59 if(scores[i]<=3):60 y.append(0)61 else:62 y.append(1)63# In[95]:64print(X.todense()[0])65print('----')66print(X[0])67print(X.shape)68print(reviews[0])69print(len(reviews))70print(len(reviews[0]))71print(vectorizer.get_feature_names())72print(len(y))73# In[96]:74from sklearn.model_selection import train_test_split75X_train,X_test,y_train,y_test = train_test_split(X.todense(),y,test_size=0.21,random_state=42) #split the data to train set and test set76print(X_train.shape)77print(X_test.shape)78print(y_test)79# In[97]:80from sklearn.linear_model import LogisticRegression81model = LogisticRegression()82model.fit(X_train, y_train)83print("training done.")84# In[98]:85y_pred = model.predict(X_test)86print(y_pred)87# In[99]:88from sklearn.metrics import classification_report89r = classification_report(y_test,y_pred)90print(r)91# In[100]:92from sklearn import svm93from sklearn.preprocessing import StandardScaler94#regularization95sc = StandardScaler()96xtrain = sc.fit_transform(X_train)97xtest = sc.transform(X_test)98# In[101]:99model = svm.SVC()100model.fit(xtrain, y_train)101y_pred = model.predict(xtest)102print(y_pred)103r = classification_report(y_test,y_pred)104print(r)105# In[102]:106from sklearn import tree107tr = tree.DecisionTreeClassifier()108tr.fit(X_train, y_train)109print("training done.")110# In[103]:111tree_predict = tr.predict(X_test)112print(tree_predict)113rc = classification_report(y_test,tree_predict)114print(rc)115# In[104]:116from sklearn.ensemble import GradientBoostingClassifier117gdb = GradientBoostingClassifier() #取长补短118gdb.fit(X_train, y_train)119print("training done.")120# In[105]:121gdb_pred = gdb.predict(X_test)122gdb_report = classification_report(y_test,gdb_pred)123print(gdb_report)124# In[106]:125import lightgbm as lgb126rng = lgb.LGBMClassifier()127rng.fit(X_train, y_train)128print('training done')129# In[107]:130rng_pred = rng.predict(X_test)131rng_report = classification_report(y_test,rng_pred)132print(rng_report)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful