o
    HXh                     @   s2  d dl Z d dlZd dlmZ d dlmZ d dlZd dlZedZedZ	ee	d ze
ddZW n ey<   ed	w e eee	jd
ZW d   n1 sRw   Y  eded  Zee ed fvroed[[[zd dlZW n ey   dZY nw G dd dejZedkre  dS dS )    N)get_attribute)import_modulefcntltermios	TIOCGPGRP/dev/ttyrbzUnable to open /dev/tty    izBNeither the process group nor the session are attached to /dev/ttyc                   @   s>   e Zd Zdd ZdddZdd Zdd	 Zd
d Zdd ZdS )
IoctlTestsc                 C   sn   t  t df}tdd}t|tjd}t	d|d }| 
|| W d    d S 1 s0w   Y  d S )Nr   r   r   r	   r
   )osgetpgrpgetsidopenr   ioctlr   r   structunpackassertIn)selfidsttyrrpgrp r   9/opt/python-3.10.19/usr/lib/python3.10/test/test_ioctl.py
test_ioctl   s   "zIoctlTests.test_ioctlNc           	      C   s   t  d}|j}t tdf}d}|d ur,||g||   | t|| | n|| t	dd}t
|tj|d}W d    n1 sJw   Y  |d }| |d | || d S )Nr
   r   ir   r   T)arrayitemsizer   r   r   extendZassertEquallenappendr   r   r   r   r   r   )	r   nbytesbufZintsizer   fillr   r   r   r   r   r   _check_ioctl_mutate_len'   s   

z"IoctlTests._check_ioctl_mutate_lenc                 C   s   |    d S Nr$   r   r   r   r   test_ioctl_mutate9   s   zIoctlTests.test_ioctl_mutatec                 C      |  d d S )Ni   r&   r'   r   r   r   test_ioctl_mutate_1024<   s   z!IoctlTests.test_ioctl_mutate_1024c                 C   r)   )Ni   r&   r'   r   r   r   test_ioctl_mutate_2048A   s   z!IoctlTests.test_ioctl_mutate_2048c              	   C   s   t stdt  \}}zAtjdk rtj}tjd@ }ntj}tdtdtj\}tddddd}t	
|||}t	
|||}W t| t| d S t| t| w )	Nzpty module requiredr   l    r
   IZHHHHP      )ptyunittestSkipTestopenptyr   Z
TIOCSWINSZr   r   packr   r   r   close)r   ZmfdZsfdZset_winsz_opcode_maybe_negZset_winsz_opcode_posZ	our_winszZ	new_winszr   r   r   %test_ioctl_signed_unsigned_code_paramE   s$   



z0IoctlTests.test_ioctl_signed_unsigned_code_paramr%   )	__name__
__module____qualname__r   r$   r(   r*   r+   r5   r   r   r   r   r      s    
	r   __main__)r   r0   Ztest.supportr   Ztest.support.import_helperr   r   r   r   r   r   r   OSErrorr1   r   r   r   r   r   r   r   r/   ImportErrorZTestCaser   r6   mainr   r   r   r   <module>   s:    


>