MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Functions | Variables
test_slotsmanager.c File Reference
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <math.h>
#include <mpi.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <gsl/gsl_rng.h>
#include "stub.h"
#include <libgadget/partmanager.h>
#include <libgadget/domain.h>
#include <libgadget/slotsmanager.h>
Include dependency graph for test_slotsmanager.c:

Go to the source code of this file.

Functions

static int setup_particles (void **state)
 
static int teardown_particles (void **state)
 
static void test_slots_gc (void **state)
 
static void test_slots_gc_sorted (void **state)
 
static void test_slots_reserve (void **state)
 
static void test_slots_zero (void **state)
 
static void test_slots_fork (void **state)
 
static void test_slots_convert (void **state)
 
int main (void)
 

Variables

struct part_manager_type PartManager [1] = {{0}}
 

Function Documentation

◆ main()

int main ( void  )

Definition at line 223 of file test_slotsmanager.c.

223  {
224  const struct CMUnitTest tests[] = {
225  cmocka_unit_test(test_slots_gc),
226  cmocka_unit_test(test_slots_gc_sorted),
227  cmocka_unit_test(test_slots_reserve),
228  cmocka_unit_test(test_slots_fork),
229  cmocka_unit_test(test_slots_convert),
230  cmocka_unit_test(test_slots_zero),
231  };
232  return cmocka_run_group_tests_mpi(tests, NULL, NULL);
233 }
static void test_slots_convert(void **state)
static void test_slots_zero(void **state)
static void test_slots_fork(void **state)
static void test_slots_gc(void **state)
static void test_slots_gc_sorted(void **state)
static void test_slots_reserve(void **state)

References test_slots_convert(), test_slots_fork(), test_slots_gc(), test_slots_gc_sorted(), test_slots_reserve(), and test_slots_zero().

Here is the call graph for this function:

◆ setup_particles()

static int setup_particles ( void **  state)
static

Definition at line 21 of file test_slotsmanager.c.

22 {
23  PartManager->MaxPart = 1024;
24  PartManager->NumPart = 128 * 6;
25 
26  int64_t newSlots[6] = {128, 128, 128, 128, 128, 128};
27 
28  PartManager->Base = (struct particle_data *) mymalloc("P", PartManager->MaxPart* sizeof(struct particle_data));
29  memset(PartManager->Base, 0, sizeof(struct particle_data) * PartManager->MaxPart);
30 
32  int ptype;
36  for(ptype = 1; ptype < 4; ptype++) {
38  }
39 
40  slots_reserve(1, newSlots, SlotsManager);
41 
43 
44  int64_t i;
45  #pragma omp parallel for
46  for(i = 0; i < PartManager->NumPart; i ++) {
47  P[i].ID = i;
48  }
49 
51 
52  return 0;
53 }
#define mymalloc(name, size)
Definition: mymalloc.h:15
#define P
Definition: partmanager.h:88
void slots_setup_id(const struct part_manager_type *pman, struct slots_manager_type *sman)
Definition: slotsmanager.c:653
size_t slots_reserve(int where, int64_t atleast[6], struct slots_manager_type *sman)
Definition: slotsmanager.c:475
void slots_set_enabled(int ptype, size_t elsize, struct slots_manager_type *sman)
Definition: slotsmanager.c:560
void slots_setup_topology(struct part_manager_type *pman, int64_t *NLocal, struct slots_manager_type *sman)
Definition: slotsmanager.c:624
struct slots_manager_type SlotsManager[1]
Definition: slotsmanager.c:7
void slots_init(double increase, struct slots_manager_type *sman)
Definition: slotsmanager.c:550
struct particle_data * Base
Definition: partmanager.h:74
struct part_manager_type PartManager[1]
static enum TransferType ptype
Definition: zeldovich.c:146

References part_manager_type::Base, part_manager_type::MaxPart, mymalloc, part_manager_type::NumPart, P, PartManager, ptype, slots_init(), slots_reserve(), slots_set_enabled(), slots_setup_id(), slots_setup_topology(), and SlotsManager.

Referenced by test_slots_convert(), test_slots_fork(), test_slots_gc(), test_slots_gc_sorted(), test_slots_reserve(), and test_slots_zero().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ teardown_particles()

