1. 07 May, 2019 8 commits
    • Mathieu Desnoyers's avatar
      rseq/selftests: arm: use udf instruction for RSEQ_SIG · 2b845d4b
      Mathieu Desnoyers authored
      Use udf as the guard instruction for the restartable sequence abort
      handler.
      
      Previously, the chosen signature was not a valid instruction, based
      on the assumption that it could always sit in a literal pool. However,
      there are compilation environments in which literal pools are not
      available, for instance execute-only code. Therefore, we need to
      choose a signature value that is also a valid instruction.
      
      Handle compiling with -mbig-endian on ARMv6+, which generates binaries
      with mixed code vs data endianness (little endian code, big endian
      data).
      
      Else mismatch between code endianness for the generated signatures and
      data endianness for the RSEQ_SIG parameter passed to the rseq
      registration will trigger application segmentation faults when the
      kernel try to abort rseq critical sections.
      
      Prior to ARMv6, -mbig-endian generates big-endian code and data, so
      endianness should not be reversed in that case.
      Signed-off-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
      CC: Peter Zijlstra <peterz@infradead.org>
      CC: Thomas Gleixner <tglx@linutronix.de>
      CC: Joel Fernandes <joelaf@google.com>
      CC: Catalin Marinas <catalin.marinas@arm.com>
      CC: Dave Watson <davejwatson@fb.com>
      CC: Will Deacon <will.deacon@arm.com>
      CC: Shuah Khan <shuah@kernel.org>
      CC: Andi Kleen <andi@firstfloor.org>
      CC: linux-kselftest@vger.kernel.org
      CC: "H . Peter Anvin" <hpa@zytor.com>
      CC: Chris Lameter <cl@linux.com>
      CC: Russell King <linux@arm.linux.org.uk>
      CC: Michael Kerrisk <mtk.manpages@gmail.com>
      CC: "Paul E . McKenney" <paulmck@linux.vnet.ibm.com>
      CC: Paul Turner <pjt@google.com>
      CC: Boqun Feng <boqun.feng@gmail.com>
      CC: Josh Triplett <josh@joshtriplett.org>
      CC: Steven Rostedt <rostedt@goodmis.org>
      CC: Ben Maurer <bmaurer@fb.com>
      CC: linux-api@vger.kernel.org
      CC: Andy Lutomirski <luto@amacapital.net>
      CC: Andrew Morton <akpm@linux-foundation.org>
      CC: Linus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      2b845d4b
    • Martin Schwidefsky's avatar
      rseq/selftests: s390: use trap4 for RSEQ_SIG · 3d4d1f05
      Martin Schwidefsky authored
      Use trap4 as the guard instruction for the restartable sequence abort
      handler.
      Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
      Signed-off-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      3d4d1f05
    • Mathieu Desnoyers's avatar
      rseq/selftests: x86: use ud1 instruction as RSEQ_SIG opcode · 24fa5d1e
      Mathieu Desnoyers authored
      Use ud1 as the guard instruction for the restartable sequence abort
      handler. Its benefit compared to nopl is to trap execution if the
      program ends up trying to execute it by mistake, which makes debugging
      easier.
      
      The 4-byte signature per se is unchanged (it is the instruction
      operand). Only the opcode is changed from nopl to ud1.
      Signed-off-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Suggested-by: default avatarPeter Zijlstra <peterz@infradead.org>
      CC: Peter Zijlstra <peterz@infradead.org>
      CC: Thomas Gleixner <tglx@linutronix.de>
      CC: Joel Fernandes <joelaf@google.com>
      CC: Catalin Marinas <catalin.marinas@arm.com>
      CC: Dave Watson <davejwatson@fb.com>
      CC: Will Deacon <will.deacon@arm.com>
      CC: Shuah Khan <shuah@kernel.org>
      CC: Andi Kleen <andi@firstfloor.org>
      CC: linux-kselftest@vger.kernel.org
      CC: "H . Peter Anvin" <hpa@zytor.com>
      CC: Chris Lameter <cl@linux.com>
      CC: Russell King <linux@arm.linux.org.uk>
      CC: Michael Kerrisk <mtk.manpages@gmail.com>
      CC: "Paul E . McKenney" <paulmck@linux.vnet.ibm.com>
      CC: Paul Turner <pjt@google.com>
      CC: Boqun Feng <boqun.feng@gmail.com>
      CC: Josh Triplett <josh@joshtriplett.org>
      CC: Steven Rostedt <rostedt@goodmis.org>
      CC: Ben Maurer <bmaurer@fb.com>
      CC: linux-api@vger.kernel.org
      CC: Andy Lutomirski <luto@amacapital.net>
      CC: Andrew Morton <akpm@linux-foundation.org>
      CC: Linus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      24fa5d1e
    • Mathieu Desnoyers's avatar
      rseq/selftests: s390: use jg instruction for jumps outside of the asm · 97b8be81
      Mathieu Desnoyers authored
      The branch target range of the "j" instruction is 64K, which is not
      enough for the general case.
      Suggested-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
      Signed-off-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
      CC: Thomas Gleixner <tglx@linutronix.de>
      CC: Joel Fernandes <joelaf@google.com>
      CC: Peter Zijlstra <peterz@infradead.org>
      CC: Catalin Marinas <catalin.marinas@arm.com>
      CC: Dave Watson <davejwatson@fb.com>
      CC: Will Deacon <will.deacon@arm.com>
      CC: Shuah Khan <shuah@kernel.org>
      CC: Andi Kleen <andi@firstfloor.org>
      CC: linux-kselftest@vger.kernel.org
      CC: "H . Peter Anvin" <hpa@zytor.com>
      CC: Chris Lameter <cl@linux.com>
      CC: Russell King <linux@arm.linux.org.uk>
      CC: Michael Kerrisk <mtk.manpages@gmail.com>
      CC: "Paul E . McKenney" <paulmck@linux.vnet.ibm.com>
      CC: Paul Turner <pjt@google.com>
      CC: Boqun Feng <boqun.feng@gmail.com>
      CC: Josh Triplett <josh@joshtriplett.org>
      CC: Steven Rostedt <rostedt@goodmis.org>
      CC: Ben Maurer <bmaurer@fb.com>
      CC: linux-api@vger.kernel.org
      CC: Andy Lutomirski <luto@amacapital.net>
      CC: Andrew Morton <akpm@linux-foundation.org>
      CC: Linus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      97b8be81
    • Mathieu Desnoyers's avatar
      rseq/selftests: Use __rseq_handled symbol to coexist with glibc · 5b0c308a
      Mathieu Desnoyers authored
      In order to integrate rseq into user-space applications, expose a
      __rseq_handled symbol so many rseq users can be linked into the same
      application (e.g. librseq and glibc).
      
      The __rseq_refcount TLS variable is static to the librseq library. It
      ensures that rseq syscall registration/unregistration happens only for
      the most early/late caller to rseq_{,un}register_current_thread for each
      thread, thus ensuring that rseq is registered across the lifetime of all
      rseq users for a given thread.
      Signed-off-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
      CC: Shuah Khan <shuah@kernel.org>
      CC: Carlos O'Donell <carlos@redhat.com>
      CC: Florian Weimer <fweimer@redhat.com>
      CC: Joseph Myers <joseph@codesourcery.com>
      CC: Szabolcs Nagy <szabolcs.nagy@arm.com>
      CC: Thomas Gleixner <tglx@linutronix.de>
      CC: Ben Maurer <bmaurer@fb.com>
      CC: Peter Zijlstra <peterz@infradead.org>
      CC: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
      CC: Boqun Feng <boqun.feng@gmail.com>
      CC: Will Deacon <will.deacon@arm.com>
      CC: Dave Watson <davejwatson@fb.com>
      CC: Paul Turner <pjt@google.com>
      CC: linux-api@vger.kernel.org
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      5b0c308a
    • Mathieu Desnoyers's avatar
      rseq/selftests: Introduce __rseq_cs_ptr_array, rename __rseq_table to __rseq_cs · a3e3131f
      Mathieu Desnoyers authored
      The entries within __rseq_table are aligned on 32 bytes due to
      linux/rseq.h struct rseq_cs uapi requirements, but the start of the
      __rseq_table section is not guaranteed to be 32-byte aligned. It can
      cause padding to be added at the start of the section, which makes it
      hard to use as an array of items by debuggers.
      
      Considering that __rseq_table does not really consist of a table due to
      the presence of padding, rename this section to __rseq_cs.
      
      Create a new __rseq_cs_ptr_array section which contains 64-bit packed
      pointers to entries within the __rseq_cs section.
      Signed-off-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
      CC: Thomas Gleixner <tglx@linutronix.de>
      CC: Joel Fernandes <joelaf@google.com>
      CC: Peter Zijlstra <peterz@infradead.org>
      CC: Catalin Marinas <catalin.marinas@arm.com>
      CC: Dave Watson <davejwatson@fb.com>
      CC: Will Deacon <will.deacon@arm.com>
      CC: Shuah Khan <shuah@kernel.org>
      CC: Andi Kleen <andi@firstfloor.org>
      CC: linux-kselftest@vger.kernel.org
      CC: "H . Peter Anvin" <hpa@zytor.com>
      CC: Chris Lameter <cl@linux.com>
      CC: Russell King <linux@arm.linux.org.uk>
      CC: Michael Kerrisk <mtk.manpages@gmail.com>
      CC: "Paul E . McKenney" <paulmck@linux.vnet.ibm.com>
      CC: Paul Turner <pjt@google.com>
      CC: Boqun Feng <boqun.feng@gmail.com>
      CC: Josh Triplett <josh@joshtriplett.org>
      CC: Steven Rostedt <rostedt@goodmis.org>
      CC: Ben Maurer <bmaurer@fb.com>
      CC: linux-api@vger.kernel.org
      CC: Andy Lutomirski <luto@amacapital.net>
      CC: Andrew Morton <akpm@linux-foundation.org>
      CC: Linus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      a3e3131f
    • Mathieu Desnoyers's avatar
      rseq/selftests: Add __rseq_exit_point_array section for debuggers · 4fe2088e
      Mathieu Desnoyers authored
      Knowing all exit points is useful to assist debuggers stepping over the
      rseq critical sections without requiring them to disassemble the content
      of the critical section to figure out the exit points.
      Signed-off-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
      CC: Thomas Gleixner <tglx@linutronix.de>
      CC: Joel Fernandes <joelaf@google.com>
      CC: Peter Zijlstra <peterz@infradead.org>
      CC: Catalin Marinas <catalin.marinas@arm.com>
      CC: Dave Watson <davejwatson@fb.com>
      CC: Will Deacon <will.deacon@arm.com>
      CC: Shuah Khan <shuah@kernel.org>
      CC: Andi Kleen <andi@firstfloor.org>
      CC: linux-kselftest@vger.kernel.org
      CC: "H . Peter Anvin" <hpa@zytor.com>
      CC: Chris Lameter <cl@linux.com>
      CC: Russell King <linux@arm.linux.org.uk>
      CC: Michael Kerrisk <mtk.manpages@gmail.com>
      CC: "Paul E . McKenney" <paulmck@linux.vnet.ibm.com>
      CC: Paul Turner <pjt@google.com>
      CC: Boqun Feng <boqun.feng@gmail.com>
      CC: Josh Triplett <josh@joshtriplett.org>
      CC: Steven Rostedt <rostedt@goodmis.org>
      CC: Ben Maurer <bmaurer@fb.com>
      CC: linux-api@vger.kernel.org
      CC: Andy Lutomirski <luto@amacapital.net>
      CC: Andrew Morton <akpm@linux-foundation.org>
      CC: Linus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      4fe2088e
    • Mathieu Desnoyers's avatar
      rseq/selftests: x86: Work-around bogus gcc-8 optimisation · fe22983d
      Mathieu Desnoyers authored
      gcc-8 version 8.1.0, 8.2.0, and 8.3.0 generate broken assembler with asm
      goto that have a thread-local storage "m" input operand on both x86-32
      and x86-64. For instance:
      
      __thread int var;
      
      static int fct(void)
      {
              asm goto (      "jmp %l[testlabel]\n\t"
                              : : [var] "m" (var) : : testlabel);
              return 0;
      testlabel:
              return 1;
      }
      
      int main()
      {
              return fct();
      }
      
      % gcc-8 -O2 -o test-asm-goto test-asm-goto.c
      /tmp/ccAdHJbe.o: In function `main':
      test-asm-goto.c:(.text.startup+0x1): undefined reference to `.L2'
      collect2: error: ld returned 1 exit status
      
      % gcc-8 -m32 -O2 -o test-asm-goto test-asm-goto.c
      /tmp/ccREsVXA.o: In function `main':
      test-asm-goto.c:(.text.startup+0x1): undefined reference to `.L2'
      collect2: error: ld returned 1 exit status
      
      Work-around this compiler bug in the rseq-x86.h header by passing the
      address of the __rseq_abi TLS as a register operand rather than using
      the "m" input operand.
      
      Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90193Signed-off-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
      CC: Ingo Molnar <mingo@redhat.com>
      CC: Peter Zijlstra <peterz@infradead.org>
      CC: Thomas Gleixner <tglx@linutronix.de>
      CC: Joel Fernandes <joelaf@google.com>
      CC: Catalin Marinas <catalin.marinas@arm.com>
      CC: Dave Watson <davejwatson@fb.com>
      CC: Will Deacon <will.deacon@arm.com>
      CC: Shuah Khan <shuah@kernel.org>
      CC: Andi Kleen <andi@firstfloor.org>
      CC: linux-kselftest@vger.kernel.org
      CC: "H . Peter Anvin" <hpa@zytor.com>
      CC: Chris Lameter <cl@linux.com>
      CC: Russell King <linux@arm.linux.org.uk>
      CC: Michael Kerrisk <mtk.manpages@gmail.com>
      CC: "Paul E . McKenney" <paulmck@linux.vnet.ibm.com>
      CC: Paul Turner <pjt@google.com>
      CC: Boqun Feng <boqun.feng@gmail.com>
      CC: Josh Triplett <josh@joshtriplett.org>
      CC: Steven Rostedt <rostedt@goodmis.org>
      CC: Ben Maurer <bmaurer@fb.com>
      CC: linux-api@vger.kernel.org
      CC: Andy Lutomirski <luto@amacapital.net>
      CC: Andrew Morton <akpm@linux-foundation.org>
      CC: Linus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      fe22983d
  2. 25 Apr, 2019 8 commits
  3. 22 Apr, 2019 1 commit
    • Shuah Khan's avatar
      selftests: build and run gpio when output directory is the src dir · d917fb87
      Shuah Khan authored
      Build and run gpio when output directory is the src dir.  gpio has
      dependency on tools/gpio and builds tools/gpio objects in the src
      directory in all cases making the src repo dirty even when object
      relocation is specified.
      
      This fixes the following commands from generating gpio objects in
      the source repository:
      
      make O=dir kselftest
      export KBUILD_OUTPUT=dir; make kselftest
      make O=dir -C tools/testing/selftests
      expoert KBUILD_OUTPUT=dir; make -C tools/testing/selftests
      
      The following commands still build gpio objects in the source repo
      (gpio Makefile needs to fixed):
      make O=dir kselftest TARGETS="gpio"
      export KBUILD_OUTPUT=dir; make kselftest TARGETS="gpio"
      make O=dir -C tools/testing/selftests TARGETS="gpio"
      expoert KBUILD_OUTPUT=dir; make -C tools/testing/selftests TARGETS="gpio"
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      d917fb87
  4. 19 Apr, 2019 3 commits
    • Kees Cook's avatar
      selftests/ipc: Fix msgque compiler warnings · a147faa9
      Kees Cook authored
      This fixes the various compiler warnings when building the msgque
      selftest. The primary change is using sys/msg.h instead of linux/msg.h
      directly to gain the API declarations.
      
      Fixes: 3a665531 ("selftests: IPC message queue copy feature test")
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      a147faa9
    • Po-Hsu Lin's avatar
      selftests/efivarfs: clean up test files from test_create*() · dff6d2ae
      Po-Hsu Lin authored
      Test files created by test_create() and test_create_empty() tests will
      stay in the $efivarfs_mount directory until the system was rebooted.
      
      When the tester tries to run this efivarfs test again on the same
      system, the immutable characteristics in that directory will cause some
      "Operation not permitted" noises, and a false-positve test result as the
      file was created in previous run.
          --------------------
          running test_create
          --------------------
          ./efivarfs.sh: line 59: /sys/firmware/efi/efivars/test_create-210be57c-9849-4fc7-a635-e6382d1aec27: Operation not permitted
            [PASS]
          --------------------
          running test_create_empty
          --------------------
          ./efivarfs.sh: line 78: /sys/firmware/efi/efivars/test_create_empty-210be57c-9849-4fc7-a635-e6382d1aec27: Operation not permitted
           [PASS]
          --------------------
      
      Create a file_cleanup() to remove those test files in the end of each
      test to solve this issue.
      
      For the test_create_read, we can move the clean up task to the end of
      the test to ensure the system is clean.
      
      Also, use this function to replace the existing file removal code.
      Signed-off-by: default avatarPo-Hsu Lin <po-hsu.lin@canonical.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      dff6d2ae
    • Shuah Khan's avatar
      selftests: fix headers_install circular dependency · 8ce72dc3
      Shuah Khan authored
      "make kselftest" fails with "Circular Makefile.o <- prepare dependency
      dropped." error, when lib.mk invokes "make headers_install".
      
      Make level 0: Main make calls selftests run_tests target
      ...
      Make level n: selftests lib.mk invokes main make's headers_install
      
      The secondary level make inherits builtin-rules which will use the rule
      to generate Makefile.o  and runs into "Circular Makefile.o <- prepare
      dependency dropped." error, and kselftest compile fails.
      
      Invoke headers_install target with --no-builtin-rules to avoid circular
      error.
      
      In addition, lib.mk installs headers in the default HDR_PATH, even when
      build relocation is requested with O= or export KBUILD_OUTPUT. Fix the
      problem by passing in INSTALL_HDR_PATH. The headers are installed under
      the specified output "dir/usr".
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      8ce72dc3
  5. 17 Apr, 2019 10 commits
  6. 16 Apr, 2019 2 commits
  7. 08 Apr, 2019 8 commits
    • Roman Gushchin's avatar
      selftests: cgroup: fix cleanup path in test_memcg_subtree_control() · e14d314c
      Roman Gushchin authored
      Dan reported, that cleanup path in test_memcg_subtree_control()
      triggers a static checker warning:
        ./tools/testing/selftests/cgroup/test_memcontrol.c:76 \
        test_memcg_subtree_control()
        error: uninitialized symbol 'child2'.
      
      Fix this by initializing child2 and parent2 variables and
      split the cleanup path into few stages.
      Signed-off-by: default avatarRoman Gushchin <guro@fb.com>
      Fixes: 84092dbc ("selftests: cgroup: add memory controller self-tests")
      Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Cc: Dan Carpenter <dan.carpenter@oracle.com>
      Cc: Shuah Khan (Samsung OSG) <shuah@kernel.org>
      Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
      Signed-off-by: default avatarShuah Khan <shuah@kernel.org>
      e14d314c
    • ZhangXiaoxu's avatar
      selftests: efivarfs: remove the test_create_read file if it was exist · f8a0590f
      ZhangXiaoxu authored
      After the first run, the test case 'test_create_read' will always
      fail because the file is exist and file's attr is 'S_IMMUTABLE',
      open with 'O_RDWR' will always return -EPERM.
      Signed-off-by: default avatarZhangXiaoxu <zhangxiaoxu5@huawei.com>
      Signed-off-by: default avatarShuah Khan <shuah@kernel.org>
      f8a0590f
    • Mathieu Desnoyers's avatar
      rseq/selftests: Adapt number of threads to the number of detected cpus · 0a7dc82e
      Mathieu Desnoyers authored
      On smaller systems, running a test with 200 threads can take a long
      time on machines with smaller number of CPUs.
      
      Detect the number of online cpus at test runtime, and multiply that
      by 6 to have 6 rseq threads per cpu preempting each other.
      Signed-off-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Cc: Shuah Khan <shuah@kernel.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Joel Fernandes <joelaf@google.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Dave Watson <davejwatson@fb.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: Andi Kleen <andi@firstfloor.org>
      Cc: linux-kselftest@vger.kernel.org
      Cc: "H . Peter Anvin" <hpa@zytor.com>
      Cc: Chris Lameter <cl@linux.com>
      Cc: Russell King <linux@arm.linux.org.uk>
      Cc: Michael Kerrisk <mtk.manpages@gmail.com>
      Cc: "Paul E . McKenney" <paulmck@linux.vnet.ibm.com>
      Cc: Paul Turner <pjt@google.com>
      Cc: Boqun Feng <boqun.feng@gmail.com>
      Cc: Josh Triplett <josh@joshtriplett.org>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Ben Maurer <bmaurer@fb.com>
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarShuah Khan <shuah@kernel.org>
      0a7dc82e
    • Tobin C. Harding's avatar
      lib: Add test module for strscpy_pad · 0b0600c8
      Tobin C. Harding authored
      Add a test module for the new strscpy_pad() function.  Tie it into the
      kselftest infrastructure for lib/ tests.
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarTobin C. Harding <tobin@kernel.org>
      Signed-off-by: default avatarShuah Khan <shuah@kernel.org>
      0b0600c8
    • Tobin C. Harding's avatar
      lib/string: Add strscpy_pad() function · 458a3bf8
      Tobin C. Harding authored
      We have a function to copy strings safely and we have a function to copy
      strings and zero the tail of the destination (if source string is
      shorter than destination buffer) but we do not have a function to do
      both at once.  This means developers must write this themselves if they
      desire this functionality.  This is a chore, and also leaves us open to
      off by one errors unnecessarily.
      
      Add a function that calls strscpy() then memset()s the tail to zero if
      the source string is shorter than the destination buffer.
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarTobin C. Harding <tobin@kernel.org>
      Signed-off-by: default avatarShuah Khan <shuah@kernel.org>
      458a3bf8
    • Tobin C. Harding's avatar
      lib: Use new kselftest header · 6b1a4d5b
      Tobin C. Harding authored
      We just added a new C header file for use with test modules that are
      intended to be run with kselftest.  We can reduce code duplication by
      using this header.
      
      Use new kselftest header to reduce code duplication in test_printf and
      test_bitmap test modules.
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarTobin C. Harding <tobin@kernel.org>
      Signed-off-by: default avatarShuah Khan <shuah@kernel.org>
      6b1a4d5b
    • Tobin C. Harding's avatar
      kselftest: Add test module framework header · eebf4dd4
      Tobin C. Harding authored
      kselftest runs as a userspace process.  Sometimes we need to test things
      from kernel space.  One way of doing this is by creating a test module.
      Currently doing so requires developers to write a bunch of boiler plate
      in the module if kselftest is to be used to run the tests.  This means
      we currently have a load of duplicate code to achieve these ends.  If we
      have a uniform method for implementing test modules then we can reduce
      code duplication, ensure uniformity in the test framework, ease code
      maintenance, and reduce the work required to create tests.  This all
      helps to encourage developers to write and run tests.
      
      Add a C header file that can be included in test modules.  This provides
      a single point for common test functions/macros.  Implement a few macros
      that make up the start of the test framework.
      
      Add documentation for new kselftest header to kselftest documentation.
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarTobin C. Harding <tobin@kernel.org>
      Signed-off-by: default avatarShuah Khan <shuah@kernel.org>
      eebf4dd4
    • Tobin C. Harding's avatar
      kselftest: Add test runner creation script · d3460527
      Tobin C. Harding authored
      Currently if we wish to use kselftest to run tests within a kernel
      module we write a small script to load/unload and do error reporting.
      There are a bunch of these under tools/testing/selftests/lib/ that are
      all identical except for the test name.  We can reduce code duplication
      and improve maintainability if we have one version of this.  However
      kselftest requires an executable for each test.  We can move all the
      script logic to a central script then have each individual test script
      call the main script.
      
      Oneliner to call kselftest_module.sh courtesy of Kees, thanks!
      
      Add test runner creation script.  Convert
      tools/testing/selftests/lib/*.sh to use new test creation script.
      
      Testing
      -------
      
      Configure kselftests for lib/ then build and boot kernel.  Then run
      kselftests as follows:
      
        $ cd /path/to/kernel/tree
        $ sudo make O=$output_path -C tools/testing/selftests TARGETS="lib" run_tests
      
      and also
      
        $ cd /path/to/kernel/tree
        $ cd tools/testing/selftests
        $ sudo make O=$output_path TARGETS="lib" run_tests
      
      and also
      
        $ cd /path/to/kernel/tree
        $ cd tools/testing/selftests
        $ sudo make TARGETS="lib" run_tests
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarTobin C. Harding <tobin@kernel.org>
      Signed-off-by: default avatarShuah Khan <shuah@kernel.org>
      d3460527