diff mbox

[ndctl] test: override current kernel version with environment variable

Message ID 146741093296.25756.14218284344995187267.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Williams July 1, 2016, 10:08 p.m. UTC
For backport kernels where the functionality is more advanced than the base
kernel version implies, allow 'KVER' environment to override the results of
'uname -r'.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 test/core.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Johannes Thumshirn July 4, 2016, 7:29 a.m. UTC | #1
On Fri, Jul 01, 2016 at 03:08:53PM -0700, Dan Williams wrote:
> For backport kernels where the functionality is more advanced than the base
> kernel version implies, allow 'KVER' environment to override the results of
> 'uname -r'.
> 
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>

Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
diff mbox

Patch

diff --git a/test/core.c b/test/core.c
index b5703273fa76..c2d225d4921e 100644
--- a/test/core.c
+++ b/test/core.c
@@ -14,12 +14,16 @@  struct ndctl_test {
 
 static unsigned int get_system_kver(void)
 {
+	const char *kver = getenv("KVER");
 	struct utsname utsname;
 	int a, b, c;
 
-	uname(&utsname);
+	if (!kver) {
+		uname(&utsname);
+		kver = utsname.release;
+	}
 
-	if (sscanf(utsname.release, "%d.%d.%d", &a, &b, &c) != 3)
+	if (sscanf(kver, "%d.%d.%d", &a, &b, &c) != 3)
 		return LINUX_VERSION_CODE;
 
 	return KERNEL_VERSION(a,b,c);