| Server IP : 20.75.53.88 / Your IP : 216.73.217.72 [ Web Server : Apache System : Linux VMRALP-3 4.4.0-256-generic #290~14.04.1-Ubuntu SMP Thu Jun 20 09:24:50 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 5.5.9-1ubuntu4.29+esm15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Domains : 3 Domains MySQL : ON | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/apport/testsuite/ |
Upload File : |
'''Test recoverable_problem'''
# Copyright (C) 2012 Canonical Ltd.
# Author: Evan Dandrea <ev@ubuntu.com>
#
# 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()