]> err.no Git - util-linux/commitdiff
tests: add cpuset regression test
authorKarel Zak <kzak@redhat.com>
Mon, 24 May 2010 12:13:33 +0000 (14:13 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 1 Jun 2010 09:06:49 +0000 (11:06 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/Makefile.am
lib/cpuset.c
tests/commands.sh.in
tests/expected/schedutils/cpuset [new file with mode: 0644]
tests/ts/schedutils/cpuset [new file with mode: 0755]

index 0f008b3028ae506290472120da507d36fdcd278d..93b79a5a75665dbd02b24da65e5977050fb38982 100644 (file)
@@ -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
index abdd40901686ead1b11840f9cfe64ab038ed7e94..92ed73043a6dac51061111df2cf12ce4fe5c2884 100644 (file)
@@ -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
index f52a6868785bcbe482558414c61557e9ead734b0..94f6521e85ff9bf0c3659fda62a4145829c5a266 100644 (file)
@@ -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"
diff --git a/tests/expected/schedutils/cpuset b/tests/expected/schedutils/cpuset
new file mode 100644 (file)
index 0000000..10e1760
--- /dev/null
@@ -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]
diff --git a/tests/ts/schedutils/cpuset b/tests/ts/schedutils/cpuset
new file mode 100755 (executable)
index 0000000..6ad240d
--- /dev/null
@@ -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