static int teardown_particles ( void **  state)
static

Definition at line 56 of file test_slotsmanager.c.

57 {
60  return 0;
61 }
#define myfree(x)
Definition: mymalloc.h:19
void slots_free(struct slots_manager_type *sman)
Definition: slotsmanager.c:570

References part_manager_type::Base, myfree, PartManager, slots_free(), and SlotsManager.

Referenced by test_slots_convert(), test_slots_fork(), test_slots_gc(), test_slots_gc_sorted(), and test_slots_zero().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_slots_convert()

static void test_slots_convert ( void **  state)
static

Definition at line 205 of file test_slotsmanager.c.

206 {
207  setup_particles(state);
208  int i;
209  for(i = 0; i < 6; i ++) {
210  slots_convert(128 * i, P[i * 128].Type, -1, PartManager, SlotsManager);
211  }
212 
213  assert_int_equal(PartManager->NumPart, 128 * i);
214 
215  assert_int_equal(SlotsManager->info[0].size, 129);
216  assert_int_equal(SlotsManager->info[4].size, 129);
217  assert_int_equal(SlotsManager->info[5].size, 129);
218 
219  teardown_particles(state);
220  return;
221 }
int slots_convert(int parent, int ptype, int placement, struct part_manager_type *pman, struct slots_manager_type *sman)
Definition: slotsmanager.c:60
int64_t size
Definition: slotsmanager.h:12
struct slot_info info[6]
Definition: slotsmanager.h:112
static int setup_particles(void **state)
static int teardown_particles(void **state)

References slots_manager_type::info, part_manager_type::NumPart, P, PartManager, setup_particles(), slot_info::size, slots_convert(), SlotsManager, teardown_particles(), and particle_data::Type.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_slots_fork()

static void test_slots_fork ( void **  state)
static

Definition at line 184 of file test_slotsmanager.c.

185 {
186  setup_particles(state);
187  int i;
188  for(i = 0; i < 6; i ++) {
189  slots_split_particle(128 * i, 0, PartManager);
190  slots_convert(128 * i, P[i * 128].Type, -1, PartManager, SlotsManager);
191 
192  }
193 
194  assert_int_equal(PartManager->NumPart, 129 * i);
195 
196  assert_int_equal(SlotsManager->info[0].size, 129);
197  assert_int_equal(SlotsManager->info[4].size, 129);
198  assert_int_equal(SlotsManager->info[5].size, 129);
199 
200  teardown_particles(state);
201  return;
202 }
int slots_split_particle(int parent, double childmass, struct part_manager_type *pman)
Definition: slotsmanager.c:103

References slots_manager_type::info, part_manager_type::NumPart, P, PartManager, setup_particles(), slot_info::size, slots_convert(), slots_split_particle(), SlotsManager, teardown_particles(), and particle_data::Type.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_slots_gc()

static void test_slots_gc ( void **  state)
static

Definition at line 64 of file test_slotsmanager.c.

65 {
66  setup_particles(state);
67  int i;
68  int compact[6];
69  for(i = 0; i < 6; i ++) {
71  compact[i] = 1;
72  }
74  assert_int_equal(PartManager->NumPart, 127 * i);
75 
76  assert_int_equal(SlotsManager->info[0].size, 127);
77  assert_int_equal(SlotsManager->info[4].size, 127);
78  assert_int_equal(SlotsManager->info[5].size, 127);
79 
81  teardown_particles(state);
82  return;
83 }
void slots_mark_garbage(int i, struct part_manager_type *pman, struct slots_manager_type *sman)
Definition: slotsmanager.c:577
int slots_gc(int *compact_slots, struct part_manager_type *pman, struct slots_manager_type *sman)
Definition: slotsmanager.c:145
void slots_check_id_consistency(struct part_manager_type *pman, struct slots_manager_type *sman)
Definition: slotsmanager.c:587

References slots_manager_type::info, part_manager_type::NumPart, PartManager, setup_particles(), slot_info::size, slots_check_id_consistency(), slots_gc(), slots_mark_garbage(), SlotsManager, and teardown_particles().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_slots_gc_sorted()

static void test_slots_gc_sorted ( void **  state)
static

Definition at line 86 of file test_slotsmanager.c.

