Your IP : 172.28.240.42


Current Path : /usr/share/apport/testsuite/
Upload File :
Current File : //usr/share/apport/testsuite/test_ui.pyc


Yc@sWddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZyddlm
Z
Wn!ek
rddlm
Z
nXddlZddlmZddlZddlZddlZddlZdejjfdYZdejfdYZejdS(iN(tStringIO(t_tTestSuiteUserInterfacecBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZRS(s?Concrete apport.ui.UserInterface suitable for automatic testingcCstj|_|jjd|jj|jjtjd<tj	j
j|tjj
jdidd6dd6|_t|_d|_t|_d|_d|_d|_d|_d|_d|_d|_d|_t|_|jdS(Nszdefault = 'testsuite'
databases = {
    'testsuite': {
        'impl': 'memory',
        'bug_pattern_url': None,
    }
}
tAPPORT_CRASHDB_CONFit
dummy_datatt	dupdb_urli(ttempfiletNamedTemporaryFiletcrashdb_conftwritetflushtnametostenvirontapporttuit
UserInterfacet__init__tcrashdb_impltmemoryt
CrashDatabasetNonetcrashdbtFalsetic_progress_activetic_progress_pulsestupload_progress_activetupload_progress_pulsestpresent_package_error_responsetpresent_kernel_error_responsetpresent_details_responsetquestion_yesno_responsetquestion_choice_responsetquestion_file_responset
opened_urltpresent_details_shownt	clear_msg(tself((s&/usr/share/apport/testsuite/test_ui.pyRs*	
												cCs(d|_d|_d|_d|_dS(N(Rt	msg_titletmsg_texttmsg_severitytmsg_choices(R&((s&/usr/share/apport/testsuite/test_ui.pyR%;s			cCst|_|jS(N(tTrueR$R(R&t	is_update((s&/usr/share/apport/testsuite/test_ui.pytui_present_report_detailsBs	cCs||_||_d|_dS(Ntinfo(R'R(R)(R&ttitlettext((s&/usr/share/apport/testsuite/test_ui.pytui_info_messageFs		cCs||_||_d|_dS(Nterror(R'R(R)(R&R/R0((s&/usr/share/apport/testsuite/test_ui.pytui_error_messageKs		cCsd|_t|_dS(Ni(RR+R(R&((s&/usr/share/apport/testsuite/test_ui.pyt!ui_start_info_collection_progressPs	cCs"|jst|jd7_dS(Ni(RtAssertionErrorR(R&((s&/usr/share/apport/testsuite/test_ui.pyt!ui_pulse_info_collection_progressTscCs
t|_dS(N(RR(R&((s&/usr/share/apport/testsuite/test_ui.pyt ui_stop_info_collection_progressXscCsd|_t|_dS(Ni(RR+R(R&((s&/usr/share/apport/testsuite/test_ui.pytui_start_upload_progress[s	cCs"|jst|jd7_dS(Ni(RR5R(R&tprogress((s&/usr/share/apport/testsuite/test_ui.pytui_set_upload_progress_scCs
t|_dS(N(RR(R&((s&/usr/share/apport/testsuite/test_ui.pytui_stop_upload_progresscscCs
||_dS(N(R#(R&turl((s&/usr/share/apport/testsuite/test_ui.pytopen_urlfscCs||_|jS(N(R(R (R&R0((s&/usr/share/apport/testsuite/test_ui.pytui_question_yesnois	cCs||_||_|jS(N(R(R*R!(R&R0toptionstmultiple((s&/usr/share/apport/testsuite/test_ui.pytui_question_choicems		cCs||_|jS(N(R(R"(R&R0((s&/usr/share/apport/testsuite/test_ui.pytui_question_filers	(t__name__t
__module__t__doc__RR%R-R1R3R4R6R7R8R:R;R=R>RARB(((s&/usr/share/apport/testsuite/test_ui.pyRs 	'													tTcBsWeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZedZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"d Z#d!Z$d"Z%d#Z&d$Z'd%Z(d&Z)d'Z*d(Z+d)Z,d*Z-d+Z.d,Z/d-Z0d.Z1d/Z2d0Z3d1Z4d2Z5d3Z6d4Z7d5Z8d6Z9d7Z:d8Z;d9Z<d:Z=d;Z>d<Z?d=Z@d>ZAd?ZBd@ZCRS(AcCsx<ddddgD](}ytj|=Wqtk
r:qXqWtjj|_tjtj_tj	j
|_tjtj	_
tjj
|_tj\}tj_
tj|tj|_dgt_t|_	tj|_d|jd<d|jd	<d
|jd<dd
|jd<dd|jd<tj|_|jtj|_tjj|_|jtj_dtjd<dtjd<dS(NtLANGtLANGUAGEtLC_MESSAGEStLC_ALLsui-tests	/bin/bashtExecutablePathslibfoo1 1-1tPackagetfoot
SourcePackagetAitFooitCoreDumpt1tAPPORT_IGNORE_OBSOLETE_PACKAGEStAPPORT_DISABLE_DISTRO_CHECK(R
RtKeyErrorRt	fileutilst
report_dirtorig_report_dirRtmkdtempRtsymptom_script_dirtorig_symptom_script_dirtreportt_ignore_filetorig_ignore_filetmkstemptclosetsystargvt	orig_argvRtReportRtreport_filetupdate_report_filethookdirt	_hook_dirt
orig_hook_dir(R&tvtfd((s&/usr/share/apport/testsuite/test_ui.pytsetUpws8






cCsA|jjd|jj|jj|j|jjdS(Ni(RetseekttruncateR\R
R(R&((s&/usr/share/apport/testsuite/test_ui.pyRfs
cCs|jt_tjtjj|jtj_d|_tjtj
j|jtj
_d|_t
jtjj|jtj_d|_
|jj|jtjddgddx<tjdD]+}yt
j|Wqtk
rqXqWtj|j|jtj_dS(Ntpidofs/bin/yesisno stray test processess/var/crash/_usr_bin_yes.*.crash(RcRaRbtshutiltrmtreeRRVRWRXRRRZR[R
tunlinkR\R]R^ReR`tassertEqualt
subprocesstcalltglobtOSErrorRgRiRh(R&tf((s&/usr/share/apport/testsuite/test_ui.pyttearDowns&			
"
cCs|j|jjdd|j|jjdd|j|jjdd|j|jjdd|j|jjd	d
|j|jjdd|j|jjdd|j|jjdddS(sformat_filesize()is0.0 KBis2.0 KBi
s2.6 KBi?Bs	1000.0 KBi@Bs1.0 MBg@s2.7 MBis1.0 GBs2.6 GBNgpDAi	=I(RsRtformat_filesize(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_format_filesizescCs%|jj|jjtjj|jj}t|jj|}|j	|dkob|dk|jj
}|j	|dk|j	|dkdd|jjd<|jj}|j	||dk|j	||d	k|jj
}|j	|d
k|j	|d	kdS(s=get_complete_size() and get_reduced_size() for loaded ReportsgGz?g)\(?ii'ROiPt	ExtraInfoii`i8N(Rtload_reportReRR
tpathtgetsizetfloattget_complete_sizet
assertTruetget_reduced_sizeR\(R&tfsizetcomplete_ratiotrsts((s&/usr/share/apport/testsuite/test_ui.pyttest_get_size_loadedscCswtjd|j_d|jjd<|jj}|j|dk|j|dk|j||jjdS(sAget_complete_size() and get_reduced_size() for on-the-fly ReportstBugtWorldtHelloiidN(RRdRR\RRRsR(R&R((s&/usr/share/apport/testsuite/test_ui.pyttest_get_size_constructedscCsz|jj|jj|j|jj|j|j|jjd	|jd=|jd=|jd=|j|jj|jj|j	|jjd	k|j|jjt
d|j|jjd|jj|jj
d|jj|jjd|jj|jj|jj|j	|jjd	k|j|jjt
d|j|jjdd	S(
s
load_report()RLRNRKsInvalid problem reportR.is4Type: test
Package: foo 1-1
CoreDump: base64
bOgUs=
R2N(RR}ReRRsR\R'RRfRRR)R%RmRnR
R(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_load_reports*





	
cCstjjtjjd}tjjtjjd}d||jd<|j|jj	|j
j|jjt
jd|jtjj||jtjj|tj|d||jd<|j|jj	|j
j|jjt
jd|jtjj||jtjj|tj||jd=d|jd<|j|jj	|j
jdS(s	restart()tProcCmdlinetCustomstouch itRespawnCommands/nonexistingN(R
R~tjoinRRVRWR\RfRR}ReRtrestartttimetsleepRtexistsRr(R&tptr((s&/usr/share/apport/testsuite/test_ui.pyttest_restarts,










cCsvtj|j_|jj|jtddddgjt|jjj|j	|jj
dddS(s9collect_info() on report without information (distro bug)tDatetUnamet
DistroReleasetProblemTypeis1no progress dialog for distro bug info collectionN(RRdRR\tcollect_infoRtsettissubsettkeysRsR(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_collect_info_distro6s
c
Cstjd|_d|jd<|j|jj|jjdtf|jjd<t	j
d|jjd<|jj|jt
dd	d
ddd
ddgjt
|jjj|j|jjdkd|j|jjtddS(s1collect_info() on report with only ExecutablePathRs	/bin/bashRKs
/etc/fstabtFstabtTesttCompressedValueRNRLRRtDependenciesRRis/progress dialog for package bug info collections8progress dialog for package bug info collection finishedN(RRdR\RfRR}ReRR+tproblem_reportRRRRRRRRsRR(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_collect_info_exepathAs


(c	Cstjd|j_d|j_|jj|jtddddddd	gjt|jjj	|j|jj
d
kd|j|jjt
dd
S(s'collect_info() on report with a packageRtbashRNRLRRRRRis/progress dialog for package bug info collections8progress dialog for package bug info collection finishedN(RRdRR\tcur_packageRRRRRRRsRR(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_collect_info_packageVs
	(cCsjtjd|j_d|j_|jj|j_|jj|jt	j
|jjjt
j@dS(s8collect_info() leaves the report accessible to the groupRRN(
RRdRR\RReRRRR
tstattst_modetS_IRGRP(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_collect_info_permissionses

cCs[|jj|jj|j|jjt|j|jjd|j|jj	dd}||j
d<|j|jj|jj|j|jjt|j|jj
d|j|jj	|d|j_	d}d|j
d<|j|jj|jj|j|jjt|j|jj
d|j|jj	ddS(shandle_duplicate()shttp://example.com/1tKnownReportR.RRN(RR}ReRRsthandle_duplicateRR'RR#R\RfR+R)(R&tdemo_url((s&/usr/share/apport/testsuite/test_ui.pyttest_handle_duplicatens&



cCs2gt_t|_|j|jjtdS(s0running the frontend without any pending reportsN(RaRbRRRstrun_argvR(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_run_nopendings	cCs|j}tjjtjjd}t|d}|j|WdQXgt	_
t|_it
d6t
d6t
d6t
d6|j_|jj|j|jjtdS(s8running the frontend with pending reports offers restarts
test.crashtwbNR\t	blacklisttexamineR(t_gen_test_crashR
R~RRRVRWtopenR
RaRbRRRRRRst
offer_restartR+(R&RReRx((s&/usr/share/apport/testsuite/test_ui.pyttest_run_restarts	

cCsNddgt_t|_|j|jjt|j|jjddS(s-run_report_bug() without specifying argumentssui-tests-fR2N(RaRbRRRsRRR)(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_run_report_bug_noargsscCsddgt_t|_tj}tt_|j|jjttjj	}|t_|j|t
jjddS(s6run_report_bug() as "ubuntu-bug" with version arguments
ubuntu-bugs-vs
N(RaRbRRtstdoutRRsRR+tgetvalueRt__version__(R&torig_stdouttoutput((s&/usr/share/apport/testsuite/test_ui.pyttest_run_versions		cCsddddgt_t|_itd6td6td6td6|j_|j|jjt|j|jj	d|j|jjd|j|jj
|j|jjd	|jjj|j|jjd
k|j|jjdd|jd|jjjk|jd
|jjjk|j|jjddddddgt_t|_|jj|j|jj	ddS(srun_report_bug() for a packagesui-tests-fs-pRR\RRRshttp://bash.bugs.example.com/%iiRNRtProcEnvironRRtnonexisting_gibberishR2N(RaRbRRR+RRRsRR)RR'RR$R#Rt	latest_idRR\R(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_run_report_bug_packages(
&
cCstj}|dkrhtjtjdtjtjjtjddgt	sht
dntjdzrddd	d
dt
|gt_t|_itd6t	d
6t	d6t	d6|j_|j|jjtWdtj|tjtj|dX|jd|jjjk|jd|jjjk|jd|jjjk|j|jjdd|jd|jjk|jd|jjjk|j|jjdd|jd|jjjk|jd
|jjdk|j|jjd|j|jjd|j|jj d|jj!j"|j|jj#|j|jj$dkdS(s*run_report_bug() for a pid with extra tagsis	/dev/nulls/usr/bin/yestyessCould not execute /usr/bin/yesg?sui-tests-fs--tagRMs-PR\RRRNRNRtProcMapsRKRRRRtTagss$http://coreutils.bugs.example.com/%i(%R
tforktdup2RtO_WRONLYRaRtfilenotexecvRR5RRtstrRbRRR+RRsRtkilltsignaltSIGKILLtwaitpidRR\RtassertFalseR)RR'R#RRR$R(R&tpid((s&/usr/share/apport/testsuite/test_ui.pyttest_run_report_bug_pid_tagss<(
!
&cCsad}xTtr\|d7}ytj|dWq	tk
rX}|jtjkrYPqYq	Xq	W|S(sFind and return an unused PIDii(R+R
RRwterrnotESRCH(tklassRte((s&/usr/share/apport/testsuite/test_ui.pyt_find_unused_pids	
cCsD|j}dddt|gt_t|_|jjdS(s&run_report_bug() for a nonexisting pidsui-tests-fs-PN(RRRaRbRRR(R&R((s&/usr/share/apport/testsuite/test_ui.pyttest_run_report_bug_wrong_pidscCst}tjdkr4tjdddt}nzHddddgt_t|_|jj	|j
|jjdWd	|rtjdddnXd	S(
s9run_report_bug() for a pid which runs as a different useriiisui-tests-fs-PRRR2N(RR
tgetuidt	setresuidR+RaRbRRRRsR)(R&trestore_root((s&/usr/share/apport/testsuite/test_ui.pyttest_run_report_bug_noperm_pids	
cCs*tj\}}tj|tdjtj|tj|dtj}|dkrtj	tjdtj
tjj
tj||gnzAdddt|gt_t|_|jt|jjWdtj|tjtjtj|X|j|jjd	dS(
s3run_report_bug() for a pid of an unpackaged programs/usr/bin/yesiis	/dev/nullsui-tests-fs-PNR2(RR_R
R
RtreadR`tchmodRRRRaRRRRRbRRtassertRaisest
SystemExitRRRRtwaitRrRsR)(R&RktexenameR((s&/usr/share/apport/testsuite/test_ui.pyt"test_run_report_bug_unpackaged_pid$s 
(
cCsd}xctjdD]R}t|jj}t|d}|tjj@rt|d}PqqW|j	|dkdddt
|gt_t
|_itd6td6td	6td
6|j_|jj|j|jjdjtjjdS(
s-run_report_bug() for a pid of a kernel threads/proc/[0-9]*/statiisui-tests-fs-PR\RRRRLN(RRvRRtsplittintRRt
PF_KTHREADRRRaRbRR+RRRRR\t
startswitht	packagingtget_kernel_package(R&RR~Rtflags((s&/usr/share/apport/testsuite/test_ui.pyt!test_run_report_bug_kernel_thread>s 

cCstjjtjjd}tj|tjj|d}ddddd|gt_t	|_
|j|j
jt
|j|j
jd|j|j
jd|j|j
jd|j|j
j|j|j
jdktj}|jt||j|d	d|jd
|jk|jd|jk|j|dd
dd|gt_t	|_
it
d6td6td6td6|j
_|j|j
jt
|j|j
jd|j|j
jd|j|j
jdS(s/run_report_bug() with saving report into a filethomesbashisbad.apportsui-tests-fs-pRs--saveiRNRRRRs-cR\RRRN(R
R~RRRVRWtmkdirRaRbRRRsRR+R)RR'R#RR$RRRdtloadRRRRR((R&tdt
reportfileR((s&/usr/share/apport/testsuite/test_ui.pyttest_run_report_bug_fileTs6

cCsd}tj|tjs+t|dtj}|dkrtjtjdtjtj	j
tjjtj
tjtjd
tjtjjtj||gtstd|ntjdtj}||d<d	|d
<|j||jtjjtjjd}tj|tj tj!|dtjdtjj"|s{t|f|d<|S(s&Generate a Report with real crash datas/usr/bin/yess is not executableis	/dev/nullisCould not execute g?RKt11tSignaltcoreRQ(ii(#R
taccesstX_OKR5RRRRRaRRtstdinR`tsetsidtresourcet	setrlimittRLIMIT_COREtchdirRRVRWRRRRRdt
add_proc_infot
add_user_infoR~RRRtSIGSEGVRR(R&ttest_executableRRtcoredump((s&/usr/share/apport/testsuite/test_ui.pyR{s0%(








cCs|j}tjjtjjd}|jt|dt	|_
itd6td6td6td6|j
_|j
j
||j|j
jd|j|j
jd|j|j
jd|j|j
jd|j|j
jt|jt|dt	|_
itd6td6td6td6|j
_|j
j
||j|j
jd|j
j|j|j
jd|j|j
jd|j
jj|j|j
j|j|j
jd|j|j
j|jd	|j
jjk|jd
|j
jjk|jd|j
jjk|jd|j
jjk|jd
|j
jjk|jd|j
jjk|j|j
jdd|jt |j
jddk|j|j
jdj!d|j|j
jj"|jt|dt	|_
itd6td6td6td6|j
_|j
j
||j|j
jd|j|j
jd|j|j
jd|j|j
jd|j|j
jj"|j|j
jtdS(srun_crash()s
test.crashtwR\RRRis$http://coreutils.bugs.example.com/%iRNRt
StacktraceRtExecutableTimestamptStacktraceAddressSignatureRtCrashRQi'tTitlesyes crashed with SIGSEGVN(#RR
R~RRRVRWR
RRRRRt	run_crashRsR)RR'R#RRR+R(RRRRtassertNotEqualRR$R\RtlenRt
check_ignored(R&RRe((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crashsd

&# 
cCs|j}d|d<tjjtjjd}|jt|dit	d6t
d6t
d6t
d6|j_|jj
||j|jjd|jj|jd	|jjjk|jd
|jjjk|jd|jjjk|jd|jjjk|jd
|jjjk|j|jjdd|j|jjd|j|jjdS(s4run_crash() for an abort() without assertion messaget6Rs
test.crashRR\RRRRNRRRRN(RR
R~RRRVRWR
RR+RRRRRsR)RR(RR\RRR$(R&RRe((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_aborts$

cCstj}d|d<d|d<tj|d<d|d_|jtjjtj	j
d}|jt|dit
d	6td
6td6td6|j_|jj||j|jjd
|jj|jd|jjk|j|jjdS(s$run_crash() for an invalid core dumps/usr/bin/yesRKRRRQtAAAAAAAAs
test.crashRR\RRRR2t
decompressN(RRdRRt	gzipvalueRR
R~RRVRWR
RR+RRRRRsR)R(RR$(R&RRe((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_brokens 




cCsd|jd<|jdd|jjgt_t|_itd6t	d6t	d6t	d6|j_
|j|jjt|j|jj
d|j|jjd|j|jjd|jd<d	|jd
<|jdd|jjgt_t|_itd6t	d6t	d6t	d6|j_
|j|jjt|jd|jj
kd|jj|jj
f|j|jjd
dddgt_t|_|j|jjt|j|jjddS(s8run_crash() through a file specified on the command lineRRLsui-tests-cR\RRRuIt stinks. ♥tUnreportableReasons
It stinks.s%s: %sR.s/nonexisting.crashR2N(R\RfReRRaRbRRR+RRRsRR(RR)RR$R'(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_argv_files:






cCsd|jd<d|jd<d|jd<|jitd6td6td	6td
6|j_|jj|jj|j	d|jj
kd|jj|jj
f|j|jj
dd
S(s8run_crash() on a crash with the UnreportableReason fields
It stinks.Rs	/bin/bashRKsbash 1RLR\RRRs%s: %sR.N(R\RfR+RRRRReRRR(R'RsR)(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_unreportable@s




cCstjdd}|jd|jd|jd<ddtjj|jd|jd	<|j	it
d
6td6td6td
6|j_
|jj|jj|jtjjd|jd|jjdS(sPackage: path traversaltsuffixs.pys5def add_info(r, u):
  open('/tmp/pwned', 'w').close()s	/bin/bashRKs../iiRLR\RRRs
/tmp/pwnedsinvalid Package:N(RRR
RR\R
R~tsplitextRRfR+RRRRReRRtassertInR((R&tbad_hook((s&/usr/share/apport/testsuite/test_ui.pyt test_run_crash_malicious_packageRs


(

cCsad|jd<d|jd<d|jd<|j|jj|jj|j|jjddS(s,run_crash() on a crash with the Ignore fieldR+tIgnores	/bin/bashRKsbash 1RLN(	R\RfRRReRRsR)R(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_ignorefs



cCsd}tj|tjs+t|dtj}|dkrtjtjtjdtjt	j
jtj||gt
std|nzHtjdtj}||d<d|d	<|j||jWd
tj|tjtj|dXtjjtjjd}|jt|dt|_|jj||j |jj!d
|j"d|jj#kd|jj$|jj#fd
S(s-run_crash() for a crash dump without CoreDumps/usr/bin/yess is not executableis	/dev/nullsCould not execute g?RKt42RNs
test.crashRR2Rs%s: %s(%R
RRR5RRRRRRaRRRRRRRRdRRRRRRR~RRVRWR
RRRRsR)RR(R'(R&RRRRe((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_nocoreps0%
(



cCs|j}|j|d=tjjtjjd}|jt	|dt
|_itd6td6td6td6|j_
|jj||j|jjd	d|jjt|jjt|jjf|j|jjd	|j|jjd	S(
srun_crash() pre-retraced reports.

        This happens with crashes which are pre-processed by
        apport-retrace.
        RQs
test.crashRR\RRRshas %s message: %s: %sN(Rtadd_gdb_infoR
R~RRRVRWR
RRRRRRRsR)RRR'R(RR$(R&RRe((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_preretraceds

/cCs7|j|j_|jjd|jjd<tjjtjj	d}|jjj
t|dt|_it
d6td6td6td6|j_|jj||j|jjd	|j|jjdd
|jjt|jjt|jjf|j|jjjd|j|jjdS(
srun_crash() on complete report on uninstalled package

        This happens when reporting a problem from a different machine through
        copying a .crash file.
        suninstalled_pkg 1RLs
test.crashRR\RRRtuninstalled_pkgshas %s message: %s: %ss!http://coreutils.bugs.example.comN(RRR\RR
R~RRRVRWR
RRR+RRRRsRR)RRR'R(RR#RR$(R&Re((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_precollecteds 

/cCstj}d|d<d|d<tjjtjjd}|jt|dit	d6t
d6t
d	6t
d
6|j_|jj
||j|jjtd|j|jjdd
S(s'run_crash() on various error conditionss	/bin/bashRKt	foobarbazRLs
test.crashRR\RRRsInvalid problem reportR2N(RRdR
R~RRVRWR
RR+RRRRRsR'RR)(R&RRe((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_errorss


cCs|j}d|d<d|d<tjjtjjd}|jt|dit	d6t
d6t
d	6t
d
6|j_|jj
||j|jjtd|j|jjdtj}d|d<d
|d<d|d<|jj
||j|jjtd|j|jjdtj}d|d<d|d<d|d<|jj
||j|jjtd|j|jjddS(s=run_crash() on reports with subsequently uninstalled packagess/bin/nonexistingRKRRLs
test.crashRR\RRRsInvalid problem reportR.s/usr/bin/pythontInterpreterPaths5ZeroDivisionError: integer division or modulo by zerot	Tracebacks/bin/shs/usr/bin/nonexistingN(RR
R~RRRVRWR
RR+RRRRRsR'RR)Rd(R&RRe((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_uninstalleds4








cCs4|j}tt|dd|d<tjjtjjd}|j	t
|ditd6td6td6td6|j
_|j
j||jd|j
jk|j|j
jd	|j
jkd
|j
j|j
jf|jd|j
jkd
|j
j|j
jf|j|j
jdd
S(s6run_crash() on binary that got updated in the meantimeRi
s
test.crashRR\RRRRKs%s: %stchangedR.N(RRRR
R~RRRVRWR
RR+RRRRRR\RR(R'RsR)(R&RRe((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_updated_binarys
"cCstjd}d|d<d|d<d|d<d|d<|jtjjtjjd}|jt	|d	t
|_itd
6td6td6td
6|j_
|jj||j|jjd|j|jjd|j|jjd|j|jjd|j|jj|jt	|d	t
|_itd
6td6td6td
6|j_
|jj||j|jjd|j|jjd|j|jjd|jjj|j|jj|jd|jjjk|jd|jjjk|j|jjdd|jd|jjjk|jd|jjjk|jd|jjjkdS(srun_crash() for a package errorRLRRNsIt broketErrorMessagesfoo
bartVarLogPackagerlogs
test.crashRR\RRRishttp://bash.bugs.example.com/%iRtArchitectureRRN(RRdtadd_os_infoR
R~RRVRWR
RRRRRRRsR)RR'R#RRR$R+RRR\R(R&RRe((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_package sH






&cCsttjj|jdd}|jd|jtjd}tj	j
|d<d|d<tjjtjjd}|jt|dt
|_itd	6td
6td6td6|j_|jj||j|jjdd
|jj|jjf|j|jjd|j|jjd|j|jjd|j|jj|jt|dt
|_itd	6td
6td6td6|j_|jj||j|jjdt|jjdt|jj|j|jjd|j|jjd|jjj|j|jj|jd|jjj k|jd|jjj k|j|jjdddS(srun_crash() for a kernel errorssource_linux.pyRsEdef add_info(report, ui):
    report['KernelDebug'] = 'LotsMoreInfo'
tKernelCrashRLtlinuxRNs
test.crashR\RRRserror: %s - %sit s http://linux.bugs.example.com/%itKernelDebugRN(!RR
R~RRgR
R`RRdRRRVRWRRRRRRsR)RR'R(R#RRR$R+RRRR\R(R&RxRRe((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_kernelRsH!



'&cCs|j}dtjd|d<dtjd|d<tjjtjjd}|jt	|dt
|_itd6t
d	6t
d
6t
d6|j_|jj||j|jjd|jj|jd|jjkt}|jjj|tjtj}tjd|d
|d|dtjg}x.|D]&}|j||jkd|qRWdS(srun_crash() anonymizationu
ä %s ♥ itProcUnicodeValues
ä %s ♥ tProcByteArrayValues
test.crashRR\RRRtProcCwdiiis"dump contains sensitive string: %sN(RR
tunameR~RRRVRWR
RRRR+RRRRsR)RR(RR\RtpwdtgetpwuidRtgetcwdR(R&RRetdumpRtbad_stringsR((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_anonymitys&
	1
cswtjdddddftj}tjjj}fdt_d}z|j}|tjj_d|d	<tjjtj	j
d
}|jt|dt
|_itd6td
6td6td6|j_|jj||j|jjd|jj|j|jjd	d|j|jjjdWd|t_|tjj_XdS(sBrun_crash() anonymization runs after info and duplicate collectionit
0xDEADBEEFiiicsS(N(((R;(s&/usr/share/apport/testsuite/test_ui.pyt<lambda>scSs0d|d<d|d<|jdks,tdS(Ns#0  0xDEADBEEF in h (p=0x0) at crash.c:25
#1  0x10000042 in g (x=1, y=42) at crash.c:26
#1  0x10000001 in main () at crash.c:40
RsC
10000000-DEADBEF0 r-xp 00000000 08:02 100000           /bin/crash
R(tcrash_signature_addressesRR5(R&((s&/usr/share/apport/testsuite/test_ui.pytfake_add_gdb_infos

s
my 0xDEADBEEFtProcAuxInfos
test.crashRR\RRRsmy hostnameN(R
R;RR\RdR#RR~RRVRWR
RRRR+RRRRsR)RR(RD(R&t
orig_unametorig_add_gdb_infoRERRe((R;s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_anonymity_orders.%		


 	cstjdddddftj}fdt_z=|j}d|d<d	|d
<d|d<tjjtjjd
}|jt	|dt
|_itd6t
d6t
d6t
d6|j_|jj||j|jjd|jj|j|jjdjd|jjd|j|jjdd|j|jjd
d|j|jjddWd|t_XdS(s2run_crash() anonymization only catches whole wordsitediiicsS(N(((R;(s&/usr/share/apport/testsuite/test_ui.pyRCssmy edt	ProcInfo1s
"ed.localnet"t	ProcInfo2t	educationt	ProcInfo3s
test.crashRR\RRRRsyes crashed with SIGSEGVsmy hostnames"hostname.localnet"N(R
R;RR~RRRVRWR
RRRR+RRRRsR)RR(RR\R(R&RGRRe((R;s&/usr/share/apport/testsuite/test_ui.pyt"test_run_crash_anonymity_substrings0%	



cCs|j}tjjtjjd}t|_it	d6t
d6t
d6t
d6|j_t|d}|j
|WdQXd|jj_|jj||j|jjd	d
|j|jjd|j|jjdt|_it	d6t
d6t
d6t
d6|j_t|d}|j
|WdQXd|jj_|jj||j|jjd	d
|j|jjd|j|jjd
dS(s%run_crash() for already known problems
test.crashR\RRRRNcSstS(N(R+(R((s&/usr/share/apport/testsuite/test_ui.pyRCsRRRR.cSsdS(Nshttp://myreport/1((R((s&/usr/share/apport/testsuite/test_ui.pyRCsshttp://myreport/1(RR
R~RRRVRWRRR+RRRR
RtknownRRsR\R)R#R(R&RReRx((s&/usr/share/apport/testsuite/test_ui.pyttest_run_crash_knowns4

cCsgdddgt_t|_|j|jjt|jd|jjk|j	|jj
dS(s7run_update_report() on a nonexisting package (from bug)sui-tests-uRRs$No additional information collected.N(RaRbRRRsRRRR(RR$(R&((s&/usr/share/apport/testsuite/test_ui.pyt3test_run_update_report_nonexisting_package_from_bugs	cCsmdddddgt_t|_|j|jjt|jd|jjk|j	|jj
dS(s;run_update_report() on a nonexisting package (CLI argument)sui-tests-uRRs-ptbars$No additional information collected.N(RaRbRRRsRRRR(RR$(R&((s&/usr/share/apport/testsuite/test_ui.pyt.test_run_update_report_nonexisting_package_clis	cCsjdddgt_t|_itd6td6td6td6|j_d|jjjd	d
<d|jjjd	d<|j	|jj
t|j	|jjd|jj
|j	|jjd|j	|jjd|j|jj|j|jjdk|j|jjdjd
|jd|jjjk|jd|jjjkdS(s5run_update_report() on an existing package (from bug)sui-tests-uRRR\RRRRiRNRLisbash RRN(RaRbRRR+RRRtdownloadRsRR)RR(R'R#RR$RR\RR(R&((s&/usr/share/apport/testsuite/test_ui.pyt0test_run_update_report_existing_package_from_bug(s"
 cCsadddddddgt_t|_itd6td	6td
6td6|j_|j|jjt|j|jj	d|jj|j|jjd|j|jj
d|j|jj|j|jjdk|j|jjd
jd|jd|jjjk|jd|jjjk|jd|jjdkdS(sHrun_update_report() on an existing package (CLI argument) with extra tagsui-tests-uRRs-pRs--tagRMR\RRRiRLsbash RRRN(RaRbRRR+RRRsRR)RR(R'R#RR$RR\RR(R&((s&/usr/share/apport/testsuite/test_ui.pyt0test_run_update_report_existing_package_cli_tags?s 
 cCs;ddddgt_t|_itd6td6td6td6|j_|j|jjt|j|jj	d|jj|j|jjd|j|jj
d|j|jj|j|jjd	k|j|jjd
jd|jd|jjjk|jd
|jjjkdS(s=run_update_report() on an existing package (-collect program)sapport-collects-pRRRR\RRRiRLsbash RRN(RaRbRRR+RRRsRR)RR(R'R#RR$RR\RR(R&((s&/usr/share/apport/testsuite/test_ui.pyt3test_run_update_report_existing_package_cli_cmdnameUs
 cCsmdddgt_t|_itd6td6td6td6|j_ttj	j
|jdd	}|jd
WdQX|j
|jjt|jj|j
|jjd|jj|j
|jjd|j
|jjd|j|jj|j|jjdk|j
|jjd
d|j
|jjdd|jd|jjjkdS(s@run_update_report() on an uninstalled package with a source hooksui-tests-uRRR\RRRs
source_foo.pyRs1def add_info(r, ui):
  r["MachineType"]="Laptop"
NiRLsfoo (not installed)tMachineTypetLaptopR(RaRbRRR+RRRR
R~RRgR
RsRR\R)RR(R'R#RR$RR(R&Rx((s&/usr/share/apport/testsuite/test_ui.pyt,test_run_update_report_noninstalled_but_hookjs"
$"cCstjj}tjj|}|j||d|jtjj|dd||jttjj|dd|ddgt_	t
|_itd6t
d	6t
d
6t
d6|j_ttjj|jd|d
}|jdWdQX|j|jjt|jj|j|jjd|jj|j|jjd|j|jjd|j|jj|j|jjdk|j|jjdd||j|jjdd|jd|jjj kdS(sUrun_update_report() on a source package which does not have a binary of the same namesIthis test assumes that the kernel binary package != kernel source packageRs@this test assumes that the kernel binary package %s is installedsui-tests-ps-uRRR\RRRssource_%s.pyRs1def add_info(r, ui):
  r["MachineType"]="Laptop"
NiRLs%s (not installed)RYRZR(!RRRt
get_sourceR
tget_versionRt
ValueErrorRaRbRRR+RRRR
R~RRgR
RsRR\R)RR(R'R#RR$RR(R&t
kernel_pkgt
kernel_srcRx((s&/usr/share/apport/testsuite/test_ui.pyt.test_run_update_report_different_binary_sources0
("cCsttjj|jdd}|jddjg|jD]}d|^q=|jd|jj	_
|jjdS(Nscoreutils.pyRsdef add_info(report, ui):
%s
s
s    t	coreutils(RR
R~RRgR
t
splitlinesR`RR?tpackagetrun_report_bug(R&tcodeRxtl((s&/usr/share/apport/testsuite/test_ui.pyt	_run_hooks!	.
cCsitd6td6td6td6|j_|jd|j|jjdd|j|jjdd|j|jjd	d
S(s'interactive hooks: HookUI.information()R\RRRsEreport['begin'] = '1'
ui.information('InfoText')
report['end'] = '1'
tbeginRRtendtInfoTextN(RRRRhRsR\R((R&((s&/usr/share/apport/testsuite/test_ui.pyt"test_interactive_hooks_informations
cCsCitd6td6td6td6|j_t|j_|jd|j|jjdd|j|jjdd|j|jjd	|j|jjd
dt|j_|jj	|j|jjd
d|j|jjddd|j_|jj	|j|jjd
d
|j|jjdddS(s!interactive hooks: HookUI.yesno()R\RRRsUreport['begin'] = '1'
report['answer'] = str(ui.yesno('YesNo?'))
report['end'] = '1'
RiRRRjsYesNo?tanswerR+RRN(RRRR+R RhRsR\R(ReR(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_interactive_hooks_yesnos&


cCsitd6td6td6td6|j_d|j_|jd|j|jjdd|j|jjd	d|j|jjd
|j|jjddd
|j_|jj	|j|jjdd|j|jjd	dd
S(s interactive hooks: HookUI.file()R\RRRs
/etc/fstabsWreport['begin'] = '1'
report['answer'] = str(ui.file('YourFile?'))
report['end'] = '1'
RiRRRjs	YourFile?RmRN(
RRRR"RhRsR\R(RRe(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_interactive_hooks_files

cCsitd6td6td6td6|j_dg|j_|jd|j|jjdd|j|jjd	d|j|jjd
|j|jjddd|j_|jj	|j|jjdd
|j|jjd	ddS(s"interactive hooks: HookUI.choice()R\RRRiskreport['begin'] = '1'
report['answer'] = str(ui.choice('YourChoice?', ['foo', 'bar']))
report['end'] = '1'
RiRRRjsYourChoice?Rms[1]RN(
RRRR!RhRsR\R(RRe(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_interactive_hooks_choicess

cCs|jt|jddS(sinteractive hooks: user cancelss>report['begin'] = '1'
raise StopIteration
report['end'] = '1'
N(RRRh(R&((s&/usr/share/apport/testsuite/test_ui.pyttest_interactive_hooks_cancelscCsKdddgt_t|_itd6td6td6td6|j_|j|jjt|j	d|jj
k|j|jjd	tt
jjtjjd
d}|jd|jtj}ddd
gt_t|_tt_|jt|jjtjj}|t_|j	d|ktt
jjtjjdd}|jd|jdddgt_t|_tt_|jt|jjtjj}|t_|j	d|ktt
jjtjjdd}|jd|jdddgt_t|_tt_|jt|jjtjj}|t_|j	d|k|j	d|ktt
jjtjjdd}|jd|jdddgt_t|_itd6td6td6td6|j_|j|jjt|j|jj
d,|j|jjd,|j	|jj|j|jjdd|j	d|jjk|j|jjdd|j	|jjd jd!|j|jjd"d#dd$d%ddgt_t|_itd6td6td6td6|j_|j|jjt|j|jj
d,|j|jjd,|j	|jj|j|jjdd|j	d%|jjd&ktt
jjtjjdd}|jd'|jdddgt_t|_itd6td6td6td6|j_t|j_|j|jjt|j	|jj|j|jj
d(|j|jjdd)|j	d|jjk|j|jjdd|j	|jjd jd!|j|jjd"d#|j|jjd*d+d,S(-s
run_symptom()sui-tests-stfoobarR\RRRsfoobar" is not knownR2snopkg.pyRsdef run(report, ui):
    pass
tnopkgs&did not determine the affected packagesnorun.pys"def something(x, y):
    return 1
tnorunsnorun.py crashed:scrash.pys$def run(report, ui):
    return 1/0
tcrashscrash.py crashed:sZeroDivisionError:s
itching.pysBdef run(report, ui):
  report["itch"] = "scratch"
  return "bash"
titchingtitchtscratchRRNRRLsbash RRs--tagRMRsndef run(report, ui):
    report['itch'] = 'slap'
    report['q'] = str(ui.yesno('do you?'))
    return 'bash'
sdo you?tslaptqR+N(RaRbRRR+RRRsRRR(R)RR
R~RRRZR
R`tstderrRRRRRR$R\RR (R&Rxtorig_stderrterr((s&/usr/share/apport/testsuite/test_ui.pyttest_run_symptoms
$

		$

	$

	$


 
$

 cCsttjjtjjdd}|jd|jttjjtjjdd}|jd|jddgt	_
t|_itd6t
d	6t
d
6t
d6|j_d|j_|j|jjt|j|jjd|jd|jjk|jt|jjtd
ddg|j|jjd|j|jjd|j|jj|jjjdg|j_|j|jjt|j|jjd|j|jjdk|j|jj|j|jjdjddS(sDrun_report_bug() without specifying arguments and available symptomssfoo.pyRsIdescription = 'foo does not work'
def run(report, ui):
    return 'bash'
sbar.pys*def run(report, ui):
  return "coreutils"
sui-tests-fR\RRRskind of problemRSsfoo does not works
Other problemiRLRN(RR
R~RRRRZR
R`RaRbRR+RRRR!RsRR)RR(RR*RR\RR$tindexR(R&Rx((s&/usr/share/apport/testsuite/test_ui.pyt!test_run_report_bug_list_symptoms~s8$
$


csfd}|ddi	td6dd6dd6dd6dd6dd6dd	6td
6gd6jt|ddi|d
di	td6dd6dd6dd6dd6dd6dd	6td
6gd6ttjjt	j
jdd}|jd|j
|ddi	td6dd6dd6dd6dd6dd6dd	6td
6gd6|ddi	td6dd6dd6dd6dd6dd6dd	6td
6gd6xedD]]}|dd|i	td6dd6dd6d|d6dd6dd6dd	6td
6gd6qW|ddi	td6dd6dd6dd6dd6dd6dd	6td
6gd6|dditd6dd6dd6dd6dd6gd6|dditd6dd6dd6dd6dd6gd6dS(s3parse_args() option inference for a single argumentcs|gt_|r%tjj|ntj}tddt_ztjj}Wdtjj|t_Xd|d<j
|jgj
|j|dS(Ns	/dev/nullRtversion(
RaRbtappendR{RRRRR`RRstargsR?(tprogram_nametargt
expected_optsR|R(R&(s&/usr/share/apport/testsuite/test_ui.pyt_chks	


s
apport-gtktfilebugRdRt
crash_filetsymptomt
update_reporttsavetwindowttagsapport-collects
apport-kdeRbscoreutils.pyRsEdescription = 'foo does not work'
def run(report, ui):
return 'bash'
s
apport-clit1234s.crashs.apports	/tmp/f oos
/usr/bin/tailisapport-update-bugN(s.crashs.apport(RRRRR+RR
R~RRRRZR
R`(R&RRxR((R&s&/usr/share/apport/testsuite/test_ui.pyttest_parse_argv_single_argsN$

csnfd}|gi	td6dd6dd6dd6dd6dd6dd6td	6gd
6|dgi	td6dd6dd6dd6dd6dd6dd6td	6gd
6ttjjtjj	dd
}|j
d|j|dgi	td6dd6dd6dd6dd6dd6dd6td	6gd
6tjtjjtjj	d|dgi	td6dd6dd6dd6dd6dd6dd6td	6gd
6xedD]]}|d|gi	td6dd6dd6d|d6dd6dd6dd6td	6gd
6qW|dgi	td6dd6dd6dd6dd6dd6dd6td	6gd
6|dddgi	td6dd6dd6dd6dd6dd6dd6td	6gd
6|dddgi	td6dd6dd6dd6dd6dd6dd6td	6dgd
6|dddddgi	td6dd6dd6dd6dd6dd6dd6td	6ddgd
6dS(s3parse_args() option inference when invoked as *-bugcsdg|t_tj}tddt_ztjj}Wdtjj|t_Xd|d<j	|j
gj	|j|dS(Ns
apport-bugs	/dev/nullRR(RaRbR{RRRRR`RRsRR?(RRR|R(R&(s&/usr/share/apport/testsuite/test_ui.pyRs	


RRdRRRRRRRRbscoreutils.pyRsEdescription = 'foo does not work'
def run(report, ui):
return 'bash'
Rs.crashs.apports	/tmp/f oos
/usr/bin/tails--saves
foo.apports--tagRMRSN(s.crashs.apport(
R+RRRR
R~RRRRZR
R`Rr(R&RRxR((R&s&/usr/share/apport/testsuite/test_ui.pyttest_parse_argv_apport_bugsX$
"
cCs~|jj|jjtjd}|jj}z.d|j_dtjd<|j|jjt	tj
jtj
jtj
jtj
j
td}tjtj
j|dtjr|tjd<|j|jjtn"|j|jjt	tgkd|j_|j|jjt	||j_|j|jjt	Wd|tjd<||j_XdS(s(can_examine_locally() for a crash reporttPATHcSstS(N(R+(tcommand((s&/usr/share/apport/testsuite/test_ui.pyRCNsRtbinsapport-retracecSstS(N(R(R((s&/usr/share/apport/testsuite/test_ui.pyRC^sN(RR}ReRR
Rtui_run_terminalRstcan_examine_locallyRR~Rtdirnametrealpatht__file__RRR+R(R&t	orig_pathtorig_fnt
src_bindir((s&/usr/share/apport/testsuite/test_ui.pyttest_can_examine_locally_crashFs(

	'	$
"
cCso|jj|jj|jjd=|jj}z,d|j_|j|jjtWd||j_XdS(s,can_examine_locally() for a non-crash reportRQcSstS(N(R+(R((s&/usr/share/apport/testsuite/test_ui.pyRCqsN(	RR}ReRR\RRsRR(R&R((s&/usr/share/apport/testsuite/test_ui.pyt test_can_examine_locally_nocrashis
cCs|jjj}ddddgt_t|_d|jj_itd6td6td6td	6|j_	|j
|jjt|j
|jjd|j
|jjd|j|jj|j
|jjd
d|jd|jjjk|jd|jjjk|j
|jjd
d|j
|jjd|j
|jjd|j
|jjj|dS(s%crash database does not accept reportsui-tests-fs-pRcSstS(N(R(R((s&/usr/share/apport/testsuite/test_ui.pyRCsR\RRRRNRRRRiN(RRRRaRbRtacceptsR+RRRsRR)RR'RR$R\RR#R(R&tlatest_id_before((s&/usr/share/apport/testsuite/test_ui.pyttest_db_no_acceptvs&
(DRCRDRlRfRyR{RRRRRRRRRRRRRRRtclassmethodRRRRRRRRRRRRRR R"R$R&R(R+R-R2R7RARIRORQRRRTRVRWRXR[RaRhRlRnRoRpRqR~RRRRRR(((s&/usr/share/apport/testsuite/test_ui.pyRFvs	*						$	!												*	
				'	$	B			+			
	%				)		2	4		.	!	"							#								r	(	I	W	#	
(tunittestRpRRRR<RR
RaRtRRvt	cStringIORtImportErrortiot	apport.uiRRt
apport.reportRtapport.crashdb_impl.memoryRRRRtTestCaseRFtmain(((s&/usr/share/apport/testsuite/test_ui.pyt<module>s*l$
e*