Hi! > Try to reset the RLIMIT_NPROC/RLIMIT_NOFILE to satify the test > option. If fail, just exit the test with warning. Also fix the bug for > subthreads opening files failed, the main will infinitely wait.
Can you split the patch into two fixes, one for each problem? > Signed-off-by: George Wang <x...@redhat.com> > --- > testcases/kernel/fs/openfile/openfile.c | 50 > +++++++++++++++++++++++++++++++-- > 1 file changed, 47 insertions(+), 3 deletions(-) > > diff --git a/testcases/kernel/fs/openfile/openfile.c > b/testcases/kernel/fs/openfile/openfile.c > index 8657064..091fb39 100644 > --- a/testcases/kernel/fs/openfile/openfile.c > +++ b/testcases/kernel/fs/openfile/openfile.c > @@ -34,6 +34,7 @@ > #include <stdlib.h> > #include <stdint.h> > #include <unistd.h> > +#include <sys/resource.h> > > #include "test.h" > #include "usctest.h" > @@ -49,11 +50,12 @@ struct cb { > pthread_mutex_t m; > pthread_cond_t init_cv; > pthread_cond_t thr_cv; > + pthread_spinlock_t fail_lock; > int thr_sleeping; > } c; > > /* Global Variables */ > -int numthreads = 10, numfiles = 10; > +int numthreads = 10, numfiles = 10, failedthreads = 0; > int debug = 0; > char *filename = "FILETOOPEN"; > > @@ -68,6 +70,30 @@ void cleanup(void) > > } > > +int adjust_system_limit(int limit_type, int value) > +{ > + struct rlimit limit; > + > + if (getrlimit(limit_type, &limit)) { > + /* get limit failed, just return 0 to make the test run */ > + return 0; > + } > + > + if (RLIM_INFINITY == limit.rlim_cur) { > + /* unlimited for this resource */ Please avoid adding useless comments like this one, everybody can see that the the current limit is unlimited from the if body. > + return 0; > + } > + if (value <= (int)limit.rlim_cur) { > + /* current limit can satify the value */ Here as well. > + return 0; > + } > + > + > + limit.rlim_cur = value < (int)limit.rlim_max ? (int)limit.rlim_max : > value; > + > + return setrlimit(limit_type, &limit); > +} We have SAFE_SETRLIMIT/SAFE_GETRLIMIT that exit the test automatically if something went wrong. > /* Procedures */ > void *threads(void *thread_id); > > @@ -125,6 +151,13 @@ int main(int argc, char *argv[]) > numthreads = MAXTHREADS; > } > > + if (adjust_system_limit(RLIMIT_NPROC, numthreads) || > + adjust_system_limit(RLIMIT_NOFILE, numfiles)) { > + tst_resm(TWARN, "can not run according to current system > limition"); > + cleanup(); > + _exit(1); This should be tst_brkm(TBROK, cleanup, ....); Moreover the rest of the test uses the tst_ interface incorrectly as well. If you look at: /* Grab mutex lock */ if (pthread_mutex_lock(&c.m)) { tst_resm(TFAIL, "failed to grab mutex lock"); fclose(fd); unlink(filename); cleanup(); } The fd should be closed in cleanup(), the unlink() does not neet to be done at all as the tst_rmdir() removes the directory recursively and the cleanup() does not exit the test, which it should at this moment. So it really should be: if (pthread_mutex_lock(&c.m)) tst_brkm(TBROK, cleanup, "failed to grab mutex lock"); And the cleaup should contain: if (fd > 0 && close(fd)) tst_resm(TWARN | TERRNO, "Failed to close(fd)); (the fd variable needs to be global). Moreover the _exit(0); at the end of the main causes the test not to propagate the failure to the results. It should be tst_exit(). Can you please fix that (in a separate patch) before we start doing functional changes in the testcase? You can also remove useless comments as: OTHER PROCEDURES, /* Open files */ etc. while you are at it. -- Cyril Hrubis chru...@suse.cz ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list