Your IP : 172.28.240.42


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


Yc@sdZddlZddlZddlZddlZddlZddlZddlZddlZyddl	m
Z
Wn!ek
rddlm
Z
nXddl
Z
ddlZ
ejdZejjddZdejfdYZejdS(	sTest the various package hooks.iN(tStringIOs%prog [options]tAPPORT_DATA_DIRs/usr/share/apporttTcBsqeZdZdZdZdZdZdZdZe	dZ
dZd	Zd
Z
RS(cCsGtjj|_tjtj_tjjtjd<tj|_dS(NtAPPORT_REPORT_DIR(	tapportt	fileutilst
report_dirtorig_report_dirttempfiletmkdtemptostenvirontworkdir(tself((s)/usr/share/apport/testsuite/test_hooks.pytsetUpscCs6tjtjj|jtj_tj|jdS(N(tshutiltrmtreeRRRRR(R
((s)/usr/share/apport/testsuite/test_hooks.pyttearDown"scCstjdtddgdtj}|jd|j|jddtjj	}|jt
|dd	tj}|jt
|d|j|d
d|j|dd|j|dd|j|d
ddS(s#package_hook without any log files.s%s/package_hooks-ptbashtstdinssomething is wrongis"package_hook finished successfullyispackage_hook created a reporttProblemTypetPackaget
SourcePackagetErrorMessageN(t
subprocesstPopentdatadirtPIPEtcommunicatetassertEqualt
returncodeRRtget_new_reportstlentReporttloadtopen(R
tphtrepstr((s)/usr/share/apport/testsuite/test_hooks.pyttest_package_hook_nologs(s
cCstjj}tjdtd|gdtj}|jd|j|j	ddtj
j}|jt|ddtj
}|jt|d|j|d	d
|j|d
||j|dtjj||j|ddd
S(s?package_hook on an uninstalled package (might fail to install).s%s/package_hooks-pRssomething is wrongis"package_hook finished successfullyispackage_hook created a reportRRRRN(Rt	packagingtget_uninstalled_packageRRRRRRRRRR R!R"R#t
get_source(R
tpkgR$R%R&((s)/usr/share/apport/testsuite/test_hooks.pyttest_package_hook_uninstalled;s
 cCssttjj|jddjdttjj|jddjdtjtjj|jdttjj|jdddjdtjd	t	d
ddtjj
tjd
d|jgdtj
}|jd|j|jd
dtjj}|jt|ddtj}|jt|d
d}d}d}xx|jD]j}|jdr|}qn|jdr|}qn|jdr|}qnd|krn|jdqnqnW|j||j||j||jd||k|jt||tjjtjd
|j||d|j||ddS(s+package_hook with a log dir and a log file.s	log_1.logtws	Log 1
blatlog2sYet
another
logtlogsubs	notme.logsnot me!s%s/package_hooks-pRs-liRssomething is wrongs"package_hook finished successfullyispackage_hook created a reporttTesthookspytLog1logtLog2tsubs#logsub should not go into log filest	0234lkjasN(R#R
tpathtjoinRtwritetmkdirRRRtrealpathtsystargvRRRRRRRR R!R"tNonetkeystendswithtfailt
assertTruetgetsize(R
R$R%R&tfilekeytlog1keytlog2keytk((s)/usr/share/apport/testsuite/test_hooks.pyttest_package_hook_logsOs@((+%
			


-cCsttjjtjjdd}|jdd|jttjjtjjdd}|jd|j|j	t
jdtdd	tjj
}|j	t|d
dtj}|jt|d|j	t|jtdd
ddddddg|j	|dd|j	|dd|j	|ddd|jd|d
k|jtjdjdd|d
k|j|d
|jd|d
kdS(skernel_crashdump.tvmcoreR-sids
vmcore.logsvmcore successfully dumpeds%s/kernel_crashdumpis&kernel_crashdump finished successfullyis!kernel_crashdump created a reporttDateRRtVmCoret	VmCoreLogtUnametArchitecturet
DistroReleasetKernelCrashtlinuxit-t N(R#R
R5R6RRRR7tcloseRRtcallRRR R!R"tsetR=R@tunametsplittadd_package_info(R
tfR%R&((s)/usr/share/apport/testsuite/test_hooks.pyttest_kernel_crashdumpxs*$
$

!.cCsttjjtjjdd}|jdd|jtj	dtjjtjjd|j
tjdt
dtjdd	|jtjjgd
S(sattempted DoS with vmcore.log symlink

        We must only accept plain files, otherwise vmcore.log might be a
        symlink to the .crash file, which would recursively fill itself.
        RGtwbsids
vmcore.logs%s/kernel_crashdumptstderris'kernel_crashdump unexpectedly succeededN(R#R
R5R6RRRR7RRtsymlinktassertNotEqualRRSRRRR(R
RX((s)/usr/share/apport/testsuite/test_hooks.pyt!test_kernel_crashdump_log_symlinks$
%	
cCstjddgdtj}|jd}|jdksItddj|jdjdjdd }d|}tj	|dgdtjdkst|d	||fS(
sVDetermine a valid version and executable path of gcc and return it
        as a tuple.tgccs	--versiontstdoutis-"gcc --version" must work for this test suitet.is
/usr/bin/gcc-s( must exist and work for this test suite(
RRRRRtAssertionErrorR6t
splitlinesRVRS(tklassR_touttgcc_vertgcc_path((s)/usr/share/apport/testsuite/test_hooks.pyt_gcc_version_paths0
'
cCsE|j\}}tj}|jd|j|jd|jtjdt	||j
gddtjj
}|jt|ddtj}|jt|d|j|dd|j|d	||j|d
|j|j|j|djdd||j|d
jddS(s#gcc_ice_hook with a temporary file.s
int f(int x);is%s/gcc_ice_hooks"gcc_ice_hook finished successfullyisgcc_ice_hook created a reportRtCrashtExecutablePathtPreprocessedSourceRsgcc-RR_N(RhRtNamedTemporaryFileR7tflushtseekRRRSRtnameRRRR R!R"R#treadRWRVR@t
startswith(R
tgcc_versionRgttest_sourceR%R&((s)/usr/share/apport/testsuite/test_hooks.pyttest_gcc_ide_hook_files"



"cCs1|j\}}d}tjdt|dgdtj}|j||j|jddtj	j
}|jt|ddtj}|j
t|d|j|d	d
|j|d||j|d||j|j|d
jdd||j|djddS(sgcc_ice_hook with piping.s
int f(int x);s%s/gcc_ice_hookRPRis"gcc_ice_hook finished successfullyisgcc_ice_hook created a reportRRiRjRkRsgcc-RR_N(RhRRRRRRRRRRR R!R"R#RWRVR@Rq(R
RrRgRsthookR%R&((s)/usr/share/apport/testsuite/test_hooks.pyttest_gcc_ide_hook_pipes 

"cCsd}tjdtgdtj}|j||j|jddtjj	}|jt
|ddtj}|jt
|d|j|dd	|j|d
||j|d|j|djddS(
Ns`------------[ cut here ]------------
kernel BUG at /tmp/oops.c:5!
invalid opcode: 0000 [#1] SMP
Modules linked in: oops cpufreq_stats ext2 i915 drm nf_conntrack_ipv4 ipt_REJECT iptable_filter ip_tables nf_conntrack_ipv6 xt_state nf_conntrack xt_tcpudp ip6t_ipv6header ip6t_REJECT ip6table_filter ip6_tables x_tables ipv6 loop dm_multipath rtc_cmos iTCO_wdt iTCO_vendor_support pcspkr i2c_i801 i2c_core battery video ac output power_supply button sg joydev usb_storage dm_snapshot dm_zero dm_mirror dm_mod ahci pata_acpi ata_generic ata_piix libata sd_mod scsi_mod ext3 jbd mbcache uhci_hcd ohci_hcd ehci_hcd
s%s/kernel_oopsRis!kernel_oops finished successfullyiskernel_oops created a reportRt
KernelOopstOopsTextRslinux-image-(RRRRRRRRRRR R!R"R#RWR@Rq(R
RsRuR%R&((s)/usr/share/apport/testsuite/test_hooks.pyttest_kernel_oops_hooks
(t__name__t
__module__RRR'R,RFRYR^tclassmethodRhRtRvRy(((s)/usr/share/apport/testsuite/test_hooks.pyRs					)				(t__doc__tunittestRRR
Rtos.pathR:toptparset	cStringIORtImportErrortioRtapport.fileutilstOptionParsert	optparserRtgetRtTestCaseRtmain(((s)/usr/share/apport/testsuite/test_hooks.pyt<module>s`