
    i'                     H   S SK r S SKJr  S SKJr  S SKJrJrJrJrJ	r	  S SK
r
S SKJr  S SKJrJrJrJrJr  S SKJr  S SKJr  S S	KJr  S
\S\S\4S jrS\S-  4S jr  S,S\\-  S\\   S\R8                  S-  S\4S jjr       S-S\S\S\S\S\\   S\\   S\R8                  S-  S\4S jjr       S.S\S\\   S\\   S\R8                  S-  S\4
S jjr    S/S\\-  S\\   S\\   S\R8                  S-  S\4
S jjr!\
RD                  RG                  \" 5       =(       a    \" S5      (       + \$SS9r% \
RD                  RG                  \" 5       =(       a    \" S5      (       + \$S S9r& \
RD                  RO                  \" 5       (       + \$S!S9r( \
RD                  RG                  \" 5       (       + \)S"S9r* \\+\\,\-   4   -  r.\" S#5      r/\	" S$5      r0\\\/\04   /\\/\04   4   r1    S0S%\S&\2\\4   S'\2\\.4   S-  S(\2\\4   S-  S)\3S*\2\\4   S-  S\14S+ jjr4g)1    N)datetime)Path)AnyCallableOptional	ParamSpecTypeVar)EthosUCompileSpec)arm_executor_runner_existscorstone300_installedcorstone320_installedmodel_converter_installedvkml_emulation_layer_installed)TosaSpecification)TosaCompileSpec)VgfCompileSpecpath
log_prefixreturnc                     [        [        U 5      U S[        R                  " 5       R	                  S5       S3-  5      $ )a  Returns the log path with the current time appended to it. Used for
debugging.

Args:
    path: The path to the folder where the log file will be stored.
    log_prefix: The name of the test.

Example output:
    './my_log_folder/test_INT_artifact_28-Nov-14:14:38.log'

_z%d-%b-%H:%M:%Sz.log)strr   r   nowstrftime)r   r   s     b/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/executorch/backends/arm/test/common.pyget_time_formatted_pathr      s=     T

|1X\\^%<%<=M%N$OtTT     c                     [         R                  R                  S5      n U (       a  [         R                  R                  S5      nUR                  S5      S   R                  S5      S   nSU;   a!  [         R                  R                  U S5      n OGS	U;   a!  [         R                  R                  U S
5      n O [         R                  R                  U S5      n [         R                  R                  X5      $ g)zChecks the environment variable TOSA_TESTCASES_BASE_PATH and returns the
path to the where to store the current tests if it is set.
TOSA_TESTCASES_BASE_PATHPYTEST_CURRENT_TESTz::    r   INTztosa-intFPztosa-fpotherN)osenvirongetsplitr   join)tosa_test_basecurrent_test	test_names      r   maybe_get_tosa_collate_pathr.   .   s     ZZ^^$>?Nzz~~&;< &&t,Q/55c:1=	IWW\\.*ENYWW\\.)DNWW\\.'BNww||N66r   	tosa_speccustom_pathtosa_debug_modec                     U(       d
  [        5       nUb  [        R                  " USS9  [        U 5      R	                  U5      R                  U5      nU$ )z,Get the compile spec for default TOSA tests.Texist_ok)r.   r&   makedirsr   dump_intermediate_artifacts_todump_debug_info)r/   r0   r1   compile_specs       r   get_tosa_compile_specr9   B   sO     13
K$/ 		"	'	'	4		) 
 r   macssystem_configmemory_modeextra_flagsconfigc                     U(       d
  [        5       nUb  [        R                  " USS9  U S;   d   S5       eUb  UR                  S5      nO/ n[	        SU  3UUUUS9R                  U5      R                  U5      nU$ )z)Default compile spec for Ethos-U55 tests.Tr3   )    @         Unsupported MACs valuer"   z
ethos-u55-r;   r<   r=   
config_inir.   r&   r5   r)   r
   r6   r7   	r:   r;   r<   r=   r0   r>   r1   extra_flags_listr8   s	            r   get_u55_compile_specrJ   U   s     13
K$/ %%?'??%&,,S1'#(	
 
(	'	4		)  r   c                     U(       d
  [        5       nUb  [        R                  " USS9  U S;   d   S5       eUb  UR                  S5      nO/ n[	        SU  3UUUUS9R                  U5      R                  U5      nU$ )z)Default compile spec for Ethos-U85 tests.Tr3   )rB   rC   i   i   i   rD   r"   z
ethos-u85-rE   rG   rH   s	            r   get_u85_compile_specrL   y   s     13
K$/..H0HH.&,,S1 	'#(	
 
(	'	4		)  r   compiler_flagsc                    U(       d
  [        5       n/ nS[        U 5      ;   a  UR                  S5        S[        U 5      ;   a  UR                  S5        [        U5      S:X  a  [	        S[        U 5       35      eUb  [
        R                  " USS9  Ub  UR                  S	5      nO/ n[        X5      R                  U5      R                  U5      nU$ )
zuGet the ArmCompileSpec for the default VGF tests, to modify the compile
spec before calling .build() to finalize it.
r$   fpr#   intr   zUnsupported vgf compile_spec: Tr3   r"   )r.   reprappendlen
ValueErrorr&   r5   r)   r   r6   r7   )r/   rM   r0   r1   profilescompiler_flags_listr8   s          r   get_vgf_compile_specrW      s     13HtIY
8}9$y/9JKLL
K$/!,2237  	y6	'	'	4		)  r   zcorstone-300z8Did not find Corstone-300 FVP or executor_runner on path)	conditionraisesreasonzcorstone-320z8Did not find Corstone-320 FVP or executor_runner on pathz$Did not find model-converter on pathzGVKML environment is not set properly or executor_runner path is misused_P_Rarg_name	test_dataxfailsskipsstrictflakiesc                    ^ ^^^^^ Tc  0 mTc  0 mTc  0 mS[         [        [        4   S[         [        [        4   4U UUUUU4S jjnU$ )a  Custom version of pytest.mark.parametrize with some syntatic sugar and
added xfail functionality.

- test_data is expected as a dict of (id, test_data) pairs
- alllows to specifiy a dict of (id, failure_reason) pairs to mark specific tests as xfail.
  Failure_reason can be str, type[Exception], or tuple[str, type[Exception]].
  Strings set the reason for failure, the exception type sets expected error.

funcr   c                 R  > / nTR                  5        H  u  p#UT;   a"  [        R                  R                  TU   S94nOUT;   a"  [        R                  R	                  TU   S94nOnUT;   af  TU   nSnSn[        U[        5      (       a  UnO%[        U[        5      (       a  Uu  pgO[        S5      e[        R                  R                  XgTS94nOSn[        R                  " X2US9nUR                  U5        M     [        R                  R                  T
U5      n	U	" U 5      $ )	zTest data is transformed from a dict of (id, data) pairs to a list of
pytest params to work with the native pytests parametrize function.
)reruns)rZ    Nz:xfail info needs to be str, or tuple[str, type[Exception]])rZ   rY   ra    )idmarks)itemspytestmarkflakyskip
isinstancer   tupleRuntimeErrorxfailparamrR   parametrize)rd   pytest_testsuiteri   test_parametersmarker
xfail_inforZ   rY   pytest_param	decoratorr]   rb   r`   ra   r^   r_   s             r   decorator_func#parametrize.<locals>.decorator_func  s#    #,??#4BW} ++++72;+?Au ++**%)*<>v#BZ
j#..'F
E22%/NFF&T  KK%%V6%R !<<fML##L19 $5: KK++H6FG	r   )r   r[   r\   )r]   r^   r_   r`   ra   rb   r|   s   `````` r   ru   ru      sV    " ~}#Xb"f- #(2r62B # #J r   )NN)rB   Ethos_U55_High_End_EmbeddedShared_Sramz--arena-cache-size=2097152NNN)rB   Ethos_U85_SYS_DRAM_Midr   z.--output-format=raw --arena-cache-size=2097152NNN)rg   NN)NNTN)5r&   r   pathlibr   typingr   r   r   r   r	   rl   executorch.backends.arm.ethosur
   )executorch.backends.arm.test.runner_utilsr   r   r   r   r   executorch.backends.arm.tosar   )executorch.backends.arm.tosa.compile_specr   executorch.backends.arm.vgfr   r   r   r.   	DebugModer9   rP   rJ   rL   rW   rm   rs   FileNotFoundErrorXfailIfNoCorstone300XfailIfNoCorstone320skipifSkipIfNoModelConverter	TypeErrorXfailfNoVKMLEmulationLayerrq   type	Exception
xfail_typer[   r\   	Decoratordictboolru   rh   r   r   <module>r      s   
   > >  <  ; E 6# 3 3 "S4Z , "&8<&&# %..5 	( 6$3!% :>!
!! ! 	!
 #! SM! '0047! !J *@!% :>"
"
 #" SM" '0047" "N %'!%7;	!&&!SM! #! $--4	!
 !H {{((N$>~$N E )   {{((N$>~$N E )    ++,./1 ,  
 8#[[..134T /  
 >5d9o-..
t_T]hr2v&'"b&)99:	 ,0#'%)==CH~= j!D(= S>D 	=
 = #s(^d"= =r   