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

          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             :         }
      43             : 
      44             :         return new;
      45             : }
      46             : 
      47           0 : buffer* deallocate_buffer(buffer *head, unsigned i)
      48             : {
      49             :         buffer *prev = NULL;
      50             :         buffer *to_free = head;
      51             : 
      52             :         for (unsigned j = 0; j < i; j++) {
      53             :                 prev = to_free;
      54             :                 to_free = to_free->next;
      55             :         }
      56             : 
      57             :         if (prev != NULL) {
      58             :                 prev->next = to_free->next;
      59             :                 free(to_free);
      60             :                 return head;
      61             :         }
      62             : 
      63             :         prev = head->next;
      64             :         free(head);
      65             :         return prev;
      66             : }
      67             : 
      68           0 : static uint32_t crc_table[256];
      69             : 
      70           0 : void crc_table_init(void)
      71             : {
      72             :         uint32_t n = 256;
      73             :         while(n--) {
      74             :                 uint32_t c = n;
      75             :                 int k = 8;
      76             :                 while(k--) {
      77             :                         if (c & 1) {
      78             :                                 c = 0xedb88320UL ^ (c >> 1);
      79             :                         } else {
      80             :                                 c = c >> 1;
      81             :                         }
      82             :                 }
      83             :                 crc_table[n] = c;
      84             :         }
      85             : }
      86             : 
      87           0 : uint32_t crc_update(const uint64_t *buf, size_t n, uint32_t crc)
      88             : {
      89             :         uint32_t c = crc ^ 0xffffffffUL;
      90             :         while (n--) {
      91             :                 unsigned k = 64;
      92             :                 do {
      93             :                         k -= 8;
      94             :                         c = crc_table[(c ^ (buf[n] >> k)) & 0xff] ^ (c >> 8);
      95             :                 } while(k);
      96             :         }
      97             :         return c ^ 0xffffffffUL;
      98             : }

Generated by: LCOV version 1.14