LTP GCOV extension - code coverage report
Current view: directory - src/engine/data_structures_api - data_test_result.c
Test: min.info
Date: 2009-06-18 Instrumented lines: 161
Code covered: 100.0 % Executed lines: 161

       1                 : /*
       2                 :  * This file is part of MIN Test Framework. Copyright © 2008 Nokia Corporation
       3                 :  * and/or its subsidiary(-ies).
       4                 :  * Contact: Marko Hyyppä
       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                 : /**
      22                 :  *  @file       data_test_result.c
      23                 :  *  @version    0.1
      24                 :  *  @brief      This file contains implementation of Test Result API
      25                 :  */
      26                 : 
      27                 : /* ------------------------------------------------------------------------- */
      28                 : /* INCLUDE FILES */
      29                 : 
      30                 : #include <string.h>
      31                 : #include <pthread.h>
      32                 : #include <data_test_result.h>
      33                 : 
      34                 : /* ------------------------------------------------------------------------- */
      35                 : /* EXTERNAL DATA STRUCTURES */
      36                 : /* None */
      37                 : 
      38                 : /* ------------------------------------------------------------------------- */
      39                 : /* EXTERNAL FUNCTION PROTOTYPES */
      40                 : /* None */
      41                 : 
      42                 : /* ------------------------------------------------------------------------- */
      43                 : /* CONSTANTS */
      44                 : /* None */
      45                 : 
      46                 : /* ------------------------------------------------------------------------- */
      47                 : /* MACROS */
      48                 : /* None */
      49                 : 
      50                 : /* ------------------------------------------------------------------------- */
      51                 : /* LOCAL CONSTANTS AND MACROS */
      52                 : 
      53                 : /** Test Result thread spesicific mutex data variable.
      54                 : Initial value is PTHREAD_MUTEX_INITIALIZER.
      55                 : (Note scope of variable and mutex are the same)
      56                 :  */
      57                 : LOCAL pthread_mutex_t TR_MUTEX = PTHREAD_MUTEX_INITIALIZER;
      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                 : /* None */
      73                 : 
      74                 : /* ======================== FUNCTIONS ====================================== */
      75                 : 
      76                 : /** Adds Test Result data item to linked list
      77                 :  *  @param list_handle pointer to linked list of Test Result data
      78                 :  *  @param test_result pointer to Test Result data structure.
      79                 :  *  @return pointer to Test Result data item,
      80                 :  *          or returns INITPTR if operation failed.  
      81                 :  *
      82                 :  *  Possible errors:
      83                 :  *  INITPTR if Test Result data item adding to list failed.
      84                 :  */
      85                 : DLListIterator tr_add (DLList * list_handle, test_result_s * test_result)
      86             201 : {
      87             201 :         pthread_mutex_lock (&TR_MUTEX);
      88                 : 
      89             201 :         DLListIterator  dllist_item = INITPTR;
      90                 : 
      91                 :         /* Add Test Result data item to given linked list */
      92             201 :         if (list_handle != INITPTR) {
      93             201 :                 dl_list_add (list_handle, (void *)test_result);
      94             201 :                 dllist_item = dl_list_tail (list_handle);
      95                 :         }
      96                 : 
      97             201 :         pthread_mutex_unlock (&TR_MUTEX);
      98                 : 
      99             201 :         return dllist_item;
     100                 : }
     101                 : 
     102                 : /* ------------------------------------------------------------------------- */
     103                 : 
     104                 : /** Creates Test Result data structure
     105                 :  *  @param tc_data_item pointer to Test Case data item which processed this
     106                 :  *                      Test Result data.
     107                 :  *  @return pointer to Test Result data structure,
     108                 :  *          or returns INITPTR if operation failed.  
     109                 :  *
     110                 :  *  Possible errors:
     111                 :  *  INITPTR if Test Result data structure creation failed.
     112                 :  */
     113                 : test_result_s  *tr_create_data_item (DLListIterator tc_data_item)
     114             126 : {
     115             126 :         pthread_mutex_lock (&TR_MUTEX);
     116                 : 
     117             126 :         test_result_s  *test_result = INITPTR;
     118                 : 
     119             126 :         test_result_s  *data = NEW (test_result_s);
     120                 : 
     121             126 :         if (data) {
     122             126 :                 test_result = data;
     123                 : 
     124                 :                 /* Test Result given data */
     125             126 :                 test_result->tc_data_item_ = tc_data_item;
     126                 : 
     127                 :                 /* Test Result basic initialization data */
     128             126 :                 test_result->start_time_ = 0;
     129             126 :                 test_result->end_time_ = 0;
     130             126 :                 test_result->result_type_ = TEST_RESULT_NOT_RUN;
     131             126 :                 test_result->result_code_ = 0;
     132             126 :                 test_result->printouts_list_ = INITPTR;
     133                 :         }
     134                 : 
     135             126 :         pthread_mutex_unlock (&TR_MUTEX);
     136                 : 
     137             126 :         return test_result;
     138                 : }
     139                 : 
     140                 : /* ------------------------------------------------------------------------- */
     141                 : 
     142                 : /** Removes given Test Result data item from linked list.
     143                 :  *  @param tr_data_item pointer to given Test Result data item.
     144                 :  */
     145                 : void tr_remove (DLListIterator tr_data_item)
     146              84 : {
     147                 :         /* Mutex locking not used because next function including also it */
     148              84 :         tr_remove_printouts_list (tr_data_item);
     149                 : 
     150              84 :         pthread_mutex_lock (&TR_MUTEX);
     151                 : 
     152              84 :         dl_list_remove_it (tr_data_item);
     153                 : 
     154              84 :         pthread_mutex_unlock (&TR_MUTEX);
     155              84 : }
     156                 : 
     157                 : /* ------------------------------------------------------------------------- */
     158                 : 
     159                 : /** Gets result description string from  given Test Result data item.
     160                 :  *  @param tr_data_item pointer to given Test Result data item.
     161                 :  */
     162                 : void tr_get_result_description (DLListIterator tr_data_item,
     163                 :                                 result_description_t result_desc)
     164               3 : {
     165               3 :         pthread_mutex_lock (&TR_MUTEX);
     166                 : 
     167                 :         test_result_s  *test_result =
     168               3 :             (test_result_s *) dl_list_data (tr_data_item);
     169                 : 
     170               3 :         if ((test_result != INITPTR) && (test_result != NULL)) {
     171               1 :                 STRCPY (result_desc, test_result->result_description_,
     172                 :                         strlen (test_result->result_description_) + 1);
     173                 :         }
     174                 : 
     175               3 :         pthread_mutex_unlock (&TR_MUTEX);
     176               3 : }
     177                 : 
     178                 : /* ------------------------------------------------------------------------- */
     179                 : 
     180                 : /** Gets result type value from given Test Result Data item
     181                 :  *  @param tr_data_item pointer to given Test Result data item.
     182                 :  *  @return positive integer result type value,
     183                 :  *          or returns -1 if operation failed.  
     184                 :  *
     185                 :  *  Possible errors:
     186                 :  *  -1 if Test Result data item not available.
     187                 :  */
     188                 : int tr_get_result_type (DLListIterator tr_data_item)
     189             360 : {
     190             360 :         pthread_mutex_lock (&TR_MUTEX);
     191                 : 
     192                 :         /* If result type not available then returns error code -1 */
     193             360 :         int             result_type = -1;
     194                 : 
     195                 :         test_result_s  *test_result =
     196             360 :             (test_result_s *) dl_list_data (tr_data_item);
     197                 : 
     198             360 :         if ((test_result != INITPTR) && (test_result != NULL)) {
     199             356 :                 result_type = test_result->result_type_;
     200                 :         }
     201                 : 
     202             360 :         pthread_mutex_unlock (&TR_MUTEX);
     203                 : 
     204             360 :         return result_type;
     205                 : }
     206                 : 
     207                 : /* ------------------------------------------------------------------------- */
     208                 : 
     209                 : /** Gets result code value from given Test Result Data item
     210                 :  *  @param tr_data_item pointer to given Test Result data item.
     211                 :  *  @return positive integer result code value,
     212                 :  *          or returns -1 if operation failed.  
     213                 :  *
     214                 :  *  Possible errors:
     215                 :  *  -1 if Test Result data item not available.
     216                 :  */
     217                 : int tr_get_result_code (DLListIterator tr_data_item)
     218               3 : {
     219               3 :         pthread_mutex_lock (&TR_MUTEX);
     220                 : 
     221                 :         /* If result code not available then returns error code -1 */
     222               3 :         int             result_code = -1;
     223                 : 
     224                 :         test_result_s  *test_result =
     225               3 :             (test_result_s *) dl_list_data (tr_data_item);
     226               3 :         if ((test_result != INITPTR) && (test_result != NULL)) {
     227               1 :                 result_code = test_result->result_code_;
     228                 :         }
     229                 : 
     230               3 :         pthread_mutex_unlock (&TR_MUTEX);
     231                 : 
     232               3 :         return result_code;
     233                 : }
     234                 : 
     235                 : /* ------------------------------------------------------------------------- */
     236                 : 
     237                 : /** Gets start time value from given Test Result Data item
     238                 :  *  @param tr_data_item pointer to given Test Result data item.
     239                 :  *  @return long type start time value.
     240                 :  *
     241                 :  *  Possible errors:
     242                 :  *  None.
     243                 :  */
     244                 : long tr_get_start_time (DLListIterator tr_data_item)
     245              73 : {
     246              73 :         pthread_mutex_lock (&TR_MUTEX);
     247                 : 
     248                 :         /* Default start time value is 0 */
     249              73 :         long            start_time = 0;
     250                 : 
     251                 :         test_result_s  *test_result =
     252              73 :             (test_result_s *) dl_list_data (tr_data_item);;
     253              73 :         if ((test_result != INITPTR) && (test_result != NULL)) {
     254              73 :                 start_time = test_result->start_time_;
     255                 :         }
     256                 : 
     257              73 :         pthread_mutex_unlock (&TR_MUTEX);
     258                 : 
     259              73 :         return start_time;
     260                 : }
     261                 : 
     262                 : /* ------------------------------------------------------------------------- */
     263                 : 
     264                 : /** Gets end time value from given Test Result Data item
     265                 :  *  @param tr_data_item pointer to given Test Result data item.
     266                 :  *  @return long type end time value.
     267                 :  *
     268                 :  *  Possible errors:
     269                 :  *  None.
     270                 :  */
     271                 : long tr_get_end_time (DLListIterator tr_data_item)
     272              73 : {
     273              73 :         pthread_mutex_lock (&TR_MUTEX);
     274                 : 
     275                 :         /* Default end time value is 0 */
     276              73 :         long            end_time = 0;
     277                 : 
     278                 :         test_result_s  *test_result =
     279              73 :             (test_result_s *) dl_list_data (tr_data_item);
     280                 : 
     281              73 :         if ((test_result != INITPTR) && (test_result != NULL)) {
     282              73 :                 end_time = test_result->end_time_;
     283                 :         }
     284                 : 
     285              73 :         pthread_mutex_unlock (&TR_MUTEX);
     286                 : 
     287              73 :         return end_time;
     288                 : }
     289                 : 
     290                 : /* ------------------------------------------------------------------------- */
     291                 : 
     292                 : /** Gets pointer to linked list of printouts list
     293                 :  *  @param tr_data_item pointer to Test Result data item.
     294                 :  *  @return returns pointer to linked list of printouts list data,
     295                 :  *          or returns INITPTR if operation failed.  
     296                 :  *
     297                 :  *  Possible errors:
     298                 :  *  INITPTR if Test Result data item not available.
     299                 :  */
     300                 : DLList         *tr_get_priontouts_list (DLListIterator tr_data_item)
     301              67 : {
     302              67 :         pthread_mutex_lock (&TR_MUTEX);
     303                 : 
     304              67 :         DLList         *printouts_list = INITPTR;
     305                 :         test_result_s  *test_result =
     306              67 :             (test_result_s *) dl_list_data (tr_data_item);
     307                 : 
     308              67 :         if ((test_result != INITPTR) && (test_result != NULL)) {
     309              67 :                 printouts_list = test_result->printouts_list_;
     310                 :         }
     311                 : 
     312              67 :         pthread_mutex_unlock (&TR_MUTEX);
     313                 : 
     314              67 :         return printouts_list;
     315                 : }
     316                 : 
     317                 : /* ------------------------------------------------------------------------- */
     318                 : 
     319                 : /** Sets new result description string text for given Test Result data item
     320                 :  *  @param tr_data_item pointer to given Test Result data item.
     321                 :  *  @param result_desc new result description string text. 
     322                 :  */
     323                 : void tr_set_result_description (DLListIterator tr_data_item,
     324                 :                                 result_description_t result_desc)
     325              76 : {
     326              76 :         pthread_mutex_lock (&TR_MUTEX);
     327                 : 
     328              76 :         size_t          str_size = 0;
     329                 :         test_result_s  *test_result =
     330              76 :             (test_result_s *) dl_list_data (tr_data_item);
     331                 : 
     332              76 :         str_size = strlen (result_desc) + 1;
     333                 : 
     334              76 :         if ((str_size <= MaxTestResultDescription) &&
     335                 :             (test_result != INITPTR) && (test_result != NULL)) {
     336              74 :                 STRCPY (test_result->result_description_, result_desc,
     337                 :                         str_size);
     338                 :         }
     339                 : 
     340              76 :         pthread_mutex_unlock (&TR_MUTEX);
     341              76 : }
     342                 : 
     343                 : /* ------------------------------------------------------------------------- */
     344                 : 
     345                 : /** Sets result type value for given Test Result data item
     346                 :  *  @param tr_data_item pointer to given Test Result data item.
     347                 :  */
     348                 : void tr_set_result_type (DLListIterator tr_data_item, int result_type)
     349              76 : {
     350              76 :         pthread_mutex_lock (&TR_MUTEX);
     351                 : 
     352                 :         test_result_s  *test_result =
     353              76 :             (test_result_s *) dl_list_data (tr_data_item);
     354                 : 
     355              76 :         if ((test_result != INITPTR) && (test_result != NULL)) {
     356              74 :                 test_result->result_type_ = result_type;
     357                 :         }
     358                 : 
     359              76 :         pthread_mutex_unlock (&TR_MUTEX);
     360              76 : }
     361                 : 
     362                 : /* ------------------------------------------------------------------------- */
     363                 : 
     364                 : /** Sets result code for given Test Result data item.
     365                 :  *  @param tr_data_item pointer to given Test Result data item.
     366                 :  */
     367                 : void tr_set_result_code (DLListIterator tr_data_item, int result_code)
     368               3 : {
     369               3 :         pthread_mutex_lock (&TR_MUTEX);
     370                 : 
     371                 :         test_result_s  *test_result =
     372               3 :             (test_result_s *) dl_list_data (tr_data_item);
     373                 : 
     374               3 :         if ((test_result != INITPTR) && (test_result != NULL)) {
     375               1 :                 test_result->result_code_ = result_code;
     376                 :         }
     377                 : 
     378               3 :         pthread_mutex_unlock (&TR_MUTEX);
     379               3 : }
     380                 : 
     381                 : /* ------------------------------------------------------------------------- */
     382                 : 
     383                 : /** Sets start time for given Test Result data item
     384                 :  *  @param tr_data_item pointer to given Test Result data item.
     385                 :  */
     386                 : void tr_set_start_time (DLListIterator tr_data_item, long start_time)
     387             101 : {
     388             101 :         pthread_mutex_lock (&TR_MUTEX);
     389                 : 
     390                 :         test_result_s  *test_result =
     391             101 :             (test_result_s *) dl_list_data (tr_data_item);
     392                 : 
     393             101 :         if ((test_result != INITPTR) && (test_result != NULL)) {
     394             100 :                 test_result->start_time_ = start_time;
     395                 :         }
     396                 : 
     397             101 :         pthread_mutex_unlock (&TR_MUTEX);
     398             101 : }
     399                 : 
     400                 : /* ------------------------------------------------------------------------- */
     401                 : 
     402                 : /** Sets end time for given Test Result data item
     403                 :  *  @param tr_data_item pointer to given Test Result data item.
     404                 :  */
     405                 : void tr_set_end_time (DLListIterator tr_data_item, long end_time)
     406              74 : {
     407              74 :         pthread_mutex_lock (&TR_MUTEX);
     408                 : 
     409                 :         test_result_s  *test_result =
     410              74 :             (test_result_s *) dl_list_data (tr_data_item);
     411                 : 
     412              74 :         if ((test_result != INITPTR) && (test_result != NULL)) {
     413              74 :                 test_result->end_time_ = end_time;
     414                 :         }
     415                 : 
     416              74 :         pthread_mutex_unlock (&TR_MUTEX);
     417              74 : }
     418                 : 
     419                 : /* ------------------------------------------------------------------------- */
     420                 : 
     421                 : /** Sets pointer to linked list of printouts list for Test Result data item
     422                 :  *  @param tr_data_item pointer to given Test Result data item.
     423                 :  */
     424                 : void tr_set_priontouts_list (DLListIterator tr_data_item,
     425                 :                              DLList * printouts_list)
     426             102 : {
     427             102 :         pthread_mutex_lock (&TR_MUTEX);
     428                 : 
     429                 :         test_result_s  *test_result =
     430             102 :             (test_result_s *) dl_list_data (tr_data_item);
     431                 : 
     432             102 :         if ((test_result != INITPTR) && (test_result != NULL)) {
     433             101 :                 test_result->printouts_list_ = printouts_list;
     434                 :         }
     435                 : 
     436             102 :         pthread_mutex_unlock (&TR_MUTEX);
     437             102 : }
     438                 : 
     439                 : /* ------------------------------------------------------------------------- */
     440                 : 
     441                 : /** Creates Test Result prinout data structure
     442                 :  *  @param tr_data_item pointer to Test Result data item.
     443                 :  *  @return returns pointer to printout data structure,
     444                 :  *          or returns NULL if operation failed.  
     445                 :  *
     446                 :  *  Possible errors:
     447                 :  *  NULL if not possible create and allocate memory for printout data.
     448                 :  */
     449                 : test_result_printout_s *tr_create_printout (int priority, char *printout)
     450              80 : {
     451              80 :         pthread_mutex_lock (&TR_MUTEX);
     452                 : 
     453              80 :         test_result_printout_s *tr_printout = NEW (test_result_printout_s);
     454              80 :         int             len = 0;
     455                 : 
     456              80 :         if (tr_printout != NULL) {
     457              80 :                 tr_printout->priority_ = priority;
     458              80 :                 tr_printout->printout_ = NULL;
     459                 : 
     460              80 :                 if (printout != NULL) {
     461              79 :                         len = strlen (printout);
     462              79 :                         if (len > 0) {
     463              79 :                                 tr_printout->printout_ =
     464                 :                                     NEW2 (char, (len + 1));
     465              79 :                                 STRCPY (tr_printout->printout_, printout,
     466                 :                                         (len + 1));
     467                 :                         }
     468                 :                 }
     469                 :         }
     470                 : 
     471              80 :         pthread_mutex_unlock (&TR_MUTEX);
     472                 : 
     473              80 :         return tr_printout;
     474                 : }
     475                 : 
     476                 : /* ------------------------------------------------------------------------- */
     477                 : 
     478                 : /** Removes printouts data structure and freeing used memery allocation
     479                 :  *  @param tr_data_item pointer to given Test Result data item.
     480                 :  */
     481                 : void tr_remove_printout (test_result_printout_s * tr_printout)
     482               4 : {
     483               4 :         pthread_mutex_lock (&TR_MUTEX);
     484                 : 
     485               4 :         if (tr_printout != NULL) {
     486               4 :                 if (tr_printout->printout_ != NULL)
     487               3 :                         DELETE (tr_printout->printout_);
     488               4 :                 DELETE (tr_printout);
     489                 :         }
     490                 : 
     491               4 :         pthread_mutex_unlock (&TR_MUTEX);
     492               4 : }
     493                 : 
     494                 : /* ------------------------------------------------------------------------- */
     495                 : 
     496                 : /** Removes linked list of printouts data from given Test Result data item
     497                 :  *  @param tr_data_item pointer to given Test Result data item.
     498                 :  */
     499                 : void tr_remove_printouts_list (DLListIterator tr_data_item)
     500              85 : {
     501              85 :         pthread_mutex_lock (&TR_MUTEX);
     502                 : 
     503                 :         test_result_s  *test_result =
     504              85 :             (test_result_s *) dl_list_data (tr_data_item);
     505              85 :         DLList         *prt_list = INITPTR;
     506              85 :         DLListIterator  prt_data_item = INITPTR;
     507              85 :         test_result_printout_s *prt_data = INITPTR;
     508                 : 
     509              85 :         if (test_result != INITPTR) {
     510              85 :                 prt_list = test_result->printouts_list_;
     511              85 :                 if (prt_list != INITPTR) {
     512              10 :                         prt_data_item = dl_list_head (prt_list);
     513              30 :                         while (prt_data_item != INITPTR) {
     514              10 :                                 prt_data =
     515                 :                                     (test_result_printout_s *)
     516                 :                                     dl_list_data (prt_data_item);
     517              10 :                                 if (prt_data->printout_ != INITPTR) {
     518              10 :                                         DELETE (prt_data->printout_);
     519                 :                                 }
     520              10 :                                 DELETE (prt_data);
     521              10 :                                 prt_data_item = dl_list_next (prt_data_item);
     522                 :                         }
     523                 :                 }
     524                 : 
     525              85 :                 dl_list_free (&prt_list);
     526              85 :                 test_result->printouts_list_ = INITPTR;
     527                 :         }
     528                 : 
     529              85 :         pthread_mutex_unlock (&TR_MUTEX);
     530              85 : }
     531                 : 
     532                 : /* ------------------------------------------------------------------------- */
     533                 : 
     534                 : /* ================= OTHER EXPORTED FUNCTIONS ============================== */
     535                 : /* None */
     536                 : 
     537                 : /* ================= TESTS FOR LOCAL FUNCTIONS ============================= */
     538                 : /* None */
     539                 : 
     540                 : /* ========================================================================= */
     541                 : /* End of file */

Generated by: LTP GCOV extension version 1.6