aboutsummaryrefslogtreecommitdiff
path: root/tests/benchmarks
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/benchmarks.h8
-rw-r--r--tests/benchmarks/latency.c26
2 files changed, 27 insertions, 7 deletions
diff --git a/tests/benchmarks/benchmarks.h b/tests/benchmarks/benchmarks.h
index fa32c9c9..e9979f96 100644
--- a/tests/benchmarks/benchmarks.h
+++ b/tests/benchmarks/benchmarks.h
@@ -25,7 +25,15 @@
#include <libssh/libssh.h>
/* latency.c */
+
+struct timestamp_struct {
+ struct timeval timestamp;
+};
+
int benchmarks_ping_latency (const char *host, float *average);
int benchmarks_ssh_latency (ssh_session session, float *average);
+void timestamp_init(struct timestamp_struct *ts);
+float elapsed_time(struct timestamp_struct *ts);
+
#endif /* BENCHMARKS_H_ */
diff --git a/tests/benchmarks/latency.c b/tests/benchmarks/latency.c
index 17379453..9d68fd3f 100644
--- a/tests/benchmarks/latency.c
+++ b/tests/benchmarks/latency.c
@@ -34,7 +34,7 @@
* @brief Calculates the RTT of the host with ICMP ping, and returns the
* average of the calculated RTT.
* @param[in] host hostname to ping.
- * @param[out] average average RTT in ms.
+ * @param[out] average average RTT in milliseconds.
* @returns 0 on success, -1 if there is an error.
* @warning relies on an external ping program which may not exist on
* certain OS.
@@ -84,15 +84,20 @@ parseerror:
return -1;
}
-struct timestamp_struct {
- struct timeval timestamp;
-};
-
-static void timestamp_init(struct timestamp_struct *ts){
+/** @internal
+ * @brief initialize a timestamp to the current time.
+ * @param[out] ts A timestamp_struct pointer.
+ */
+void timestamp_init(struct timestamp_struct *ts){
gettimeofday(&ts->timestamp,NULL);
}
-static float elapsed_time(struct timestamp_struct *ts){
+/** @internal
+ * @brief return the elapsed time since now and the moment ts was initialized.
+ * @param[in] ts An initialized timestamp_struct pointer.
+ * @return Elapsed time in milliseconds.
+ */
+float elapsed_time(struct timestamp_struct *ts){
struct timeval now;
time_t secdiff;
long usecdiff; /* may be negative */
@@ -104,6 +109,13 @@ static float elapsed_time(struct timestamp_struct *ts){
return (float) (secdiff*1000) + ((float)usecdiff)/1000;
}
+/** @internal
+ * @brief Calculates the RTT of the host with SSH channel operations, and
+ * returns the average of the calculated RTT.
+ * @param[in] session active SSH session to test.
+ * @param[out] average average RTT in milliseconds.
+ * @returns 0 on success, -1 if there is an error.
+ */
int benchmarks_ssh_latency(ssh_session session, float *average){
float times[3];
struct timestamp_struct ts;