
    J~j                         d dl Zd dlmc mZ d dlmZ d dlm	Z	  e	d          Z
d Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd ZdS )    N)Path)load_bin_modulewatchdogc                  8   t           j        } dddii} | |          }dg}||k    }|st          j        d|fd||f          dt	          j                    v st          j        t                     rt          j        t                     ndt          j        |           t          j        |          t          j        |          t          j        |          dz  }d	d
|iz  }t          t          j	        |                    d x} x}x}x}}t           j        } dddii} | |          }ddg}||k    }|st          j        d|fd||f          dt	          j                    v st          j        t                     rt          j        t                     ndt          j        |           t          j        |          t          j        |          t          j        |          dz  }d	d
|iz  }t          t          j	        |                    d x} x}x}x}}d S )Ncameramodesbs_h264camera_primary==)zZ%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.camera_service_names
}(%(py4)s)
} == %(py9)sr   py0py2py4py6py9assert %(py11)spy11dual_node_mjpegcamera_leftcamera_right)
r   camera_service_names
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanation@py_assert1@py_assert3@py_assert5@py_assert8@py_assert7@py_format10@py_format12s          BC:\Users\jvoigtlander\Desktop\BubbleCamCode\tests\test_watchdog.py(test_camera_service_names_single_vs_dualr*      s   (`(VZ4H)I`(()IJJ`O_N``JN```````````JN`````````````8`````8``````(````)I````J````N````````````````````````````````( (V=N4O)P (()PQQ V Q V        Q V                     )    *Q    R   V                                   c                  8   t           j        } dddii} | |          }dg}||k    }|st          j        d|fd||f          dt	          j                    v st          j        t                     rt          j        t                     ndt          j        |           t          j        |          t          j        |          t          j        |          dz  }d	d
|iz  }t          t          j	        |                    d x} x}x}x}}t           j        } dddii} | |          }ddg}||k    }|st          j        d|fd||f          dt	          j                    v st          j        t                     rt          j        t                     ndt          j        |           t          j        |          t          j        |          t          j        |          dz  }d	d
|iz  }t          t          j	        |                    d x} x}x}x}}d S )Nr   r   	sbs_mjpegz bubblecam-camera@primary.servicer   )zZ%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.camera_systemd_units
}(%(py4)s)
} == %(py9)sr   r   r   r   dual_node_h264zbubblecam-camera@left.servicezbubblecam-camera@right.service)
r   camera_systemd_unitsr   r   r   r   r   r   r   r    r!   s          r)   (test_camera_systemd_units_single_vs_dualr0      s   ( (V[4I)J (()JKK *P K P        K P                     )    *K    L   P                              ( (V=M4N)O (()OPP '(U P U        P U                     )    *P    Q   U                               r+   c                 B    t                               dddii           d S )Nr   r   r-   )r   stop_camera_servicessim_envs    r)   4test_stop_camera_services_in_sim_mode_does_not_raiser5      s(     !!8fk-B"CDDDDDr+   c                 8    t                                            d S N)r   trigger_rebootr3   s    r)   .test_trigger_reboot_in_sim_mode_does_not_raiser9       s    r+   c                 8    t                                            d S r7   )r   force_rebootr3   s    r)   ,test_force_reboot_in_sim_mode_does_not_raiser<   $   s    r+   c                    |                     dd           t          j        } ||          }d}||u }|st          j        d|fd||f          dt          j                    v st          j        t                    rt          j        t                    ndt          j        |          dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          d	z  }d
d|iz  }t          t          j
        |                    d x}x}x}}d S )NBUBBLECAM_SIMFraisingTiszU%(py5)s
{%(py5)s = %(py2)s
{%(py2)s = %(py0)s.storage_healthy
}(%(py3)s)
} is %(py8)sr   tmp_pathr   r   py3py5py8assert %(py10)spy10delenvr   storage_healthyr   r   r   r   r   r   r   r    )	r4   monkeypatchrD   r"   @py_assert4r&   @py_assert6@py_format9@py_format11s	            r)   ,test_storage_healthy_true_for_a_writable_dirrS   )   sb   666#5##H--55-5555555555-5555555555558555558555555#55555555555H55555H555555-55555555555555555555555555555555555r+   c           	         |                     dd           t          j        }d}||z  } ||          }d}||u }|st          j        d|fd||f          dt          j                    v st          j        t                    rt          j        t                    ndt          j        |          dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          t          j        |          d	z  }	d
d|	iz  }
t          t          j
        |
                    d x}x}x}x}x}}d S )Nr>   Fr?   zdoes-not-existrA   )zb%(py8)s
{%(py8)s = %(py2)s
{%(py2)s = %(py0)s.storage_healthy
}((%(py3)s / %(py5)s))
} is %(py11)sr   rD   )r   r   rF   rG   rH   r   zassert %(py13)spy13rK   )r4   rN   rD   r"   rO   rP   r&   @py_assert10@py_assert9r(   @py_format14s              r)   1test_storage_healthy_false_when_dir_is_unwritablerY   .   s   666#I/?IH/?$?I##$?@@IEI@EIIIIIIIIII@EIIIIIIIIIIII8IIIII8IIIIII#IIIIIIIIIIIHIIIIIHIIIIII/?IIII@IIIIEIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIr+   c                    ddl |                    dd           |                    t          j        dd           fd}|                    d	|                                           }t          j        } ||          }d}||u }|st          j        d
|fd||f          dt          j
                    v st          j        t                    rt          j        t                    ndt          j        |          dt          j
                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          dz  }	dd|	iz  }
