It may happen, that the first execution of 'rmmod module_name'
may fail for some reason (like the module is in use for some short time).

Changed tst_module_unload() to execute 'rmmod module_name' multiple
times with the total number limited by a timeout.

Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmansk...@oracle.com>
---
Changes since V1:
 * rely on the exit code of rmmod
 * removed tst_module_unload
 * added missing usleep()


 lib/tst_module.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/lib/tst_module.c b/lib/tst_module.c
index 8104582..0be6ced 100644
--- a/lib/tst_module.c
+++ b/lib/tst_module.c
@@ -100,6 +100,21 @@ void tst_module_load(void (cleanup_fn)(void),
 
 void tst_module_unload(void (cleanup_fn)(void), const char *mod_name)
 {
+       int i, rc;
+
        const char *const argv[] = { "rmmod", mod_name, NULL };
-       tst_run_cmd(cleanup_fn, argv, NULL, NULL, 0);
+
+       rc = 1;
+       for (i = 0; i < 50; i++) {
+               rc = tst_run_cmd(NULL, argv, "/dev/null", "/dev/null", 1);
+               if (!rc)
+                       break;
+
+               usleep(20000);
+       }
+
+       if (rc) {
+               tst_brkm(TBROK, cleanup_fn,
+                        "could not unload %s module", mod_name);
+       }
 }
-- 
1.7.1


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to