tests: add cpuset regression test
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
efcb71f8ff
commit
125b6a9191
|
@ -3,13 +3,14 @@ include $(top_srcdir)/config/include-Makefile.am
|
|||
AM_CPPFLAGS += -DTEST_PROGRAM
|
||||
|
||||
noinst_PROGRAMS = test_blkdev test_ismounted test_wholedisk test_mangle \
|
||||
test_strtosize
|
||||
test_strtosize test_cpuset
|
||||
|
||||
test_blkdev_SOURCES = blkdev.c
|
||||
test_ismounted_SOURCES = ismounted.c
|
||||
test_wholedisk_SOURCES = wholedisk.c
|
||||
test_mangle_SOURCES = mangle.c
|
||||
test_strtosize_SOURCES = strtosize.c
|
||||
test_cpuset_SOURCES = cpuset.c
|
||||
|
||||
if LINUX
|
||||
test_blkdev_SOURCES += linux_version.c
|
||||
|
|
70
lib/cpuset.c
70
lib/cpuset.c
|
@ -239,3 +239,73 @@ int cstr_to_cpuset(struct bitmask *mask, const char* str)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
|
||||
#include <err.h>
|
||||
#include <getopt.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct bitmask *set;
|
||||
char *buf, *mask = NULL, *range = NULL;
|
||||
int ncpus = 2048, rc, c;
|
||||
|
||||
struct option longopts[] = {
|
||||
{ "ncpus", 1, 0, 'n' },
|
||||
{ "mask", 1, 0, 'm' },
|
||||
{ "range", 1, 0, 'r' },
|
||||
{ NULL, 0, 0, 0 }
|
||||
};
|
||||
|
||||
while ((c = getopt_long(argc, argv, "n:m:r:", longopts, NULL)) != -1) {
|
||||
switch(c) {
|
||||
case 'n':
|
||||
ncpus = atoi(optarg);
|
||||
break;
|
||||
case 'm':
|
||||
mask = strdup(optarg);
|
||||
break;
|
||||
case 'r':
|
||||
range = strdup(optarg);
|
||||
break;
|
||||
default:
|
||||
goto usage_err;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mask && !range)
|
||||
goto usage_err;
|
||||
|
||||
set = bitmask_alloc(ncpus);
|
||||
if (!set)
|
||||
err(EXIT_FAILURE, "failed to allocate cpu set");
|
||||
|
||||
buf = malloc(7 * ncpus);
|
||||
if (!buf)
|
||||
err(EXIT_FAILURE, "failed to allocate cpu set buffer");
|
||||
|
||||
if (mask)
|
||||
rc = str_to_cpuset(set, mask);
|
||||
else
|
||||
rc = cstr_to_cpuset(set, range);
|
||||
|
||||
if (rc)
|
||||
errx(EXIT_FAILURE, "failed to parse string: %s", mask ? : range);
|
||||
|
||||
printf("%-15s = %15s ", mask ? : range, cpuset_to_str(set, buf));
|
||||
printf("[%s]\n", cpuset_to_cstr(set, buf));
|
||||
|
||||
free(buf);
|
||||
free(set->maskp);
|
||||
free(set);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
usage_err:
|
||||
fprintf(stderr,
|
||||
"usage: %s [--ncpus <num>] --mask <mask> | --range <list>",
|
||||
program_invocation_short_name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -11,6 +11,7 @@ TS_HELPER_MD5="$TS_TOPDIR/helpers/test_md5"
|
|||
|
||||
TS_HELPER_ISMOUNTED="$TOPDIR/lib/test_ismounted"
|
||||
TS_HELPER_STRTOSIZE="$TOPDIR/lib/test_strtosize"
|
||||
TS_HELPER_CPUSET="$TOPDIR/lib/test_cpuset"
|
||||
|
||||
# TODO: use partx
|
||||
TS_HELPER_PARTITIONS="$TOPDIR/shlibs/blkid/samples/partitions"
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
masks:
|
||||
0x00000001 = 1 [0]
|
||||
0x00000002 = 2 [1]
|
||||
0x00000003 = 3 [0,1]
|
||||
0x00000004 = 4 [2]
|
||||
0x00000005 = 5 [0,2]
|
||||
0x00000006 = 6 [1,2]
|
||||
0x00000007 = 7 [0-2]
|
||||
0x00000008 = 8 [3]
|
||||
0x00000009 = 9 [0,3]
|
||||
0x00005555 = 5555 [0,2,4,6,8,10,12,14]
|
||||
0x00007777 = 7777 [0-2,4-6,8-10,12-14]
|
||||
strings:
|
||||
0 = 1 [0]
|
||||
1 = 2 [1]
|
||||
0,1 = 3 [0,1]
|
||||
2 = 4 [2]
|
||||
0,2 = 5 [0,2]
|
||||
1,2 = 6 [1,2]
|
||||
0-2 = 7 [0-2]
|
||||
3 = 8 [3]
|
||||
0,3 = 9 [0,3]
|
||||
0,2,4,6,8,10,12,14 = 5555 [0,2,4,6,8,10,12,14]
|
||||
0-2,4-6,8-10,12-14 = 7777 [0-2,4-6,8-10,12-14]
|
|
@ -0,0 +1,57 @@
|
|||
#!/bin/bash
|
||||
|
||||
#
|
||||
# This file is part of util-linux-ng.
|
||||
#
|
||||
# This file is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This file 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 General Public License for more details.
|
||||
#
|
||||
|
||||
TS_TOPDIR="$(dirname $0)/../.."
|
||||
TS_DESC="cpuset"
|
||||
|
||||
. $TS_TOPDIR/functions.sh
|
||||
ts_init "$*"
|
||||
|
||||
MASKS=" 0x00000001 \
|
||||
0x00000002 \
|
||||
0x00000003 \
|
||||
0x00000004 \
|
||||
0x00000005 \
|
||||
0x00000006 \
|
||||
0x00000007 \
|
||||
0x00000008 \
|
||||
0x00000009 \
|
||||
0x00005555 \
|
||||
0x00007777"
|
||||
|
||||
RANGES="0 \
|
||||
1 \
|
||||
0,1 \
|
||||
2 \
|
||||
0,2 \
|
||||
1,2 \
|
||||
0-2 \
|
||||
3 \
|
||||
0,3 \
|
||||
0,2,4,6,8,10,12,14 \
|
||||
0-2,4-6,8-10,12-14"
|
||||
|
||||
ts_log "masks:"
|
||||
for i in $MASKS; do
|
||||
$TS_HELPER_CPUSET --mask $i >> $TS_OUTPUT
|
||||
done
|
||||
|
||||
ts_log "strings:"
|
||||
for i in $RANGES; do
|
||||
$TS_HELPER_CPUSET --range $i >> $TS_OUTPUT
|
||||
done
|
||||
|
||||
ts_finalize
|
Loading…
Reference in New Issue