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

          Line data    Source code
       1           0 : /**
       2             :  * @file test/integration/model/application.c
       3             :  *
       4             :  * @brief Main module 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 <test.h>
      12             : 
      13             : #include <inttypes.h>
      14             : #include <stdio.h>
      15             : #include <stdlib.h>
      16             : 
      17             : struct ap_option model_options[] = {{0}};
      18             : 
      19           0 : #define do_random() (lcg_random(state->rng_state))
      20             : 
      21           0 : void ProcessEvent(lp_id_t me, simtime_t now, unsigned event_type, const void *event_content, unsigned event_size, void *st)
      22             : {
      23             :         lp_state *state = st;
      24             :         if (state && state->events >= COMPLETE_EVENTS) {
      25             :                 if (event_type == LP_FINI) {
      26             :                         if (model_expected_output[me] != state->total_checksum) {
      27             :                                 puts("[ERROR] Incorrect output!");
      28             :                                 abort();
      29             :                         }
      30             :                         while(state->head)
      31             :                                 state->head = deallocate_buffer(state->head, 0);
      32             :                         free(state);
      33             :                 }
      34             :                 return;
      35             :         }
      36             : 
      37             :         if (!state && event_type != LP_INIT && event_type != MODEL_INIT &&
      38             :                         event_type != MODEL_FINI) {
      39             :                 puts("[ERROR] Requested to process an weird event!");
      40             :                 abort();
      41             :         }
      42             :         switch (event_type) {
      43             :         case MODEL_INIT:
      44             :                 crc_table_init();
      45             :                 break;
      46             : 
      47             :         case LP_INIT:
      48             :                 state = malloc(sizeof(lp_state));
      49             :                 if (state == NULL)
      50             :                         exit(-1);
      51             : 
      52             :                 memset(state, 0, sizeof(lp_state));
      53             : 
      54             :                 lcg_init(state->rng_state, ((test_rng_state)me + 1) *
      55             :                          4390023366657240769ULL);
      56             :                 SetState(state);
      57             : 
      58             :                 unsigned buffers_to_allocate = do_random() * MAX_BUFFERS;
      59             :                 for (unsigned i = 0; i < buffers_to_allocate; ++i) {
      60             :                         unsigned c = do_random() * MAX_BUFFER_SIZE / sizeof(uint64_t);
      61             :                         state->head = allocate_buffer(state, NULL, c);
      62             :                         state->buffer_count++;
      63             :                 }
      64             : 
      65             :                 ScheduleNewEvent(me, 20 * do_random(), LOOP, NULL, 0);
      66             :                 break;
      67             : 
      68             :         case LOOP:
      69             :                 state->events++;
      70             :                 ScheduleNewEvent(me, now + do_random() * 10, LOOP, NULL, 0);
      71             :                 lp_id_t dest = do_random() * n_lps;
      72             :                 if(do_random() < DOUBLING_PROBABILITY && dest != me)
      73             :                         ScheduleNewEvent(dest, now + do_random() * 10, LOOP, NULL, 0);
      74             : 
      75             :                 if (state->buffer_count)
      76             :                         state->total_checksum = read_buffer(state->head, do_random() * state->buffer_count, state->total_checksum);
      77             : 
      78             :                 if (state->buffer_count < MAX_BUFFERS && do_random() < ALLOC_PROBABILITY) {
      79             :                         unsigned c = do_random() * MAX_BUFFER_SIZE / sizeof(uint64_t);
      80             :                         state->head = allocate_buffer(state, NULL, c);
      81             :                         state->buffer_count++;
      82             :                 }
      83             : 
      84             :                 if (state->buffer_count && do_random() < DEALLOC_PROBABILITY) {
      85             :                         state->head = deallocate_buffer(state->head, do_random() * state->buffer_count);
      86             :                         state->buffer_count--;
      87             :                 }
      88             : 
      89             :                 if (state->buffer_count && do_random() < SEND_PROBABILITY) {
      90             :                         unsigned i = do_random() * state->buffer_count;
      91             :                         buffer *to_send = get_buffer(state->head, i);
      92             : 
      93             :                         dest = do_random() * n_lps;
      94             :                         ScheduleNewEvent(dest, now + do_random() * 10, RECEIVE, to_send->data, to_send->count * sizeof(uint64_t));
      95             : 
      96             :                         state->head = deallocate_buffer(state->head, i);
      97             :                         state->buffer_count--;
      98             :                 }
      99             :                 break;
     100             : 
     101             :         case RECEIVE:
     102             :                 if(state->buffer_count >= MAX_BUFFERS)
     103             :                         break;
     104             :                 state->head = allocate_buffer(state, event_content, event_size / sizeof(uint64_t));
     105             :                 state->buffer_count++;
     106             :                 break;
     107             : 
     108             :         case MODEL_FINI:
     109             :                 break;
     110             : 
     111             :         default:
     112             :                 puts("[ERROR] Requested to process an unknown event!");
     113             :                 abort();
     114             :                 break;
     115             :         }
     116             : }
     117             : 
     118           0 : bool CanEnd(lp_id_t me, const void *snapshot)
     119             : {
     120             :         (void)me;
     121             :         const lp_state *state = snapshot;
     122             :         return state->events >= COMPLETE_EVENTS;
     123             : }

Generated by: LCOV version 1.14