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

          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           1 : 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             :                         test_printf("%" PRIu32 "\n", state->total_checksum);
      27             :                         while(state->head)
      28             :                                 state->head = deallocate_buffer(state->head, 0);
      29             :                         free(state);
      30             :                 }
      31             :                 return;
      32             :         }
      33             : 
      34             :         if (!state && event_type != LP_INIT && event_type != MODEL_INIT &&
      35             :                         event_type != MODEL_FINI) {
      36             :                 printf("[ERR] Requested to process an weird event\n");
      37             :                 abort();
      38             :         }
      39             :         switch (event_type) {
      40             :         case MODEL_INIT:
      41             :                 crc_table_init();
      42             :                 break;
      43             : 
      44             :         case LP_INIT:
      45             :                 state = malloc(sizeof(lp_state));
      46             :                 if (state == NULL) {
      47             :                         exit(-1);
      48             :                 }
      49             :                 memset(state, 0, sizeof(lp_state));
      50             : 
      51             :                 lcg_init(state->rng_state, ((test_rng_state)me + 1) *
      52             :                          4390023366657240769ULL);
      53             :                 SetState(state);
      54             : 
      55             :                 unsigned buffers_to_allocate = do_random() * MAX_BUFFERS;
      56             :                 for (unsigned i = 0; i < buffers_to_allocate; ++i) {
      57             :                         unsigned c = do_random() * MAX_BUFFER_SIZE / sizeof(uint64_t);
      58             :                         state->head = allocate_buffer(state, NULL, c);
      59             :                         state->buffer_count++;
      60             :                 }
      61             : 
      62             :                 ScheduleNewEvent(me, 20 * do_random(), LOOP, NULL, 0);
      63             :                 break;
      64             : 
      65             :         case LOOP:
      66             :                 state->events++;
      67             :                 ScheduleNewEvent(me, now + do_random() * 10, LOOP, NULL, 0);
      68             :                 lp_id_t dest = do_random() * n_lps;
      69             :                 if(do_random() < DOUBLING_PROBABILITY && dest != me)
      70             :                         ScheduleNewEvent(dest, now + do_random() * 10, LOOP, NULL, 0);
      71             : 
      72             :                 if (state->buffer_count) {
      73             :                         state->total_checksum = read_buffer(state->head, do_random() * state->buffer_count, state->total_checksum);
      74             :                 }
      75             : 
      76             :                 if (state->buffer_count < MAX_BUFFERS && do_random() < ALLOC_PROBABILITY) {
      77             :                         unsigned c = do_random() * MAX_BUFFER_SIZE / sizeof(uint64_t);
      78             :                         state->head = allocate_buffer(state, NULL, c);
      79             :                         state->buffer_count++;
      80             :                 }
      81             : 
      82             :                 if (state->buffer_count && do_random() < DEALLOC_PROBABILITY) {
      83             :                         state->head = deallocate_buffer(state->head, do_random() * state->buffer_count);
      84             :                         state->buffer_count--;
      85             :                 }
      86             : 
      87             :                 if (state->buffer_count && do_random() < SEND_PROBABILITY) {
      88             :                         unsigned i = do_random() * state->buffer_count;
      89             :                         buffer *to_send = get_buffer(state->head, i);
      90             : 
      91             :                         dest = do_random() * n_lps;
      92             :                         ScheduleNewEvent(dest, now + do_random() * 10, RECEIVE, to_send->data, to_send->count * sizeof(uint64_t));
      93             : 
      94             :                         state->head = deallocate_buffer(state->head, i);
      95             :                         state->buffer_count--;
      96             :                 }
      97             :                 break;
      98             : 
      99             :         case RECEIVE:
     100             :                 if(state->buffer_count >= MAX_BUFFERS)
     101             :                         break;
     102             :                 state->head = allocate_buffer(state, event_content, event_size / sizeof(uint64_t));
     103             :                 state->buffer_count++;
     104             :                 break;
     105             : 
     106             :         case MODEL_FINI:
     107             :                 break;
     108             : 
     109             :         default:
     110             :                 printf("[ERR] Requested to process an unknown event\n");
     111             :                 abort();
     112             :                 break;
     113             :         }
     114             : }
     115             : 
     116           0 : bool CanEnd(lp_id_t me, const void *snapshot)
     117             : {
     118             :         (void)me;
     119             :         const lp_state *state = snapshot;
     120             :         return state->events >= COMPLETE_EVENTS;
     121             : }

Generated by: LCOV version 1.14