
    .h+                        d dl Z d dlZd dlZ G d de          Zdaej                            e	 d          Z
ej                            dej                            e	 d                    Zej                            ej                            e	 d          d          Zej                            ej                            e	 d          d	          Zd
Zej                            ej                            d          d          Zej                            ed          ZdadddZd Zd Zd Zd Zd Z G d dej                  Zd Zd ZdS )    Nc                       e Zd ZdS )NoTraceExceptionN)__name__
__module____qualname__     a/home/osmocom-build/jenkins/workspace/osmith-ttcn3-bts-test-io_uring/_testenv/testenv/__init__.pyr   r      s        Dr	   r   z	/../../..TESTENV_SRC_DIRz/../../../..z/../..dataz.linuxdebian:trixiez~/.cachezosmo-ttcn3-testenvccachez	[testenv]	Debian_12	Debian_13)zdebian:bookwormr   c                 h    ddi}| |v r)t          j        d||           d|  d           ||          S | S )Nggsn
ggsn_testszUsing testsuite z (via alias ))loggingdebug)namemappings     r
   resolve_testsuite_name_aliasr       sP    G wKKKDKKKLLLt}Kr	   c            
      	   t          j        t           j        d          } |                     ddd          }|                    dd          }|                    d	dd	
          }|                    dd           |                    dd          }|                    dddd           |                    ddt          dt           d           |                    dd          }|                    d          }|                    dd           |                    ddd            |                    d!d"d#d$           |                    d%d&dd'           |                    d(d)d*           |                    dd+dd,           |                    d-d.          }|                    d/d0d1d23           |                    d4d5d6t          t          j
                    7           |                    d8d9dd:           |                    d;d<          }|                                }|                    d=d>dd?           |                    d@dAddB           |                    dCdD          }|                                }|                    dEdFdGdHdIdJK           |                    dLdMdGdHdNdOt           dK           |                    dPdQ          }|                    dRddS           |                    dTdU          }|                    dVdWddX           |                    ddd dt           d           |                    dYdZdd[           |                    d\d]d^d#d_d`a           |                    db          }|                    dcddde           |                    dfdgdhdidjk           |                    dl          }|                    dmdnt           dt          o           |                    dpdqt           dt          o           |                    drds           |                                 at           j        dk    rtt%          t           j                  t           _        t           j        rAt           j                            dt          r$t-          j        du           dt           _        d S d S d S dvt           _        d S )wNa  Build/install everything for a testsuite and run it.

examples:
  ./testenv.py run mgw
  ./testenv.py run mgw --test TC_crcx
  ./testenv.py run mgw --podman --binary-repo osmocom:latest
  ./testenv.py run mgw --podman --binary-repo osmocom:nightly
  ./testenv.py run mgw --podman --binary-repo osmocom:nightly:asan
  ./testenv.py run mgw --io-uring
  ./testenv.py run ggsn --config open5gs
  ./testenv.py run ggsn --config 'osmo_ggsn_v4_only'
  ./testenv.py run ggsn --config 'osmo_ggsn*'
)formatter_classdescriptionactionT)titledestrequiredinitzinitialize osmo-dev/podman)helpruntime)r   r    r   zosmo-devzprepare osmo-dev (top-level makefile scripts, for building test components from source when using 'run' without '--binary-repo')podmanz-prepare the podman image (for 'run --podman')z-fz--force
store_truez$build image even if it is up-to-date)r   r"   z-dz--distroz"distribution for podman (default: r   )defaultr"   runz$build components and run a testsuiteztestsuite options	testsuitez8a directory in osmo-ttcn3-hacks.git (msc, bsc, mgw, ...)z-tz--testzKonly run one specific test (e.g. TC_selftest, BTS_Tests_OML.TC_wrong_mdisc)z-cz--configappendz;which testenv.cfg to use (supports * wildcards via fnmatch)z-iz
--io-uringzset LIBOSMO_IO_BACKEND=IO_URINGz-Tz--titan-versionz"which eclipse-titan version to usez--fastz>skip recording pcaps (+ sleep before/after) and talloc reportszsource/binary optionsz0All components are built from source by default.z-bz--binary-repoOBS_PROJECTzPuse binary packages from this Osmocom OBS project instead (e.g. osmocom:nightly))metavarr"   z-jz--jobsz5number of jobs to run simultaneously (default: nproc))r"   typer&   z-az--asanz3pass --enable-sanitize to Osmocom configure scriptszexit optionsz+When and how testenv should exit when done.z-Bz--bisectz@exit with != 0 if at least one test failed (use with git bisect)z-uz--until-nokz-run until there was either a failure or errorzQEMU optionszOFor some tests, the SUT can or must run in QEMU, typically to use kernel GTP-U.z-Dz--debian-kernelstore_constkerneldebianz"run SUT in QEMU with debian kernel)r   r   constr"   z-Cz--custom-kernelcustomz$run SUT in QEMU with custom kernel (zconfig file optionszTestsuite and test component configs for nightly/master versions of test components are used, unless a binary repository ending in :latest is set or --latest is used.z--latestzuse latest configszpodman optionsz7All components are run directly on the host by default.z-pz--podmanz run all components inside podmanz-sz--shellz:run an interactive shell before stopping daemons/containerz-Iz--install-packageinstall_packagesPACKAGEz5temporarily install a debian package in the container)r   r   r+   r"   zoutput optionsz-lz	--log-dirz(log here instead of a random dir in /tmpz-nz--no-teeteestore_falsez,don't send test component's output to stdout)r   r   r"   zcache optionsz--cachezcache path (default: )r"   r&   z--ccachezccache path (default: cleanzclean previous build artifactsz:latestz7Binary repository ends in :latest, using latest configsF)argparseArgumentParserRawDescriptionHelpFormatteradd_subparsers
add_parseradd_argumentdistro_defaultadd_argument_groupintos	cpu_countadd_mutually_exclusive_groupcustom_kernel_pathcache_dir_defaultccache_dir_default
parse_argsargsr   r   r(   binary_repoendswithr   r   latestr$   )parsersubsub_initsub_init_runtime
sub_podmansub_rungroups          r
   rF   rF   ,   s   $ <:  F  

