diff mbox series

[RFC,ndctl,3/9] test: Unload the nfit module during cleanup

Message ID 165030182353.3224737.2306830041576864838.stgit@lep8c.aus.stglabs.ibm.com (mailing list archive)
State New
Headers show
Series test: Enable PAPR test family by default | expand

Commit Message

Shivaprasad G Bhat April 18, 2022, 5:10 p.m. UTC
The nfit module which is needed for nfit_test is probed and is never
unloaded. The future patches attempt to load the ndtest modules and
continue the tests for PAPR family. Let there be clean state, so
unload it.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
---
 test/common |    7 +++++++
 test/core.c |   14 ++++++++++++++
 2 files changed, 21 insertions(+)
diff mbox series

Patch

diff --git a/test/common b/test/common
index d3216a0c..d2cb3f73 100644
--- a/test/common
+++ b/test/common
@@ -31,6 +31,10 @@  if [ -z $TEST_PATH ]; then
 	export TEST_PATH=.
 fi
 
+if [ ! -v NDCTL_TEST_FAMILY ]; then
+	export NDCTL_TEST_FAMILY=INTEL
+fi
+
 # NFIT_TEST_BUS[01]
 #
 NFIT_TEST_BUS0="nfit_test.0"
@@ -111,6 +115,9 @@  _cleanup()
 	$NDCTL disable-region -b $NFIT_TEST_BUS0 all
 	$NDCTL disable-region -b $NFIT_TEST_BUS1 all
 	modprobe -r nfit_test
+	if [ $NDCTL_TEST_FAMILY == "INTEL" ]; then
+		modprobe -r nfit
+	fi
 }
 
 _init()
diff --git a/test/core.c b/test/core.c
index 7b23e258..bc7542aa 100644
--- a/test/core.c
+++ b/test/core.c
@@ -130,8 +130,22 @@  void ndctl_test_module_remove(struct kmod_ctx **ctx, struct kmod_module **mod,
 	if (rc < 0 && rc != -ENOENT) {
 		fprintf(stderr, "couldn't remove module %s\n",
 				    strerror(-rc));
+		kmod_unref(*ctx);
+		return;
 	}
 
+	rc = kmod_module_new_from_name(*ctx, "nfit", mod);
+	if (rc == 0) {
+		int state = kmod_module_get_initstate(*mod);
+
+		if (state > 0) {
+			rc = kmod_module_remove_module(*mod, 0);
+			if (rc < 0) {
+				fprintf(stderr, "couldn't remove module %s\n",
+				    strerror(-rc));
+			}
+		}
+	}
 	kmod_unref(*ctx);
 }