tst_module: introduce a timeout to unload modules

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.kholmanskikh@oracle.com>
Acked-by: Cyril Hrubis <chrubis@suse.cz>
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_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);
+	}
 }