hX

M
MC~~f+G~HHH..YT].^^L      ",,X<k,llJ3	     C.CCC	     nnU)OnPPG&&':;;E	G     
Z    
 
J	     
.	     
1    
 
M	     &&'>@rssE	_	     
D     
B	     &&~7deeE..00E	O	     
<	     &&Y E ..00E	1     
I4FIII     &&	  E 
!     &&'79rssE	/	     
C.CCC	     
I	     
D     &&'788E	7    
 
;     &&77E	9%6999!    
 
;&8;;;"     NN7!ANBBBD{e5dnEE 	 0 9 9) D D 	MSTTTDKKK	 	 	 	
 r	   c                     t           j        dk    rd S t           j        rt           j        rt	          d          t           j        rt           j        st	          d          t           j        rt           j        st	          d          t           j        r=t           j        t          vr*t	          dd                    t                               t           j	        dk    rt           j        st	          d          t           j
        rt           j        st	          d	          t           j	        d
k    rOt          j                            t                    s+t          j        d           t	          dt                     t          j                            t"          t           j                  } t          j                            |           st	          d|            d S )Nr'   ze--binary-repo cannot be used with --asan, consider using '--binary-repo osmocom:nightly:asan' insteadz--binary-repo requires --podmanz--distro requires --podmanz--distro must be one of z, r/   z!--kernel-debian requires --podmanz$--install-packages requires --podmanr1   zjSee _testenv/README.md for more information on downloading a pre-built kernel or building your own kernel.z>For --kernel-custom, put a symlink or copy of your kernel to: ztestsuite dir not found: )rG   r   rH   asanr   r$   distrodistros_repodirsjoinr.   r2   r@   pathexistsrC   r   criticalttcn3_hacks_dirr(   )testsuite_dirs    r
   verify_args_runr\     s   {e 
DI 
s
 
 	
  B B@AAA{ =4; =;<<<{ Yt{*:::W$))DT:U:UWWXXX{ht{BCCC GT[ GEFFF{hrw~~6H'I'Ix	
 	
 	
 t`rttuuuGLL$.AAM7>>-(( LJ=JJKKKL Lr	   c                  r    t          t          d          rt          j        t          t          _        dS dS dS )zgSome defaults are set later, e.g. after verifying that --distro is not
    being used without --podman.rT   N)hasattrrG   rT   r=   r   r	   r
   set_args_defaultsr_   )  s8     tX %4;#6$% %#6#6r	   c                  Z    t                       t                       t                       d S N)rF   r\   r_   r   r	   r
   	init_argsrb   0  s)    LLLr	   c                   6     e Zd ZdddddddZ fdZd Z xZS )	ColorFormatterz[37mz[94mz[93mz[91mz[0m)r   infowarningerrorrY   resetc                    | j                                         D ]N}d|                                 }|t          j        v r't          j                            |          | j         |<   Ot                                                       d S )NTESTENV_COLOR_)colorskeysupperr@   environgetsuper__init__)selfcolorenv_var	__class__s      r
   rq   zColorFormatter.__init__@  sy    [%%'' 	= 	=E6u{{}}66G"*$$%'Z^^G%<%<E"r	   c                    |j         t          j        k    rd}n_|j         t          j        k    rd}nG|j         t          j        k    rd}n/|j         t          j        k    rd}n|j         t          j        k    rd}| j        |          t           d| j        d          | j	        _
        t          j                            | |          }|S )Nr   re   rf   rg   rY   z %(msg)srh   )levelnor   DEBUGINFOWARNINGERRORCRITICALrk   
log_prefix_style_fmt	Formatterformat)rr   recordrs   results       r
   r   zColorFormatter.formatH  s    >W]**EE^w|++EE^w..EE^w},,EE^w///E"k%0\*\\dkRYFZ\\"))$77r	   )r   r   r   rk   rq   r   __classcell__)ru   s   @r
   rd   rd   6  se         F          r	   rd   c                     t                      } t          j                    }|                    t          j                   g |_        t          j                    }|                    |            |                    |           d S ra   )	rd   r   	getLoggersetLevelrx   handlersStreamHandlersetFormatter
addHandler)	formatterroot_loggerhandlers      r
   init_loggingr   Z  su      I#%%K'''K#%%G###7#####r	   c                 
    | a d S ra   )r}   )news    r
   set_log_prefixr   e  s     JJJr	   ) r7   r   os.pathr@   	Exceptionr   rG   rW   realpath__file__rZ   rn   ro   src_dirrV   data_dirrC   r=   
expanduserrD   rE   r}   rU   r   rF   r\   r_   rb   r   rd   r   r   r   r	   r
   <module>r      s     	 	 	 	 	y 	 	 	 '""h#9#9#9::
*..*BG,<,<=V=V=V,W,W
X
X7<<((H)<)<)<==vFFW\\"'"2"2h3I3I3I"J"JHUU  GLL!3!3J!?!?AUVV W\\"3X>> 

 #   	 	 	W W Wt L  L  LF% % %  ! ! ! ! !W& ! ! !H$ $ $    r	   