LCOV - code coverage report
Current view: top level - core/test/integration/model - functions.c Hit Total Coverage
Test: ROOT-Sim master Documentation Coverage Lines: 1 8 12.5 %
Date: 2021-03-25 15:11:55

          Line data    Source code
       1           1 : /**
       2             :  * @file test/integration/model/functions.c
       3             :  *
       4             :  * @brief Helper functions of the model used to verify the runtime correctness
       5             :  *
       6             :  * SPDX-FileCopyrightText: 2008-2021 HPDCS Group <rootsim@googlegroups.com>
       7             :  * SPDX-License-Identifier: GPL-3.0-only
       8             :  */
       9             : #include <integration/model/application.h>
      10             : 
      11             : #include <stdio.h>
      12             : #include <string.h>
      13             : 
      14             : uint32_t crc_update(const uint64_t *buf, size_t n, uint32_t crc);
      15             : 
      16           0 : buffer* get_buffer(buffer *head, unsigned i)
      17             : {
      18             :         while (i--)
      19             :                 head = head->next;
      20             : 
      21             :         return head;
      22             : }
      23             : 
      24           0 : uint32_t read_buffer(buffer *head, unsigned i, uint32_t old_crc)
      25             : {
      26             :         head = get_buffer(head, i);
      27             :         return crc_update(head->data, head->count, old_crc);
      28             : }
      29             : 
      30           0 : buffer* allocate_buffer(lp_state *state, const unsigned *data, unsigned count)
      31             : {
      32             :         buffer *new = malloc(sizeof(buffer) + count * sizeof(uint64_t));
      33             :         new->next = state->head;
      34             :         new->count = count;
      35             : 
      36             :         if (data != NULL)
      37             :                 memcpy(new->data, data, count * sizeof(uint64_t));
      38             :         else
      39             :                 for(unsigned i = 0; i < count; i++)
      40             :                         new->data[i] = lcg_random_u(state->rng_state);
      41             : 
      42             :         return new;
      43             : }
      44             : 
      45           0 : buffer* deallocate_buffer(buffer *head, unsigned i)
      46             : {
      47             :         buffer *prev = NULL;
      48             :         buffer *to_free = head;
      49             : 
      50             :         for (unsigned j = 0; j < i; j++) {
      51             :                 prev = to_free;
      52             :                 to_free = to_free->next;
      53             :         }
      54             : 
      55             :         if (prev != NULL) {
      56             :                 prev->next = to_free->next;
      57             :                 free(to_free);
      58             :                 return head;
      59             :         }
      60             : 
      61             :         prev = head->next;
      62             :         free(head);
      63             :         return prev;
      64             : }
      65             : 
      66           0 : static uint32_t crc_table[256];
      67             : 
      68           0 : void crc_table_init(void)
      69             : {
      70             :         uint32_t n = 256;
      71             :         while (n--) {
      72             :                 uint32_t c = n;
      73             :                 int k = 8;
      74             :                 while(k--) {
      75             :                         if (c & 1) {
      76             :                                 c = 0xedb88320UL ^ (c >> 1);
      77             :                         } else {
      78             :                                 c = c >> 1;
      79             :                         }
      80             :                 }
      81             :                 crc_table[n] = c;
      82             :         }
      83             : }
      84             : 
      85           0 : uint32_t crc_update(const uint64_t *buf, size_t n, uint32_t crc)
      86             : {
      87             :         uint32_t c = crc ^ 0xffffffffUL;
      88             :         while (n--) {
      89             :                 unsigned k = 64;
      90             :                 do {
      91             :                         k -= 8;
      92             :                         c = crc_table[(c ^ (buf[n] >> k)) & 0xff] ^ (c >> 8);
      93             :                 } while(k);
      94             :         }
      95             :         return c ^ 0xffffffffUL;
      96             : }

Generated by: LCOV version 1.14