Back to index

apport  2.3
Public Member Functions | Public Attributes | Private Member Functions
test_hooks.T Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_package_hook_nologs
def test_package_hook_uninstalled
def test_package_hook_logs
def test_package_hook_tags
def test_kernel_crashdump
def test_gcc_ide_hook_file
def test_gcc_ide_hook_pipe
def test_kernel_oops_hook

Public Attributes

 orig_report_dir
 workdir

Private Member Functions

def _gcc_version_path

Detailed Description

Definition at line 22 of file test_hooks.py.


Member Function Documentation

def test_hooks.T._gcc_version_path (   klass) [private]
Determine a valid version and executable path of gcc and return it
as a tuple.

Definition at line 173 of file test_hooks.py.

00173 
00174     def _gcc_version_path(klass):
00175         '''Determine a valid version and executable path of gcc and return it
00176         as a tuple.'''
00177 
00178         gcc = subprocess.Popen(['gcc', '--version'], stdout=subprocess.PIPE)
00179         out = gcc.communicate()[0].decode()
00180         assert gcc.returncode == 0, '"gcc --version" must work for this test suite'
00181 
00182         gcc_ver = '.'.join(out.splitlines()[0].split()[2].split('.')[:2])
00183         gcc_path = '/usr/bin/gcc-' + gcc_ver
00184 
00185         assert subprocess.call([gcc_path, '--version'], stdout=subprocess.PIPE) == 0, \
00186             gcc_path + ' must exist and work for this test suite'
00187 
00188         return (gcc_ver, gcc_path)

Here is the caller graph for this function:

def test_hooks.T.setUp (   self)

Definition at line 23 of file test_hooks.py.

00023 
00024     def setUp(self):
00025         self.orig_report_dir = apport.fileutils.report_dir
00026         apport.fileutils.report_dir = tempfile.mkdtemp()
00027         os.environ['APPORT_REPORT_DIR'] = apport.fileutils.report_dir
00028 
00029         self.workdir = tempfile.mkdtemp()

def test_hooks.T.tearDown (   self)

Definition at line 30 of file test_hooks.py.

00030 
00031     def tearDown(self):
00032         shutil.rmtree(apport.fileutils.report_dir)
00033         apport.fileutils.report_dir = self.orig_report_dir
00034 
00035         shutil.rmtree(self.workdir)

gcc_ice_hook with a temporary file.

Definition at line 189 of file test_hooks.py.

00189 
00190     def test_gcc_ide_hook_file(self):
00191         '''gcc_ice_hook with a temporary file.'''
00192 
00193         (gcc_version, gcc_path) = self._gcc_version_path()
00194 
00195         test_source = tempfile.NamedTemporaryFile()
00196         test_source.write(b'int f(int x);')
00197         test_source.flush()
00198         test_source.seek(0)
00199 
00200         self.assertEqual(subprocess.call(['%s/gcc_ice_hook' % datadir, gcc_path, test_source.name]),
00201                          0, 'gcc_ice_hook finished successfully')
00202 
00203         reps = apport.fileutils.get_new_reports()
00204         self.assertEqual(len(reps), 1, 'gcc_ice_hook created a report')
00205 
00206         r = apport.Report()
00207         with open(reps[0], 'rb') as f:
00208             r.load(f)
00209         self.assertEqual(r['ProblemType'], 'Crash')
00210         self.assertEqual(r['ExecutablePath'], gcc_path)
00211         self.assertEqual(r['PreprocessedSource'], test_source.read().decode())
00212 
00213         r.add_package_info()
00214 
00215         self.assertEqual(r['Package'].split()[0], 'gcc-' + gcc_version)
00216         self.assertTrue(r['SourcePackage'].startswith('gcc'))

Here is the call graph for this function:

gcc_ice_hook with piping.

Definition at line 217 of file test_hooks.py.

00217 
00218     def test_gcc_ide_hook_pipe(self):
00219         '''gcc_ice_hook with piping.'''
00220 
00221         (gcc_version, gcc_path) = self._gcc_version_path()
00222 
00223         test_source = 'int f(int x);'
00224 
00225         hook = subprocess.Popen(['%s/gcc_ice_hook' % datadir, gcc_path, '-'],
00226                                 stdin=subprocess.PIPE)
00227         hook.communicate(test_source.encode())
00228         self.assertEqual(hook.returncode, 0, 'gcc_ice_hook finished successfully')
00229 
00230         reps = apport.fileutils.get_new_reports()
00231         self.assertEqual(len(reps), 1, 'gcc_ice_hook created a report')
00232 
00233         r = apport.Report()
00234         with open(reps[0], 'rb') as f:
00235             r.load(f)
00236 
00237         self.assertEqual(r['ProblemType'], 'Crash')
00238         self.assertEqual(r['ExecutablePath'], gcc_path)
00239         self.assertEqual(r['PreprocessedSource'], test_source)
00240 
00241         r.add_package_info()
00242 
00243         self.assertEqual(r['Package'].split()[0], 'gcc-' + gcc_version)
00244         self.assertTrue(r['SourcePackage'].startswith('gcc'))

