B
    u9a                 @   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 ye	ddZ
W n ek
rv   edY nPX ee
ejd	Ze
  ed
ed  Zee ed fkred[
[[yd dlZW n ek
r   dZY nX G dd dejZedkre  dS )    N)import_moduleget_attributefcntltermios	TIOCGPGRPz/dev/ttyrbzUnable to open /dev/ttyz    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   sX   t  t df}tdd2}t|tjd}t	d|d }| 
|| W d Q R X d S )Nr   z/dev/ttyr   z    r   )osgetpgrpgetsidopenr   ioctlr   r   structunpackassertIn)selfidsttyrrpgrp r    /usr/lib/python3.7/test_ioctl.py
test_ioctl   s
    zIoctlTests.test_ioctlNc       	   	   C   s   t  d}|j}t tdf}d}|d k	rX||g||   | t|| | n
|| t	dd}t
|tj|d}W d Q R X |d }| |d | || d S )Nr   r   iz/dev/ttyr      )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_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  \}}zlt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 d t| t| X 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&   r0   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   r*   ImportErrorZTestCaser	   r1   mainr   r   r   r   <module>   s.   


>
