[LTP] [PATCH v2 2/4] lib: add tst_set_timeout for reset entire timeout
Li Wang
liwang@redhat.com
Thu Jan 9 05:55:30 CET 2025
Signed-off-by: Li Wang <liwang@redhat.com>
---
doc/old/C-Test-API.asciidoc | 9 +++++++++
include/tst_test.h | 5 +++++
lib/tst_test.c | 13 +++++++++++++
3 files changed, 27 insertions(+)
diff --git a/doc/old/C-Test-API.asciidoc b/doc/old/C-Test-API.asciidoc
index d4e0276e4..fe9904439 100644
--- a/doc/old/C-Test-API.asciidoc
+++ b/doc/old/C-Test-API.asciidoc
@@ -402,6 +402,15 @@ Returns string describing the status as returned by 'wait()'.
WARNING: This function is not thread safe.
+[source,c]
+-------------------------------------------------------------------------------
+void tst_set_timeout(int timeout);
+-------------------------------------------------------------------------------
+
+Allows for setting the entire timeout dynamically during the test setup(). The
+timeout is specified in seconds and represents the total time allowed for a single
+test iteration, including setup, runtime, and teardown phases.
+
[source,c]
-------------------------------------------------------------------------------
void tst_set_runtime(int runtime);
diff --git a/include/tst_test.h b/include/tst_test.h
index 8df05b9bb..2ddfde5b4 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -675,6 +675,11 @@ void tst_reinit(void);
*/
int tst_run_script(const char *script_name, char *const params[]);
+/*
+ * Sets entire timeout in seconds.
+ */
+void tst_set_timeout(int timeout);
+
unsigned int tst_multiply_timeout(unsigned int timeout);
/*
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 486df6cd7..43583e2f9 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1729,6 +1729,19 @@ static void set_overall_timeout(void)
results->overall_time % 60);
}
+void tst_set_timeout(int timeout)
+{
+ int timeout_adj = DEFAULT_TIMEOUT + timeout;
+
+ results->overall_time = tst_multiply_timeout(timeout_adj) + results->runtime;
+
+ tst_res(TINFO, "Overall timeout per run is %uh %02um %02us",
+ results->overall_time/3600, (results->overall_time%3600)/60,
+ results->overall_time % 60);
+
+ heartbeat();
+}
+
void tst_set_runtime(int runtime)
{
results->runtime = multiply_runtime(runtime);
--
2.47.1
More information about the ltp
mailing list