ifw-daq 3.1.0
IFW Data Acquisition modules
Loading...
Searching...
No Matches
testRsyncAsyncProcess.cpp
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup daq_test
4 * @copyright (c) Copyright ESO 2022
5 * All Rights Reserved
6 * ESO (eso.org) is an Intergovernmental Organisation, and therefore special legal conditions apply.
7 *
8 * @brief daq::ParseRsyncProgress
9 *
10 */
11#include <thread>
12
13#include <gtest/gtest.h>
14
16
17using namespace std::chrono_literals;
19
20TEST(TestParseRsyncProgress, Invalid) {
21 EXPECT_FALSE(ParseRsyncProgress(""));
22 EXPECT_FALSE(ParseRsyncProgress("a"));
23 EXPECT_FALSE(ParseRsyncProgress("120"));
24 EXPECT_FALSE(ParseRsyncProgress("120 1 z :::"));
25 EXPECT_FALSE(ParseRsyncProgress("a b c d"));
26 EXPECT_FALSE(ParseRsyncProgress(" 0 0% 0.00aB/s 0:00:00"))
27 << "aB/s should not be accepted";
28 EXPECT_FALSE(ParseRsyncProgress(" 0 0% 0.00aaaaa 0:00:00"))
29 << "bad unit should not be accepted";
30 EXPECT_FALSE(ParseRsyncProgress(" 0 0% 0,00kB/s 0:00:00"))
31 << "Comma separated speed should not be accepted";
32 EXPECT_FALSE(ParseRsyncProgress(" 0 0% 0,00kB/s 0;00;00"))
33 << "Semi-colon separated time should not be accepted";
34 EXPECT_FALSE(ParseRsyncProgress(" 0 0% 0,00kB/s 0.00.00"))
35 << "Period separated time should not be accepted";
36}
37
38TEST(TestParseRsyncProgress, Initial) {
39 auto p = ParseRsyncProgress(" 0 0% 0.00kB/s 0:00:00");
40 EXPECT_EQ(p->transferred, 0u);
41 EXPECT_NEAR(p->progress, 0.f, 0.01);
42 EXPECT_NEAR(p->speed, 0.f, 0.01);
43 EXPECT_EQ(p->remaining, 0s);
44}
45
46TEST(TestParseRsyncProgress, Mid1) {
47 auto p = ParseRsyncProgress(" 361234432 33% 344.50MB/s 0:00:02");
48 EXPECT_EQ(p->transferred, 361'234'432u);
49 EXPECT_NEAR(p->progress, 0.33f, 0.01);
50 EXPECT_NEAR(p->speed, 344.5 * 1024 * 1024, 0.01);
51 EXPECT_EQ(p->remaining, 2s);
52}
53
54TEST(TestParseRsyncProgress, Mid2) {
55 auto p = ParseRsyncProgress("6881280 0% 200.09kB/s 1:28:51");
56 EXPECT_EQ(p->transferred, 6'881'280u);
57 EXPECT_NEAR(p->progress, 0.0f, 0.01);
58 EXPECT_NEAR(p->speed, 200.09 * 1024, 0.01);
59 EXPECT_EQ(p->remaining, 1h + 28min + 51s);
60}
61
62TEST(TestParseRsyncProgress, Final) {
63 auto p = ParseRsyncProgress(" 200000 100% 344.50MB/s 0:00:00 (xfr#1 to-chk=0/1)");
64 EXPECT_EQ(p->transferred, 200'000u);
65 EXPECT_NEAR(p->progress, 1.f, 0.01);
66 EXPECT_NEAR(p->speed, 344.5 * 1024.0f * 1024.0f, 0.01);
67 EXPECT_EQ(p->remaining, 0s);
68}
TEST(TestParseRsyncProgress, Invalid)
std::optional< RsyncProgress > ParseRsyncProgress(std::string const &line) noexcept
Parse progress update from rsync.
daq::RsyncAsyncProcess and related class declarations.
EXPECT_EQ(meta.rr_uri, "zpb.rr://meta")