/*
 *  ticket-519.sli
 *
 *  This file is part of NEST.
 *
 *  Copyright (C) 2004 The NEST Initiative
 *
 *  NEST is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  NEST is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with NEST.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/* BeginDocumentation

Name: testsuite::ticket-519 - Ensure that multimeter behaves even if no data on some threads

Synopsis: (ticket-519) run -> NEST exits if test fails

Description:
If multimeter is recording from fewer nodes than threads, then the instance on some threads will
collect no data. Up to r9252, this can cause NEST to crash at least in accumulator mode. This
test ensures that no crash occurs.
 
Author: Hans Ekkehard Plesser, 2011-06-16
 */

(unittest) run
/unittest using

M_ERROR setverbosity

% test in non-accumulating mode
{
  ResetKernel

  0 << /total_num_virtual_procs 2 /local_num_threads 2 >> SetStatus
  
  /n1 /iaf_neuron Create def
  /n2 /iaf_neuron Create def
  /m1 /multimeter << /record_from [/V_m] /withtime false /withgid false >> Create def
  /m2 /multimeter << /record_from [/V_m] /withtime false /withgid false >> Create def
  m1 n1 Connect
  m2 n2 Connect

  10 Simulate
 
  (M1: ) ==only
  m1 [/events /V_m] get ==
  (M2: ) ==only
  m2 [/events /V_m] get ==
}
pass_or_die

% test in accumulating mode
{
  ResetKernel

  0 << /total_num_virtual_procs 2 /local_num_threads 2 >> SetStatus
  
  /n1 /iaf_neuron Create def
  /n2 /iaf_neuron Create def
  /m1 /multimeter << /record_from [/V_m] /withtime false /withgid false /to_accumulator true >> Create def
  /m2 /multimeter << /record_from [/V_m] /withtime false /withgid false /to_accumulator true >> Create def
  m1 n1 Connect
  m2 n2 Connect

  10 Simulate

  (Acc M1: ) ==only
  m1 [/events /V_m] get ==
  (Acc M2: ) ==only
  m2 [/events /V_m] get ==
}
pass_or_die

endusing