t          t          j        |
                    dx}x}x}}j        } |            }||z
  }d}||k     }|st          j        d|fd||f          dt          j
                    v st          j                  rt          j                  ndt          j        |          t          j        |          dt          j
                    v st          j        |          rt          j        |          ndt          j        |          dz  }dd|iz  }t          t          j        |                    dx}x}x}x}}dS )zAThe real failure mode: writes to a dead card never return at all.r   Nr>   Fr?   DEFAULT_TIMEOUT_SECONDSg?c                  2                         d           d S )N   )sleep)argskwargstimes     r)   hangz9test_storage_healthy_false_when_write_hangs.<locals>.hang:   s    

2r+   zbuiltins.openrA   rC   r   rD   rE   rI   rJ   g      @)<)zS(%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.monotonic
}()
} - %(py5)s) < %(py9)sra   started)r   r   r   rG   r   r   r   )ra   rL   setattrr   
bounded_io	monotonicrM   r   r   r   r   r   r   r   r    )r4   rN   rD   rb   rd   r"   rO   r&   rP   rQ   rR   r#   r%   r'   r(   ra   s                  @r)   +test_storage_healthy_false_when_write_hangsrh   3   s   KKK666+-FLLL     ...nnG#6##H--66-6666666666-6666666666668666668666666#66666666666H66666H666666-666666666666666666666666666666666>+>>+g%++%++++++++++%++++++++++++4+++++4++++++>+++++++++++++++g+++++g+++++++++++++++++++++++++++++++++++++++r+   c           	         |                     dd           t                              |           |j        } |            }t	          |          }g }||k    }|st          j        d|fd||f          dt          j                    v st          j	        t                    rt          j
        t                    nddt          j                    v st          j	        |          rt          j
        |          ndt          j
        |          t          j
        |          t          j
        |          t          j
        |          dz  }d	d
