LTP GCOV extension - code coverage report
Current view: directory - src/tmc - tmc_tpc.c
Test: min.info
Date: 2009-06-18 Instrumented lines: 62
Code covered: 79.0 % Executed lines: 49

       1                 : /*
       2                 :  * This file is part of MIN Test Framework. Copyright © 2008 Nokia Corporation
       3                 :  * and/or its subsidiary(-ies).
       4                 :  * Contact: Konrad Marek Zapalowicz
       5                 :  * Contact e-mail: DG.MIN-Support@nokia.com
       6                 :  * 
       7                 :  * This program is free software: you can redistribute it and/or modify it 
       8                 :  * under the terms of the GNU General Public License as published by the Free 
       9                 :  * Software Foundation, version 2 of the License. 
      10                 :  * 
      11                 :  * This program is distributed in the hope that it will be useful, but WITHOUT 
      12                 :  * ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or 
      13                 :  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General  Public License for
      14                 :  * more details. You should have received a copy of the GNU General Public 
      15                 :  * License along with this program. If not,  see 
      16                 :  * <http://www.gnu.org/licenses/>.
      17                 :  */
      18                 : 
      19                 : 
      20                 : /**
      21                 :  *  @file       tmc_tpc.c
      22                 :  *  @version    0.1
      23                 :  *  @brief      This file contains implementation of the TP supervising part
      24                 :  *              of TMC.
      25                 :  */
      26                 : 
      27                 : /* ------------------------------------------------------------------------- */
      28                 : /* INCLUDE FILES */
      29                 : #include "tmc.h"
      30                 : #include "tmc_tpc.h"
      31                 : #include <sched.h>
      32                 : 
      33                 : /* ------------------------------------------------------------------------- */
      34                 : /* EXTERNAL DATA STRUCTURES */
      35                 : /* None */
      36                 : 
      37                 : /* ------------------------------------------------------------------------- */
      38                 : /* EXTERNAL GLOBAL VARIABLES */
      39                 : /** pointer to global TMC structure. Needed in signal handlers */
      40                 : extern TMC_t   *ptmc;
      41                 : /* ------------------------------------------------------------------------- */
      42                 : /* EXTERNAL FUNCTION PROTOTYPES */
      43                 : /* None */
      44                 : 
      45                 : /* ------------------------------------------------------------------------- */
      46                 : /* GLOBAL VARIABLES */
      47                 : /* None */
      48                 : 
      49                 : /* ------------------------------------------------------------------------- */
      50                 : /* CONSTANTS */
      51                 : /* None */
      52                 : 
      53                 : /* ------------------------------------------------------------------------- */
      54                 : /* MACROS */
      55                 : /* None */
      56                 : 
      57                 : /* ------------------------------------------------------------------------- */
      58                 : /* LOCAL GLOBAL VARIABLES */
      59                 : /* None */
      60                 : 
      61                 : /* ------------------------------------------------------------------------- */
      62                 : /* LOCAL CONSTANTS AND MACROS */
      63                 : /* None */
      64                 : 
      65                 : /* ------------------------------------------------------------------------- */
      66                 : /* MODULE DATA STRUCTURES */
      67                 : /* None */
      68                 : 
      69                 : /* ------------------------------------------------------------------------- */
      70                 : /* LOCAL FUNCTION PROTOTYPES */
      71                 : /* ------------------------------------------------------------------------- */
      72                 : LOCAL void      tp_timeout_handler (int signum);
      73                 : /* ------------------------------------------------------------------------- */
      74                 : /* FORWARD DECLARATIONS */
      75                 : /* None */
      76                 : 
      77                 : /* ==================== LOCAL FUNCTIONS ==================================== */
      78                 : /* ------------------------------------------------------------------------- */
      79                 : /** Handles test timeout.
      80                 :  *  @param signum [in] number of the signal the function is handling (SIGALRM)
      81                 :  */
      82                 : LOCAL void tp_timeout_handler (int signum)
      83               0 : {
      84               0 :         if (ptmc->tpc_.tp_status_ == TP_RUNNING) {
      85                 : 
      86               0 :                 if (--(ptmc->tpc_.tp_timeout_) == 0) {
      87               0 :                         ptmc->tpc_.tp_status_ = TP_TIMEOUT;
      88               0 :                         kill (ptmc->tpc_.tp_pid_, SIGKILL);
      89               0 :                         return;
      90                 :                 }
      91                 :         }
      92               0 :         ualarm (100, 0);
      93                 : }
      94                 : 
      95                 : /* ------------------------------------------------------------------------- */
      96                 : /* ======================== FUNCTIONS ====================================== */
      97                 : /* ------------------------------------------------------------------------- */
      98                 : /** Initializes Test Process Controller
      99                 :  *  @param tpc [in:out] adress of the test proces controller.
     100                 :  */
     101                 : void tp_init (TestProcessController * tpc)
     102             100 : {
     103             100 :         tpc->tp_pid_ = 0;
     104             100 :         tpc->tp_status_ = TP_NONE;
     105             100 :         tpc->tp_timeout_ = 0;
     106             100 : }
     107                 : 
     108                 : /* ------------------------------------------------------------------------- */
     109                 : /** Pauses an ongoing test process.
     110                 :  *  @param tpc [in:out] adress of the test proces controller.
     111                 :  */
     112                 : void tp_pause (TestProcessController * tpc)
     113               3 : {
     114               3 :         int             retval = 0;
     115               3 :         if (tpc->tp_status_ == TP_RUNNING) {
     116               3 :                 retval = kill (tpc->tp_pid_, SIGSTOP);
     117               3 :                 if (retval == -1)
     118               0 :                         MIN_ERROR ("Pausing Test Proces failed");
     119                 :                 else {
     120               3 :                         tpc->tp_status_ = TP_PAUSED;
     121               3 :                         MIN_INFO ("Test Process paused");
     122                 :                 }
     123                 :         }
     124               3 : }
     125                 : 
     126                 : /* ------------------------------------------------------------------------- */
     127                 : /** Resumes paused test process.
     128                 :  *  @param tpc [in:out] adress of the test proces controller.
     129                 :  */
     130                 : void tp_resume (TestProcessController * tpc)
     131               1 : {
     132               1 :         int             retval = 0;
     133               1 :         if (tpc->tp_status_ == TP_PAUSED) {
     134               1 :                 retval = kill (tpc->tp_pid_, SIGCONT);
     135               1 :                 if (retval == -1)
     136               0 :                         MIN_ERROR ("Resuming Test Proces failed");
     137                 :                 else {
     138               1 :                         tpc->tp_status_ = TP_RUNNING;
     139               1 :                         MIN_INFO ("Test Process resumed");
     140                 :                 }
     141                 :         }
     142               1 : }
     143                 : 
     144                 : /* ------------------------------------------------------------------------- */
     145                 : /** Aborts test process.
     146                 :  *  @param tpc [in:out] adress of the test proces controller.
     147                 :  */
     148                 : void tp_abort (TestProcessController * tpc)
     149              10 : {
     150              10 :         int             retval = 1;
     151              10 :         if (tpc->tp_pid_ != 0) {
     152              10 :                 tpc->tp_status_ = TP_ABORTED;
     153              10 :                 retval = kill (tpc->tp_pid_, SIGKILL);
     154              10 :                 if (retval == -1)
     155               0 :                         MIN_ERROR ("Aborting Test Proces failed");
     156                 :                 else {
     157              10 :                         tpc->tp_status_ = TP_ABORTED;
     158              10 :                         MIN_INFO ("Test Process aborted");
     159                 :                 }
     160                 :         }
     161              10 : }
     162                 : 
     163                 : /* ------------------------------------------------------------------------- */
     164                 : /** Sets timeout for test process.
     165                 :  *  @param tpc [in:out] adress of the test proces controller.
     166                 :  *  @param t [in] timeout value in seconds.
     167                 :  */
     168                 : void tp_set_timeout (TestProcessController * tpc, unsigned int t)
     169              98 : {
     170              98 :         tpc->tp_timeout_ = t;
     171              98 : }
     172                 : 
     173                 : /* ------------------------------------------------------------------------- */
     174                 : /** Gets timeout for test process.
     175                 :  *  @param tpc adress of the test proces controller.
     176                 :  *  @return timeout value for the test process.
     177                 :  */
     178                 : unsigned int tp_timeout (const TestProcessController * tpc)
     179               0 : {
     180               0 :         return tpc->tp_timeout_;
     181                 : }
     182                 : 
     183                 : /* ------------------------------------------------------------------------- */
     184                 : /** Sets status of a test process.
     185                 :  *  @param tpc [in:out] adress of the test proces controller.
     186                 :  *  @param s [in] new status
     187                 :  */
     188                 : void tp_set_status (TestProcessController * tpc, MINTPStatus s)
     189             184 : {
     190             184 :         tpc->tp_status_ = s;
     191             184 : }
     192                 : 
     193                 : /* ------------------------------------------------------------------------- */
     194                 : /** Gets status of a test process.
     195                 :  *  @param tpc [in] adress of the test proces controller.
     196                 :  *  @return the current status of the test process.
     197                 :  */
     198                 : MINTPStatus tp_status (const TestProcessController * tpc)
     199             358 : {
     200             358 :         return tpc->tp_status_;
     201                 : }
     202                 : 
     203                 : /* ------------------------------------------------------------------------- */
     204                 : /** Setter for the tp_pid_ field of TestProcessController
     205                 :  *  @param tpc [in:out] adress of the test proces controller.
     206                 :  *  @param pid [in] the pid.
     207                 :  */
     208                 : void tp_set_pid (TestProcessController * tpc, pid_t pid)
     209             176 : {
     210             176 :         tpc->tp_pid_ = pid;
     211             176 : }
     212                 : 
     213                 : /* ------------------------------------------------------------------------- */
     214                 : /** Getter for the tp_pid_ field of TestProcessController
     215                 :  *  @param tpc [in] adress of the test proces controller.
     216                 :  *  @return pid of the test process.
     217                 :  */
     218                 : pid_t tp_pid (const TestProcessController * tpc)
     219             156 : {
     220             156 :         return tpc->tp_pid_;
     221                 : }
     222                 : 
     223                 : /* ------------------------------------------------------------------------- */
     224                 : /** Setter for the tp_pid_ field of TestProcessController
     225                 :  */
     226                 : void tp_set_timeout_handler ()
     227              98 : {
     228              98 :         sl_set_sighandler (SIGALRM, tp_timeout_handler);
     229              98 : }
     230                 : 
     231                 : /* ------------------------------------------------------------------------- */
     232                 : /** Starts timeouting the test process if timeout is set.
     233                 :  *  @param tpc [in] adress of the test proces controller.
     234                 :  */
     235                 : void tp_start_timeout (const TestProcessController * tpc)
     236              88 : {
     237              88 :         if (tpc->tp_timeout_ > 0)
     238               0 :                 ualarm (100, 0);
     239              88 : }
     240                 : 
     241                 : /* ------------------------------------------------------------------------- */
     242                 : /* ================= OTHER EXPORTED FUNCTIONS ============================== */
     243                 : /* None */
     244                 : 
     245                 : /* ------------------------------------------------------------------------- */
     246                 : /* ================= TESTS FOR LOCAL FUNCTIONS ============================= */
     247                 : /* None */
     248                 : 
     249                 : /* ------------------------------------------------------------------------- */
     250                 : /* End of file */

Generated by: LTP GCOV extension version 1.6