@@ -29,27 +29,27 @@ const char *stream_url = "https://commadataci.blob.core.windows.net/openpilotci/
29
29
// }
30
30
// }
31
31
32
- // std::string sha_256(const QString &dat) {
33
- // return QString(QCryptographicHash::hash(dat.toUtf8(), QCryptographicHash::Sha256).toHex()).toStdString();
34
- // }
32
+ std::string sha_256 (const QString &dat) {
33
+ return QString (QCryptographicHash::hash (dat.toUtf8 (), QCryptographicHash::Sha256).toHex ()).toStdString ();
34
+ }
35
35
36
- // TEST_CASE("httpMultiPartDownload") {
37
- // char filename[] = "/tmp/XXXXXX";
38
- // int fd = mkstemp(filename);
39
- // REQUIRE(fd != -1);
40
- // close(fd);
41
-
42
- // SECTION("http 200") {
43
- // REQUIRE(httpMultiPartDownload(stream_url, filename, 5));
44
- // std::string content = util::read_file(filename);
45
- // REQUIRE(content.size() == 37495242);
46
- // std::string checksum = sha_256(QString::fromStdString(content));
47
- // REQUIRE(checksum == "d8ff81560ce7ed6f16d5fb5a6d6dd13aba06c8080c62cfe768327914318744c4");
48
- // }
49
- // SECTION("http 404") {
50
- // REQUIRE(httpMultiPartDownload(util::string_format("%s_abc", stream_url), filename, 5) == false);
51
- // }
52
- // }
36
+ TEST_CASE (" httpMultiPartDownload" ) {
37
+ char filename[] = " /tmp/XXXXXX" ;
38
+ int fd = mkstemp (filename);
39
+ REQUIRE (fd != -1 );
40
+ close (fd);
41
+
42
+ SECTION (" http 200" ) {
43
+ REQUIRE (httpMultiPartDownload (stream_url, filename, 5 ));
44
+ std::string content = util::read_file (filename);
45
+ REQUIRE (content.size () == 37495242 );
46
+ std::string checksum = sha_256 (QString::fromStdString (content));
47
+ REQUIRE (checksum == " d8ff81560ce7ed6f16d5fb5a6d6dd13aba06c8080c62cfe768327914318744c4" );
48
+ }
49
+ SECTION (" http 404" ) {
50
+ REQUIRE (httpMultiPartDownload (util::string_format (" %s_abc" , stream_url), filename, 5 ) == false );
51
+ }
52
+ }
53
53
54
54
int random_int (int min, int max) {
55
55
std::random_device dev;
@@ -73,35 +73,34 @@ bool is_events_ordered(const std::vector<Event *> &events) {
73
73
}
74
74
75
75
const QString DEMO_ROUTE = " 4cf7a6ad03080c90|2021-09-29--13-46-36" ;
76
- // Route demo_route(DEMO_ROUTE);
77
-
78
- // TEST_CASE("Segment") {
79
- // REQUIRE(demo_route.load());
80
- // REQUIRE(demo_route.size() == 121);
81
-
82
- // QEventLoop loop;
83
- // Segment segment(0, demo_route.at(0), false, false);
84
- // REQUIRE(segment.isValid() == true);
85
- // REQUIRE(segment.isLoaded() == false);
86
- // QObject::connect(&segment, &Segment::loadFinished, [&]() {
87
- // REQUIRE(segment.isLoaded() == true);
88
- // REQUIRE(segment.log != nullptr);
89
- // REQUIRE(segment.log->events.size() > 0);
90
- // REQUIRE(is_events_ordered(segment.log->events));
91
- // REQUIRE(segment.frames[RoadCam] != nullptr);
92
- // REQUIRE(segment.frames[RoadCam]->getFrameCount() > 0);
93
- // REQUIRE(segment.frames[DriverCam] == nullptr);
94
- // REQUIRE(segment.frames[WideRoadCam] == nullptr);
95
- // loop.quit();
96
- // });
97
- // loop.exec();
98
- // }
76
+
77
+ TEST_CASE ( " Segment " ) {
78
+ Route demo_route (DEMO_ROUTE);
79
+ REQUIRE (demo_route.load ());
80
+ REQUIRE (demo_route.size () == 121 );
81
+
82
+ QEventLoop loop;
83
+ Segment segment (0 , demo_route.at (0 ), false , false );
84
+ REQUIRE (segment.isValid () == true );
85
+ REQUIRE (segment.isLoaded () == false );
86
+ QObject::connect (&segment, &Segment::loadFinished, [&]() {
87
+ REQUIRE (segment.isLoaded () == true );
88
+ REQUIRE (segment.log != nullptr );
89
+ REQUIRE (segment.log ->events .size () > 0 );
90
+ REQUIRE (is_events_ordered (segment.log ->events ));
91
+ REQUIRE (segment.frames [RoadCam] != nullptr );
92
+ REQUIRE (segment.frames [RoadCam]->getFrameCount () > 0 );
93
+ REQUIRE (segment.frames [DriverCam] == nullptr );
94
+ REQUIRE (segment.frames [WideRoadCam] == nullptr );
95
+ loop.quit ();
96
+ });
97
+ loop.exec ();
98
+ }
99
99
100
100
// helper class for unit tests
101
101
class TestReplay : public Replay {
102
102
public:
103
- TestReplay (const QString &route) : Replay(route, {}, {}) {
104
- }
103
+ TestReplay (const QString &route) : Replay(route, {}, {}) {}
105
104
void test_seek ();
106
105
107
106
protected:
@@ -118,49 +117,46 @@ void TestReplay::testSeekTo(int seek_to, int invalid_segment) {
118
117
119
118
// verify result
120
119
INFO (" seek to [" << seek_to << " s segment " << seek_to / 60 << " ]" );
121
- INFO (" events size " << events_->size ());
122
- // INFO("mono" << (cur_mono_time_ - route_start_ts_) / 1e9);
123
120
REQUIRE (is_events_ordered (*events_));
124
121
REQUIRE (uint64_t (route_start_ts_ + seek_to * 1e9 ) == cur_mono_time_);
125
122
REQUIRE (!events_->empty ());
126
123
Event cur_event (cereal::Event::Which::INIT_DATA, cur_mono_time_);
127
124
auto eit = std::upper_bound (events_->begin (), events_->end (), &cur_event, Event::lessThan ());
128
-
125
+
129
126
REQUIRE (eit != events_->end ());
130
127
const int seek_to_segment = seek_to / 60 ;
131
- const int real_segment = int (((*eit)->mono_time - route_start_ts_) / 60 / 1e9 );
132
- INFO (" event [" << ((*eit)->mono_time - route_start_ts_) / 1e9 << " s segment " << real_segment << " ]" );
128
+ current_segment_ = int (((*eit)->mono_time - route_start_ts_) / 60 / 1e9 );
129
+ INFO (" event [" << ((*eit)->mono_time - route_start_ts_) / 1e9 << " s segment " << current_segment_ << " ]" );
133
130
REQUIRE ((*eit)->mono_time >= seek_to * 1e9 + route_start_ts_);
134
131
if (seek_to_segment != invalid_segment) {
135
- REQUIRE (real_segment == seek_to_segment); // in the same segment
132
+ REQUIRE (current_segment_ == seek_to_segment); // in the same segment
136
133
} else {
137
- // skipped invalid_segment
138
- REQUIRE (real_segment == seek_to_segment + 1 );
139
-
134
+ // has invalid_segment
135
+ if (current_segment_ == seek_to_segment) {
136
+ // seek cross-boundary. e.g. seek_to 60s, but the first segment end at 60.021.
137
+ REQUIRE (std::nearbyint (((*eit)->mono_time - route_start_ts_)/1e9 ) == seek_to);
138
+ } else {
139
+ REQUIRE (current_segment_ == seek_to_segment + 1 );
140
+ }
140
141
}
141
142
}
142
143
143
144
void TestReplay::test_seek () {
144
145
QEventLoop loop;
145
146
146
- REQUIRE (load ());
147
- // // limit the segment count to 5
148
- // REQUIRE(route_->size() >= 5);
149
- // segments_.resize(5);
150
-
151
147
std::thread thread = std::thread ([&]() {
152
148
// random seek 500 times in first 3 good segments
153
149
for (int i = 0 ; i < 200 ; ++i) {
154
150
testSeekTo (random_int (0 , 60 * 3 - 1 ));
155
151
}
156
152
157
- // make segment 1 invalid
158
- // segments_[1]->valid_ = segments_[1]->loaded_ = false;
159
- // queueSegment() ;
160
- // // random seek 200 times
161
- // for (int i = 0; i < 200; ++i) {
162
- // testSeekTo(random_int(0, 60 * 3 - 1), 1);
163
- // }
153
+ // random seek 200 times in first 3 segments. segment 1 is invalid.
154
+ // invalid segmen 1
155
+ segments_[ 1 ]-> valid_ = segments_[ 1 ]-> loaded_ = false ;
156
+ queueSegment ();
157
+ for (int i = 0 ; i < 200 ; ++i) {
158
+ testSeekTo (random_int (0 , 60 * 3 - 1 ), 1 );
159
+ }
164
160
165
161
loop.quit ();
166
162
});
@@ -171,7 +167,6 @@ void TestReplay::test_seek() {
171
167
172
168
TEST_CASE (" Replay" ) {
173
169
TestReplay replay (DEMO_ROUTE);
174
- // REQUIRE(replay.load());
175
- // modify the route
170
+ REQUIRE (replay.load ());
176
171
replay.test_seek ();
177
172
}
0 commit comments