K2LL33D SHELL

 Apache/2.4.7 (Ubuntu)
 Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64
 uid=33(www-data) gid=33(www-data) groups=33(www-data)
 safemode : OFF
 MySQL: ON | Perl: ON | cURL: OFF | WGet: ON
  >  / usr / share / apport / testsuite /
server ip : 172.67.156.115

your ip : 172.70.126.22

H O M E


Filename/usr/share/apport/testsuite/test_recoverable_problem.py
Size2.7 kb
Permissionrw-r--r--
Ownerroot : root
Create time27-Apr-2025 09:55
Last modified04-Apr-2014 22:30
Last accessed06-Jul-2025 19:05
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
'''Test recoverable_problem'''

# Copyright (C) 2012 Canonical Ltd.
# Author: Evan Dandrea <[email protected]>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
# the full text of the license.

import unittest
import sys
import os
import subprocess
import tempfile
import time
import shutil
import apport.report


class T(unittest.TestCase):
def setUp(self):
self.report_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.report_dir)
os.environ['APPORT_REPORT_DIR'] = self.report_dir
self.datadir = os.environ.get('APPORT_DATA_DIR', '/usr/share/apport')

def wait_for_report(self):
base = os.path.abspath(sys.argv[0]).replace('/', '_')
path = os.path.join(self.report_dir,
'%s.%d.crash' % (base, os.getuid()))
seconds = 0
while not os.path.exists(path):
time.sleep(1)
seconds += 1
self.assertTrue(seconds < 10, 'timeout while waiting for %s to be created.' % path)
return path

def call_recoverable_problem(self, data):
cmd = ['%s/recoverable_problem' % self.datadir]
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
err = proc.communicate(data.encode('UTF-8'))[1]
if proc.returncode != 0:
self.assertNotEqual(err, b'') # we expect some error message
raise subprocess.CalledProcessError(proc.returncode, cmd[0])
self.assertEqual(err, b'')

def test_recoverable_problem(self):
'''recoverable_problem with valid data'''

self.call_recoverable_problem('hello\0there')
path = self.wait_for_report()
with open(path, 'rb') as report_path:
report = apport.report.Report()
report.load(report_path)
self.assertEqual(report['hello'], 'there')
self.assertTrue('Pid:\t%d' % os.getpid() in report['ProcStatus'])

def test_invalid_data(self):
'''recoverable_problem with invalid data'''

self.assertRaises(subprocess.CalledProcessError,
self.call_recoverable_problem, 'hello')

self.assertRaises(subprocess.CalledProcessError,
self.call_recoverable_problem,
'hello\0there\0extraneous')

self.assertRaises(subprocess.CalledProcessError,
self.call_recoverable_problem,
'hello\0\0there')


unittest.main()