|iz  }	t          t          j        |	                    d x}x}x}x}}d S )Nr>   Fr?   r   )ze%(py7)s
{%(py7)s = %(py0)s(%(py5)s
{%(py5)s = %(py3)s
{%(py3)s = %(py1)s.iterdir
}()
})
} == %(py10)slistrD   )r   py1rF   rG   py7rJ   zassert %(py12)spy12)rL   r   rM   iterdirrj   r   r   r   r   r   r   r   r    )
r4   rN   rD   @py_assert2rO   rP   rW   r%   rR   @py_format13s
             r)   (test_storage_probe_leaves_no_file_behindrq   C   s   666X&&& )  "")4"##)r)#r))))))))))#r))))))))))))4)))))4)))))))))))))))))))))))) ))))"))))#))))r)))))))))))))))))))))))))))))))))r+   c           
         t           j        }d}t          |          } ||          }d}||u }|s5t          j        d|fd||f          dt          j                    v st          j        t                     rt          j        t                     ndt          j        |          dt          j                    v st          j        t                    rt          j        t                    ndt          j        |          t          j        |          t          j        |          t          j        |          dz  }dd	|iz  }t          t          j
        |                    d x}x}x}x}x}}d S )
Nz/definitely/not/hereTrA   )zt%(py9)s
{%(py9)s = %(py2)s
{%(py2)s = %(py0)s.storage_healthy
}(%(py7)s
{%(py7)s = %(py3)s(%(py5)s)
})
} is %(py12)sr   r   )r   r   rF   rG   rl   r   rm   zassert %(py14)spy14)r   rM   r   r   r   r   r   r   r   r   r    )	r4   r"   rO   rP   r%   @py_assert11rV   rp   @py_format15s	            r)   *test_storage_healthy_is_a_noop_in_sim_moderv   I   s   #I)?ID)?$@$@I##$@AAITIATIIIIIIIIIIATIIIIIIIIIIII8IIIII8IIIIII#IIIIIIIIIIIDIIIIIDIIIIII)?IIII$@IIIIAIIIITIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIr+   c                 n   ddl }ddlm} |                    dd           |                    d          }|dxx         dz  cc<   | d         d	z                      |                    |                     t                              d
          }d}||v }|st          j
        d|fd||f          t          j        |          dt          j                    v st          j        |          rt          j        |          nddz  }dd|iz  }t          t          j        |                    dx}}dS )zRegression guard: the LED service froze solid (alive per systemd,
    heartbeat stale) -- only the state file's age reveals that.r   N	state_libledredlast_updatei  	state_dirzled.jsonx   stale_after)rz   zbubblecam-led.service)in)z%(py1)s in %(py3)sstale)rk   rF   zassert %(py5)srG   )json	bubblecamry   write_state
read_state
write_textdumpsr   stale_noncritical_unitsr   r   r   r   r   r   r   r    )	r4   r   ry   stater   @py_assert0ro   @py_format4@py_format6s	            r)   +test_stale_noncritical_finds_wedged_servicer   N   so    KKK######%'''  ''E	-C[J&224::e3D3DEEE,,,==E+4+u4444444444+u44444+44444444444u44444u44444444444444444444444444444r+   c                 N   ddl m} |                    dd           t          j        }d} ||          }g }||k    }|st          j        d|fd||f          d	t          j                    v st          j	        t                    rt          j
        t                    nd	t          j
        |          t          j
        |          t          j
        |          t          j
        |          d
z  }dd|iz  }t          t          j        |                    d x}x}x}x}}d S )Nr   rx   rz   r{   r~   r   r   )zi%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.stale_noncritical_units
}(stale_after=%(py4)s)
} == %(py9)sr   r   r   r   )r   ry   r   r   r   r   r   r   r   r   r   r   r    )	r4   ry   r"   r#   r$   r%   r&   r'   r(   s	            r)   6test_stale_noncritical_ignores_fresh_and_never_startedr   ^   sU   ######%''' +BB++<<<BB<BBBBBBBBBB<BBBBBBBBBBBB8BBBBB8BBBBBB+BBBBBBBB<BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBr+   )builtinsr   _pytest.assertion.rewrite	assertionrewriter   pathlibr   conftestr   r   r*   r0   r5   r9   r<   rS   rY   rh   rq   rv   r   r    r+   r)   <module>r      s                       $ $ $ $ $ $?:&&    E E E    
6 6 6
J J J
, , , * * *J J J
5 5 5 C C C C Cr+   