a
    ze                     @   s.  d dl Z d dlZd dlmZ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yt   edY nl0 e
  ee
ejd	ZW d   n1 s0    Y  ed
ed  Zee ed fvred[
[[zd dlZW n ey   dZY n0 G dd dejZedkr*e  dS )    N)import_moduleget_attribute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   sl   t  t df}tdd<}t|tjd}t	d|d }| 
|| W d    n1 s^0    Y  d S )Nr   r   r   r	   r
   )osgetpgrpgetsidopenr   ioctlr   r   structunpackassertIn)selfidsttyrrpgrp r   %/usr/lib/python3.9/test/test_ioctl.py
test_ioctl   s
    zIoctlTests.test_ioctlNc           	      C   s   t  d}|j}t tdf}d}|d urX||g||   | t|| | n
|| t	dd"}t
|tj|d}W d    n1 s0    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    

0z"IoctlTests._check_ioctl_mutate_lenc                 C   s   |    d S )Nr$   r   r   r   r   test_ioctl_mutate8   s    zIoctlTests.test_ioctl_mutatec                 C   s   |  d d S )Ni   r%   r&   r   r   r   test_ioctl_mutate_1024;   s    z!IoctlTests.test_ioctl_mutate_1024c                 C   s   |  d d S )Ni   r%   r&   r   r   r   test_ioctl_mutate_2048@   s    z!IoctlTests.test_ioctl_mutate_2048c              	   C   s   t stdt  \}}ztjdk r8tj}tjd@ }ntj}tdtdtj\}tddddd}t	
|||}t	
|||}W t| t| nt| t| 0 d S )	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_paramD   s$    



z0IoctlTests.test_ioctl_signed_unsigned_code_param)N)	__name__
__module____qualname__r   r$   r'   r(   r)   r3   r   r   r   r   r      s   	
r   __main__)r   r.   Ztest.supportr   r   r   r   r   r   r   r   OSErrorr/   r   r   r   r   r   r   r   r-   ImportErrorZTestCaser   r4   mainr   r   r   r   <module>   s.   
.

>
