From f008b01b691ca7ede0cf3f3bf2ef5bf2d77dcea6 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Fri, 28 Aug 2015 07:11:17 +0000 Subject: [PATCH] tests: convert getrandom.test from match_awk to match_diff * tests/getrandom.c (main): Print expected output. * tests/getrandom.test: Use match_diff instead of match_awk. * tests/getrandom.awk: Remove. * tests/Makefile.am (EXTRA_DIST): Remove getrandom.awk. --- tests/Makefile.am | 1 - tests/getrandom.awk | 11 ----------- tests/getrandom.c | 43 ++++++++++++++++++++++++++++++++++++++++++- tests/getrandom.test | 8 +++++--- 4 files changed, 47 insertions(+), 16 deletions(-) delete mode 100644 tests/getrandom.awk diff --git a/tests/Makefile.am b/tests/Makefile.am index 36bb5100..f81f109e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -162,7 +162,6 @@ EXTRA_DIST = init.sh run.sh match.awk \ filter-unavailable.expected \ getdents.awk \ getdents.out \ - getrandom.awk \ ioctl.expected \ ip_mreq.expected \ ipc.sh \ diff --git a/tests/getrandom.awk b/tests/getrandom.awk deleted file mode 100644 index 09d2a0f0..00000000 --- a/tests/getrandom.awk +++ /dev/null @@ -1,11 +0,0 @@ -BEGIN { - r[1] = "^getrandom\\(\"(\\\\x[0-9a-f][0-9a-f]){3}\", 3, 0\\) += 3$" - r[2] = "^getrandom\\(\"(\\\\x[0-9a-f][0-9a-f]){3}\"\\.\\.\\., 4, GRND_NONBLOCK\\) += 4$" - r[3] = "^getrandom\\(0x[[0-9a-f]+, 4, GRND_NONBLOCK\\|GRND_RANDOM\\|0x3000\\) += -1 " - s[4] = "+++ exited with 0 +++" - - lines = 4 - fail = 0 -} - -@include "match.awk" diff --git a/tests/getrandom.c b/tests/getrandom.c index 4620f9f5..f15ef74c 100644 --- a/tests/getrandom.c +++ b/tests/getrandom.c @@ -1,3 +1,35 @@ +/* + * Copyright (c) 2015 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include #include #include @@ -5,15 +37,24 @@ int main(void) { #ifdef __NR_getrandom - char buf[4]; + unsigned char buf[4]; if (syscall(__NR_getrandom, buf, sizeof(buf) - 1, 0) != sizeof(buf) - 1) return 77; + printf("getrandom(\"\\x%02x\\x%02x\\x%02x\", 3, 0) = 3\n", + (int) buf[0], (int) buf[1], (int) buf[2]); + if (syscall(__NR_getrandom, buf, sizeof(buf), 1) != sizeof(buf)) return 77; + printf("getrandom(\"\\x%02x\\x%02x\\x%02x\"..., 4, GRND_NONBLOCK) = 4\n", + (int) buf[0], (int) buf[1], (int) buf[2]); + if (syscall(__NR_getrandom, buf, sizeof(buf), 0x3003) != -1) return 77; + printf("getrandom(%p, 4, GRND_NONBLOCK|GRND_RANDOM|0x3000) = " + "-1 EINVAL (Invalid argument)\n", buf); + puts("+++ exited with 0 +++"); return 0; #else return 77; diff --git a/tests/getrandom.test b/tests/getrandom.test index 3dd76f29..d429cdeb 100755 --- a/tests/getrandom.test +++ b/tests/getrandom.test @@ -4,8 +4,10 @@ . "${srcdir=.}/init.sh" -run_prog -run_strace -e getrandom -xx -s3 $args -match_awk +run_prog > /dev/null +OUT="$LOG.out" +run_strace -e getrandom -xx -s3 -a32 $args > "$OUT" +match_diff "$OUT" "$LOG" +rm -f "$OUT" exit 0 -- 2.50.1