STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_send_policy.cpp
Go to the documentation of this file.
1
/**
2
* sensorBatchReady: when a sensor board ships its queued chunks.
3
*
4
* The bug it guards: an LC board at SINC4 / 20 SPS takes ~0.8 s per chunk, and
5
* waiting for a full packet of 9 held every reading back 7-12 s.
6
*/
7
#include <unity.h>
8
9
#include "
send_policy.h
"
10
11
static
const
size_t
kMax
= 9;
12
static
const
uint32_t
kAge
= 250;
13
14
void
test_empty_queue_never_sends
() {
15
TEST_ASSERT_FALSE(
sensorBatchReady
(0,
kMax
, 0, 100000,
kAge
));
16
}
17
18
void
test_full_packet_sends_regardless_of_age
() {
19
TEST_ASSERT_TRUE(
sensorBatchReady
(
kMax
,
kMax
, 1000, 1000,
kAge
));
20
}
21
22
void
test_fast_board_still_batches
() {
23
// A 75 Hz PT board: 3 chunks in 40 ms is young, keep filling.
24
TEST_ASSERT_FALSE(
sensorBatchReady
(3,
kMax
, 1000, 1040,
kAge
));
25
}
26
27
void
test_slow_board_sends_single_old_chunk
() {
28
// An LC chunk started 800 ms ago: ship it now, not 8 chunks from now.
29
TEST_ASSERT_TRUE(
sensorBatchReady
(1,
kMax
, 1000, 1800,
kAge
));
30
}
31
32
void
test_age_boundary
() {
33
TEST_ASSERT_FALSE(
sensorBatchReady
(1,
kMax
, 1000, 1000 +
kAge
- 1,
kAge
));
34
TEST_ASSERT_TRUE(
sensorBatchReady
(1,
kMax
, 1000, 1000 +
kAge
,
kAge
));
35
}
36
37
void
test_age_survives_millis_wrap
() {
38
// Oldest chunk 100 ms before the uint32 wrap, now 200 ms after it.
39
TEST_ASSERT_TRUE(
sensorBatchReady
(1,
kMax
, 0xFFFFFFFFu - 99u, 200u,
kAge
));
40
TEST_ASSERT_FALSE(
sensorBatchReady
(1,
kMax
, 0xFFFFFFFFu - 99u, 50u,
kAge
));
41
}
42
43
void
setUp
() {
44
}
45
void
tearDown
() {
46
}
47
48
int
main
(
int
argc,
char
** argv) {
49
UNITY_BEGIN();
50
RUN_TEST(
test_empty_queue_never_sends
);
51
RUN_TEST(
test_full_packet_sends_regardless_of_age
);
52
RUN_TEST(
test_fast_board_still_batches
);
53
RUN_TEST(
test_slow_board_sends_single_old_chunk
);
54
RUN_TEST(
test_age_boundary
);
55
RUN_TEST(
test_age_survives_millis_wrap
);
56
return
UNITY_END();
57
}
send_policy.h
sensorBatchReady
bool sensorBatchReady(size_t queued, size_t max_chunks, uint32_t oldest_ms, uint32_t now_ms, uint32_t max_age_ms)
Definition
send_policy.h:22
main
int main()
Definition
test_abort_ordering.cpp:67
test_fast_board_still_batches
void test_fast_board_still_batches()
Definition
test_send_policy.cpp:22
test_age_survives_millis_wrap
void test_age_survives_millis_wrap()
Definition
test_send_policy.cpp:37
kAge
static const uint32_t kAge
Definition
test_send_policy.cpp:12
kMax
static const size_t kMax
sensorBatchReady: when a sensor board ships its queued chunks.
Definition
test_send_policy.cpp:11
test_full_packet_sends_regardless_of_age
void test_full_packet_sends_regardless_of_age()
Definition
test_send_policy.cpp:18
test_empty_queue_never_sends
void test_empty_queue_never_sends()
Definition
test_send_policy.cpp:14
setUp
void setUp()
Definition
test_send_policy.cpp:43
test_slow_board_sends_single_old_chunk
void test_slow_board_sends_single_old_chunk()
Definition
test_send_policy.cpp:27
test_age_boundary
void test_age_boundary()
Definition
test_send_policy.cpp:32
tearDown
void tearDown()
Definition
test_send_policy.cpp:45
firmware
Hotfire_Code
Hotfire_Tests
test
test_send_policy
test_send_policy.cpp
Generated by
1.15.0