From: Adam Litke <a...@us.ibm.com> Now that libhugetlbfs can work with multiple huge page sizes, testing this support has become a priority. The following patch enables automatic testing of page sizes that are mounted and have at least one page allocated. Care is taken to assure that only valid combinations are tested. For example, 32bit tests are not run with 16GB pages. Following the run, a summary of all page sizes tested is printed. The following is some example output of the new script:
********** TEST SUMMARY * 64K 16M 16G * 32-bit 64-bit 32-bit 64-bit 32-bit 64-bit * Total testcases: 86 89 86 89 0 89 * Skipped: 20 0 20 0 0 0 * PASS: 59 75 62 85 0 49 * FAIL: 5 6 1 1 0 29 * Killed by signal: 0 0 0 0 0 0 * Bad configuration: 2 2 3 3 0 10 * Expected FAIL: 0 0 0 0 0 0 * Unexpected PASS: 0 0 0 0 0 0 * Strange test result: 0 6 0 0 0 1 ********** Script programming language conversion alert: This patch rewrites run_tests.sh in python. I already anticipate the "why change languages" comments so I come prepared with justification for the conversion. Our test harness has extended beyond simply executing a list of test cases and dumping the output to stdout. The data set for the test summary is now three-dimensional. It is indexed by result type (total tests, total passed, etc), word size, and now page size. The simple arrays in bash are not up to the task. As the number of tests that are run increases, so does the challenge of presenting the results in a meaningful, easy to digest format. Shell scripts lack the output formatting constructs that are present in languages such as Python and that make flexible output formatting possible. For these reasons (and the guarantee that the test harness will need to get even more sophisticated in the future), I made the inevitable decision to cut over to Python now. Signed-off-by: Eric B Munson <ebmun...@us.ibm.com> --- Makefile | 12 +- tests/run_tests.py | 612 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/run_tests.sh | 438 ------------------------------------- 3 files changed, 618 insertions(+), 444 deletions(-) create mode 100755 tests/run_tests.py delete mode 100755 tests/run_tests.sh diff --git a/Makefile b/Makefile index 40c8c45..4909872 100644 --- a/Makefile +++ b/Makefile @@ -191,22 +191,22 @@ tests/%: tools: $(foreach file,$(INSTALL_BIN),$(BIN_OBJ_DIR)/$(file)) check: all - cd tests; ./run_tests.sh + cd tests; ./run_tests.py checkv: all - cd tests; ./run_tests.sh -vV + cd tests; ./run_tests.py -vV func: all - cd tests; ./run_tests.sh -t func + cd tests; ./run_tests.py -t func funcv: all - cd tests; ./run_tests.sh -t func -vV + cd tests; ./run_tests.py -t func -vV stress: all - cd tests; ./run_tests.sh -t stress + cd tests; ./run_tests.py -t stress stressv: all - cd tests; ./run_tests.sh -t stress -vV + cd tests; ./run_tests.py -t stress -vV # Don't want to remake objects just 'cos the directory timestamp changes $(OBJDIRS): %: diff --git a/tests/run_tests.py b/tests/run_tests.py new file mode 100755 index 0000000..d41a5f9 --- /dev/null +++ b/tests/run_tests.py @@ -0,0 +1,612 @@ +#! /usr/bin/env python + +import subprocess +import os +import sys +import getopt + +# The superset of wordsizes that should be tested (default 32, 64) +wordsizes = set() + +# The super set of page sizes that should be tested. Defaults to all supported +# huge page sizes with an active mount and at least one huge page allocated +pagesizes = set() + +# Each page size may have a subset of valid wordsizes +# This is a dictionary (indexed by page size) of sets +wordsizes_by_pagesize = {} + +# The linkhuge tests may only be valid on a subset of word sizes +# This set contains the wordsizes valid for linkhuge tests +linkhuge_wordsizes = set() + +# A list of all discovered mountpoints that may be used by libhugetlbfs for +# this run of tests. This is used for cleaning up left-over share files. +mounts = [] + +# Results matrix: This 3-D dictionary is indexed as follows: +# [type] - Test results fall into one of the 'result_types' categories +# [pagesize] - a page size from the set 'pagesizes' +# [bits] - a word size from the set 'wordsizes' +# The indexed value is the number of tests matching the above traits +R = {} +result_types = ("total", "pass", "config", "fail", "xfail", "xpass", + "signal", "strange", "skip") + +def bash(cmd, extra_env={}): + """ + Run 'cmd' in the shell and return the exit code and output. + """ + local_env = os.environ.copy() + for key,value in extra_env.items(): + local_env[key] = value + p = subprocess.Popen(cmd, shell=True, env=local_env, \ + stdout=subprocess.PIPE) + try: + rc = p.wait() + except KeyboardInterrupt: + # Abort and mark this a strange test result + return (127, "") + out = p.stdout.read().strip() + return (rc, out) + +def setup_env(override, defaults): + """ + Set up the environment for running commands in the shell. + """ + # All items in override are unconditionally set or unset + for (var, val) in override.items(): + if val == None: + if var in os.environ: + del os.environ[var] + else: + os.environ[var] = val + # If not already set, these variables are given default values + for (var, val) in defaults.items(): + if var not in os.environ or os.environ[var] == "": + os.environ[var] = val + +def init_results(): + """ + Define the structure of the results matrix and initialize all results to 0. + """ + global R + + for t in result_types: + R[t] = {} + for p in pagesizes: + R[t][p] = {} + for bits in (32, 64): + R[t][p][bits] = 0 + +def pretty_page_size(size): + """ + Convert a page size to a formatted string + + Given a page size in bytes, return a string that expresses the size in + a sensible unit (K, M, or G). + """ + factor = 0 + while size > 1024: + factor += 1 + size /= 1024 + + if factor == 0: return "%iB" % size + elif factor == 1: return "%iK" % size + elif factor == 2: return "%iM" % size + elif factor == 3: return "%iG" % size + +def print_per_size(title, values): + """ + Print one line of test results + + Print the results of a given result type on one line. The results for all + page sizes and word sizes are written in a table format. + """ + print "*%20s: " % title, + for sz in pagesizes: + print "%4s %4s " % (values[sz][32], values[sz][64]), + print + +def results_summary(): + """ + Display a summary of the test results + """ + print "********** TEST SUMMARY" + print "*%21s" % "", + for p in pagesizes: print "%-13s " % pretty_page_size(p), + print + print "*%21s" % "", + for p in pagesizes: print "32-bit 64-bit ", + print + + print_per_size("Total testcases", R["total"]) + print_per_size("Skipped", R["skip"]) + print_per_size("PASS", R["pass"]) + print_per_size("FAIL", R["fail"]) + print_per_size("Killed by signal", R["signal"]) + print_per_size("Bad configuration", R["config"]) + print_per_size("Expected FAIL", R["xfail"]) + print_per_size("Unexpected PASS", R["xpass"]) + print_per_size("Strange test result", R["strange"]) + print "**********" + +def free_hpages(): + """ + Return the number of free huge pages. + + Parse /proc/meminfo to obtain the number of free huge pages for + the default page size. + XXX: This function is not multi-size aware yet. + """ + (rc, out) = bash("grep 'HugePages_Free:' /proc/meminfo | cut -f2 -d:") + return (rc, int(out)) + +def total_hpages(): + """ + Return the total number of huge pages in the pool. + + Parse /proc/meminfo to obtain the number of huge pages for the default + page size. + XXX: This function is not multi-size aware yet. + """ + (rc, out) = bash("grep 'HugePages_Total:' /proc/meminfo | cut -f2 -d:") + return (rc, int(out)) + +def hpage_size(): + """ + Return the size of the default huge page size in bytes. + + Parse /proc/meminfo to obtain the default huge page size. This number is + reported in Kb so multiply it by 1024 to convert it to bytes. + XXX: This function is not multi-size aware yet. + """ + (rc, out) = bash("grep 'Hugepagesize:' /proc/meminfo | awk '{print $2}'") + if out == "": out = 0 + out = int(out) * 1024 + return (rc, out) + +def clear_hpages(): + """ + Remove stale hugetlbfs files after sharing tests. + + Traverse the mount points that are in use during testing to find left-over + files that were created by the elflink sharing tests. These are not + cleaned up automatically and must be removed to free up the huge pages. + """ + for mount in mounts: + dir = mount + "/elflink-uid-" + `os.getuid()` + for root, dirs, files in os.walk(dir, topdown=False): + for name in files: + os.remove(os.path.join(root, name)) + for name in dirs: + os.rmdir(os.path.join(root, name)) + try: + os.rmdir(dir) + except OSError: + pass + +def cmd_env(bits, pagesize=""): + """ + Construct test-specific environment settings. + + Set PATH and LD_LIBRARY_PATH so that the executable and libraries for a + libhugetlbfs test or utility that is run from within the source tree can + be found. Additionally, tell libhugetlbfs to use the requested page size. + """ + str = "PATH=$PATH:./obj%s:../obj%s " \ + "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../obj%s:obj%s " % \ + (`bits`, `bits`, `bits`, `bits`) + if len(`pagesize`) > 0: str += "HUGETLB_DEFAULT_PAGE_SIZE=%s " % pagesize + return str + +def get_pagesizes(): + """ + Get a list of configured huge page sizes. + + Use libhugetlbfs' hugeadm utility to get a list of page sizes that have + active mount points and at least one huge page allocated to the pool. + """ + sizes = set() + (rc, out) = bash(cmd_env('') + "hugeadm --page-sizes") + if rc != 0: return sizes + + for size in out.split("\n"): sizes.add(int(size)) + return sizes + +def check_hugetlbfs_path(): + """ + Check each combination of page size and word size for validity. + + Some word sizes may not be valid for all page sizes. For example, a 16G + page is too large to be used in a 32 bit process. Use a helper program to + weed out invalid combinations and print informational messages as required. + """ + global wordsizes, pagesizes, mounts, wordsizes_by_pagesize + + for p in pagesizes: + okbits = [] + for b in wordsizes: + cmd = cmd_env(b, p) + "get_hugetlbfs_path" + (rc, out) = bash(cmd) + if rc == 0: + okbits.append(b) + mounts.append(out) + if len(okbits) == 0: + print "run_tests.py: No mountpoints available for page size %s" % \ + pretty_page_size(p) + wordsizes_by_pagesize[p] = set() + continue + for b in wordsizes - set(okbits): + print "run_tests.py: The %i bit word size is not compatible with " \ + "%s pages" % (b, pretty_page_size(p)) + wordsizes_by_pagesize[p] = set(okbits) + +def check_linkhuge_tests(): + """ + Check if the linkhuge tests are safe to run on this system. + + Newer versions of binutils (>= 2.18) are known to be incompatible with the + linkhuge tests and running them may cause unreliable behavior. Determine + which word sizes can be tested with linkhuge. The others will be skipped. + NOTE: The linhuge_rw tests are always safe to run and will not be skipped. + """ + okbits = [] + + for bits in wordsizes: + cmd = "gcc -m%i -Wl,--verbose 2> /dev/null | grep -q SPECIAL" % bits + (rc, out) = bash(cmd) + if rc != 0: okbits.append(bits) + return set(okbits) + +def run_test(pagesize, bits, cmd, pre, desc): + """ + Execute a test, print the output and log the result + + Run a test using the specified page size and word size. The parameter + 'pre' may contain additional environment settings and will be prepended to + cmd. A line showing info about the test is printed and after completion + the test output is printed. The result is recorded in the result matrix. + """ + global R + + objdir = "obj%i" % bits + if not os.path.isdir(objdir): + return + + cmd_str = "%s %s %s" % (cmd_env(bits, pagesize), pre, cmd) + if desc != "": print desc, + if pre != "": print pre, + print "%s (%s: %i):\t" % (cmd, pretty_page_size(pagesize), bits), + sys.stdout.flush() + + (rc, out) = bash(cmd_str) + print out + + R["total"][pagesize][bits] += 1 + if rc == 0: R["pass"][pagesize][bits] += 1 + elif rc == 1: R["config"][pagesize][bits] += 1 + elif rc == 2: R["fail"][pagesize][bits] += 1 + elif rc == 3: R["xfail"][pagesize][bits] += 1 + elif rc == 4: R["xpass"][pagesize][bits] += 1 + elif rc > 127: R["signal"][pagesize][bits] += 1 + else: R["strange"][pagesize][bits] += 1 + +def skip_test(pagesize, bits, cmd, pre, desc): + """ + Skip a test, print test information, and log that it was skipped. + """ + global tot_tests, tot_skip + R["total"][pagesize][bits] += 1 + R["skip"][pagesize][bits] += 1 + if desc != "": print desc, + if pre != "": print pre, + print "%s (%s: %i):\tSKIPPED" % (cmd, pretty_page_size(pagesize), bits) + +def do_test(cmd, pre="", bits=None, desc=""): + """ + Run a test case, testing each page size and each indicated word size. + """ + if bits == None: bits = wordsizes + for p in pagesizes: + for b in (set(bits) & wordsizes_by_pagesize[p]): + run_test(p, b, cmd, pre, desc) + +def do_elflink_test(cmd, pre="", desc=""): + """ + Run an elflink test case, skipping known-bad configurations. + """ + for p in pagesizes: + for b in wordsizes_by_pagesize[p]: + if b in linkhuge_wordsizes: run_test(p, b, cmd, pre, desc) + else: skip_test(p, b, cmd, pre, desc) + +def combine(a, b): + """ + Concatenate strings a and b with a space between only if needed. + """ + if len(b) != 0: + return a + " " + b + else: + return a + +def elflink_test(cmd, pre=""): + """ + Run an elflink test case with different configuration combinations. + + Test various combinations of: preloading libhugetlbfs, B vs. BDT link + modes, minimal copying on or off, and disabling segment remapping. + """ + do_test(cmd, pre) + # Test we don't blow up if not linked for hugepage + do_test(cmd, combine("LD_PRELOAD=libhugetlbfs.so", pre)) + do_elflink_test("xB." + cmd) + do_elflink_test("xBDT." + cmd) + # Test we don't blow up if HUGETLB_MINIMAL_COPY is diabled + do_elflink_test("xB." + cmd, combine("HUGETLB_MINIMAL_COPY=no", pre)) + do_elflink_test("xBDT." + cmd, combine("HUGETLB_MINIMAL_COPY=no", pre)) + # Test that HUGETLB_ELFMAP=no inhibits remapping as intended + do_elflink_test("xB." + cmd, combine("HUGETLB_ELFMAP=no", pre)) + do_elflink_test("xBDT." + cmd, combine("HUGETLB_ELFMAP=no", pre)) + +def elflink_rw_test(cmd, pre=""): + """ + Run the elflink_rw test with different configuration combinations. + + Test various combinations of: remapping modes and minimal copy on or off. + """ + # Basic tests: None, Read-only, Write-only, Read-Write, exlicit disable + do_test(cmd, pre) + do_test(cmd, combine("HUGETLB_ELFMAP=R", pre)) + do_test(cmd, combine("HUGETLB_ELFMAP=W", pre)) + do_test(cmd, combine("HUGETLB_ELFMAP=RW", pre)) + do_test(cmd, combine("HUGETLB_ELFMAP=no", pre)) + + # Test we don't blow up if HUGETLB_MINIMAL_COPY is disabled + do_test(cmd, combine("HUGETLB_MINIMAL_COPY=no HUGETLB_ELFMAP=R", pre)) + do_test(cmd, combine("HUGETLB_MINIMAL_COPY=no HUGETLB_ELFMAP=W", pre)) + do_test(cmd, combine("HUGETLB_MINIMAL_COPY=no HUGETLB_ELFMAP=RW", pre)) + +def elfshare_test(cmd, pre=""): + """ + Test segment sharing with multiple configuration variations. + """ + # Run each elfshare test invocation independently - clean up the + # sharefiles before and after in the first set of runs, but leave + # them there in the second: + clear_hpages() + do_elflink_test("xB." + cmd, combine("HUGETLB_SHARE=1", pre)) + clear_hpages() + do_elflink_test("xBDT." + cmd, combine("HUGETLB_SHARE=1", pre)) + clear_hpages() + do_elflink_test("xB." + cmd, combine("HUGETLB_SHARE=1", pre)) + do_elflink_test("xBDT." + cmd, combine("HUGETLB_SHARE=1", pre)) + clear_hpages() + +def elflink_and_share_test(cmd, pre=""): + """ + Run the ordinary linkhuge tests with sharing enabled + """ + # Run each elflink test pair independently - clean up the sharefiles + # before and after each pair + clear_hpages() + for link_str in ("xB.", "xBDT."): + for i in range(2): + do_elflink_test(link_str + cmd, combine("HUGETLB_SHARE=1", pre)) + clear_hpages() + +def elflink_rw_and_share_test(cmd, pre=""): + """ + Run the ordinary linkhuge_rw tests with sharing enabled + """ + clear_hpages() + for mode in ("R", "W", "RW"): + for i in range(2): + do_test(cmd, combine("HUGETLB_ELFMAP=" + mode + " " + \ + "HUGETLB_SHARE=1", pre)) + clear_hpages() + +def setup_shm_sysctl(limit): + """ + Adjust the kernel shared memory limits to accomodate a desired size. + + The original values are returned in a dictionary that can be passed to + restore_shm_sysctl() to restore the system state. + """ + if os.getuid() != 0: return {} + sysctls = {} + files = [ "/proc/sys/kernel/shmmax", "/proc/sys/kernel/shmall"] + for f in files: + fh = open(f, "r") + sysctls[f] = fh.read() + fh.close() + fh = open(f, "w") + fh.write(`limit`) + fh.close() + print "set shmmax limit to %s" % limit + return sysctls + +def restore_shm_sysctl(sysctls): + """ + Restore the sysctls named in 'sysctls' to the given values. + """ + if os.getuid() != 0: return + for (file, val) in sysctls.items(): + fh = open(file, "w") + fh.write(val) + fh.close() + +def functional_tests(): + """ + Run the set of functional tests. + """ + global linkhuge_wordsizes + + # Kernel background tests not requiring hugepage support + do_test("zero_filesize_segment") + + # Library background tests not requiring hugepage support + do_test("test_root") + do_test("meminfo_nohuge") + + # Library tests requiring kernel hugepage support + do_test("gethugepagesize") + do_test("gethugepagesizes") + do_test("empty_mounts", "HUGETLB_VERBOSE=1") + do_test("large_mounts", "HUGETLB_VERBOSE=1") + + # Tests requiring an active and usable hugepage mount + do_test("find_path") + do_test("unlinked_fd") + do_test("readback") + do_test("truncate") + do_test("shared") + do_test("mprotect") + do_test("mlock") + do_test("misalign") + + # Specific kernel bug tests + do_test("ptrace-write-hugepage") + do_test("icache-hygiene") + do_test("slbpacaflush") + do_test("straddle_4GB", bits=(64,)) + do_test("huge_at_4GB_normal_below", bits=(64,)) + do_test("huge_below_4GB_normal_above", bits=(64,)) + do_test("map_high_truncate_2") + do_test("misaligned_offset") + do_test("truncate_above_4GB") + do_test("brk_near_huge") + do_test("task-size-overrun") + do_test("stack_grow_into_huge") + + # Tests requiring an active mount and hugepage COW + do_test("private") + do_test("fork-cow") + do_test("direct") + do_test("malloc") + do_test("malloc", "LD_PRELOAD=libhugetlbfs.so HUGETLB_MORECORE=yes") + do_test("malloc_manysmall") + do_test("malloc_manysmall", \ + "LD_PRELOAD=libhugetlbfs.so HUGETLB_MORECORE=yes") + do_test("heapshrink") + do_test("heapshrink", "LD_PRELOAD=libheapshrink.so") + do_test("heapshrink", "LD_PRELOAD=libhugetlbfs.so HUGETLB_MORECORE=yes") + do_test("heapshrink", "LD_PRELOAD=\"libhugetlbfs.so libheapshrink.so\" " + \ + "HUGETLB_MORECORE=yes") + do_test("heapshrink", "LD_PRELOAD=libheapshrink.so HUGETLB_MORECORE=yes " +\ + "HUGETLB_MORECORE_SHRINK=yes") + do_test("heapshrink", "LD_PRELOAD=\"libhugetlbfs.so libheapshrink.so\" " + \ + "HUGETLB_MORECORE=yes HUGETLB_MORECORE_SHRINK=yes") + do_test("heap-overflow", "HUGETLB_VERBOSE=1 HUGETLB_MORECORE=yes") + + # Run the remapping tests' up-front checks + linkhuge_wordsizes = check_linkhuge_tests() + # Original elflink tests + elflink_test("linkhuge_nofd", "HUGETLB_VERBOSE=0") + elflink_test("linkhuge") + + # Original elflink sharing tests + elfshare_test("linkshare") + elflink_and_share_test("linkhuge") + + # elflink_rw tests + elflink_rw_test("linkhuge_rw") + # elflink_rw sharing tests + elflink_rw_and_share_test("linkhuge_rw") + + # Accounting bug tests + # reset free hpages because sharing will have held some + # alternatively, use + do_test("chunk-overcommit") + do_test("alloc-instantiate-race shared") + do_test("alloc-instantiate-race private") + do_test("truncate_reserve_wraparound") + do_test("truncate_sigbus_versus_oom") + + # Test direct allocation API + do_test("get_huge_pages") + + # Test overriding of shmget() + do_test("shmoverride_linked") + do_test("shmoverride_unlinked", "LD_PRELOAD=libhugetlbfs.so") + + # Test hugetlbfs filesystem quota accounting + do_test("quota.sh") + + # Test accounting of HugePages_{Total|Free|Resv|Surp} + # Alters the size of the hugepage pool so should probably be run last + do_test("counters") + +def stress_tests(): + """ + Run the set of stress tests. + """ + iterations = 10 # Number of iterations for looping tests + + # Don't update NRPAGES every time like above because we want to catch the + # failures that happen when the kernel doesn't release all of the huge pages + # after a stress test terminates + (rc, nr_pages) = free_hpages() + + do_test("mmap-gettest %i %i" % (iterations, nr_pages)) + + # mmap-cow needs a hugepages for each thread plus one extra + do_test("mmap-cow %i %i" % (nr_pages - 1, nr_pages)) + + (rc, tot_pages) = total_hpages() + (rc, size) = hpage_size() + sysctls = setup_shm_sysctl(tot_pages * size) + threads = 10 # Number of threads for shm-fork + # Run shm-fork once using half available hugepages, then once using all + # This is to catch off-by-ones or races in the kernel allocated that + # can make allocating all hugepages a problem + if nr_pages > 1: + do_test("shm-fork %i %i" % (threads, nr_pages / 2)) + do_test("shm-fork %i %i" % (threads, nr_pages)) + + do_test("shm-getraw %i %s" % (nr_pages, "/dev/full")) + restore_shm_sysctl(sysctls) + + + +def main(): + global wordsizes, pagesizes + testsets = set() + env_override = {"QUIET_TEST": "1", "HUGETLBFS_MOUNTS": "", + "HUGETLB_ELFMAP": None, "HUGETLB_MORECORE": None} + env_defaults = {"HUGETLB_VERBOSE": "0"} + + try: + opts, args = getopt.getopt(sys.argv[1:], "vVdt:b:p:") + except getopt.GetoptError, err: + print str(err) + sys.exit(1) + for opt, arg in opts: + if opt == "-v": + env_override["QUIET_TEST"] = None + env_defaults["HUGETLB_VERBOSE"] = "2" + elif opt == "-V": + env_defaults["HUGETLB_VERBOSE"] = "99" + elif opt == "-t": + for t in arg.split(): testsets.add(t) + elif opt == "-b": + for b in arg.split(): wordsizes.add(int(b)) + elif opt == "-p": + for p in arg.split(): pagesizes.add(int(p)) + else: + assert False, "unhandled option" + if len(testsets) == 0: testsets = set(["func", "stress"]) + if len(wordsizes) == 0: wordsizes = set([32, 64]) + if len(pagesizes) == 0: pagesizes = get_pagesizes() + + setup_env(env_override, env_defaults) + init_results() + check_hugetlbfs_path() + + if "func" in testsets: functional_tests() + if "stress" in testsets: stress_tests() + + results_summary() + +if __name__ == "__main__": + main() diff --git a/tests/run_tests.sh b/tests/run_tests.sh deleted file mode 100755 index 84b5b5d..0000000 --- a/tests/run_tests.sh +++ /dev/null @@ -1,438 +0,0 @@ -#! /bin/bash - -export QUIET_TEST=1 -unset HUGETLB_ELF -unset HUGETLB_MORECORE -HUGETLBFS_MOUNTS="" - -if [ -z "$HUGETLB_VERBOSE" ]; then - HUGETLB_VERBOSE=0 -fi -export HUGETLB_VERBOSE - -ENV=/usr/bin/env - -for BITS in 32 64; do - tot_tests[$BITS]=0 - tot_pass[$BITS]=0 - tot_fail[$BITS]=0 - tot_config[$BITS]=0 - tot_signal[$BITS]=0 - tot_strange[$BITS]=0 - tot_xpass[$BITS]=0 - tot_xfail[$BITS]=0 - tot_skip[$BITS]=0 -done - -function free_hpages() { - H=$(grep 'HugePages_Free:' /proc/meminfo | cut -f2 -d:) - [ -z "$H" ] && H=0 - echo "$H" -} - -# Check for valid hugetlbfs mountpoints -# On error, adjust tests to be run or exit immediately. We must check for -# mounts using both the 32 bit and 64 bit helpers because it is possible that -# a mount point will only be usable with a certain word size. For example, a -# mount with a 16GB configured page size is usable by 64 bit programs only. -function check_hugetlbfs_path() { - newbits="" - skipbits="" - - for b in $WORDSIZES; do - MP=$(PATH="obj$b:$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH:../obj$b" \ - get_hugetlbfs_path) - if [ $? -ne 0 ]; then - skipbits="$skipbits $b" - else - HUGETLBFS_MOUNTS="$HUGETLBFS_MOUNTS $MP" - newbits="$newbits $b" - fi - done - - if [ -z "$newbits" ]; then - echo "run_tests.sh: unable to find hugetlbfs mountpoint" - exit 1 - fi - for b in $skipbits; do - echo -n "run_tests.sh: No suitable mountpoint exists for $b bit " - echo "programs. Disabling the $b word size." - done - WORDSIZES="$newbits" -} - -function clear_hpages() { - # It is not straightforward to know which mountpoint was used so clean - # up share files in all possible mount points - for dir in $HUGETLBFS_MOUNTS; do - rm -rf "$dir"/elflink-uid-`id -u` - done -} - -TOTAL_HPAGES=$(grep 'HugePages_Total:' /proc/meminfo | cut -f2 -d:) -[ -z "$TOTAL_HPAGES" ] && TOTAL_HPAGES=0 -HPAGE_SIZE=$(grep 'Hugepagesize:' /proc/meminfo | awk '{print $2}') -[ -z "$HPAGE_SIZE" ] && HPAGE_SIZE=0 -HPAGE_SIZE=$(( $HPAGE_SIZE * 1024 )) - -# Up-front checks for the remapping test cases: -function check_linkhuge_tests() { - # In some circumstances, our linker scripts are known to be broken and - # they will produce binaries with undefined runtime behavior. In those - # cases don't bother running the xNNN.linkhuge tests. This checks if the - # system linker scripts use the SPECIAL keyword (for placing the got and - # plt). Our linker scripts do not use SPECIAL and are thus broken when the - # system scripts use it. - - # LINKHUGE_WORDSIZES is a copy of WORDSIZES with the exception that any - # word sizes for which the linkhuge tests should be skipped are prefixed - # with 'no' (ie. LINKHUGE_WORDSIZES="32 no64" - LINKHUGE_WORDSIZES="" - for bits in $WORDSIZES; do - gcc -m$bits -Wl,--verbose 2> /dev/null | grep -q SPECIAL - if [ $? -eq 0 ]; then - bits="no$bits" - fi - LINKHUGE_WORDSIZES="$LINKHUGE_WORDSIZES $bits" - done -} - -run_test_bits () { - BITS=$1 - shift - - if [ -d obj$BITS ]; then - tot_tests[$BITS]=$[tot_tests[$BITS] + 1] - echo -n "$@ ($BITS): " - if PATH="obj$BITS:$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH:../obj$BITS:obj$BITS" $ENV "$@"; then - tot_pass[$BITS]=$[tot_pass[$BITS] + 1] - else - rc="$?" - if [ "$rc" == "1" ]; then - tot_config[$BITS]=$[tot_config[$BITS] + 1] - elif [ "$rc" == "2" ]; then - tot_fail[$BITS]=$[tot_fail[$BITS] + 1] - elif [ "$rc" == "3" ]; then - tot_xfail[$BITS]=$[tot_xfail[$BITS] + 1] - elif [ "$rc" == "4" ]; then - tot_xpass[$BITS]=$[tot_xpass[$BITS] + 1] - elif [ "$rc" -gt 127 ]; then - tot_signal[$BITS]=$[tot_signal[$BITS] + 1] - else - tot_strange[$BITS]=$[tot_strange[$BITS] + 1] - fi - fi - fi -} - -run_test () { - for bits in $WORDSIZES; do - run_test_bits $bits "$@" - done -} - -skip_test_bits () { - bits=$1 - shift - - echo "$@ ($bits): SKIPPED" - tot_tests[$bits]=$[tot_tests[$bits] + 1] - tot_skip[$bits]=$[tot_skip[$bits] + 1] -} - -# To manually disable a test (e.g., one that panics an older kernel), -# replace "run_test <options>" with "skip_test <options>". -skip_test () { - for bits in $WORDSIZES; do - skip_test_bits $bits "$@" - done -} - -maybe_run_linkhuge_test () { - for bits in $LINKHUGE_WORDSIZES; do - case "$bits" in - no*) skip_test_bits ${bits#no} "$@" ;; - *) run_test_bits $bits "$@" ;; - esac - done -} - -preload_test () { - run_test LD_PRELOAD=libhugetlbfs.so "$@" -} - -elflink_test () { - args=("$@") - N="$[$#-1]" - baseprog="${args[$N]}" - unset args[$N] - set -- "${ar...@]}" - run_test "$@" "$baseprog" - # Test we don't blow up if not linked for hugepage - preload_test "$@" "$baseprog" - maybe_run_linkhuge_test "$@" "xB.$baseprog" - maybe_run_linkhuge_test "$@" "xBDT.$baseprog" - # Test we don't blow up if HUGETLB_MINIMAL_COPY is diabled - maybe_run_linkhuge_test HUGETLB_MINIMAL_COPY=no "$@" "xB.$baseprog" - maybe_run_linkhuge_test HUGETLB_MINIMAL_COPY=no "$@" "xBDT.$baseprog" - # Test that HUGETLB_ELFMAP=no inhibits remapping as intended - maybe_run_linkhuge_test HUGETLB_ELFMAP=no "$@" "xB.$baseprog" - maybe_run_linkhuge_test HUGETLB_ELFMAP=no "$@" "xBDT.$baseprog" -} - -elflink_rw_test() { - # Basic tests: None, Read-only, Write-only, Read-Write, exlicit disable - run_test linkhuge_rw - run_test HUGETLB_ELFMAP=R linkhuge_rw - run_test HUGETLB_ELFMAP=W linkhuge_rw - run_test HUGETLB_ELFMAP=RW linkhuge_rw - run_test HUGETLB_ELFMAP=no linkhuge_rw - - # Test we don't blow up if HUGETLB_MINIMAL_COPY is disabled - run_test HUGETLB_MINIMAL_COPY=no HUGETLB_ELFMAP=R linkhuge_rw - run_test HUGETLB_MINIMAL_COPY=no HUGETLB_ELFMAP=W linkhuge_rw - run_test HUGETLB_MINIMAL_COPY=no HUGETLB_ELFMAP=RW linkhuge_rw -} - -elfshare_test () { - args=("$@") - N="$[$#-1]" - baseprog="${args[$N]}" - unset args[$N] - set -- "${ar...@]}" - # Run each elfshare test invocation independently - clean up the - # sharefiles before and after in the first set of runs, but leave - # them there in the second: - clear_hpages - maybe_run_linkhuge_test HUGETLB_SHARE=1 "$@" "xB.$baseprog" - clear_hpages - maybe_run_linkhuge_test HUGETLB_SHARE=1 "$@" "xBDT.$baseprog" - clear_hpages - maybe_run_linkhuge_test HUGETLB_SHARE=1 "$@" "xB.$baseprog" - maybe_run_linkhuge_test HUGETLB_SHARE=1 "$@" "xBDT.$baseprog" - clear_hpages -} - -elflink_and_share_test () { - args=("$@") - N="$[$#-1]" - baseprog="${args[$N]}" - unset args[$N] - set -- "${ar...@]}" - # Run each elflink test pair independently - clean up the sharefiles - # before and after each pair - clear_hpages - maybe_run_linkhuge_test HUGETLB_SHARE=1 "$@" "xB.$baseprog" - maybe_run_linkhuge_test HUGETLB_SHARE=1 "$@" "xB.$baseprog" - clear_hpages - maybe_run_linkhuge_test HUGETLB_SHARE=1 "$@" "xBDT.$baseprog" - maybe_run_linkhuge_test HUGETLB_SHARE=1 "$@" "xBDT.$baseprog" - clear_hpages -} - -elflink_rw_and_share_test () { - clear_hpages - run_test HUGETLB_ELFMAP=R HUGETLB_SHARE=1 linkhuge_rw - run_test HUGETLB_ELFMAP=R HUGETLB_SHARE=1 linkhuge_rw - clear_hpages - run_test HUGETLB_ELFMAP=W HUGETLB_SHARE=1 linkhuge_rw - run_test HUGETLB_ELFMAP=W HUGETLB_SHARE=1 linkhuge_rw - clear_hpages - run_test HUGETLB_ELFMAP=RW HUGETLB_SHARE=1 linkhuge_rw - run_test HUGETLB_ELFMAP=RW HUGETLB_SHARE=1 linkhuge_rw - clear_hpages -} - -setup_shm_sysctl() { - if [ $UID == 0 ]; then - SHMMAX=`cat /proc/sys/kernel/shmmax` - SHMALL=`cat /proc/sys/kernel/shmall` - LIMIT=$(( $HPAGE_SIZE * $TOTAL_HPAGES )) - echo "$LIMIT" > /proc/sys/kernel/shmmax - echo "set shmmax limit to $LIMIT" - echo "$LIMIT" > /proc/sys/kernel/shmall - fi -} - -restore_shm_sysctl() { - if [ $UID == 0 ]; then - echo "$SHMMAX" > /proc/sys/kernel/shmmax - echo "$SHMALL" > /proc/sys/kernel/shmall - fi -} - -functional_tests () { -# Kernel background tests not requiring hugepage support - run_test zero_filesize_segment - -# Library background tests not requiring hugepage support - run_test test_root - run_test meminfo_nohuge - -# Library tests requiring kernel hugepage support - run_test gethugepagesize - run_test gethugepagesizes - run_test HUGETLB_VERBOSE=1 empty_mounts - run_test HUGETLB_VERBOSE=1 large_mounts - -# Tests requiring an active and usable hugepage mount - run_test find_path - run_test unlinked_fd - run_test readback - run_test truncate - run_test shared - run_test mprotect - run_test mlock - run_test misalign - -# Specific kernel bug tests - run_test ptrace-write-hugepage - run_test icache-hygiene - run_test slbpacaflush - run_test_bits 64 straddle_4GB - run_test_bits 64 huge_at_4GB_normal_below - run_test_bits 64 huge_below_4GB_normal_above - run_test map_high_truncate_2 - run_test misaligned_offset - run_test truncate_above_4GB - run_test brk_near_huge - run_test task-size-overrun - run_test stack_grow_into_huge - -# Tests requiring an active mount and hugepage COW - run_test private - run_test fork-cow - run_test direct - run_test malloc - preload_test HUGETLB_MORECORE=yes malloc - run_test malloc_manysmall - preload_test HUGETLB_MORECORE=yes malloc_manysmall - run_test heapshrink - run_test LD_PRELOAD=libheapshrink.so heapshrink - preload_test HUGETLB_MORECORE=yes heapshrink - run_test LD_PRELOAD="libhugetlbfs.so libheapshrink.so" HUGETLB_MORECORE=yes heapshrink - preload_test HUGETLB_MORECORE=yes HUGETLB_MORECORE_SHRINK=yes heapshrink - run_test LD_PRELOAD="libhugetlbfs.so libheapshrink.so" HUGETLB_MORECORE=yes HUGETLB_MORECORE_SHRINK=yes heapshrink - run_test HUGETLB_VERBOSE=1 HUGETLB_MORECORE=yes heap-overflow # warnings expected - -# Run the remapping tests' up-front checks -check_linkhuge_tests -# Original elflink tests - elflink_test HUGETLB_VERBOSE=0 linkhuge_nofd # Lib error msgs expected - elflink_test linkhuge -# Original elflink sharing tests - elfshare_test linkshare - elflink_and_share_test linkhuge - -# elflink_rw tests - elflink_rw_test -# elflink_rw sharing tests - elflink_rw_and_share_test - -# Accounting bug tests -# reset free hpages because sharing will have held some -# alternatively, use - run_test chunk-overcommit - run_test alloc-instantiate-race shared - run_test alloc-instantiate-race private - run_test truncate_reserve_wraparound - run_test truncate_sigbus_versus_oom - -# Test direct allocation API - run_test get_huge_pages - -# Test hugepage-backed region API - run_test get_hugepage_region - -# Test overriding of shmget() - run_test HUGETLB_SHM=no shmoverride_linked - run_test HUGETLB_SHM=yes shmoverride_linked - run_test HUGETLB_SHM=no LD_PRELOAD=libhugetlbfs.so shmoverride_unlinked - run_test HUGETLB_SHM=yes LD_PRELOAD=libhugetlbfs.so shmoverride_unlinked - -# Test hugetlbfs filesystem quota accounting - run_test quota.sh - -# Test accounting of HugePages_{Total|Free|Resv|Surp} -# Alters the size of the hugepage pool so should probably be run last - run_test counters -} - -stress_tests () { - ITERATIONS=10 # Number of iterations for looping tests - - # Don't update NRPAGES every time like above because we want to catch the - # failures that happen when the kernel doesn't release all of the huge pages - # after a stress test terminates - NRPAGES=`free_hpages` - - run_test mmap-gettest ${ITERATIONS} ${NRPAGES} - - # mmap-cow needs a hugepages for each thread plus one extra - run_test mmap-cow $[NRPAGES-1] ${NRPAGES} - - setup_shm_sysctl - THREADS=10 # Number of threads for shm-fork - # Run shm-fork once using half available hugepages, then once using all - # This is to catch off-by-ones or races in the kernel allocated that - # can make allocating all hugepages a problem - if [ ${NRPAGES} -gt 1 ]; then - run_test shm-fork ${THREADS} $[NRPAGES/2] - fi - run_test shm-fork ${THREADS} $[NRPAGES] - - run_test shm-getraw ${NRPAGES} /dev/full - restore_shm_sysctl -} - -while getopts "vVdt:b:" ARG ; do - case $ARG in - "v") - unset QUIET_TEST - export HUGETLB_VERBOSE=2 - ;; - "V") - export HUGETLB_VERBOSE=99 - ;; - "t") - TESTSETS=$OPTARG - ;; - "b") - WORDSIZES=$OPTARG - ;; - esac -done - -if [ -z "$TESTSETS" ]; then - TESTSETS="func stress" -fi - -if [ -z "$WORDSIZES" ]; then - WORDSIZES="32 64" -fi - -check_hugetlbfs_path - -for set in $TESTSETS; do - case $set in - "func") - functional_tests - ;; - "stress") - stress_tests - ;; - esac -done - -echo -e "********** TEST SUMMARY" -echo -e "* 32-bit\t64-bit" -echo -e "* Total testcases: ${tot_tests[32]}\t${tot_tests[64]}" -echo -e "* Skipped: ${tot_skip[32]}\t${tot_skip[64]}" -echo -e "* PASS: ${tot_pass[32]}\t${tot_pass[64]}" -echo -e "* FAIL: ${tot_fail[32]}\t${tot_fail[64]}" -echo -e "* Killed by signal: ${tot_signal[32]}\t${tot_signal[64]}" -echo -e "* Bad configuration: ${tot_config[32]}\t${tot_config[64]}" -echo -e "* Expected FAIL: ${tot_xfail[32]}\t${tot_xfail[64]}" -echo -e "* Unexpected PASS: ${tot_xpass[32]}\t${tot_xpass[64]}" -echo -e "* Strange test result: ${tot_strange[32]}\t${tot_strange[64]}" -echo -e "**********" -- 1.6.0.3 ------------------------------------------------------------------------------ This SF.net email is sponsored by: SourcForge Community SourceForge wants to tell your story. http://p.sf.net/sfu/sf-spreadtheword _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel