
    %h9                         d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZi adadadaddZd Zd ZddZd ZddZd	 Zd
 Zd Zd Zd Zd Zd Zd Zd ZdS )    )VersionNc                    | a d}t          j        j        rd| d}| dk    rt          j        d|            d S |                     dd          } |                     dd          } t          j        d| d|  d           d S )	N z[loop-]testenv.cfgz	[testenv]testenv_.cfg[)currenttestenvargs	until_nokset_log_prefixreplace)cfg_name
loop_countloop_strs      X/home/osmocom-build/jenkins/workspace/ttcn3-ns-test-asan/_testenv/testenv/testenv_cfg.pyset_currentr      s    GH| *)J)))=  585566666##J33##FB//A8AAhAAABBBBB    c                      t           j                            t          j        d          } t          j        d|             t          j        d           d S )Nz_testenv/README.mdzMore information:    )	ospathjoinr   ttcn3_hacks_dirloggingerrorsysexit)readmes    r   exit_error_readmer"   $   sE    W\\'13GHHFM/v//000HQKKKKKr   c                 \   | D ]}| |         D ]}|                     d          st          j        j        rN|                    dd          }t          j        | d| d| d| d           | |         |         | |         |<   nt          j        | d| d| d           | |         |= d	S )
z]Remove _latest keys from cfg or use them instead of the regular keys,
    if --latest is set._latestr   : [z	]: using z instead of z (--latest is set)z]: ignoring z (--latest is not set)N)endswithr   r   latestr   r   debug)cfgr   sectionkeykey_regulars        r   handle_latestr-   *   s      " "w< 	" 	"C<<	** |" \!kk)R88ll'llCll[lllmmm,/L,=G[))ZZ'ZZsZZZ[[[GS!!	"" "r   c                    d}d }| D ]}d| |         v rS|rCt          j        d| d| d           t          j        d           t          j        d           | |         d         }d| |         v rS|sCt          j        d| d| d           t          j        d	           t          j        d           | |         d         }||fS )
Nz	127.0.0.1vty_portz	Error in z
, section :z=  Found vty_port in multiple sections. This is not supported.r   vty_hostz-  Found vty_host in section without vty_port.)r   r   r   r    )r)   r   hostportr*   s        r   get_vty_host_portr4   =   s    DD , ,W%% D$DD'DDDEEE]^^^w<
+DW%% D$DD'DDDEEEMNNNw<
+D:r   c                  d   t           rt           S d } t          j                            ddgdd          }|j                            d          D ]^}|                    d          rG|                    dd          d                                         } t          j	        d	|              n_| a | S )
Nttcn3_compilerz-vT)capture_outputtext
z	Version: r0   r   zeclipse-titan version: )
titan_version_in_pathr   cmdrunstderrsplit
startswithstripr   r(   )retvlines      r   get_titan_version_in_pathrD   R   s      %$$
C)40DQQAt$$  ??;'' 	**S!$$Q'--//CM9C99:::E	  Jr   c           	         | d         d         }d}t           rt           d         |k    rt          j        d           t          j        d| d|            t          j        dt           d          dt           d                     t          j        d	           t          j        d
           ||da t
          j        j        rt          |          t          t
          j        j                  k    r@t          j        dt
          j        j         d| d|            t          j        d
           t
          j        j        }d}t
          j        j	        s't          j                            d|           st                      }|s@t          j        d           t          j        d| d           t          j        d
           t
          j        j        r5||k    r/t          j        d| d| d           t          j        d
           t          |          t          |          k    rJt          j        d| d| d| d           t          j        d| d           t          j        d
           |}d}||fS )N	testsuite	titan_minzfrom titan_min= in testenv.cfgversionzOFound different titan_min= versions in testenv.cfg files of the same directory:z  titan_min=z in r   %This is not supported, please fix it.r   )rH   r   z--titan-version=z is lower than titan_min=zfrom --titan-versionz/opt/eclipse-titan-z+Failed to parse the ttcn3_compiler version.zInstall eclipse-titan z or higher or use --podman.z Installed eclipse-titan version z$ is not the same as --titan-version=.zinstalled on host system)titan_min_previousr   r   r   r    r   r   titan_versionr   podmanr   r   existsrD   )r)   r   ret_version
ret_reasonpath_versions        r   get_titan_versionrR   c   s    k";/K1J 0;{JJghhh<[<<d<<===d%7	%BddHZ[aHbddeee=>>>%0$??|! ,;'',*D"E"EEEMo7<#=ooXcooimoo   HQKKKl0+
< 0rw~~6YK6Y6Y'Z'Z 0022 	MGHHHM[;[[[\\\HQKKK<% 	+*E*EMs<ssepsss   HQKKK;',"7"777Mr<rrZerrkorrr   M[;[[[\\\HQKKK"/

""r   c                      t          t          t                                                              \  } }t	          |          S )zThe titan version is the same for all testenv.cfg files in the same
    testsuite directory, this is enforced in get_titan_version().)nextitercfgsitemsrR   )_r)   s     r   get_titan_version_first_cfgrY      s3     $tzz||$$%%FAsS!!!r   c                 *   d}d }|                                  D ]9\  }}|d                             dd           }||||k    rd} n0|}3|rd} n:|sd S t          j        d           t          j        d           t	          j        d           d S )NFrF   max_jobs_per_gb_ramTzWFound different max_jobs_per_gb_ram= values in testenv.cfg files of the same directory.rI   r   )rW   getr   r   r   r    )cfgs_allr   r[   r   r)   cfg_maxs         r   verify_max_jobs_per_gb_ramr_      s    E!))  #k"&&'<dCC".111 EE 2 '.##  	EE	  MklllM9:::HQKKKKKr   c            	         t          t          t                                                              \  } }|d                             dd           }d }|r@	 d}t          d          5 }|                                }|                    d          rTt          |	                    d          d                   dz  dz  }t          j        d	t          |d
           d           d d d            n# 1 swxY w Y   t          j        |t          |          z            }|dk     rt!          d| d|           nY# t"          $ rL}t%          j        t)          |          ||j                   t          j        d| d           d}Y d }~nd }~ww xY w|rD|t.          j        j        k     r/t          j        d| dt.          j        j         d| d           |S t.          j        j        S )NrF   r[   r   z/proc/meminfoz	MemTotal: i   zBuilding with    z
 GB of RAMr   zmax_jobs is invalid: max_jobs=z	, gb_ram=z.Calculating max jobs with max_jobs_per_gb_ram=z failed, assuming 4   zUsing only z jobs instead of z  because of max_jobs_per_gb_ram=z in testenv.cfg)rT   rU   rV   rW   r\   openreadliner?   intr>   r   r(   roundmathfloorfloatRuntimeError	Exception	tracebackprint_exceptiontype__traceback__r   r   r   jobsinfo)rX   r)   r[   max_jobsgb_ramfrC   exs           r   get_titan_make_job_countrx      sg   $tzz||$$%%FAsk*../DdKKH 	Fo&& Q!zz||??;// Q C!455<tCFM"O53C3C"O"O"OPPPQ Q Q Q Q Q Q Q Q Q Q Q Q Q Q z&51D+E+E"EFFH!||"#_H#_#_W]#_#_```   	 	 	%d2hhB4DEEEMsK^ssstttHHHHHH	
  Hw|000I( I IW\5F I I$7I I I	
 	
 	
 <s?   D? *A>C4(D? 4C88D? ;C8<AD? ?
F	AFFc            	      J   t           j        j        } d}d}t                                          D ]\  }}|                                D ]$}d||         v rd}||         d         dk    rd} n%t           j        j        r*|s(t          j        |  d| d           t                       t           j        j        si|rgt          j
        |  d| d| d           t          j
        d	           t          j
        d
           t          j
        d           t                       dS )zBCheck if passed -C or -K args make sense with the testenv configs.FqemuTrequired/z!: doesn't support running in QEMU: z must run in QEMUzUse one of:z  -D, --debian-kernelz  -C, --custom-kernelN)r   r   rF   rV   rW   keyskernelr   criticalr"   r   )rF   qemu_supportedqemu_requiredbasenamer)   r*   s         r   verify_qemu_cfgsr      sI   &INM    #xxzz 	 	GW%%!%w<':55$(M	 & < 	 ~ 	 	WWHWWWXXX|" 	 } 	 MYOOOOWOOOPPPM-(((M1222M1222#   r   c           	          d||         vrdS ddg}||         d         }||vr/t          j        |  d| d| d|            t                       dS dS )z$Verify that qemu= has proper values.rz   Noptionalr{   r%   z]: qemu=z is invalid, must be one of: )r   r   r"   )r   r)   r*   validvalues        r   verify_qemu_sectionr      s    S\!!$EL EE^^'^^5^^W\^^___ r   c           
      j   g d}g d}dddd}ddg}d| vr%t          j        | d	           t                       d| d         vr%t          j        | d
           t                       d| d         vr%t          j        | d           t                       d| d         d         v r%t          j        | d           t                       d| d         d         v r%t          j        | d           t                       d| d         vr%t          j        | d           t                       | D ]\}| |                                         D ][}|}|dk    r|}||v r| d| d| d}	||v r||         |v r|	d||          dz  }	t          j        |	           t                       \t	          || |           |dvrFd| |         vr<t          j        | d| d           t          j        d           t                       |D ]}|| |         v ryd| |         |         v rit          j        | d| d| d           t          j        d| |         |          d            t          j        d!           t          j        d"           ^t          | |           t          | |           d S )#N)cleanconfigcopyprepareprogramrG   r[   )
