File: //usr/local/lib/python3.10/test/__pycache__/test_faulthandler.cpython-310.opt-1.pyc
o
�inx � @ s d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl m
Z
d dlmZ d dlm
Z
mZ d dlmZ d dlZd dlZd dlmZ zd dlZW n ey[ dZY nw dZejd kZddd�Zd
d� Zedd� �ZG dd� dej�Zedkr�e�� dS dS )� )�contextmanagerN)�support)� os_helper)�
script_helper�
is_android)�skip_if_sanitizer)�dedentg �?�nt� c C sH |}|d| 7 }|d| 7 }d|k rd|d |d | S d| d S )Nz# File "<string>", line %s in func
z& File "<string>", line %s in <module>r
�^�
�$� )Zlineno1Zlineno2�header� min_count�regexr r �3/usr/local/lib/python3.10/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 t�| � d S t�| � w �N)�tempfile�mktempr �unlink��filenamer r r �temporary_filename( s
�r c @ sZ e Zd Zd�dd�Zddddddddd�dd �Zd�d
d�Zdd
� Ze�e j
�d�d�dd� �Ze
dd� �Ze
dd� �Zdd� Zdd� Ze�e j
dkd�dd� �Ze�edu d�e�eed�d �e
d!d"� ���Ze�edu d�e�eed#�d$�e
d%d&� ���Zd'd(� Zd)d*� Zd+d,� Ze�e j
�d-�d.�e�eed/� d0�d1d2� ��Ze
d3d4� �Zeddd5d6�e
d7d8� ��Z e�e j
dkd9�eddd5d6�e
d:d;� ���Z!e
d<d=� �Z"e
d>d?� �Z#e
d@dA� �Z$dBdC� Z%dDdE� Z&dFdG� Z'dHdI� Z(dddJ�dKdL�Z)dMdN� Z*dOdP� Z+e�e j
dkd9�dQdR� �Z,dSdT� Z-dUdV� Z.dWdX� Z/dYdZ� Z0d�dddJ�d\d]�Z1d^d_� Z2d`da� Z3dbdc� Z4ddde� Z5e�e j
dkd9�dfdg� �Z6dhdi� Z7e�eedj� dk� d�dldm��Z8dndo� Z9dpdq� Z:drds� Z;e�e j
dkd9�dtdu� �Z<dvdw� Z=dxdy� Z>e?dzd{� �Z@d|d}� ZAe�eBd~�dd�� �ZCe�eBd~�d�d�� �ZDe�eBd~�d�d�� �ZEe�eBd~�d�d�� �ZFd�d�� ZGdS )��FaultHandlerTestsNc
C s` t |��� }g }|dur|�|� t�� �, tjd||d�}|� |�� \}}|�� }W d � n1 s5w Y W d � n1 sDw Y |� dd�}|rw| �
|d� t|d��} | �� }W d � n1 skw Y |� dd�}n3|dur�| �
|d� t
�|t
jd� t|dd d
��} | �� }W d � n1 s�w Y |� 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".
N�-c)�pass_fds�ascii�backslashreplace� �rbr F)�closefd)r �strip�appendr �SuppressCrashReportr Zspawn_python�communicate�wait�decode�assertEqual�open�read�os�lseek�SEEK_SET�
splitlines)
�self�coder �fdr! �process�output�stderr�exitcode�fpr r r �
get_output1 s6
���
�
�zFaultHandlerTests.get_outputTFz<module>)r �all_threads�other_regexr6 �know_current_thread�py_fatal_error�garbage_collecting�functionc C s� |r
|rd}nd}nd}d|� �g}
| r|
� d� |
� d� |
� |� d�� |
r-|
� d� |
� d |� d
|� �� d�|
�}
|rHd|
� d
|� d�}
d|
� �}
| j|||d�\}}d�|�}| �||
� | �|d� dS )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]+ZStackr z!Python runtime state: initializedr$ z \(most recent call first\):z Garbage-collectingz File "<string>", line z in r z(?:�|�)z(?m)�r r6 r N)r( �joinr<