Here is the call graph for this function:

kernel_crashdump.

Definition at line 139 of file test_hooks.py.

00139 
00140     def test_kernel_crashdump(self):
00141         '''kernel_crashdump.'''
00142 
00143         f = open(os.path.join(apport.fileutils.report_dir, 'vmcore'), 'wb')
00144         f.write(b'\x01' * 100)
00145         f.close()
00146         f = open(os.path.join(apport.fileutils.report_dir, 'vmcore.log'), 'w')
00147         f.write('vmcore successfully dumped')
00148         f.close()
00149 
00150         self.assertEqual(subprocess.call('%s/kernel_crashdump' % datadir), 0,
00151                          'kernel_crashdump finished successfully')
00152 
00153         reps = apport.fileutils.get_new_reports()
00154         self.assertEqual(len(reps), 1, 'kernel_crashdump created a report')
00155 
00156         r = apport.Report()
00157         with open(reps[0], 'rb') as f:
00158             r.load(f)
00159 
00160         self.assertEqual(set(r.keys()), set(['Date', 'Package', 'ProblemType',
00161                                              'VmCore', 'VmCoreLog', 'Uname',
00162                                              'Architecture', 'DistroRelease']))
00163         self.assertEqual(r['ProblemType'], 'KernelCrash')
00164         self.assertEqual(r['VmCoreLog'], 'vmcore successfully dumped')
00165         self.assertEqual(r['VmCore'], b'\x01' * 100)
00166         self.assertTrue('linux' in r['Package'])
00167 
00168         self.assertTrue(os.uname()[2].split('-')[0] in r['Package'])
00169 
00170         r.add_package_info(r['Package'])
00171         self.assertTrue(' ' in r['Package'])  # appended version number

Here is the call graph for this function:

Definition at line 245 of file test_hooks.py.

00245 
00246     def test_kernel_oops_hook(self):
00247         test_source = '''------------[ cut here ]------------
00248 kernel BUG at /tmp/oops.c:5!
00249 invalid opcode: 0000 [#1] SMP
00250 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
00251 '''
00252         hook = subprocess.Popen(['%s/kernel_oops' % datadir], stdin=subprocess.PIPE)
00253         hook.communicate(test_source.encode())
00254         self.assertEqual(hook.returncode, 0, 'kernel_oops finished successfully')
00255 
00256         reps = apport.fileutils.get_new_reports()
00257         self.assertEqual(len(reps), 1, 'kernel_oops created a report')
00258 
00259         r = apport.Report()
00260         with open(reps[0], 'rb') as f:
00261             r.load(f)
00262 
00263         self.assertEqual(r['ProblemType'], 'KernelOops')
00264         self.assertEqual(r['OopsText'], test_source)
00265 
00266         r.add_package_info(r['Package'])
00267 
00268         self.assertTrue(r['Package'].startswith('linux-image-'))
00269 
00270 unittest.main()

Here is the call graph for this function:

package_hook with a log dir and a log file.

Definition at line 77 of file test_hooks.py.