r   r   makepackager   r   rz   setupr1   r/   r   r   r   )configspackagesprogramsr   rF   z: missing [testsuite] sectionz!: missing program= in [testsuite]rG   z#: missing titan_min= in [testsuite]ra   z1: program= in [testsuite] must not have argumentsz-: config= in [testsuite] must not have spacesz : missing config= in [testsuite]r%   z]: z= is invalidz, did you mean z=?)DEFAULTrF   r   z: missing make= in section [z].z#If this is on purpose, set make=no.z  r}   z= in section [z] has multiple spaces:z  ""z-Please separate elements with only one space.r   )	r   r   r"   r~   r   r   r    r4   rR   )
r)   r   keys_valid_testsuitekeys_valid_componentkeys_invalid
keys_listsr*   r+   r   msgs
             r   verifyr      s         L 	J
 #<<<===K(((@@@AAA#k***BBBCCC
c+y)))PPPQQQ
c+x(((LLLMMMs;'''???@@@  w<$$&& 	  	 C(E+%%,e||;;g;;#;;;Cl""|C'8E'A'A>c):>>>>M#D#w///222vS\7Q7QMTJJwJJJKKKM?@@@ 	 	Cc'l""ts7|C/@'@'@[[[[G[[[\\\8CL$5888999MNNN	 c4   c4     r   c                 n   g }| D ]a}t           j                            |          }|dk    r:||                    dd          d                             dd          d         gz  }bd| }|r|dd	                    |           d
z  }n|dt
          j        j         dz  }t          j        |          )Nr   rX   r   rJ   r   z Invalid parameter for --config: z (valid: all, z, )z (the zG testsuite only has one testenv.cfg file, therefore just omit --config))	r   r   r   r>   r   r   r   rF   NoTraceException)glob_result
config_argr   r   r   r   s         r   raise_error_config_argr   N  s    E C C7##D))}$$hnnS!,,Q/55c2>>qABBE
9Z
9
9C x3		% 0 03333w.wwww

"3
'
''r   c            	      r   t           j                            t          j        t          j        j                  } t           j                            | d          }t          t          j        |                    }|s9t          j
        d|             t                       t          j        d           t          |          dk    ryt           j                            t           j                            | d                    r<t          j
        d           t          j
        d           t          j        d           t          |          dk    rt           j                            t           j                            | d                    sct          j
        d           t          j
        dt           j                            |d	                    d
           t          j        d           t          |          dk    rt          j        j        st          j
        d           |D ]_}t          j
        dt           j                            |                              ddd                              dd                      `t          j
        d           t          j        d           |S )Nztestenv*.cfgzMissing testenv.cfg in: r   r   z/Found multiple testenv*.cfg, and a testenv.cfg.zMThe testenv.cfg file must be renamed, consider naming it testenv_generic.cfg.z9There is only one testenv*.cfg file, so please rename it:z$ mv r   z testenv.cfgz-Found multiple testenv.cfg files, use one of:z -c r   r   r	   zLYou can also select all of them (-c all) or use the * character as wildcard.)r   r   r   r   r   r   rF   sortedglobr   r   r"   r   r    lenrN   r   r   r   )dir_testsuitepatternrA   r   s       r   find_configsr   _  s   GLL!8',:PQQMgll=.99G
7##
$
$C @@@AAA
3xx!||rw||M='Q'QRR|GHHHefff
3xx1}}RW^^BGLL,V,VWW}QRRRDbg..s1v66DDDEEE
3xx!||GL/|EFFF 	j 	jDMh!1!1$!7!7!?!?
BPQ!R!R!Z!Z[ace!f!fhhiiiideeeJr   c                  n   i } t                      }|D ]}t          j                            |          }|dk    r,|                    d          st          j        d|           |dk    rt          j        d|           t          j                    }|	                    |           t          ||           t          ||           t
          j        j        s|t          |<   t                        d S || |<   t!          |            t
          j        j        D ]}|dk    r;t#          t
          j        j                  dk    rt          j        d          | a d S d	}| D ]/}d| d
}t%          j        ||          rd}| |         t          |<   0|st'          ||           t                       d S )Nr   r   z@Invalid filename, expected either testenv.cfg or testenv_*.cfg: ztestenv_all.cfgzInvalid filename: allr   z=Can't use multiple --config arguments if one of them is 'all'Fr	   T)r   r   r   r   r?   r   r   configparserConfigParserreadr-   r   r   r   rV   r   r_   r   fnmatchr   )r]   config_pathsr   r   r)   r   matchedr   s           r   initr   }  s    H>>L ! !7##D))}$$X-@-@-L-L$*]S[]]   (((*+J+J+JKKK'))c4   sD |" 	 DNFF x((( l)  
7<&''1,,./noooDFF  	4 	4H1111Gx11 4!)(!3X 	="<<<<# r   )r   )N)packaging.versionr   r   r   r   r   ri   os.pathr   r   r   rn   rV   r   r:   rK   r   r"   r-   r4   rD   rR   rY   r_   rx   r   r   r   r   r   r    r   r   <module>r      s   & % % % % %          



     	
  C C C C   " " "&   *  "+# +# +# +#\" " "  2  B     4
 
 
R! R! R!j( ( ("  <1 1 1 1 1r   