libprocps version test and documentation
test binary and man page for the version part of libprocps. It's a simple start, but it's a start!
This commit is contained in:
parent
bf97da3059
commit
8639a97250
11
Makefile.am
11
Makefile.am
@ -53,7 +53,8 @@ dist_man_MANS = \
|
||||
uptime.1 \
|
||||
vmstat.8 \
|
||||
w.1 \
|
||||
ps/ps.1
|
||||
ps/ps.1 \
|
||||
doc/procps_linux_version.3
|
||||
|
||||
EXTRA_DIST = \
|
||||
.version \
|
||||
@ -248,10 +249,7 @@ check_PROGRAMS = \
|
||||
lib/test_strutils \
|
||||
lib/test_fileutils \
|
||||
lib/test_process \
|
||||
proc/test_sysinfo \
|
||||
proc/test_namespace \
|
||||
lib/test_process \
|
||||
lib/test_strtod_nol
|
||||
$(TESTS)
|
||||
|
||||
lib_test_strutils_SOURCES = lib/test_strutils.c lib/strutils.c
|
||||
lib_test_strutils_LDADD = $(CYGWINFLAGS)
|
||||
@ -266,6 +264,8 @@ proc_test_sysinfo_SOURCES = proc/test_sysinfo.c
|
||||
proc_test_sysinfo_LDADD = proc/libprocps.la
|
||||
proc_test_namespace_SOURCES = proc/test_namespace.c
|
||||
proc_test_namespace_LDADD = proc/libprocps.la
|
||||
proc_test_version_SOURCES = include/tests.h proc/test_version.c
|
||||
proc_test_version_LDADD = proc/libprocps.la
|
||||
lib_test_strtod_nol_SOURCES = lib/test_strtod_nol.c lib/strutils.c
|
||||
lib_test_strtod_nol_LDADD = $(CYGWINFLAGS)
|
||||
|
||||
@ -277,6 +277,7 @@ BUILT_SOURCES = $(top_srcdir)/.version
|
||||
|
||||
TESTS = proc/test_sysinfo \
|
||||
proc/test_namespace \
|
||||
proc/test_version \
|
||||
lib/test_strtod_nol
|
||||
|
||||
$(top_srcdir)/.version:
|
||||
|
63
doc/procps_linux_version.3
Normal file
63
doc/procps_linux_version.3
Normal file
@ -0,0 +1,63 @@
|
||||
.\"
|
||||
.\" (C) Copyright 2016 Craig Small <csmall@enc.com.au>
|
||||
.\"
|
||||
.TH PROCPS_LINUX_VERSION 3 2016-04-14
|
||||
.\" Please adjust this date whenever revising the manpage.
|
||||
.\"
|
||||
.SH NAME
|
||||
procps_linux_version \-
|
||||
provide current version of Linux as an integer
|
||||
.SH SYNOPSIS
|
||||
.B #include <proc/procps.h>
|
||||
.sp
|
||||
.B int procps_linux_version(void);
|
||||
.sp
|
||||
Link with \fI\-lprocps\fP.
|
||||
.SH DESCRIPTION
|
||||
The function
|
||||
.BR procps_linux_version ()
|
||||
returns the current Linux version as an integer. On systems that have an emulated proc filesystem this function returns the
|
||||
version of the Linux emulation instead.
|
||||
|
||||
The Linux version consists of a triple of positive integers representing the major, minor and patch versions of the kernel.
|
||||
The library provides 3 macros for separating out the components.
|
||||
.RS 4
|
||||
.TP 1.2i
|
||||
.BR LINUX_VERSION_MAJOR (ver)
|
||||
Extract the major component from the given version integer.
|
||||
.TP
|
||||
.BR LINUX_VERSION_MINOR (ver)
|
||||
Extract the minor component from the given version integer.
|
||||
.TP
|
||||
.BR LINUX_VERSION_PATCH (ver)
|
||||
Extract the patch component from the given version integer.
|
||||
.RE
|
||||
.PP
|
||||
To encode a given Linux version, such as using it to compare against the current
|
||||
version, use the following macro:
|
||||
.TP
|
||||
.BI LINUX_VERSION( major , minor , patch )
|
||||
|
||||
.SH RETURN VALUE
|
||||
On success,
|
||||
.BR procps_linux_version ()
|
||||
return a positive integer which is the encoded Linux kernel version;
|
||||
on error, it returns a negative integer.
|
||||
|
||||
.SH ERRORS
|
||||
On error,
|
||||
.BR procps_linux_version ()
|
||||
may return the following values as errors:
|
||||
.TP
|
||||
.B -EIO
|
||||
The procps library was unable to read the osrelease file.
|
||||
.TP
|
||||
.B -ERANGE
|
||||
Unable to parse the osrelease file.
|
||||
.PP
|
||||
.BR procps_linux_version ()
|
||||
may also return any (negated) value that \fBfopen\fR() may return.
|
||||
|
||||
.SH SEE ALSO
|
||||
.BR fopen (3),
|
||||
.BR proc (5).
|
10
include/tests.h
Normal file
10
include/tests.h
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
#ifndef PROCPS_NG_TESTS_H
|
||||
#define PROCPS_NG_TESTS_H
|
||||
|
||||
struct test_func {
|
||||
int (*func)(void *data);
|
||||
char *name;
|
||||
};
|
||||
|
||||
#endif
|
3
proc/.gitignore
vendored
3
proc/.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
test_sysinfo
|
||||
test_namespace
|
||||
test_version
|
||||
test_sysinfo
|
||||
|
54
proc/test_version.c
Normal file
54
proc/test_version.c
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* libprocps - Library to read proc filesystem
|
||||
* Tests for version library calls
|
||||
*
|
||||
* Copyright 2016 Craig Small <csmall@enc.com.au>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <proc/version.h>
|
||||
#include "tests.h"
|
||||
|
||||
int check_linux_version(void *data)
|
||||
{
|
||||
return (procps_linux_version() > 0);
|
||||
}
|
||||
|
||||
struct test_func tests[] = {
|
||||
{ check_linux_version, "procps_linux_version()"},
|
||||
{ NULL, NULL}
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
struct test_func *current;
|
||||
|
||||
for(i=0; tests[i].func != NULL; i++) {
|
||||
current = &tests[i];
|
||||
if (!current->func(NULL)) {
|
||||
fprintf(stderr, "FAIL: %s\n", current->name);
|
||||
return EXIT_FAILURE;
|
||||
} else {
|
||||
fprintf(stderr, "PASS: %s\n", current->name);
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user