MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Functions | Variables
test_hci.c File Reference
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <setjmp.h>
#include <cmocka.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include "stub.h"
#include <libgadget/hci.h>
Include dependency graph for test_hci.c:

Go to the source code of this file.

Functions

static void touch (char *prefix, char *b)
 
static int exists (char *prefix, char *b)
 
static void test_hci_no_action (void **state)
 
static void test_hci_auto_checkpoint (void **state)
 
static void test_hci_auto_checkpoint2 (void **state)
 
static void test_hci_timeout (void **state)
 
static void test_hci_stop (void **state)
 
static void test_hci_checkpoint (void **state)
 
static void test_hci_terminate (void **state)
 
static int setup (void **state)
 
static int teardown (void **state)
 
int main (void)
 

Variables

char prefix [1024] = "XXXXXXXX"
 
HCIManager manager [1]
 

Function Documentation

◆ exists()

static int exists ( char *  prefix,
char *  b 
)
static

Definition at line 25 of file test_hci.c.

26 {
27  char * fn = fastpm_strdup_printf("%s/%s", prefix, b);
28  FILE * fp = fopen(fn, "r");
29  myfree(fn);
30  if(fp) {
31  fclose(fp);
32  return 1;
33  }
34  return 0;
35 }
#define myfree(x)
Definition: mymalloc.h:19
char * fastpm_strdup_printf(const char *fmt,...)
Definition: string.c:41
char prefix[1024]
Definition: test_hci.c:13

References fastpm_strdup_printf(), myfree, and prefix.

Referenced by test_hci_checkpoint(), test_hci_stop(), and test_hci_terminate().

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

◆ main()

int main ( void  )

Definition at line 174 of file test_hci.c.

174  {
175  const struct CMUnitTest tests[] = {
176  cmocka_unit_test(test_hci_no_action),
177  cmocka_unit_test(test_hci_auto_checkpoint),
178  cmocka_unit_test(test_hci_auto_checkpoint2),
179  cmocka_unit_test(test_hci_timeout),
180  cmocka_unit_test(test_hci_stop),
181  cmocka_unit_test(test_hci_checkpoint),
182  cmocka_unit_test(test_hci_terminate),
183  };
184  return cmocka_run_group_tests_mpi(tests, setup, teardown);
185 }
static int teardown(void **state)
Definition: test_hci.c:168
static void test_hci_auto_checkpoint(void **state)
Definition: test_hci.c:56
static void test_hci_auto_checkpoint2(void **state)
Definition: test_hci.c:76
static void test_hci_terminate(void **state)
Definition: test_hci.c:146
static void test_hci_stop(void **state)
Definition: test_hci.c:114
static void test_hci_timeout(void **state)
Definition: test_hci.c:96
static int setup(void **state)
Definition: test_hci.c:161
static void test_hci_checkpoint(void **state)
Definition: test_hci.c:130
static void test_hci_no_action(void **state)
Definition: test_hci.c:42

References setup(), teardown(), test_hci_auto_checkpoint(), test_hci_auto_checkpoint2(), test_hci_checkpoint(), test_hci_no_action(), test_hci_stop(), test_hci_terminate(), and test_hci_timeout().

Here is the call graph for this function:

◆ setup()

static int setup ( void **  state)
static

Definition at line 161 of file test_hci.c.

162 {
163  char * ret = mkdtemp(prefix);
164  message(0, "UsingPrefix : '%s'\n", prefix);
165  return !ret;
166 }
void message(int where, const char *fmt,...)
Definition: endrun.c:175

References message(), and prefix.

Referenced by main().

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

◆ teardown()

static int teardown ( void **  state)
static

Definition at line 168 of file test_hci.c.

169 {
170  remove(prefix);
171  return 0;
172 }

References prefix.

Referenced by main().

Here is the caller graph for this function:

◆ test_hci_auto_checkpoint()

static void test_hci_auto_checkpoint ( void **  state)
static

Definition at line 56 of file test_hci.c.

57 {
58  HCIAction action[1];
59 
61  hci_init(manager, prefix, 10.0, 1.0, 1);
62 
64  hci_query(manager, action);
65 
67  hci_query(manager, action);
68 
69  assert_int_equal(action->type, HCI_AUTO_CHECKPOINT);
70  assert_int_equal(action->write_snapshot, 1);
71  assert_int_equal(action->write_fof, 1);
72  assert_true(manager->LongestTimeBetweenQueries == 1.0);
73 }
void hci_init(HCIManager *manager, char *prefix, double WallClockTimeLimit, double AutoCheckPointTime, int FOFEnabled)
Definition: hci.c:25
int hci_query(HCIManager *manager, HCIAction *action)
Definition: hci.c:152
void hci_override_now(HCIManager *manager, double now)
Definition: hci.c:48
@ HCI_AUTO_CHECKPOINT
Definition: hci.h:24
Definition: hci.h:31
enum HCIActionType type
Definition: hci.h:32
int write_snapshot
Definition: hci.h:33
int write_fof
Definition: hci.h:34
double LongestTimeBetweenQueries
Definition: hci.h:10
HCIManager manager[1]
Definition: test_hci.c:37

References HCI_AUTO_CHECKPOINT, hci_init(), hci_override_now(), hci_query(), HCIManager::LongestTimeBetweenQueries, manager, prefix, HCIAction::type, HCIAction::write_fof, and HCIAction::write_snapshot.

Referenced by main().

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

◆ test_hci_auto_checkpoint2()

