LCOV - code coverage report
Current view: top level - core/test - run-pel.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 52 52 100.0 %
Date: 2024-01-02 21:04:04 Functions: 3 3 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
       2                 :            : /*
       3                 :            :  * Test for our PEL record generation. Currently this doesn't actually
       4                 :            :  * test that the records we generate are correct, but it at least lets
       5                 :            :  * us run valgrind over the generation routines to check for buffer
       6                 :            :  * overflows, etc.
       7                 :            :  *
       8                 :            :  * Copyright 2013-2016 IBM Corp.
       9                 :            :  */
      10                 :            : 
      11                 :            : #include <skiboot.h>
      12                 :            : #include <inttypes.h>
      13                 :            : #include <assert.h>
      14                 :            : #include <pel.h>
      15                 :            : #include <errorlog.h>
      16                 :            : #include <device.h>
      17                 :            : 
      18                 :            : #define TEST_ERROR 0x1234
      19                 :            : #define TEST_SUBSYS 0x5678
      20                 :            : 
      21                 :            : DEFINE_LOG_ENTRY(TEST_ERROR, OPAL_PLATFORM_ERR_EVT, TEST_SUBSYS,
      22                 :            :                         OPAL_PLATFORM_FIRMWARE, OPAL_INFO,
      23                 :            :                         OPAL_NA);
      24                 :            : 
      25                 :            : /* Override this for testing. */
      26                 :            : #define is_rodata(p) fake_is_rodata(p)
      27                 :            : 
      28                 :            : char __rodata_start[16];
      29                 :            : #define __rodata_end (__rodata_start + sizeof(__rodata_start))
      30                 :            : 
      31                 :          2 : static inline bool fake_is_rodata(const void *p)
      32                 :            : {
      33                 :          2 :         return ((char *)p >= __rodata_start && (char *)p < __rodata_end);
      34                 :            : }
      35                 :            : 
      36                 :            : #define zalloc(bytes) calloc((bytes), 1)
      37                 :            : 
      38                 :            : #include "../device.c"
      39                 :            : #include "../pel.c"
      40                 :            : 
      41                 :            : struct dt_node *dt_root = NULL;
      42                 :            : char dt_prop[] = "DUMMY DT PROP";
      43                 :            : 
      44                 :          4 : int rtc_cache_get_datetime(uint32_t *year_month_day,
      45                 :            :                            uint64_t *hour_minute_second_millisecond)
      46                 :            : {
      47                 :          4 :         *year_month_day = 0;
      48                 :          4 :         *hour_minute_second_millisecond = 0;
      49                 :            : 
      50                 :          4 :         return 0;
      51                 :            : }
      52                 :            : 
      53                 :          1 : int main(void)
      54                 :            : {
      55                 :            :         char *pel_buf;
      56                 :            :         size_t size;
      57                 :            :         struct errorlog *elog;
      58                 :          1 :         struct opal_err_info *opal_err_info = &err_TEST_ERROR;
      59                 :            :         char *buffer;
      60                 :            :         struct elog_user_data_section *tmp;
      61                 :            : 
      62                 :          1 :         dt_root = dt_new_root("");
      63                 :          1 :         dt_add_property_string(dt_root, "model", "run-pel-unittest");
      64                 :            : 
      65                 :          1 :         elog = malloc(sizeof(struct errorlog));
      66                 :          1 :         pel_buf = malloc(PEL_MIN_SIZE + 4);
      67                 :          1 :         assert(elog);
      68                 :          1 :         assert(pel_buf);
      69                 :            : 
      70                 :          1 :         memset(elog, 0, sizeof(struct errorlog));
      71                 :            : 
      72                 :          1 :         elog->error_event_type = opal_err_info->err_type;
      73                 :          1 :         elog->component_id = opal_err_info->cmp_id;
      74                 :          1 :         elog->subsystem_id = opal_err_info->subsystem;
      75                 :          1 :         elog->event_severity = opal_err_info->sev;
      76                 :          1 :         elog->event_subtype = opal_err_info->event_subtype;
      77                 :          1 :         elog->reason_code = opal_err_info->reason_code;
      78                 :          1 :         elog->elog_origin = ORG_SAPPHIRE;
      79                 :            : 
      80                 :          1 :         size = pel_size(elog);
      81                 :            : 
      82                 :          1 :         printf("Test buffer too small: ");
      83                 :          1 :         assert(0 == create_pel_log(elog, NULL, size - 1));
      84                 :            : 
      85                 :          1 :         assert(size <= PEL_MIN_SIZE + 4);
      86                 :          1 :         assert(size == create_pel_log(elog, pel_buf, size));
      87                 :            : 
      88                 :          1 :         memset(elog, 0, sizeof(struct errorlog));
      89                 :            : 
      90                 :          1 :         elog->error_event_type = opal_err_info->err_type;
      91                 :          1 :         elog->component_id = opal_err_info->cmp_id;
      92                 :          1 :         elog->subsystem_id = opal_err_info->subsystem;
      93                 :          1 :         elog->event_severity = opal_err_info->sev;
      94                 :          1 :         elog->event_subtype = opal_err_info->event_subtype;
      95                 :          1 :         elog->reason_code = opal_err_info->reason_code;
      96                 :          1 :         elog->elog_origin = ORG_SAPPHIRE;
      97                 :            : 
      98                 :          1 :         size = pel_size(elog);
      99                 :          1 :         pel_buf = realloc(pel_buf, size);
     100                 :          1 :         assert(pel_buf);
     101                 :            : 
     102                 :          1 :         buffer = elog->user_data_dump + elog->user_section_size;
     103                 :          1 :         tmp = (struct elog_user_data_section *)buffer;
     104                 :          1 :         tmp->tag = OPAL_ELOG_SEC_DESC;  /* ASCII of DESC */
     105                 :          1 :         tmp->size = size + sizeof(struct elog_user_data_section) - 1;
     106                 :          1 :         strcpy(tmp->data_dump, "Hello World!");
     107                 :          1 :         elog->user_section_size += tmp->size;
     108                 :          1 :         elog->user_section_count++;
     109                 :            : 
     110                 :          1 :         size = pel_size(elog);
     111                 :          1 :         pel_buf = realloc(pel_buf, size);
     112                 :          1 :         assert(pel_buf);
     113                 :            : 
     114                 :          1 :         assert(size == create_pel_log(elog, pel_buf, size));
     115                 :            : 
     116                 :          1 :         free(pel_buf);
     117                 :          1 :         free(elog);
     118                 :            : 
     119                 :          1 :         return 0;
     120                 :            : }

Generated by: LCOV version 1.14