File: //usr/local/lib/python3.7/test/__pycache__/test_faulthandler.cpython-37.pyc
B
��g�o � @ s: d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl m
Z
d dlmZm
Z
d dlZd dlZd dlZd dlmZ yd dlZW n ek
r� dZY nX dZejdkZe�d�p�d Ze�d
�p�d Zdekp�dekZd
ekp�dekZddd�Zdd� Zedd� �ZG dd� dej �Z!e"dk�r6e�#� dS )� )�contextmanagerN)�support)�
script_helper�
is_android)�dedentg �?�ntZCFLAGS� ZCONFIG_ARGSz-fsanitize=undefinedz#--with-undefined-behavior-sanitizerz-fsanitize=memoryz--with-memory-sanitizer� c C sL |}|d| 7 }|d| 7 }d|k r<d|d |d | S d| d S d S )Nz# File "<string>", line %s in func
z& File "<string>", line %s in <module>r �^�
�$� )Zlineno1Zlineno2�header� min_count�regexr
r
�2/usr/local/lib/python3.7/test/test_faulthandler.py�expected_traceback# s r c C s t �td�| �S )Nz(raising SIGSEGV on Android is unreliable)�unittest�skipIfr )�testr
r
r �skip_segfault_on_android, s r c c s$ t �� } z
| V W d t�| � X d S )N)�tempfileZmktempr �unlink)�filenamer
r
r �temporary_filename1 s
r c @ sB e Zd Zd�dd�Zdddddd�dd�Zdd � Zd
d� Ze�e j
�d�d
�dd� �Ze
dd� �Zdd� Zdd� Ze�e j
dkd�dd� �Ze�edkd�e�eed�d�e
dd� ���Ze�edkd�e�eed�d �e
d!d"� ���Zd#d$� Zd%d&� Ze�e j
�d'�d(�e�eed)� d*�d+d,� ��Ze
d-d.� �Ze�e�p>ed/�e
d0d1� ��Ze�e j
dkd2�e�e�pled/�e
d3d4� ���Z e
d5d6� �Z!e
d7d8� �Z"d9d:� Z#d;d<� Z$d=d>� Z%d?d@� Z&dddA�dBdC�Z'dDdE� Z(dFdG� Z)e�e j
dkd2�dHdI� �Z*dJdK� Z+dLdM� Z,dNdO� Z-dPdQ� Z.e�eedR� dS�d�dddA�dVdW��Z/dXdY� Z0dZd[� Z1d\d]� Z2d^d_� Z3e�e j
dkd2�d`da� �Z4dbdc� Z5e�eedd� de�d�dfdg��Z6dhdi� Z7djdk� Z8dldm� Z9e�e j
dkd2�dndo� �Z:dpdq� Z;drds� Z<e=dtdu� �Z>dvdw� Z?e�e@dx�dydz� �ZAe�e@dx�d{d|� �ZBe�e@dx�d}d~� �ZCe�e@dx�dd�� �ZDdS )��FaultHandlerTestsNc
C s t |��� }g }|dk r"|�|� t�� �: tjd||d�}|� |�� \}}|�� }W dQ R X W dQ R X t� |�} | �
dd�} |r�| �| d� t|d��}
|
�
� } W dQ R X | �
dd�} nT|dk �r| �| d� t�|tjd� t|dd d
��}
|
�
� } W dQ R X | �
dd�} | �� |fS )a{
Run the specified code in Python (in a new child process) and read the
output from the standard error or from a file (if filename is set).
Return the output lines as a list.
Strip the reference count from the standard error for Python debug
build, and replace "Current thread 0x00007f8d8fbd9700" by "Current
thread XXX".
Nz-c)�pass_fds�ascii�backslashreplacer �rbr F)�closefd)r �strip�appendr ZSuppressCrashReportr Zspawn_pythonZcommunicate�waitZstrip_python_stderr�decode�assertEqual�open�read�os�lseek�SEEK_SET�
splitlines)�self�coder �fdr Zprocess�stdout�stderr�exitcode�output�fpr
r
r �
get_output: s.
zFaultHandlerTests.get_outputT)r �all_threads�other_regexr. �know_current_threadc
C s~ |r|rd} qd} nd} d}
t |
j||| d���� }
|rD|
d| 7 }
| j|||d�\}}d�|�}| �||
� | �|d � d
S )z�
Check that the fault handler for fatal errors is enabled and check the
traceback from the child process output.
Raise an error if the output doesn't match the expected format.
zCurrent thread 0x[0-9a-f]+zThread 0x[0-9a-f]+ZStackz�
(?m)^{fatal_error}
{header} \(most recent call first\):
File "<string>", line {lineno} in <module>
)�lineno�fatal_errorr �|)r r. r r N)r �formatr! r4 �join�assertRegex�assertNotEqual)
r, r- �line_numberr9 r r5 r6 r. r7 r r r2 r1 r
r
r �check_error\ s
zFaultHandlerTests.check_errorc K s d| }| j |||f|� d S )NzFatal Python error: %s)r@ )r, r- r? �
name_regex�kwr9 r
r
r �check_fatal_error} s z#FaultHandlerTests.check_fatal_errorc K s d| }| j |||f|� d S )NzWindows fatal exception: %s)r@ )r, r- r? rA rB r9 r
r
r �check_windows_exception� s z)FaultHandlerTests.check_windows_exceptionZaixz5the first page of memory is a mapped read-only on AIXc C s&