Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit introduces a concept of max test runtime. In other words test runtime is capped at a certain value in order to make testruns more deterministic. Test is free to to finish before the runtime is used up, for example when maximal number of iterations was reached, but test must stop once the runtime has been used up. Testcases that run for more than a second or two must check for remaining runtime by regular calls to tst_remaining_runtime() and should exit when zero is returned. The test max runtime must be set either by the .max_iteration_runtime in the tst_test structure or in the test setup by a call to tst_set_runtime(). The test timeout is then computed as a sum of DEFAULT_TIMEOUT (currently set to 30 seconds) and the test runtime. The DEFAULT_TIMEOUT is nothing more than a safety margin for teardown of the test. This commit also maps the -I parameter to the test max runtime if available and introduces LTP_RUNTIME_MUL enviroment variable so that we have an easy controll over the runtime cap. Lastly but not least the function related to the timeout are turned into no-op by this commit and removed after all test are converted to the runtime API. Acked-by: Petr Vorel <pvorel@suse.cz> Reviewed-by: Li Wang <liwang@redhat.com> Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
- Loading branch information
Showing
13 changed files
with
264 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,5 +39,4 @@ static void run(void) | |
static struct tst_test test = { | ||
.test_all = run, | ||
.forks_child = 1, | ||
.timeout = 10, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Copyright (c) 2018, Linux Test Project | ||
* | ||
* Runs for 4 seconds for each test iteration. | ||
*/ | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include "tst_test.h" | ||
|
||
static void run(void) | ||
{ | ||
int runtime; | ||
|
||
tst_res(TINFO, "Running variant %i", tst_variant); | ||
|
||
do { | ||
runtime = tst_remaining_runtime(); | ||
tst_res(TINFO, "Remaining runtime %d", runtime); | ||
sleep(1); | ||
} while (runtime); | ||
|
||
tst_res(TPASS, "Finished loop!"); | ||
} | ||
|
||
static struct tst_test test = { | ||
.test_all = run, | ||
.max_runtime = 4, | ||
.test_variants = 2, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Copyright (c) 2021, Linux Test Project | ||
*/ | ||
/* | ||
* This test is set up so that the timeout is not long enough to guarantee | ||
* enough runtime for two iterations, i.e. the timeout without offset and after | ||
* scaling is too small and the tests ends up with TBROK. | ||
* | ||
* The default timeout in the test library is set to 30 seconds. The test | ||
* runtime is set to 5 so the test should timeout after 35 seconds. | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include "tst_test.h" | ||
|
||
static void run(void) | ||
{ | ||
tst_res(TINFO, "Sleeping for 40 seconds"); | ||
sleep(40); | ||
tst_res(TFAIL, "Still alive"); | ||
} | ||
|
||
static struct tst_test test = { | ||
.test_all = run, | ||
.max_runtime = 5, | ||
}; |
Oops, something went wrong.