1 /*
2 * Copyright (C) 2021 Jakub Kruszona-Zawadzki, Core Technology Sp. z o.o.
3 *
4 * This file is part of MooseFS.
5 *
6 * MooseFS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, version 2 (only).
9 *
10 * MooseFS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with MooseFS; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA
18 * or visit http://www.gnu.org/licenses/gpl-2.0.html
19 */
20
21 #include <sys/types.h>
22 #include <sys/select.h>
23 #include <sys/time.h>
24 #include <stdlib.h>
25
26 #include "delayrun.h"
27 #include "portable.h"
28 #include "clocks.h"
29
30 #include "mfstest.h"
31
32 uint32_t global_variable;
33
set_variable(void * arg)34 void set_variable(void *arg) {
35 uint32_t *a = (uint32_t*)(arg);
36 #ifdef DEBUG
37 printf("%.6lf ; set %"PRIu32"\n",monotonic_seconds(),*a);
38 #endif
39 global_variable = *a;
40 }
41
corrected_usleep(uint64_t us)42 void corrected_usleep(uint64_t us) {
43 uint64_t st,en;
44 st = monotonic_useconds();
45 do {
46 portable_usleep(100);
47 en = monotonic_useconds();
48 } while (st+us>=en);
49 }
50
main(void)51 int main(void) {
52 uint32_t values[7] = {0,1,2,3,4,5,6};
53 mfstest_init();
54
55 mfstest_start(delay_run);
56
57 delay_init();
58
59 global_variable = 0xFFFFFFFF;
60 delay_run(set_variable,values,10000);
61 corrected_usleep(20000);
62 mfstest_assert_uint32_eq(global_variable,0);
63 delay_run(set_variable,values+2,30000);
64 delay_run(set_variable,values+3,50000);
65 delay_run(set_variable,values+1,10000);
66 mfstest_assert_uint32_eq(global_variable,0);
67 corrected_usleep(20000);
68 mfstest_assert_uint32_eq(global_variable,1);
69 corrected_usleep(20000);
70 mfstest_assert_uint32_eq(global_variable,2);
71 corrected_usleep(20000);
72 mfstest_assert_uint32_eq(global_variable,3);
73 delay_run(set_variable,values+6,60000);
74 corrected_usleep(10000);
75 delay_run(set_variable,values+4,10000);
76 corrected_usleep(20000);
77 mfstest_assert_uint32_eq(global_variable,4);
78 delay_run(set_variable,values+5,10000);
79 corrected_usleep(20000);
80 mfstest_assert_uint32_eq(global_variable,5);
81 corrected_usleep(20000);
82 mfstest_assert_uint32_eq(global_variable,6);
83
84 delay_term();
85
86 mfstest_end();
87 mfstest_return();
88 }
89