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

       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.c
      22                 :  *  @version    0.1
      23                 :  *  @brief      This file contains implementation of the Test Module Controller
      24                 :  */
      25                 : 
      26                 : /* ------------------------------------------------------------------------- */
      27                 : /* INCLUDE FILES */
      28                 : #include "tmc.h"
      29                 : #include "tmc_msghnd.h"
      30                 : #include "test_module_api.h"
      31                 : 
      32                 : /* ------------------------------------------------------------------------- */
      33                 : /* EXTERNAL DATA STRUCTURES */
      34                 : /* None */
      35                 : 
      36                 : /* ------------------------------------------------------------------------- */
      37                 : /* EXTERNAL GLOBAL VARIABLES */
      38                 : TestCaseResult  globaltcr;
      39                 : 
      40                 : /* ------------------------------------------------------------------------- */
      41                 : /* EXTERNAL FUNCTION PROTOTYPES */
      42                 : extern void     gu_handle_sigchld (int);
      43                 : extern void     gu_handle_sigalrm (int);
      44                 : /* ------------------------------------------------------------------------- */
      45                 : /* GLOBAL VARIABLES */
      46                 : 
      47                 : /* ------------------------------------------------------------------------- */
      48                 : /* CONSTANTS */
      49                 : /* None */
      50                 : 
      51                 : /* ------------------------------------------------------------------------- */
      52                 : /* MACROS */
      53                 : /* None */
      54                 : 
      55                 : /* ------------------------------------------------------------------------- */
      56                 : /* LOCAL CONSTANTS AND MACROS */
      57                 : /* None */
      58                 : 
      59                 : /* ------------------------------------------------------------------------- */
      60                 : /* MODULE DATA STRUCTURES */
      61                 : /* None */
      62                 : 
      63                 : /* ------------------------------------------------------------------------- */
      64                 : /* LOCAL FUNCTION PROTOTYPES */
      65                 : /* None */
      66                 : 
      67                 : /* ------------------------------------------------------------------------- */
      68                 : /* FORWARD DECLARATIONS */
      69                 : /* None */
      70                 : 
      71                 : /* ==================== LOCAL FUNCTIONS ==================================== */
      72                 : 
      73                 : /* ======================== FUNCTIONS ====================================== */
      74                 : /* ------------------------------------------------------------------------- */
      75                 : /** Initializes the TMC_t structure and does the init phase of the TMC
      76                 :  *  @param tmc adress of the TMC_t structure to be initialized
      77                 :  *  @param argc number of arguments
      78                 :  *  @param argv[] address of the table of Test Module COntroller's arguments
      79                 :  *
      80                 :  *  This function does initialization phase of the Test Module Controller:
      81                 :  *  - opens log
      82                 :  *  - parses program arguments
      83                 :  *  - initializes message queue interface
      84                 :  *  - initializes test library loader
      85                 :  *  - sends status message
      86                 :  */
      87                 : void gu_init_tmc (TMC_t * tmc, int argc, char *argv[])
      88             100 : {
      89                 :         int             i;
      90             100 :         char           *tmp = "";
      91             100 :         memset (tmc, 0x00, sizeof (*tmc));
      92                 :         /* 1. open log */
      93                 : 
      94             100 :         min_log_open ("TMC", 3);
      95                 : 
      96             100 :         MIN_INFO ("TMC: Build date [%s %s]",__DATE__,__TIME__);
      97             100 :         MIN_DEBUG ("Process started; param: %s",
      98                 :                      argc > 1 ? argv[1] : "NULL");
      99             100 :         MIN_DEBUG ("-- Test module: %s", argc > 1 ? argv[1] : "NULL");
     100             124 :         for (i = 2; i < argc; i++) {
     101              24 :                 MIN_DEBUG ("-- Config file: %s", argv[i]);
     102                 :         }
     103                 : 
     104                 :         /* Fill list of config files */
     105             100 :         tmc->config_list_ = dl_list_create ();
     106             100 :         if (argc > 2) {
     107              48 :                 for (i = 2; i < argc; ++i) {
     108              24 :                         dl_list_add (tmc->config_list_, (void *)argv[i]);
     109                 :                 }
     110                 :         }
     111             100 :         if (dl_list_size (tmc->config_list_) == 0) {
     112              76 :                 dl_list_add (tmc->config_list_, (void *)&tmp);
     113                 :         }
     114                 : 
     115                 :         /* set handler */
     116             100 :         sl_set_sighandler (SIGCHLD, gu_handle_sigchld);
     117                 : 
     118             100 :         tp_init (&tmc->tpc_);
     119             100 :         ip_init (&tmc->tmcipi_, getppid ());
     120                 : 
     121                 :         /* 2. open MQ */
     122             100 :         if (ip_status (&tmc->tmcipi_) == -1) {
     123               0 :                 MIN_FATAL ("Unable to open Message Queue: %s",
     124                 :                           strerror (errno));
     125               0 :                 exit (-3);
     126                 :         }
     127                 : 
     128                 :         /* 3. load library and resolve functions */
     129                 : 
     130             100 :         if (argc <= 0) {
     131               0 :                 MIN_ERROR ("Incorrect number of arguments %d",argc);
     132               0 :                 goto NOT_OK;
     133                 :         }
     134                 : 
     135             100 :         if (tl_open (&tmc->lib_loader_, argv[1])) {
     136               0 :                 tm_print_err ("Library could not be loaded %s",argv[1]);
     137               0 :                 MIN_ERROR ("Library could not be loaded %s",argv[1]);
     138               0 :                 goto NOT_OK;
     139                 :         }
     140                 : 
     141                 :         /* 4. send status message */
     142             100 :         ip_send_ok (&tmc->tmcipi_);
     143             100 :         tmc->run_ = 1;
     144             100 :         return;
     145               0 :       NOT_OK:
     146               0 :         ip_send_ko (&tmc->tmcipi_, 0, "\0");
     147               0 :         return;
     148                 : }
     149                 : 
     150                 : /* ------------------------------------------------------------------------- */
     151                 : /** Main loop of the Test Module Controller
     152                 :  *  @param tmc adress of the TMC_t structure.
     153                 :  *
     154                 :  *  It does:
     155                 :  *  - reads message that comes from message queue
     156                 :  *  - handles recieved message
     157                 :  */
     158                 : void gu_run_tmc (TMC_t * tmc)
     159             100 : {
     160                 :         MsgBuffer       input_buffer;
     161             100 :         TSBool msg_pending = ESFalse;
     162            3597 :         while (tmc->run_ == 1) {
     163            3407 :                 if (tmc->send_ret_ == ESTrue) {
     164              80 :                         ip_send_ret (&tmc->tmcipi_,  
     165                 :                                      globaltcr.result_, 
     166                 :                                      globaltcr.desc_);
     167              80 :                         tmc->send_ret_ = ESFalse;
     168                 :                 }
     169            3407 :                 msg_pending = mq_peek_message (tmc->tmcipi_.mqid_, getpid ());
     170            3407 :                 if (msg_pending == ESTrue) {
     171             470 :                         gu_read_message (tmc, &input_buffer);
     172             470 :                         gu_handle_message (tmc, &input_buffer);
     173                 :                 }
     174            3397 :                 usleep (100000);
     175                 :         }
     176              90 : }
     177                 : 
     178                 : /* ------------------------------------------------------------------------- */
     179                 : /** Deinitialization of the Test Module Controller
     180                 :  *  @param tmc adress of the TMC_t structure.
     181                 :  *
     182                 :  *  It does:
     183                 :  *  - frees the list of config files
     184                 :  *  - closes the test library loader
     185                 :  *  - closes log
     186                 :  *
     187                 :  *  NOTE: Test Module Controller does not close the message queue.
     188                 :  */
     189                 : void gu_done_tmc (TMC_t * tmc)
     190              90 : {
     191              90 :         dl_list_free (&tmc->config_list_);
     192              90 :         tl_close (&tmc->lib_loader_);
     193              90 :         MIN_INFO ("Process ended");
     194              90 :         min_log_close ();
     195              90 :         mq_flush_msg_buffer ();
     196              90 : }
     197                 : 
     198                 : /* ------------------------------------------------------------------------- */
     199                 : /* ================= OTHER EXPORTED FUNCTIONS ============================== */
     200                 : /* None */
     201                 : 
     202                 : /* ================= TESTS FOR LOCAL FUNCTIONS ============================= */
     203                 : /* None */
     204                 : 
     205                 : /* ------------------------------------------------------------------------- */
     206                 : /* End of file */

Generated by: LTP GCOV extension version 1.6