00077 
00078     def test_package_hook_logs(self):
00079         '''package_hook with a log dir and a log file.'''
00080 
00081         with open(os.path.join(self.workdir, 'log_1.log'), 'w') as f:
00082             f.write('Log 1\nbla')
00083         with open(os.path.join(self.workdir, 'log2'), 'w') as f:
00084             f.write('Yet\nanother\nlog')
00085         os.mkdir(os.path.join(self.workdir, 'logsub'))
00086         with open(os.path.join(self.workdir, 'logsub', 'notme.log'), 'w') as f:
00087             f.write('not me!')
00088 
00089         ph = subprocess.Popen(['%s/package_hook' % datadir, '-p', 'bash', '-l',
00090                                os.path.realpath(sys.argv[0]), '-l', self.workdir],
00091                               stdin=subprocess.PIPE)
00092         ph.communicate(b'something is wrong')
00093         self.assertEqual(ph.returncode, 0, 'package_hook finished successfully')
00094 
00095         reps = apport.fileutils.get_new_reports()
00096         self.assertEqual(len(reps), 1, 'package_hook created a report')
00097 
00098         r = apport.Report()
00099         with open(reps[0], 'rb') as f:
00100             r.load(f)
00101 
00102         filekey = None
00103         log1key = None
00104         log2key = None
00105         for k in r.keys():
00106             if k.endswith('Testhookspy'):
00107                 filekey = k
00108             elif k.endswith('Log1log'):
00109                 log1key = k
00110             elif k.endswith('Log2'):
00111                 log2key = k
00112             elif 'sub' in k:
00113                 self.fail('logsub should not go into log files')
00114 
00115         self.assertTrue(filekey)
00116         self.assertTrue(log1key)
00117         self.assertTrue(log2key)
00118         self.assertTrue('0234lkjas' in r[filekey])
00119         self.assertEqual(len(r[filekey]), os.path.getsize(sys.argv[0]))
00120         self.assertEqual(r[log1key], 'Log 1\nbla')
00121         self.assertEqual(r[log2key], 'Yet\nanother\nlog')

Here is the call graph for this function:

package_hook without any log files.

Definition at line 36 of file test_hooks.py.

00036 
00037     def test_package_hook_nologs(self):
00038         '''package_hook without any log files.'''
00039 
00040         ph = subprocess.Popen(['%s/package_hook' % datadir, '-p', 'bash'],
00041                               stdin=subprocess.PIPE)
00042         ph.communicate(b'something is wrong')
00043         self.assertEqual(ph.returncode, 0, 'package_hook finished successfully')
00044 
00045         reps = apport.fileutils.get_new_reports()
00046         self.assertEqual(len(reps), 1, 'package_hook created a report')
00047 
00048         r = apport.Report()
00049         with open(reps[0], 'rb') as f:
00050             r.load(f)
00051 
00052         self.assertEqual(r['ProblemType'], 'Package')
00053         self.assertEqual(r['Package'], 'bash')
00054         self.assertEqual(r['SourcePackage'], 'bash')
00055         self.assertEqual(r['ErrorMessage'], 'something is wrong')

Here is the call graph for this function:

package_hook with extra tags argument.

Definition at line 122 of file test_hooks.py.

00122 
00123     def test_package_hook_tags(self):
00124         '''package_hook with extra tags argument.'''
00125 
00126         ph = subprocess.Popen(['%s/package_hook' % datadir, '-p', 'bash',
00127                                '-t', 'dist-upgrade, verybad'], stdin=subprocess.PIPE)
00128         ph.communicate(b'something is wrong')
00129         self.assertEqual(ph.returncode, 0, 'package_hook finished successfully')
00130 
00131         reps = apport.fileutils.get_new_reports()
00132         self.assertEqual(len(reps), 1, 'package_hook created a report')
00133 
00134         r = apport.Report()
00135         with open(reps[0], 'rb') as f:
00136             r.load(f)
00137 
00138         self.assertEqual(r['Tags'], 'dist-upgrade verybad')

Here is the call graph for this function:

package_hook on an uninstalled package (might fail to install).

Definition at line 56 of file test_hooks.py.

00056 
00057     def test_package_hook_uninstalled(self):
00058         '''package_hook on an uninstalled package (might fail to install).'''
00059 
00060         pkg = apport.packaging.get_uninstalled_package()
00061         ph = subprocess.Popen(['%s/package_hook' % datadir, '-p', pkg],
00062                               stdin=subprocess.PIPE)
00063         ph.communicate(b'something is wrong')
00064         self.assertEqual(ph.returncode, 0, 'package_hook finished successfully')
00065 
00066         reps = apport.fileutils.get_new_reports()
00067         self.assertEqual(len(reps), 1, 'package_hook created a report')
00068 
00069         r = apport.Report()
00070         with open(reps[0], 'rb') as f:
00071             r.load(f)
00072 
00073         self.assertEqual(r['ProblemType'], 'Package')
00074         self.assertEqual(r['Package'], pkg)
00075         self.assertEqual(r['SourcePackage'], apport.packaging.get_source(pkg))
00076         self.assertEqual(r['ErrorMessage'], 'something is wrong')

Here is the call graph for this function:


Member Data Documentation

Definition at line 24 of file test_hooks.py.

Definition at line 28 of file test_hooks.py.


The documentation for this class was generated from the following file: