]>
git.proxmox.com Git - rustc.git/blob - src/jemalloc/test/unit/nstime.c
1 #include "test/jemalloc_test.h"
3 #define BILLION UINT64_C(1000000000)
5 TEST_BEGIN(test_nstime_init
)
9 nstime_init(&nst
, 42000000043);
10 assert_u64_eq(nstime_ns(&nst
), 42000000043, "ns incorrectly read");
11 assert_u64_eq(nstime_sec(&nst
), 42, "sec incorrectly read");
12 assert_u64_eq(nstime_nsec(&nst
), 43, "nsec incorrectly read");
16 TEST_BEGIN(test_nstime_init2
)
20 nstime_init2(&nst
, 42, 43);
21 assert_u64_eq(nstime_sec(&nst
), 42, "sec incorrectly read");
22 assert_u64_eq(nstime_nsec(&nst
), 43, "nsec incorrectly read");
26 TEST_BEGIN(test_nstime_copy
)
30 nstime_init2(&nsta
, 42, 43);
31 nstime_init(&nstb
, 0);
32 nstime_copy(&nstb
, &nsta
);
33 assert_u64_eq(nstime_sec(&nstb
), 42, "sec incorrectly copied");
34 assert_u64_eq(nstime_nsec(&nstb
), 43, "nsec incorrectly copied");
38 TEST_BEGIN(test_nstime_compare
)
42 nstime_init2(&nsta
, 42, 43);
43 nstime_copy(&nstb
, &nsta
);
44 assert_d_eq(nstime_compare(&nsta
, &nstb
), 0, "Times should be equal");
45 assert_d_eq(nstime_compare(&nstb
, &nsta
), 0, "Times should be equal");
47 nstime_init2(&nstb
, 42, 42);
48 assert_d_eq(nstime_compare(&nsta
, &nstb
), 1,
49 "nsta should be greater than nstb");
50 assert_d_eq(nstime_compare(&nstb
, &nsta
), -1,
51 "nstb should be less than nsta");
53 nstime_init2(&nstb
, 42, 44);
54 assert_d_eq(nstime_compare(&nsta
, &nstb
), -1,
55 "nsta should be less than nstb");
56 assert_d_eq(nstime_compare(&nstb
, &nsta
), 1,
57 "nstb should be greater than nsta");
59 nstime_init2(&nstb
, 41, BILLION
- 1);
60 assert_d_eq(nstime_compare(&nsta
, &nstb
), 1,
61 "nsta should be greater than nstb");
62 assert_d_eq(nstime_compare(&nstb
, &nsta
), -1,
63 "nstb should be less than nsta");
65 nstime_init2(&nstb
, 43, 0);
66 assert_d_eq(nstime_compare(&nsta
, &nstb
), -1,
67 "nsta should be less than nstb");
68 assert_d_eq(nstime_compare(&nstb
, &nsta
), 1,
69 "nstb should be greater than nsta");
73 TEST_BEGIN(test_nstime_add
)
77 nstime_init2(&nsta
, 42, 43);
78 nstime_copy(&nstb
, &nsta
);
79 nstime_add(&nsta
, &nstb
);
80 nstime_init2(&nstb
, 84, 86);
81 assert_d_eq(nstime_compare(&nsta
, &nstb
), 0,
82 "Incorrect addition result");
84 nstime_init2(&nsta
, 42, BILLION
- 1);
85 nstime_copy(&nstb
, &nsta
);
86 nstime_add(&nsta
, &nstb
);
87 nstime_init2(&nstb
, 85, BILLION
- 2);
88 assert_d_eq(nstime_compare(&nsta
, &nstb
), 0,
89 "Incorrect addition result");
93 TEST_BEGIN(test_nstime_subtract
)
97 nstime_init2(&nsta
, 42, 43);
98 nstime_copy(&nstb
, &nsta
);
99 nstime_subtract(&nsta
, &nstb
);
100 nstime_init(&nstb
, 0);
101 assert_d_eq(nstime_compare(&nsta
, &nstb
), 0,
102 "Incorrect subtraction result");
104 nstime_init2(&nsta
, 42, 43);
105 nstime_init2(&nstb
, 41, 44);
106 nstime_subtract(&nsta
, &nstb
);
107 nstime_init2(&nstb
, 0, BILLION
- 1);
108 assert_d_eq(nstime_compare(&nsta
, &nstb
), 0,
109 "Incorrect subtraction result");
113 TEST_BEGIN(test_nstime_imultiply
)
117 nstime_init2(&nsta
, 42, 43);
118 nstime_imultiply(&nsta
, 10);
119 nstime_init2(&nstb
, 420, 430);
120 assert_d_eq(nstime_compare(&nsta
, &nstb
), 0,
121 "Incorrect multiplication result");
123 nstime_init2(&nsta
, 42, 666666666);
124 nstime_imultiply(&nsta
, 3);
125 nstime_init2(&nstb
, 127, 999999998);
126 assert_d_eq(nstime_compare(&nsta
, &nstb
), 0,
127 "Incorrect multiplication result");
131 TEST_BEGIN(test_nstime_idivide
)
135 nstime_init2(&nsta
, 42, 43);
136 nstime_copy(&nstb
, &nsta
);
137 nstime_imultiply(&nsta
, 10);
138 nstime_idivide(&nsta
, 10);
139 assert_d_eq(nstime_compare(&nsta
, &nstb
), 0,
140 "Incorrect division result");
142 nstime_init2(&nsta
, 42, 666666666);
143 nstime_copy(&nstb
, &nsta
);
144 nstime_imultiply(&nsta
, 3);
145 nstime_idivide(&nsta
, 3);
146 assert_d_eq(nstime_compare(&nsta
, &nstb
), 0,
147 "Incorrect division result");
151 TEST_BEGIN(test_nstime_divide
)
153 nstime_t nsta
, nstb
, nstc
;
155 nstime_init2(&nsta
, 42, 43);
156 nstime_copy(&nstb
, &nsta
);
157 nstime_imultiply(&nsta
, 10);
158 assert_u64_eq(nstime_divide(&nsta
, &nstb
), 10,
159 "Incorrect division result");
161 nstime_init2(&nsta
, 42, 43);
162 nstime_copy(&nstb
, &nsta
);
163 nstime_imultiply(&nsta
, 10);
164 nstime_init(&nstc
, 1);
165 nstime_add(&nsta
, &nstc
);
166 assert_u64_eq(nstime_divide(&nsta
, &nstb
), 10,
167 "Incorrect division result");
169 nstime_init2(&nsta
, 42, 43);
170 nstime_copy(&nstb
, &nsta
);
171 nstime_imultiply(&nsta
, 10);
172 nstime_init(&nstc
, 1);
173 nstime_subtract(&nsta
, &nstc
);
174 assert_u64_eq(nstime_divide(&nsta
, &nstb
), 9,
175 "Incorrect division result");
179 TEST_BEGIN(test_nstime_update
)
183 nstime_init(&nst
, 0);
185 assert_false(nstime_update(&nst
), "Basic time update failed.");
187 /* Only Rip Van Winkle sleeps this long. */
190 nstime_init2(&addend
, 631152000, 0);
191 nstime_add(&nst
, &addend
);
195 nstime_copy(&nst0
, &nst
);
196 assert_true(nstime_update(&nst
),
197 "Update should detect time roll-back.");
198 assert_d_eq(nstime_compare(&nst
, &nst0
), 0,
199 "Time should not have been modified");
215 test_nstime_subtract
,
216 test_nstime_imultiply
,
219 test_nstime_update
));