static void test_hci_auto_checkpoint2 ( void **  state)
static

Definition at line 76 of file test_hci.c.

77 {
78 
79  HCIAction action[1];
81  hci_init(manager, prefix, 10.0, 1.0, 0);
82 
84  hci_query(manager, action);
85 
87  hci_query(manager, action);
88 
89  assert_true(manager->LongestTimeBetweenQueries == 2.0);
90  assert_int_equal(action->type, HCI_AUTO_CHECKPOINT);
91  assert_int_equal(action->write_snapshot, 1);
92  assert_int_equal(action->write_fof, 0);
93 }

References HCI_AUTO_CHECKPOINT, hci_init(), hci_override_now(), hci_query(), HCIManager::LongestTimeBetweenQueries, manager, prefix, HCIAction::type, HCIAction::write_fof, and HCIAction::write_snapshot.

Referenced by main().

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

◆ test_hci_checkpoint()

static void test_hci_checkpoint ( void **  state)
static

Definition at line 130 of file test_hci.c.

131 {
132  HCIAction action[1];
134  hci_init(manager, prefix, 10.0, 1.0, 1);
135 
136  touch(prefix, "checkpoint");
138  hci_query(manager, action);
139  assert_false(exists(prefix, "checkpoint"));
140 
141  assert_int_equal(action->type, HCI_CHECKPOINT);
142  assert_int_equal(action->write_snapshot, 1);
143 }
@ HCI_CHECKPOINT
Definition: hci.h:25
static void touch(char *prefix, char *b)
Definition: test_hci.c:16
static int exists(char *prefix, char *b)
Definition: test_hci.c:25

References exists(), HCI_CHECKPOINT, hci_init(), hci_override_now(), hci_query(), manager, prefix, touch(), HCIAction::type, and HCIAction::write_snapshot.

Referenced by main().

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

◆ test_hci_no_action()

static void test_hci_no_action ( void **  state)
static

Definition at line 42 of file test_hci.c.

43 {
44  HCIAction action[1];
45 
47  hci_init(manager, prefix, 10.0, 1.0, 0);
48 
49  hci_query(manager, action);
50  assert_int_equal(action->type, HCI_NO_ACTION);
51  assert_int_equal(action->write_snapshot, 0);
52 
53 }
@ HCI_NO_ACTION
Definition: hci.h:21

References hci_init(), HCI_NO_ACTION, hci_override_now(), hci_query(), manager, prefix, HCIAction::type, and HCIAction::write_snapshot.

Referenced by main().

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

◆ test_hci_stop()

static void test_hci_stop ( void **  state)
static

Definition at line 114 of file test_hci.c.

115 {
116  HCIAction action[1];
118  hci_init(manager, prefix, 10.0, 1.0, 1);
119 
120  touch(prefix, "stop");
122  hci_query(manager, action);
123  assert_false(exists(prefix, "stop"));
124 
125  assert_int_equal(action->type, HCI_STOP);
126  assert_int_equal(action->write_snapshot, 1);
127 }
@ HCI_STOP
Definition: hci.h:22

References exists(), hci_init(), hci_override_now(), hci_query(), HCI_STOP, manager, prefix, touch(), HCIAction::type, and HCIAction::write_snapshot.

Referenced by main().

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

◆ test_hci_terminate()

static void test_hci_terminate ( void **  state)
static

Definition at line 146 of file test_hci.c.

147 {
148  HCIAction action[1];
150  hci_init(manager, prefix, 10.0, 1.0, 1);
151 
152  touch(prefix, "terminate");
154  hci_query(manager, action);
155  assert_false(exists(prefix, "terminate"));
156 
157  assert_int_equal(action->type, HCI_TERMINATE);
158  assert_int_equal(action->write_snapshot, 0);
159 }
@ HCI_TERMINATE
Definition: hci.h:26

References exists(), hci_init(), hci_override_now(), hci_query(), HCI_TERMINATE, manager, prefix, touch(), HCIAction::type, and HCIAction::write_snapshot.

Referenced by main().

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

◆ test_hci_timeout()

static void test_hci_timeout ( void **  state)
static

Definition at line 96 of file test_hci.c.

97 {
98  HCIAction action[1];
100  hci_init(manager, prefix, 10.0, 1.0, 1);
101 
103  hci_query(manager, action);
104 
105  assert_true(manager->LongestTimeBetweenQueries == 4.0);
106 
108  hci_query(manager, action);
109  assert_int_equal(action->type, HCI_TIMEOUT);
110  assert_int_equal(action->write_snapshot, 1);
111 }
@ HCI_TIMEOUT
Definition: hci.h:23

References hci_init(), hci_override_now(), hci_query(), HCI_TIMEOUT, HCIManager::LongestTimeBetweenQueries, manager, prefix, HCIAction::type, and HCIAction::write_snapshot.

Referenced by main().

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

◆ touch()

static void touch ( char *  prefix,
char *  b 
)
static

Definition at line 16 of file test_hci.c.

17 {
18  char * fn = fastpm_strdup_printf("%s/%s", prefix, b);
19  FILE * fp = fopen(fn, "w");
20  myfree(fn);
21  fclose(fp);
22 }

References fastpm_strdup_printf(), myfree, and prefix.

Referenced by test_hci_checkpoint(), test_hci_stop(), and test_hci_terminate().

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

Variable Documentation

◆ manager

HCIManager manager[1]

◆ prefix

char prefix[1024] = "XXXXXXXX"