87 {
88  setup_particles(state);
89  int i;
90  for(i = 0; i < 6; i ++) {
92  }
94  assert_int_equal(PartManager->NumPart, 127 * i);
95 
96  assert_int_equal(SlotsManager->info[0].size, 127);
97  assert_int_equal(SlotsManager->info[4].size, 127);
98  assert_int_equal(SlotsManager->info[5].size, 127);
99 
101  teardown_particles(state);
102  return;
103 }
void slots_gc_sorted(struct part_manager_type *pman, struct slots_manager_type *sman)
Definition: slotsmanager.c:442

References slots_manager_type::info, part_manager_type::NumPart, PartManager, setup_particles(), slot_info::size, slots_check_id_consistency(), slots_gc_sorted(), slots_mark_garbage(), SlotsManager, and teardown_particles().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_slots_reserve()

static void test_slots_reserve ( void **  state)
static

Definition at line 106 of file test_slotsmanager.c.

107 {
108  /* FIXME: these depends on the magic numbers in slots_reserve. After
109  * moving those numbers to All.* we shall rework the code here. */
110  setup_particles(state);
111 
112  int64_t newSlots[6] = {128, 128, 128, 128, 128, 128};
113  int64_t oldSize[6];
114  int ptype;
115  for(ptype = 0; ptype < 6; ptype++) {
116  oldSize[ptype] = SlotsManager->info[ptype].maxsize;
117  }
118  slots_reserve(1, newSlots, SlotsManager);
119 
120  /* shall not increase max size*/
121  for(ptype = 0; ptype < 6; ptype++) {
122  assert_int_equal(oldSize[ptype], SlotsManager->info[ptype].maxsize);
123  }
124 
125  for(ptype = 0; ptype < 6; ptype++) {
126  newSlots[ptype] += 1;
127  }
128 
129  /* shall not increase max size; because it is small difference */
130  slots_reserve(1, newSlots, SlotsManager);
131  for(ptype = 0; ptype < 6; ptype++) {
132  assert_int_equal(oldSize[ptype], SlotsManager->info[ptype].maxsize);
133  }
134 
135  for(ptype = 0; ptype < 6; ptype++) {
136  newSlots[ptype] += 8192;
137  }
138 
139  /* shall increase max size; because it large difference */
140  slots_reserve(1, newSlots, SlotsManager);
141 
142  for(ptype = 0; ptype < 6; ptype++) {
143  assert_true(oldSize[ptype] < SlotsManager->info[ptype].maxsize);
144  }
145 
146 }
int64_t maxsize
Definition: slotsmanager.h:11

References slots_manager_type::info, slot_info::maxsize, ptype, setup_particles(), slots_reserve(), and SlotsManager.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_slots_zero()

static void test_slots_zero ( void **  state)
static

Definition at line 150 of file test_slotsmanager.c.

151 {
152  setup_particles(state);
153  int i;
154  int compact[6] = {1,0,0,0,1,1};
155  for(i = 0; i < PartManager->NumPart; i ++) {
157  }
158  slots_gc(compact, PartManager, SlotsManager);
159  assert_int_equal(PartManager->NumPart, 0);
160  assert_int_equal(SlotsManager->info[0].size, 0);
161  assert_int_equal(SlotsManager->info[1].size, 128);
162  assert_int_equal(SlotsManager->info[4].size, 0);
163  assert_int_equal(SlotsManager->info[5].size, 0);
164 
165  teardown_particles(state);
166 
167  setup_particles(state);
168  for(i = 0; i < PartManager->NumPart; i ++) {
170  }
172  assert_int_equal(PartManager->NumPart, 0);
173  assert_int_equal(SlotsManager->info[0].size, 0);
174  assert_int_equal(SlotsManager->info[4].size, 0);
175  assert_int_equal(SlotsManager->info[5].size, 0);
176 
177  teardown_particles(state);
178 
179  return;
180 
181 }

References slots_manager_type::info, part_manager_type::NumPart, PartManager, setup_particles(), slot_info::size, slots_gc(), slots_gc_sorted(), slots_mark_garbage(), SlotsManager, and teardown_particles().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ PartManager

struct part_manager_type PartManager[1] = {{0}}