* [ptest-runner][PATCH 1/2] Add support to specify timeout by ptest
@ 2021-03-23 18:57 Anibal Limon
2021-03-23 18:57 ` [ptest-runner][PATCH 2/2] tests: Update to cover ptest timeout by file Anibal Limon
2021-03-24 16:25 ` [ptest-runner][PATCH 1/2] Add support to specify timeout by ptest Yi Fan Yu
0 siblings, 2 replies; 4+ messages in thread
From: Anibal Limon @ 2021-03-23 18:57 UTC (permalink / raw)
To: yocto
Cc: yifan.yu, Randy.MacLeod, nicolas.dechesne, richard.purdie,
Aníbal Limón
The ptest-runner has a default timeout of 300 secs and can be override
usint -t option in the runner.
There is a need to specify timeout by ptest because not all ptests takes
the sametime also are affected by machine. So add support to read a file
inside ptest folder (timeout-ptest) and override global timeout with it.
For example in glib-2.0,
/usr/lib/glib-2.0/ptest/run-ptest
/usr/lib/glib-2.0/ptest/timeout-ptest
Signed-off-by: Aníbal Limón <anibal.limon@linaro.org>
---
main.c | 2 +-
ptest_list.c | 3 ++-
ptest_list.h | 3 ++-
utils.c | 69 +++++++++++++++++++++++++++++++++++++---------------
utils.h | 2 +-
5 files changed, 55 insertions(+), 24 deletions(-)
diff --git a/main.c b/main.c
index e3a1b69..467548e 100644
--- a/main.c
+++ b/main.c
@@ -158,7 +158,7 @@ main(int argc, char *argv[])
for (i = 0; i < opts.dirs_no; i ++) {
struct ptest_list *tmp;
- tmp = get_available_ptests(opts.dirs[i]);
+ tmp = get_available_ptests(opts.dirs[i], opts.timeout);
if (tmp == NULL) {
fprintf(stderr, PRINT_PTESTS_NOT_FOUND_DIR, opts.dirs[i]);
continue;
diff --git a/ptest_list.c b/ptest_list.c
index 917ef4f..b689670 100644
--- a/ptest_list.c
+++ b/ptest_list.c
@@ -166,7 +166,7 @@ ptest_list_search_by_file(struct ptest_list *head, char *run_ptest, struct stat
}
struct ptest_list *
-ptest_list_add(struct ptest_list *head, char *ptest, char *run_ptest)
+ptest_list_add(struct ptest_list *head, char *ptest, char *run_ptest, int timeout)
{
struct ptest_list *n, *p;
@@ -179,6 +179,7 @@ ptest_list_add(struct ptest_list *head, char *ptest, char *run_ptest)
n->ptest = ptest;
n->run_ptest = run_ptest;
+ n->timeout = timeout;
n->prev = NULL;
n->next = NULL;
diff --git a/ptest_list.h b/ptest_list.h
index 02a64bb..e583d9f 100644
--- a/ptest_list.h
+++ b/ptest_list.h
@@ -50,6 +50,7 @@
struct ptest_list {
char *ptest;
char *run_ptest;
+ int timeout;
struct ptest_list *next;
struct ptest_list *prev;
@@ -62,7 +63,7 @@ extern int ptest_list_free_all(struct ptest_list *);
extern int ptest_list_length(struct ptest_list *);
extern struct ptest_list *ptest_list_search(struct ptest_list *, char *);
extern struct ptest_list *ptest_list_search_by_file(struct ptest_list *, char *, struct stat);
-extern struct ptest_list *ptest_list_add(struct ptest_list *, char *, char *);
+extern struct ptest_list *ptest_list_add(struct ptest_list *, char *, char *, int);
extern struct ptest_list *ptest_list_remove(struct ptest_list *, char *, int);
extern struct ptest_list *ptest_list_extend(struct ptest_list *, struct ptest_list *);
diff --git a/utils.c b/utils.c
index 1a3c90f..424115f 100644
--- a/utils.c
+++ b/utils.c
@@ -84,9 +84,30 @@ check_allocation1(void *p, size_t size, char *file, int line, int exit_on_null)
}
}
+static inline char *
+get_ptest_file(char **ptest_file, struct stat *st_buf, const char *main_dir,
+ const char *ptest_dir, const char *file_name)
+{
+ if (asprintf(ptest_file, "%s/%s/ptest/%s",
+ main_dir, ptest_dir, file_name) == -1) {
+ return NULL;
+ }
+
+ if (stat(*ptest_file, st_buf) == -1) {
+ free(*ptest_file);
+ return NULL;
+ }
+
+ if (!S_ISREG(st_buf->st_mode)) {
+ free(*ptest_file);
+ return NULL;
+ }
+
+ return *ptest_file;
+}
struct ptest_list *
-get_available_ptests(const char *dir)
+get_available_ptests(const char *dir, int global_timeout)
{
struct ptest_list *head;
struct stat st_buf;
@@ -123,10 +144,11 @@ get_available_ptests(const char *dir)
break;
}
-
fail = 0;
for (i = 0; i < n; i++) {
char *run_ptest;
+ char *timeout_ptest;
+ int timeout;
char *d_name = strdup(namelist[i]->d_name);
CHECK_ALLOCATION(d_name, sizeof(namelist[i]->d_name), 0);
@@ -142,34 +164,38 @@ get_available_ptests(const char *dir)
continue;
}
- if (asprintf(&run_ptest, "%s/%s/ptest/run-ptest",
- realdir, d_name) == -1) {
- fail = 1;
+ if (get_ptest_file(&run_ptest, &st_buf, realdir, d_name, "run-ptest") == NULL) {
saved_errno = errno;
free(d_name);
- break;
- }
-
- if (stat(run_ptest, &st_buf) == -1) {
- free(run_ptest);
- free(d_name);
continue;
}
- if (!S_ISREG(st_buf.st_mode)) {
+ if (ptest_list_search_by_file(head, run_ptest, st_buf)) {
free(run_ptest);
free(d_name);
continue;
}
- if (ptest_list_search_by_file(head, run_ptest, st_buf)) {
- free(run_ptest);
- free(d_name);
- continue;
+ timeout = global_timeout;
+ if (get_ptest_file(&timeout_ptest, &st_buf, realdir, d_name, "timeout-ptest")) {
+ FILE *f = fopen(timeout_ptest, "r");
+
+ if (f == NULL) {
+ fail = 1;
+ saved_errno = errno;
+ free(run_ptest);
+ free(d_name);
+ free(timeout_ptest);
+ break;
+ }
+ fscanf(f, "%d", &timeout);
+ fclose(f);
+
+ free(timeout_ptest);
}
struct ptest_list *p = ptest_list_add(head,
- d_name, run_ptest);
+ d_name, run_ptest, timeout);
CHECK_ALLOCATION(p, sizeof(struct ptest_list *), 0);
if (p == NULL) {
fail = 1;
@@ -229,6 +255,7 @@ filter_ptests(struct ptest_list *head, char **ptests, int ptest_num)
for (i = 0; i < ptest_num; i++) {
char *ptest;
char *run_ptest;
+ int timeout;
n = ptest_list_search(head, ptests[i]);
if (n == NULL) {
@@ -239,13 +266,14 @@ filter_ptests(struct ptest_list *head, char **ptests, int ptest_num)
ptest = strdup(n->ptest);
run_ptest = strdup(n->run_ptest);
+ timeout = n->timeout;
if (ptest == NULL || run_ptest == NULL) {
saved_errno = errno;
fail = 1;
break;
}
- if (ptest_list_add(head_new, ptest, run_ptest) == NULL) {
+ if (ptest_list_add(head_new, ptest, run_ptest, timeout) == NULL) {
saved_errno = errno;
fail = 1;
break;
@@ -509,8 +537,7 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, sttime));
fprintf(fp, "BEGIN: %s\n", ptest_dir);
-
- status = wait_child(child, opts.timeout);
+ status = wait_child(child, p->timeout);
entime = time(NULL);
duration = entime - sttime;
@@ -528,6 +555,8 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
fprintf(fp, "END: %s\n", ptest_dir);
fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, entime));
+
+ free(ptest_dir);
}
PTEST_LIST_ITERATE_END
fprintf(fp, "STOP: %s\n", progname);
diff --git a/utils.h b/utils.h
index 39832e6..69940d0 100644
--- a/utils.h
+++ b/utils.h
@@ -45,7 +45,7 @@ struct ptest_options {
extern void check_allocation1(void *, size_t, char *, int, int);
-extern struct ptest_list *get_available_ptests(const char *);
+extern struct ptest_list *get_available_ptests(const char *, int);
extern int print_ptests(struct ptest_list *, FILE *);
extern struct ptest_list *filter_ptests(struct ptest_list *, char **, int);
extern int run_ptests(struct ptest_list *, const struct ptest_options,
--
2.31.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [ptest-runner][PATCH 2/2] tests: Update to cover ptest timeout by file
2021-03-23 18:57 [ptest-runner][PATCH 1/2] Add support to specify timeout by ptest Anibal Limon
@ 2021-03-23 18:57 ` Anibal Limon
2021-03-24 16:25 ` [ptest-runner][PATCH 1/2] Add support to specify timeout by ptest Yi Fan Yu
1 sibling, 0 replies; 4+ messages in thread
From: Anibal Limon @ 2021-03-23 18:57 UTC (permalink / raw)
To: yocto
Cc: yifan.yu, Randy.MacLeod, nicolas.dechesne, richard.purdie,
Aníbal Limón
Signed-off-by: Aníbal Limón <anibal.limon@linaro.org>
---
tests/ptest_list.c | 10 +++++-----
tests/utils.c | 14 +++++++-------
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/tests/ptest_list.c b/tests/ptest_list.c
index 081f027..37d19ae 100644
--- a/tests/ptest_list.c
+++ b/tests/ptest_list.c
@@ -52,7 +52,7 @@ END_TEST
START_TEST(test_add)
{
struct ptest_list *head = ptest_list_alloc();
- ck_assert(ptest_list_add(head, strdup("perl"), NULL) != NULL);
+ ck_assert(ptest_list_add(head, strdup("perl"), NULL, 1) != NULL);
ptest_list_free_all(head);
}
END_TEST
@@ -67,7 +67,7 @@ START_TEST(test_free_all)
head = ptest_list_alloc();
for (i = 0; i < ptests_num; i++)
- ptest_list_add(head, strdup(ptest_names[i]), NULL);
+ ptest_list_add(head, strdup(ptest_names[i]), NULL, 1);
ptest_list_free_all(head);
}
@@ -84,7 +84,7 @@ START_TEST(test_length)
head = ptest_list_alloc();
for (i = 0; i < ptests_num; i++)
- ptest_list_add(head, strdup(ptest_names[i]), NULL);
+ ptest_list_add(head, strdup(ptest_names[i]), NULL, 1);
ck_assert_int_eq(ptest_list_length(head), ptests_num);
ptest_list_free_all(head);
@@ -103,7 +103,7 @@ START_TEST(test_search)
head = ptest_list_alloc();
for (i = 0; i < ptests_num; i++) {
ptest = strdup(ptest_names[i]);
- ptest_list_add(head, ptest, NULL);
+ ptest_list_add(head, ptest, NULL, 1);
}
for (i = ptests_num - 1; i >= 0; i--)
@@ -122,7 +122,7 @@ START_TEST(test_remove)
for (i = 0; i < ptests_num; i++) {
ptest = strdup(ptest_names[i]);
- ptest_list_add(head, ptest, NULL);
+ ptest_list_add(head, ptest, NULL, 1);
}
/* Remove node free'ing */
diff --git a/tests/utils.c b/tests/utils.c
index 105e0c8..8df1b54 100644
--- a/tests/utils.c
+++ b/tests/utils.c
@@ -78,7 +78,7 @@ static void test_ptest_expected_failure(struct ptest_list *, const int, char *,
START_TEST(test_get_available_ptests)
{
- struct ptest_list *head = get_available_ptests(opts_directory);
+ struct ptest_list *head = get_available_ptests(opts_directory, 1);
int i;
ck_assert(ptest_list_length(head) == ptests_found_length);
@@ -121,7 +121,7 @@ START_TEST(test_print_ptests)
ck_assert(line != NULL);
ck_assert(strcmp(line, PRINT_PTESTS_NOT_FOUND) == 0);
- head = get_available_ptests(opts_directory);
+ head = get_available_ptests(opts_directory, 1);
ck_assert(print_ptests(head, fp) == 0);
ptest_list_free_all(head);
line = fgets(line_buf, PRINT_PTEST_BUF_SIZE, fp);
@@ -143,7 +143,7 @@ END_TEST
START_TEST(test_filter_ptests)
{
- struct ptest_list *head = get_available_ptests(opts_directory);
+ struct ptest_list *head = get_available_ptests(opts_directory, 1);
struct ptest_list *head_new;
char *ptest_not_exists[] = {
"glib",
@@ -185,7 +185,7 @@ START_TEST(test_run_ptests)
fp_stderr = open_memstream(&buf_stderr, &size_stderr);
ck_assert(fp_stderr != NULL);
- head = get_available_ptests(opts_directory);
+ head = get_available_ptests(opts_directory, 1);
ptest_list_remove(head, "hang", 1);
ptest_list_remove(head, "fail", 1);
@@ -222,8 +222,8 @@ search_for_timeout_and_duration(const int rp, FILE *fp_stdout)
START_TEST(test_run_timeout_duration_ptest)
{
- struct ptest_list *head = get_available_ptests(opts_directory);
- int timeout = 1;
+ int timeout = 20;
+ struct ptest_list *head = get_available_ptests(opts_directory, timeout);
test_ptest_expected_failure(head, timeout, "hang", search_for_timeout_and_duration);
@@ -250,8 +250,8 @@ search_for_fail(const int rp, FILE *fp_stdout)
START_TEST(test_run_fail_ptest)
{
- struct ptest_list *head = get_available_ptests(opts_directory);
int timeout = 1;
+ struct ptest_list *head = get_available_ptests(opts_directory, timeout);
test_ptest_expected_failure(head, timeout, "fail", search_for_fail);
--
2.31.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [ptest-runner][PATCH 1/2] Add support to specify timeout by ptest
2021-03-23 18:57 [ptest-runner][PATCH 1/2] Add support to specify timeout by ptest Anibal Limon
2021-03-23 18:57 ` [ptest-runner][PATCH 2/2] tests: Update to cover ptest timeout by file Anibal Limon
@ 2021-03-24 16:25 ` Yi Fan Yu
2021-03-24 18:32 ` Anibal Limon
1 sibling, 1 reply; 4+ messages in thread
From: Yi Fan Yu @ 2021-03-24 16:25 UTC (permalink / raw)
To: Aníbal Limón, yocto
Cc: Randy.MacLeod, nicolas.dechesne, richard.purdie
On 3/23/21 2:57 PM, Aníbal Limón wrote:
> [Please note: This e-mail is from an EXTERNAL e-mail address]
>
> The ptest-runner has a default timeout of 300 secs and can be override
> usint -t option in the runner.
>
> There is a need to specify timeout by ptest because not all ptests takes
> the sametime also are affected by machine. So add support to read a file
> inside ptest folder (timeout-ptest) and override global timeout with it.
>
> For example in glib-2.0,
>
> /usr/lib/glib-2.0/ptest/run-ptest
> /usr/lib/glib-2.0/ptest/timeout-ptest
>
I don't see a huge amount of use of `timeout-ptest` since
many tests I looked at have their own timeout mechanism built-in to
individual tests (OR we have patched in... ex: valgrind).
This has the advantage that the entire testsuite doesn't get killed,
only that particular hanging test.
I think the highest timeout I have bumped up is with valgrind at 90s
yifan
> Signed-off-by: Aníbal Limón <anibal.limon@linaro.org>
> ---
> main.c | 2 +-
> ptest_list.c | 3 ++-
> ptest_list.h | 3 ++-
> utils.c | 69 +++++++++++++++++++++++++++++++++++++---------------
> utils.h | 2 +-
> 5 files changed, 55 insertions(+), 24 deletions(-)
>
> diff --git a/main.c b/main.c
> index e3a1b69..467548e 100644
> --- a/main.c
> +++ b/main.c
> @@ -158,7 +158,7 @@ main(int argc, char *argv[])
> for (i = 0; i < opts.dirs_no; i ++) {
> struct ptest_list *tmp;
>
> - tmp = get_available_ptests(opts.dirs[i]);
> + tmp = get_available_ptests(opts.dirs[i], opts.timeout);
> if (tmp == NULL) {
> fprintf(stderr, PRINT_PTESTS_NOT_FOUND_DIR, opts.dirs[i]);
> continue;
> diff --git a/ptest_list.c b/ptest_list.c
> index 917ef4f..b689670 100644
> --- a/ptest_list.c
> +++ b/ptest_list.c
> @@ -166,7 +166,7 @@ ptest_list_search_by_file(struct ptest_list *head, char *run_ptest, struct stat
> }
>
> struct ptest_list *
> -ptest_list_add(struct ptest_list *head, char *ptest, char *run_ptest)
> +ptest_list_add(struct ptest_list *head, char *ptest, char *run_ptest, int timeout)
> {
> struct ptest_list *n, *p;
>
> @@ -179,6 +179,7 @@ ptest_list_add(struct ptest_list *head, char *ptest, char *run_ptest)
>
> n->ptest = ptest;
> n->run_ptest = run_ptest;
> + n->timeout = timeout;
>
> n->prev = NULL;
> n->next = NULL;
> diff --git a/ptest_list.h b/ptest_list.h
> index 02a64bb..e583d9f 100644
> --- a/ptest_list.h
> +++ b/ptest_list.h
> @@ -50,6 +50,7 @@
> struct ptest_list {
> char *ptest;
> char *run_ptest;
> + int timeout;
>
> struct ptest_list *next;
> struct ptest_list *prev;
> @@ -62,7 +63,7 @@ extern int ptest_list_free_all(struct ptest_list *);
> extern int ptest_list_length(struct ptest_list *);
> extern struct ptest_list *ptest_list_search(struct ptest_list *, char *);
> extern struct ptest_list *ptest_list_search_by_file(struct ptest_list *, char *, struct stat);
> -extern struct ptest_list *ptest_list_add(struct ptest_list *, char *, char *);
> +extern struct ptest_list *ptest_list_add(struct ptest_list *, char *, char *, int);
> extern struct ptest_list *ptest_list_remove(struct ptest_list *, char *, int);
> extern struct ptest_list *ptest_list_extend(struct ptest_list *, struct ptest_list *);
>
> diff --git a/utils.c b/utils.c
> index 1a3c90f..424115f 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -84,9 +84,30 @@ check_allocation1(void *p, size_t size, char *file, int line, int exit_on_null)
> }
> }
>
> +static inline char *
> +get_ptest_file(char **ptest_file, struct stat *st_buf, const char *main_dir,
> + const char *ptest_dir, const char *file_name)
> +{
> + if (asprintf(ptest_file, "%s/%s/ptest/%s",
> + main_dir, ptest_dir, file_name) == -1) {
> + return NULL;
> + }
> +
> + if (stat(*ptest_file, st_buf) == -1) {
> + free(*ptest_file);
> + return NULL;
> + }
> +
> + if (!S_ISREG(st_buf->st_mode)) {
> + free(*ptest_file);
> + return NULL;
> + }
> +
> + return *ptest_file;
> +}
>
> struct ptest_list *
> -get_available_ptests(const char *dir)
> +get_available_ptests(const char *dir, int global_timeout)
> {
> struct ptest_list *head;
> struct stat st_buf;
> @@ -123,10 +144,11 @@ get_available_ptests(const char *dir)
> break;
> }
>
> -
> fail = 0;
> for (i = 0; i < n; i++) {
> char *run_ptest;
> + char *timeout_ptest;
> + int timeout;
>
> char *d_name = strdup(namelist[i]->d_name);
> CHECK_ALLOCATION(d_name, sizeof(namelist[i]->d_name), 0);
> @@ -142,34 +164,38 @@ get_available_ptests(const char *dir)
> continue;
> }
>
> - if (asprintf(&run_ptest, "%s/%s/ptest/run-ptest",
> - realdir, d_name) == -1) {
> - fail = 1;
> + if (get_ptest_file(&run_ptest, &st_buf, realdir, d_name, "run-ptest") == NULL) {
> saved_errno = errno;
> free(d_name);
> - break;
> - }
> -
> - if (stat(run_ptest, &st_buf) == -1) {
> - free(run_ptest);
> - free(d_name);
> continue;
> }
>
> - if (!S_ISREG(st_buf.st_mode)) {
> + if (ptest_list_search_by_file(head, run_ptest, st_buf)) {
> free(run_ptest);
> free(d_name);
> continue;
> }
>
> - if (ptest_list_search_by_file(head, run_ptest, st_buf)) {
> - free(run_ptest);
> - free(d_name);
> - continue;
> + timeout = global_timeout;
> + if (get_ptest_file(&timeout_ptest, &st_buf, realdir, d_name, "timeout-ptest")) {
> + FILE *f = fopen(timeout_ptest, "r");
> +
> + if (f == NULL) {
> + fail = 1;
> + saved_errno = errno;
> + free(run_ptest);
> + free(d_name);
> + free(timeout_ptest);
> + break;
> + }
> + fscanf(f, "%d", &timeout);
> + fclose(f);
> +
> + free(timeout_ptest);
> }
>
> struct ptest_list *p = ptest_list_add(head,
> - d_name, run_ptest);
> + d_name, run_ptest, timeout);
> CHECK_ALLOCATION(p, sizeof(struct ptest_list *), 0);
> if (p == NULL) {
> fail = 1;
> @@ -229,6 +255,7 @@ filter_ptests(struct ptest_list *head, char **ptests, int ptest_num)
> for (i = 0; i < ptest_num; i++) {
> char *ptest;
> char *run_ptest;
> + int timeout;
>
> n = ptest_list_search(head, ptests[i]);
> if (n == NULL) {
> @@ -239,13 +266,14 @@ filter_ptests(struct ptest_list *head, char **ptests, int ptest_num)
>
> ptest = strdup(n->ptest);
> run_ptest = strdup(n->run_ptest);
> + timeout = n->timeout;
> if (ptest == NULL || run_ptest == NULL) {
> saved_errno = errno;
> fail = 1;
> break;
> }
>
> - if (ptest_list_add(head_new, ptest, run_ptest) == NULL) {
> + if (ptest_list_add(head_new, ptest, run_ptest, timeout) == NULL) {
> saved_errno = errno;
> fail = 1;
> break;
> @@ -509,8 +537,7 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
> fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, sttime));
> fprintf(fp, "BEGIN: %s\n", ptest_dir);
>
> -
> - status = wait_child(child, opts.timeout);
> + status = wait_child(child, p->timeout);
>
> entime = time(NULL);
> duration = entime - sttime;
> @@ -528,6 +555,8 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
>
> fprintf(fp, "END: %s\n", ptest_dir);
> fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, entime));
> +
> + free(ptest_dir);
> }
> PTEST_LIST_ITERATE_END
> fprintf(fp, "STOP: %s\n", progname);
> diff --git a/utils.h b/utils.h
> index 39832e6..69940d0 100644
> --- a/utils.h
> +++ b/utils.h
> @@ -45,7 +45,7 @@ struct ptest_options {
>
>
> extern void check_allocation1(void *, size_t, char *, int, int);
> -extern struct ptest_list *get_available_ptests(const char *);
> +extern struct ptest_list *get_available_ptests(const char *, int);
> extern int print_ptests(struct ptest_list *, FILE *);
> extern struct ptest_list *filter_ptests(struct ptest_list *, char **, int);
> extern int run_ptests(struct ptest_list *, const struct ptest_options,
> --
> 2.31.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [ptest-runner][PATCH 1/2] Add support to specify timeout by ptest
2021-03-24 16:25 ` [ptest-runner][PATCH 1/2] Add support to specify timeout by ptest Yi Fan Yu
@ 2021-03-24 18:32 ` Anibal Limon
0 siblings, 0 replies; 4+ messages in thread
From: Anibal Limon @ 2021-03-24 18:32 UTC (permalink / raw)
To: Yi Fan Yu
Cc: Yocto discussion list, MacLeod, Randy, Nicolas Dechesne, Richard Purdie
[-- Attachment #1: Type: text/plain, Size: 11426 bytes --]
On Wed, 24 Mar 2021 at 10:25, Yi Fan Yu <yifan.yu@windriver.com> wrote:
> On 3/23/21 2:57 PM, Aníbal Limón wrote:
> > [Please note: This e-mail is from an EXTERNAL e-mail address]
> >
> > The ptest-runner has a default timeout of 300 secs and can be override
> > usint -t option in the runner.
> >
> > There is a need to specify timeout by ptest because not all ptests takes
> > the sametime also are affected by machine. So add support to read a file
> > inside ptest folder (timeout-ptest) and override global timeout with it.
> >
> > For example in glib-2.0,
> >
> > /usr/lib/glib-2.0/ptest/run-ptest
> > /usr/lib/glib-2.0/ptest/timeout-ptest
> >
>
> I don't see a huge amount of use of `timeout-ptest` since
>
> many tests I looked at have their own timeout mechanism built-in to
> individual tests (OR we have patched in... ex: valgrind).
>
>
> This has the advantage that the entire testsuite doesn't get killed,
> only that particular hanging test.
>
> I think the highest timeout I have bumped up is with valgrind at 90s
>
Ack, I changed the behavior of timeout so that's the reason I'm seeing this
error.
I don't see any reason to not support this may be useful in the future.
Regards,
Anibal
>
> yifan
>
> > Signed-off-by: Aníbal Limón <anibal.limon@linaro.org>
> > ---
> > main.c | 2 +-
> > ptest_list.c | 3 ++-
> > ptest_list.h | 3 ++-
> > utils.c | 69 +++++++++++++++++++++++++++++++++++++---------------
> > utils.h | 2 +-
> > 5 files changed, 55 insertions(+), 24 deletions(-)
> >
> > diff --git a/main.c b/main.c
> > index e3a1b69..467548e 100644
> > --- a/main.c
> > +++ b/main.c
> > @@ -158,7 +158,7 @@ main(int argc, char *argv[])
> > for (i = 0; i < opts.dirs_no; i ++) {
> > struct ptest_list *tmp;
> >
> > - tmp = get_available_ptests(opts.dirs[i]);
> > + tmp = get_available_ptests(opts.dirs[i], opts.timeout);
> > if (tmp == NULL) {
> > fprintf(stderr, PRINT_PTESTS_NOT_FOUND_DIR,
> opts.dirs[i]);
> > continue;
> > diff --git a/ptest_list.c b/ptest_list.c
> > index 917ef4f..b689670 100644
> > --- a/ptest_list.c
> > +++ b/ptest_list.c
> > @@ -166,7 +166,7 @@ ptest_list_search_by_file(struct ptest_list *head,
> char *run_ptest, struct stat
> > }
> >
> > struct ptest_list *
> > -ptest_list_add(struct ptest_list *head, char *ptest, char *run_ptest)
> > +ptest_list_add(struct ptest_list *head, char *ptest, char *run_ptest,
> int timeout)
> > {
> > struct ptest_list *n, *p;
> >
> > @@ -179,6 +179,7 @@ ptest_list_add(struct ptest_list *head, char *ptest,
> char *run_ptest)
> >
> > n->ptest = ptest;
> > n->run_ptest = run_ptest;
> > + n->timeout = timeout;
> >
> > n->prev = NULL;
> > n->next = NULL;
> > diff --git a/ptest_list.h b/ptest_list.h
> > index 02a64bb..e583d9f 100644
> > --- a/ptest_list.h
> > +++ b/ptest_list.h
> > @@ -50,6 +50,7 @@
> > struct ptest_list {
> > char *ptest;
> > char *run_ptest;
> > + int timeout;
> >
> > struct ptest_list *next;
> > struct ptest_list *prev;
> > @@ -62,7 +63,7 @@ extern int ptest_list_free_all(struct ptest_list *);
> > extern int ptest_list_length(struct ptest_list *);
> > extern struct ptest_list *ptest_list_search(struct ptest_list *, char
> *);
> > extern struct ptest_list *ptest_list_search_by_file(struct ptest_list
> *, char *, struct stat);
> > -extern struct ptest_list *ptest_list_add(struct ptest_list *, char *,
> char *);
> > +extern struct ptest_list *ptest_list_add(struct ptest_list *, char *,
> char *, int);
> > extern struct ptest_list *ptest_list_remove(struct ptest_list *, char
> *, int);
> > extern struct ptest_list *ptest_list_extend(struct ptest_list *,
> struct ptest_list *);
> >
> > diff --git a/utils.c b/utils.c
> > index 1a3c90f..424115f 100644
> > --- a/utils.c
> > +++ b/utils.c
> > @@ -84,9 +84,30 @@ check_allocation1(void *p, size_t size, char *file,
> int line, int exit_on_null)
> > }
> > }
> >
> > +static inline char *
> > +get_ptest_file(char **ptest_file, struct stat *st_buf, const char
> *main_dir,
> > + const char *ptest_dir, const char *file_name)
> > +{
> > + if (asprintf(ptest_file, "%s/%s/ptest/%s",
> > + main_dir, ptest_dir, file_name) == -1) {
> > + return NULL;
> > + }
> > +
> > + if (stat(*ptest_file, st_buf) == -1) {
> > + free(*ptest_file);
> > + return NULL;
> > + }
> > +
> > + if (!S_ISREG(st_buf->st_mode)) {
> > + free(*ptest_file);
> > + return NULL;
> > + }
> > +
> > + return *ptest_file;
> > +}
> >
> > struct ptest_list *
> > -get_available_ptests(const char *dir)
> > +get_available_ptests(const char *dir, int global_timeout)
> > {
> > struct ptest_list *head;
> > struct stat st_buf;
> > @@ -123,10 +144,11 @@ get_available_ptests(const char *dir)
> > break;
> > }
> >
> > -
> > fail = 0;
> > for (i = 0; i < n; i++) {
> > char *run_ptest;
> > + char *timeout_ptest;
> > + int timeout;
> >
> > char *d_name = strdup(namelist[i]->d_name);
> > CHECK_ALLOCATION(d_name,
> sizeof(namelist[i]->d_name), 0);
> > @@ -142,34 +164,38 @@ get_available_ptests(const char *dir)
> > continue;
> > }
> >
> > - if (asprintf(&run_ptest, "%s/%s/ptest/run-ptest",
> > - realdir, d_name) == -1) {
> > - fail = 1;
> > + if (get_ptest_file(&run_ptest, &st_buf, realdir,
> d_name, "run-ptest") == NULL) {
> > saved_errno = errno;
> > free(d_name);
> > - break;
> > - }
> > -
> > - if (stat(run_ptest, &st_buf) == -1) {
> > - free(run_ptest);
> > - free(d_name);
> > continue;
> > }
> >
> > - if (!S_ISREG(st_buf.st_mode)) {
> > + if (ptest_list_search_by_file(head, run_ptest,
> st_buf)) {
> > free(run_ptest);
> > free(d_name);
> > continue;
> > }
> >
> > - if (ptest_list_search_by_file(head, run_ptest,
> st_buf)) {
> > - free(run_ptest);
> > - free(d_name);
> > - continue;
> > + timeout = global_timeout;
> > + if (get_ptest_file(&timeout_ptest, &st_buf,
> realdir, d_name, "timeout-ptest")) {
> > + FILE *f = fopen(timeout_ptest, "r");
> > +
> > + if (f == NULL) {
> > + fail = 1;
> > + saved_errno = errno;
> > + free(run_ptest);
> > + free(d_name);
> > + free(timeout_ptest);
> > + break;
> > + }
> > + fscanf(f, "%d", &timeout);
> > + fclose(f);
> > +
> > + free(timeout_ptest);
> > }
> >
> > struct ptest_list *p = ptest_list_add(head,
> > - d_name, run_ptest);
> > + d_name, run_ptest, timeout);
> > CHECK_ALLOCATION(p, sizeof(struct ptest_list
> *), 0);
> > if (p == NULL) {
> > fail = 1;
> > @@ -229,6 +255,7 @@ filter_ptests(struct ptest_list *head, char
> **ptests, int ptest_num)
> > for (i = 0; i < ptest_num; i++) {
> > char *ptest;
> > char *run_ptest;
> > + int timeout;
> >
> > n = ptest_list_search(head, ptests[i]);
> > if (n == NULL) {
> > @@ -239,13 +266,14 @@ filter_ptests(struct ptest_list *head, char
> **ptests, int ptest_num)
> >
> > ptest = strdup(n->ptest);
> > run_ptest = strdup(n->run_ptest);
> > + timeout = n->timeout;
> > if (ptest == NULL || run_ptest == NULL) {
> > saved_errno = errno;
> > fail = 1;
> > break;
> > }
> >
> > - if (ptest_list_add(head_new, ptest, run_ptest)
> == NULL) {
> > + if (ptest_list_add(head_new, ptest, run_ptest,
> timeout) == NULL) {
> > saved_errno = errno;
> > fail = 1;
> > break;
> > @@ -509,8 +537,7 @@ run_ptests(struct ptest_list *head, const struct
> ptest_options opts,
> > fprintf(fp, "%s\n", get_stime(stime,
> GET_STIME_BUF_SIZE, sttime));
> > fprintf(fp, "BEGIN: %s\n", ptest_dir);
> >
> > -
> > - status = wait_child(child, opts.timeout);
> > + status = wait_child(child, p->timeout);
> >
> > entime = time(NULL);
> > duration = entime - sttime;
> > @@ -528,6 +555,8 @@ run_ptests(struct ptest_list *head, const struct
> ptest_options opts,
> >
> > fprintf(fp, "END: %s\n", ptest_dir);
> > fprintf(fp, "%s\n", get_stime(stime,
> GET_STIME_BUF_SIZE, entime));
> > +
> > + free(ptest_dir);
> > }
> > PTEST_LIST_ITERATE_END
> > fprintf(fp, "STOP: %s\n", progname);
> > diff --git a/utils.h b/utils.h
> > index 39832e6..69940d0 100644
> > --- a/utils.h
> > +++ b/utils.h
> > @@ -45,7 +45,7 @@ struct ptest_options {
> >
> >
> > extern void check_allocation1(void *, size_t, char *, int, int);
> > -extern struct ptest_list *get_available_ptests(const char *);
> > +extern struct ptest_list *get_available_ptests(const char *, int);
> > extern int print_ptests(struct ptest_list *, FILE *);
> > extern struct ptest_list *filter_ptests(struct ptest_list *, char **,
> int);
> > extern int run_ptests(struct ptest_list *, const struct ptest_options,
> > --
> > 2.31.0
> >
>
[-- Attachment #2: Type: text/html, Size: 14937 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-03-24 18:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23 18:57 [ptest-runner][PATCH 1/2] Add support to specify timeout by ptest Anibal Limon
2021-03-23 18:57 ` [ptest-runner][PATCH 2/2] tests: Update to cover ptest timeout by file Anibal Limon
2021-03-24 16:25 ` [ptest-runner][PATCH 1/2] Add support to specify timeout by ptest Yi Fan Yu
2021-03-24 18:32 ` Anibal Limon
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.