unit1399.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at https://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22 #include "curlcheck.h"
23 
24 #include "urldata.h"
25 #include "progress.h"
26 
27 static int usec_magnitude = 1000000;
28 
29 static bool unit_setup(void)
30 {
31  return CURLE_OK;
32 }
33 
34 static void unit_stop(void)
35 {
36 
37 }
38 
39 /*
40  * Invoke Curl_pgrsTime for TIMER_STARTSINGLE to trigger the behavior that
41  * manages is_t_startransfer_set, but fake the t_startsingle time for purposes
42  * of the test.
43  */
45  struct curltime fake_now,
46  int seconds_offset)
47 {
49  data->progress.t_startsingle.tv_sec = fake_now.tv_sec + seconds_offset;
50  data->progress.t_startsingle.tv_usec = fake_now.tv_usec;
51 }
52 
53 static bool usec_matches_seconds(time_t time_usec, int expected_seconds)
54 {
55  int time_sec = (int)(time_usec / usec_magnitude);
56  bool same = (time_sec == expected_seconds);
57  fprintf(stderr, "is %d us same as %d seconds? %s\n",
58  (int)time_usec, expected_seconds,
59  same?"Yes":"No");
60  return same;
61 }
62 
63 static void expect_timer_seconds(struct Curl_easy *data, int seconds)
64 {
65  char msg[64];
66  snprintf(msg, sizeof(msg), "about %d seconds should have passed", seconds);
68  fail_unless(usec_matches_seconds(data->progress.t_connect, seconds), msg);
71  msg);
73  msg);
74 }
75 
76 /* Scenario: simulate a redirect. When a redirect occurs, t_nslookup,
77  * t_connect, t_appconnect, t_pretransfer, and t_starttransfer are addative.
78  * E.g., if t_starttransfer took 2 seconds initially and took another 1
79  * second for the redirect request, then the resulting t_starttransfer should
80  * be 3 seconds. */
82  struct Curl_easy data;
83  struct curltime now = Curl_tvnow();
84 
85  data.progress.t_nslookup = 0;
86  data.progress.t_connect = 0;
87  data.progress.t_appconnect = 0;
88  data.progress.t_pretransfer = 0;
89  data.progress.t_starttransfer = 0;
90  data.progress.t_redirect = 0;
91  data.progress.start.tv_sec = now.tv_sec - 2;
92  data.progress.start.tv_usec = now.tv_usec;
93  fake_t_startsingle_time(&data, now, -2);
94 
100 
102 
103  /* now simulate the redirect */
104  data.progress.t_redirect = data.progress.t_starttransfer + 1;
105  fake_t_startsingle_time(&data, now, -1);
106 
111  /* ensure t_starttransfer is only set on the first invocation by attempting
112  * to set it twice */
115 
#define UNITTEST_START
Definition: curlcheck.h:86
static int usec_magnitude
Definition: unit1399.c:27
void Curl_pgrsTime(struct Curl_easy *data, timerid timer)
Definition: progress.c:162
time_t tv_sec
Definition: timeval.h:33
struct curltime now
Definition: unit1399.c:83
static bool unit_setup(void)
Definition: unit1399.c:29
time_t t_pretransfer
Definition: urldata.h:1114
static void fake_t_startsingle_time(struct Curl_easy *data, struct curltime fake_now, int seconds_offset)
Definition: unit1399.c:44
time_t t_appconnect
Definition: urldata.h:1113
time_t t_starttransfer
Definition: urldata.h:1115
time_t t_nslookup
Definition: urldata.h:1111
#define fail_unless(expr, msg)
Definition: curlcheck.h:32
static void unit_stop(void)
Definition: unit1399.c:34
#define Curl_tvnow()
Definition: timeval.h:57
struct Progress progress
Definition: urldata.h:1768
Definition: curl.h:455
#define UNITTEST_STOP
Definition: curlcheck.h:95
static void expect_timer_seconds(struct Curl_easy *data, int seconds)
Definition: unit1399.c:63
time_t t_connect
Definition: urldata.h:1112
struct curltime t_startsingle
Definition: urldata.h:1119
#define fprintf
Definition: curl_printf.h:41
#define snprintf
Definition: curl_printf.h:42
static bool usec_matches_seconds(time_t time_usec, int expected_seconds)
Definition: unit1399.c:53
Definition: debug.c:29
unsigned int tv_usec
Definition: timeval.h:34


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:16