diff mbox

[ndctl] ndctl: Grab kernel version from utsname()

Message ID 1457620089-28984-1-git-send-email-jthumshirn@suse.de (mailing list archive)
State New, archived
Headers show

Commit Message

Johannes Thumshirn March 10, 2016, 2:28 p.m. UTC
Grab the kernel version used for tests dynamically via utsname() instead of
hardcoding the version of the build host.

Otherwise tests will be skipped if the build host had a too old kernel
version.

flodin:~ # ./ndctl test
__ndctl_test_attempt: skip test_libndctl:1950 requires: 4.2.0 current: 4.1.0
test-libndctl: SKIP
__ndctl_test_attempt: skip test_dpa_alloc:300 requires: 4.2.0 current: 4.1.0
test-dpa-alloc: SKIP
__ndctl_test_attempt: skip test_parent_uuid:230 requires: 4.3.0 current: 4.1.0
test-parent-uuid: SKIP
attempted: 3 skipped: 3

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 test/core.c |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Dan Williams March 10, 2016, 6:57 p.m. UTC | #1
On Thu, Mar 10, 2016 at 6:28 AM, Johannes Thumshirn <jthumshirn@suse.de> wrote:
> Grab the kernel version used for tests dynamically via utsname() instead of
> hardcoding the version of the build host.
>
> Otherwise tests will be skipped if the build host had a too old kernel
> version.
>
> flodin:~ # ./ndctl test
> __ndctl_test_attempt: skip test_libndctl:1950 requires: 4.2.0 current: 4.1.0
> test-libndctl: SKIP
> __ndctl_test_attempt: skip test_dpa_alloc:300 requires: 4.2.0 current: 4.1.0
> test-dpa-alloc: SKIP
> __ndctl_test_attempt: skip test_parent_uuid:230 requires: 4.3.0 current: 4.1.0
> test-parent-uuid: SKIP
> attempted: 3 skipped: 3
>
> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
> ---
>  test/core.c |   15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
>
> --- a/test/core.c
> +++ b/test/core.c
> @@ -1,4 +1,5 @@
>  #include <linux/version.h>
> +#include <sys/utsname.h>
>  #include <stdlib.h>
>  #include <stdio.h>
>  #include <test.h>
> @@ -11,6 +12,18 @@ struct ndctl_test {
>         int skip;
>  };
>
> +static unsigned int get_system_kver(void)
> +{
> +       struct utsname utsname;
> +       int a, b, c;
> +
> +       uname(&utsname);
> +
> +       sscanf(utsname.version, "%d.%d.%d", &a, &b, &c);
> +
> +       return KERNEL_VERSION(a,b,c);
> +}

Hmm, on my workstation utsname.version is "#1 SMP Fri Feb 26 18:45:40
UTC 2016" while utsname.release is "4.4.3-300.fc23.x86_64".  Do
different distros define release and version differently?
Johannes Thumshirn March 11, 2016, 8:05 a.m. UTC | #2
On Thu, Mar 10, 2016 at 10:57:42AM -0800, Dan Williams wrote:
> On Thu, Mar 10, 2016 at 6:28 AM, Johannes Thumshirn <jthumshirn@suse.de> wrote:
> > Grab the kernel version used for tests dynamically via utsname() instead of
> > hardcoding the version of the build host.
> >
> > Otherwise tests will be skipped if the build host had a too old kernel
> > version.
> >
> > flodin:~ # ./ndctl test
> > __ndctl_test_attempt: skip test_libndctl:1950 requires: 4.2.0 current: 4.1.0
> > test-libndctl: SKIP
> > __ndctl_test_attempt: skip test_dpa_alloc:300 requires: 4.2.0 current: 4.1.0
> > test-dpa-alloc: SKIP
> > __ndctl_test_attempt: skip test_parent_uuid:230 requires: 4.3.0 current: 4.1.0
> > test-parent-uuid: SKIP
> > attempted: 3 skipped: 3
> >
> > Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
> > ---
> >  test/core.c |   15 ++++++++++++++-
> >  1 file changed, 14 insertions(+), 1 deletion(-)
> >
> > --- a/test/core.c
> > +++ b/test/core.c
> > @@ -1,4 +1,5 @@
> >  #include <linux/version.h>
> > +#include <sys/utsname.h>
> >  #include <stdlib.h>
> >  #include <stdio.h>
> >  #include <test.h>
> > @@ -11,6 +12,18 @@ struct ndctl_test {
> >         int skip;
> >  };
> >
> > +static unsigned int get_system_kver(void)
> > +{
> > +       struct utsname utsname;
> > +       int a, b, c;
> > +
> > +       uname(&utsname);
> > +
> > +       sscanf(utsname.version, "%d.%d.%d", &a, &b, &c);
> > +
> > +       return KERNEL_VERSION(a,b,c);
> > +}
> 
> Hmm, on my workstation utsname.version is "#1 SMP Fri Feb 26 18:45:40
> UTC 2016" while utsname.release is "4.4.3-300.fc23.x86_64".  Do
> different distros define release and version differently?

Having a look at the manpage you're right. I wonder why it worked for me. I'll
respin with utsname.release and see if it still works. /me is a bit puzzled
why it worked.
diff mbox

Patch

--- a/test/core.c
+++ b/test/core.c
@@ -1,4 +1,5 @@ 
 #include <linux/version.h>
+#include <sys/utsname.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <test.h>
@@ -11,6 +12,18 @@  struct ndctl_test {
 	int skip;
 };
 
+static unsigned int get_system_kver(void)
+{
+	struct utsname utsname;
+	int a, b, c;
+
+	uname(&utsname);
+
+	sscanf(utsname.version, "%d.%d.%d", &a, &b, &c);
+
+	return KERNEL_VERSION(a,b,c);
+}
+
 struct ndctl_test *ndctl_test_new(unsigned int kver)
 {
 	struct ndctl_test *test = calloc(1, sizeof(*test));
@@ -19,7 +32,7 @@  struct ndctl_test *ndctl_test_new(unsign
 		return NULL;
 
 	if (!kver)
-		test->kver = LINUX_VERSION_CODE;
+		test->kver = get_system_kver();
 	else
 		test->kver = kver;