[PATCH 6/6] tests: introduce tests to asinfo tool

Edgar Kaziakhmedov edgar.kaziakhmedov at virtuozzo.com
Wed Nov 8 13:44:49 UTC 2017


This set of tests cover all possible cases in asinfo tool. However,
as asinfo uses some libraries provided by strace (such as basic_filters)
there is no need to test them again in asinfo context.
Also, the set of syscalls for specific architecture (hence, its number) might
be expanded in the future, so to overcome this obstacle and avoid duplication
of the same strings reference output ptintings are stored in
ref_asinfo_output.h file.
As for syscall-related checks, tests use old syscalls as samples, so their
numbers and names can't be changed.

* configure.ac (AC_CONFIG_FILES): Add tests Makefile to be generated.
* tools/asinfo/Makefile.am (SUBDIRS): Add tests dir.
* tools/asinfo/tests/Makefile.m: New file.
* tools/asinfo/tests/init.sh: New file. Main subroutines for tests.
* tools/asinfo/test/ref_asinfo_output.h: New file.
* tools/asinfo/test/com_disp_wrong_keys.c: Likewise.
* tools/asinfo/test/com_disp_wrong_keys.test: Likewise.
* tools/asinfo/test/format_output.c: Likewise.
* tools/asinfo/test/format_output.test: Likewise.
* tools/asinfo/test/get_arch_abi.c: Likewise.
* tools/asinfo/test/get_arch_abi.test: Likewise.
* tools/asinfo/test/get_sname.c: Likewise.
* tools/asinfo/test/get_sname.test: Likewise.
* tools/asinfo/test/get_snum.c: Likewise.
* tools/asinfo/test/get_snum.test: Likewise.
* tools/asinfo/test/list_arch.c: Likewise.
* tools/asinfo/test/list_arch.test: Likewise.
* tools/asinfo/test/multiarch_get_sname.c: Likewise.
* tools/asinfo/test/multiarch_get_sname.test: Likewise.
* tools/asinfo/test/multiarch_get_snum.c: Likewise.
* tools/asinfo/test/multiarch_get_snum.test: Likewise.
* tools/asinfo/test/set_abi.c: Likewise.
* tools/asinfo/test/set_abi.test: Likewise.
* tools/asinfo/test/set_arch.c: Likewise.
* tools/asinfo/test/set_arch.test: Likewise.
* tools/asinfo/test/set_mult_abi.c: Likewise.
* tools/asinfo/test/set_mult_abi.test: Likewise.
* tools/asinfo/test/set_mult_arch.c: Likewise.
* tools/asinfo/test/set_mult_arch.test: Likewise.

Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov at virtuozzo.com>
---
 configure.ac                                |   1 +
 tools/asinfo/Makefile.am                    |   2 +
 tools/asinfo/tests/Makefile.am              |  58 +++++++++
 tools/asinfo/tests/com_disp_wrong_keys.c    |  42 +++++++
 tools/asinfo/tests/com_disp_wrong_keys.test |  32 +++++
 tools/asinfo/tests/format_output.c          |  17 +++
 tools/asinfo/tests/format_output.test       |   8 ++
 tools/asinfo/tests/get_arch_abi.c           | 180 ++++++++++++++++++++++++++++
 tools/asinfo/tests/get_arch_abi.test        |   7 ++
 tools/asinfo/tests/get_sname.c              |  26 ++++
 tools/asinfo/tests/get_sname.test           |  12 ++
 tools/asinfo/tests/get_snum.c               |  26 ++++
 tools/asinfo/tests/get_snum.test            |  12 ++
 tools/asinfo/tests/init.sh                  |  97 +++++++++++++++
 tools/asinfo/tests/list_arch.c              |  49 ++++++++
 tools/asinfo/tests/list_arch.test           |   7 ++
 tools/asinfo/tests/multiarch_get_sname.c    |  27 +++++
 tools/asinfo/tests/multiarch_get_sname.test |  12 ++
 tools/asinfo/tests/multiarch_get_snum.c     |  39 ++++++
 tools/asinfo/tests/multiarch_get_snum.test  |  12 ++
 tools/asinfo/tests/ref_asinfo_output.h      |  42 +++++++
 tools/asinfo/tests/set_abi.c                |   9 ++
 tools/asinfo/tests/set_abi.test             |   7 ++
 tools/asinfo/tests/set_arch.c               |  11 ++
 tools/asinfo/tests/set_arch.test            |   7 ++
 tools/asinfo/tests/set_mult_abi.c           |  11 ++
 tools/asinfo/tests/set_mult_abi.test        |   7 ++
 tools/asinfo/tests/set_mult_arch.c          |  12 ++
 tools/asinfo/tests/set_mult_arch.test       |   7 ++
 29 files changed, 779 insertions(+)
 create mode 100644 tools/asinfo/tests/Makefile.am
 create mode 100644 tools/asinfo/tests/com_disp_wrong_keys.c
 create mode 100755 tools/asinfo/tests/com_disp_wrong_keys.test
 create mode 100644 tools/asinfo/tests/format_output.c
 create mode 100755 tools/asinfo/tests/format_output.test
 create mode 100644 tools/asinfo/tests/get_arch_abi.c
 create mode 100755 tools/asinfo/tests/get_arch_abi.test
 create mode 100644 tools/asinfo/tests/get_sname.c
 create mode 100755 tools/asinfo/tests/get_sname.test
 create mode 100644 tools/asinfo/tests/get_snum.c
 create mode 100755 tools/asinfo/tests/get_snum.test
 create mode 100644 tools/asinfo/tests/init.sh
 create mode 100644 tools/asinfo/tests/list_arch.c
 create mode 100755 tools/asinfo/tests/list_arch.test
 create mode 100644 tools/asinfo/tests/multiarch_get_sname.c
 create mode 100755 tools/asinfo/tests/multiarch_get_sname.test
 create mode 100644 tools/asinfo/tests/multiarch_get_snum.c
 create mode 100755 tools/asinfo/tests/multiarch_get_snum.test
 create mode 100644 tools/asinfo/tests/ref_asinfo_output.h
 create mode 100644 tools/asinfo/tests/set_abi.c
 create mode 100755 tools/asinfo/tests/set_abi.test
 create mode 100644 tools/asinfo/tests/set_arch.c
 create mode 100755 tools/asinfo/tests/set_arch.test
 create mode 100644 tools/asinfo/tests/set_mult_abi.c
 create mode 100755 tools/asinfo/tests/set_mult_abi.test
 create mode 100644 tools/asinfo/tests/set_mult_arch.c
 create mode 100755 tools/asinfo/tests/set_mult_arch.test

diff --git a/configure.ac b/configure.ac
index 80951a01..c122065f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -895,6 +895,7 @@ AC_CONFIG_FILES([Makefile
 		 tools/asinfo/asinfo.1
 		 tools/Makefile
 		 tools/asinfo/Makefile
+		 tools/asinfo/tests/Makefile
 		 strace.spec
 		 debian/changelog])
 AC_OUTPUT
diff --git a/tools/asinfo/Makefile.am b/tools/asinfo/Makefile.am
index a361ea46..12347818 100644
--- a/tools/asinfo/Makefile.am
+++ b/tools/asinfo/Makefile.am
@@ -25,6 +25,8 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+SUBDIRS = . tests
+
 bin_PROGRAMS = asinfo
 man_MANS = asinfo.1
 
diff --git a/tools/asinfo/tests/Makefile.am b/tools/asinfo/tests/Makefile.am
new file mode 100644
index 00000000..e3782ec5
--- /dev/null
+++ b/tools/asinfo/tests/Makefile.am
@@ -0,0 +1,58 @@
+# Automake input for asinfo tests.
+#
+# Copyright (c) 2017 Edgar Kaziakhmedov <edgar.kaziakhmedov at virtuozzo.com>
+# 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.
+
+OS = linux
+AM_COLOR_TESTS = always
+AM_CFLAGS = $(WARN_CFLAGS)
+AM_CPPFLAGS = $(ARCH_MFLAGS) \
+	      -I$(builddir)/../ \
+	      -I$(builddir) \
+	      -I$(top_srcdir)
+AM_LDFLAGS = $(ARCH_MFLAGS)
+
+check_PROGRAMS = set_arch set_mult_arch list_arch set_abi set_mult_abi \
+		 get_arch_abi get_sname get_snum com_disp_wrong_keys \
+		 multiarch_get_sname multiarch_get_snum format_output
+TESTS = set_arch.test set_mult_arch.test list_arch.test set_abi.test \
+	set_mult_abi.test get_arch_abi.test get_sname.test get_snum.test \
+	com_disp_wrong_keys.test multiarch_get_sname.test \
+	multiarch_get_snum.test format_output.test
+
+set_arch_SOURCES = set_arch.c
+set_mult_arch_SOURCES = set_mult_arch.c
+list_arch_SOURCES = list_arch.c
+set_abi_SOURCES = set_abi.c
+set_mult_abi_SOURCES = set_mult_abi.c
+get_arch_abi_SOURCES = get_arch_abi.c
+get_sname_SOURCES = get_sname.c
+get_snum_SOURCES = get_snum.c
+com_disp_wrong_keys_SOURCES = com_disp_wrong_keys.c
+multiarch_get_sname_SOURCES = multiarch_get_sname.c
+multiarch_get_snum_SOURCES = multiarch_get_snum.c
+format_output_SOURCES = format_output.c
+
+EXTRA_DIST = $(TESTS)
diff --git a/tools/asinfo/tests/com_disp_wrong_keys.c b/tools/asinfo/tests/com_disp_wrong_keys.c
new file mode 100644
index 00000000..9dcb3ee2
--- /dev/null
+++ b/tools/asinfo/tests/com_disp_wrong_keys.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include "ref_asinfo_output.h"
+
+#define TRY_HELP "Try \'../../asinfo -h\' for more information."
+
+int
+main(int argc, char *argv[])
+{
+	puts("../../asinfo: unrecognized option \'--set-ar\'\n"
+	     TRY_HELP "\n"
+	     "../../asinfo: parameter \'--get-arch\' has been used more than "
+	     "once\n"
+	     TRY_HELP "\n"
+	     "../../asinfo: parameter \'--set-arch\' requires argument\n"
+	     TRY_HELP "\n"
+	     "../../asinfo: argument \'aarch64,\' of \'--set-arch\' parameter "
+	     "has a wrong format\n"
+	     TRY_HELP "\n"
+	     "../../asinfo: exclusive parameters\n"
+	     TRY_HELP "\n"
+	     "../../asinfo: wrong parameters\n"
+	     TRY_HELP "\n"
+	     "../../asinfo: \'--list-arch\' cannot be used with any ABI "
+	     "parameters\n"
+	     TRY_HELP "\n"
+	     "../../asinfo: ABI parameters could be used only with "
+	     "architecture parameter\n"
+	     TRY_HELP "\n"
+	     "../../asinfo: ABI modes cannot be automatically detected for "
+	     "multiple architectures\n"
+	     TRY_HELP "\n"
+	     "../../asinfo: each architecture needs respective ABI mode, "
+	     "and vice versa\n"
+	     TRY_HELP "\n"
+	     "../../asinfo: first set main output syscall characteristics\n"
+	     TRY_HELP "\n"
+	     "../../asinfo: raw data implies existing data\n"
+	     TRY_HELP "\n"
+	     "../../asinfo: must have OPTIONS\n"
+	     TRY_HELP);
+	return 0;
+}
diff --git a/tools/asinfo/tests/com_disp_wrong_keys.test b/tools/asinfo/tests/com_disp_wrong_keys.test
new file mode 100755
index 00000000..ba725ab5
--- /dev/null
+++ b/tools/asinfo/tests/com_disp_wrong_keys.test
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"
+
+run_prog > $EXP
+#Unrecognized option
+run_asinfo --set-ar > $LOG
+#More than once param
+run_asinfo --get-arch --get-arch  >> $LOG
+#Requiring argument
+run_asinfo --set-arch >> $LOG
+#Wrong format
+run_asinfo --set-arch aarch64, >> $LOG
+#More than one option in one group
+run_asinfo --get-arch --set-arch arm >> $LOG
+#syscall and list-arch
+run_asinfo --list-arch --get-sname all >> $LOG
+#list-arch and abi params
+run_asinfo --list-arch --list-abi >> $LOG
+#abi params without arch params
+run_asinfo --list-abi >> $LOG
+#auto abi for multiple archs
+run_asinfo --set-arch aarch64,arm >> $LOG
+#auto abi for multiple archs
+run_asinfo --set-arch aarch64,arm --set-abi all,all,all >> $LOG
+#nargs should be used together with other options from syscall group
+run_asinfo --set-arch x86_64 --set-abi x32 --nargs >> $LOG
+#raw check
+run_asinfo --raw >> $LOG
+#empty input
+run_asinfo >> $LOG
+match_diff "$LOG" "$EXP"
diff --git a/tools/asinfo/tests/format_output.c b/tools/asinfo/tests/format_output.c
new file mode 100644
index 00000000..870b8445
--- /dev/null
+++ b/tools/asinfo/tests/format_output.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include "ref_asinfo_output.h"
+
+int
+main(int argc, char *argv[])
+{
+	puts(
+"| N | Architecture name | ABI mode | IMPL syscalls | IPC IMPL | SOCKET IMPL |\n"
+"| 1 |             avr32 |    32bit |           329 | external |    external |"
+	);
+	puts(
+"|   |      | x86_64 | x86_64 | x86_64 |\n"
+"| N | Snum |  64bit |    x32 |  32bit |\n"
+"| 1 |    1 |  write |  write |      - |\n"
+"| 2 |    4 |      - |      - |  write |");
+	return 0;
+}
diff --git a/tools/asinfo/tests/format_output.test b/tools/asinfo/tests/format_output.test
new file mode 100755
index 00000000..6addc6e9
--- /dev/null
+++ b/tools/asinfo/tests/format_output.test
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"
+
+run_prog > $EXP
+run_asinfo --set-arch avr32 --list-abi > $LOG
+run_asinfo --set-arch x86_64 --list-abi --get-snum write >> $LOG
+match_diff "$LOG" "$EXP"
diff --git a/tools/asinfo/tests/get_arch_abi.c b/tools/asinfo/tests/get_arch_abi.c
new file mode 100644
index 00000000..e73aa0ca
--- /dev/null
+++ b/tools/asinfo/tests/get_arch_abi.c
@@ -0,0 +1,180 @@
+#include "config.h"
+#include <stdio.h>
+#include <string.h>
+#include <sys/utsname.h>
+
+#include "ref_asinfo_output.h"
+
+static inline void
+print_cannot_detect(char *arch_name)
+{
+	printf("../../asinfo: ABI mode cannot be automatically detected for "
+	       "non-target architecture \'%s\'\n", arch_name);
+}
+
+int
+main(int argc, char *argv[])
+{
+	struct utsname buf;
+	uname(&buf);
+#if defined(bfin)
+	puts("1" BFIN_32bit_STR);
+	return 0;
+#endif
+#if defined(IA64)
+	puts("1" IA64_64bit_STR);
+	return 0;
+#endif
+#if defined(M68K)
+	puts("1" M68K_32bit_STR);
+#endif
+#if defined(SPARC64)
+	print_cannot_detect(buf.machine);
+	return 0;
+#endif
+#if defined(SPARC)
+	puts("1" SPARC_32bit_STR);
+	return 0;
+#endif
+#if defined(METAG)
+	puts("1" METAG_32bit_STR);
+	return 0;
+#endif
+#if defined(MIPS)
+	if (strstr(buf.machine, "mips64")) {
+		puts(
+#if defined(LINUX_MIPSO32)
+		     "1" MIPS64_O32_STR
+#elif defined(LINUX_MIPSN32)
+		     "1" MIPS64_N32_STR
+#elif defined(LINUX_MIPSN64)
+		     "1" MIPS64_N64_STR
+#endif
+		);
+		return 0;
+	}
+	if (strstr(buf.machine, "mips")) {
+		puts("1" MIPS_O32_STR);
+		return 0;
+	}
+#endif
+#if defined(ALPHA)
+	puts("1" ALPHA_64bit_STR);
+	return 0;
+#endif
+#if defined(POWERPC64)
+	print_cannot_detect(buf.machine);
+	return 0;
+#endif
+#if defined(POWERPC)
+	puts("1" PPC_32bit_STR);
+	return 0;
+#endif
+#if defined(ARM)
+	if (strstr(buf.machine, "arm")) {
+		puts(
+#if defined(__ARM_EABI__) || !defined(ENABLE_ARM_OABI)
+		     "1" ARM_eabi_STR
+#else
+		     "1" ARM_oabi_STR
+#endif
+		);
+		return 0;
+	}
+#endif
+#if defined(AARCH64)
+	puts(
+#if defined(__ARM_EABI__)
+	     "1" AARCH64_eabi_STR
+#else
+	     "1" AARCH64_64bit_STR
+#endif
+	);
+	return 0;
+#endif
+#if defined(AVR32)
+	puts("1" AVR32_32bit_STR);
+	return 0;
+#endif
+#if defined(ARC)
+	puts("1" ARC_32bit_STR);
+	return 0;
+#endif
+#if defined(S390)
+	puts("1" S390_32bit_STR);
+	return 0;
+#endif
+#if defined(S390X)
+	puts("1" S390X_64bit_STR);
+	return 0;
+#endif
+#if defined(HPPA)
+	puts("1" PARISC_32bit_STR);
+	return 0;
+#endif
+#if defined(SH64)
+	puts("1" SH64_64bit_STR);
+	return 0;
+#endif
+#if defined(SH)
+	puts("1" SH_32bit_STR);
+	return 0;
+#endif
+#if defined(X86_64) || defined(X32)
+	puts(
+#if defined(X86_64)
+	     "1" X86_64_64bit_STR
+#elif defined(X32)
+	     "1" X86_64_X32_STR
+#endif
+	);
+	return 0;
+#endif
+#if defined(I386)
+	if (strstr(buf.machine, "64"))
+		puts("1" X86_64_32bit_STR);
+	else
+		puts("1" X86_32bit_STR);
+	return 0;
+#endif
+#if defined(CRISV10)
+	puts("1" CRISV10_32bit_STR);
+	return 0;
+#endif
+#if defined(CRISV32)
+	puts("1" CRISV32_32bit_STR);
+	return 0;
+#endif
+#if defined(TILE)
+	puts(
+#if defined(__tilepro__)
+	     "1" TILE_64bit_STR
+#else
+	     "1" TILE_32bit_STR
+#endif
+	);
+#endif
+#if defined(MICROBLAZE)
+	puts("1" MICROBLAZE_32bit_STR);
+	return 0;
+#endif
+#if defined(NIOS2)
+	puts("1" NIOS2_32bit_STR);
+	return 0;
+#endif
+#if defined(OR1K)
+	puts("1" OR1K_32bit_STR);
+	return 0;
+#endif
+#if defined(XTENSA)
+	puts("1" XTENSA_32bit_STR);
+	return 0;
+#endif
+#if defined(RISCV)
+	print_cannot_detect(buf.machine);
+	return 0;
+#endif
+	printf("../../asinfo: architecture \'%s\' is unsupported\n",
+	       buf.machine);
+	return 0;
+}
diff --git a/tools/asinfo/tests/get_arch_abi.test b/tools/asinfo/tests/get_arch_abi.test
new file mode 100755
index 00000000..d320c067
--- /dev/null
+++ b/tools/asinfo/tests/get_arch_abi.test
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"
+
+run_prog > $EXP
+run_asinfo --get-arch --raw > "$LOG"
+match_diff "$LOG" "$EXP"
diff --git a/tools/asinfo/tests/get_sname.c b/tools/asinfo/tests/get_sname.c
new file mode 100644
index 00000000..5edd7877
--- /dev/null
+++ b/tools/asinfo/tests/get_sname.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+#include "ref_asinfo_output.h"
+
+int
+main(int argc, char *argv[])
+{
+	//--get-sname write
+	puts("1;write;1;\n"
+	//--get-sname /write
+	     "1;process_vm_writev;311;\n"
+	     "2;pwrite64;18;\n"
+	     "3;pwritev;296;\n"
+	     "4;pwritev2;328;\n"
+	     "5;write;1;\n"
+	     "6;writev;20;\n"
+	//--get-sname write,read
+	     "1;read;0;\n"
+	     "2;write;1;\n"
+	//--get-sname 1
+	     "1;write;1;\n"
+	//--get-sname 1000
+	     "../../asinfo: invalid system call(x86_64/64bit) \'1000\'\n"
+	//--get-sname helloworld
+	     "../../asinfo: invalid system call(x86_64/64bit) \'helloworld\'");
+	return 0;
+}
diff --git a/tools/asinfo/tests/get_sname.test b/tools/asinfo/tests/get_sname.test
new file mode 100755
index 00000000..2bff806e
--- /dev/null
+++ b/tools/asinfo/tests/get_sname.test
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"
+
+run_prog > $EXP
+run_asinfo --set-arch x86_64 --set-abi 64bit --get-sname write --raw > $LOG
+run_asinfo --set-arch x86_64 --set-abi 64bit --get-sname /write --raw >> $LOG
+run_asinfo --set-arch x86_64 --set-abi 64bit --get-sname write,read --raw >> $LOG
+run_asinfo --set-arch x86_64 --set-abi 64bit --get-sname 1 --raw >> $LOG
+run_asinfo --set-arch x86_64 --set-abi 64bit --get-sname 1000 --raw >> $LOG
+run_asinfo --set-arch x86_64 --set-abi 64bit --get-sname helloworld --raw >> $LOG
+match_diff "$LOG" "$EXP"
diff --git a/tools/asinfo/tests/get_snum.c b/tools/asinfo/tests/get_snum.c
new file mode 100644
index 00000000..ada19312
--- /dev/null
+++ b/tools/asinfo/tests/get_snum.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+#include "ref_asinfo_output.h"
+
+int
+main(int argc, char *argv[])
+{
+	//--get-snum write
+	puts("1;1;write;\n"
+	//--get-snum /write
+	     "1;1;write;\n"
+	     "2;18;pwrite64;\n"
+	     "3;20;writev;\n"
+	     "4;296;pwritev;\n"
+	     "5;311;process_vm_writev;\n"
+	     "6;328;pwritev2;\n"
+	//--get-snum write,read
+	     "1;0;read;\n"
+	     "2;1;write;\n"
+	//--get-snum 1
+	     "1;1;write;\n"
+	//--get-snum 1000
+	     "../../asinfo: invalid system call(x86_64/64bit) \'1000\'\n"
+	//--get-snum helloworld
+	     "../../asinfo: invalid system call(x86_64/64bit) \'helloworld\'");
+	return 0;
+}
diff --git a/tools/asinfo/tests/get_snum.test b/tools/asinfo/tests/get_snum.test
new file mode 100755
index 00000000..02dceca4
--- /dev/null
+++ b/tools/asinfo/tests/get_snum.test
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"
+
+run_prog > $EXP
+run_asinfo --set-arch x86_64 --set-abi 64bit --get-snum write --raw > $LOG
+run_asinfo --set-arch x86_64 --set-abi 64bit --get-snum /write --raw >> $LOG
+run_asinfo --set-arch x86_64 --set-abi 64bit --get-snum write,read --raw >> $LOG
+run_asinfo --set-arch x86_64 --set-abi 64bit --get-snum 1 --raw >> $LOG
+run_asinfo --set-arch x86_64 --set-abi 64bit --get-snum 1000 --raw >> $LOG
+run_asinfo --set-arch x86_64 --set-abi 64bit --get-snum helloworld --raw >> $LOG
+match_diff "$LOG" "$EXP"
diff --git a/tools/asinfo/tests/init.sh b/tools/asinfo/tests/init.sh
new file mode 100644
index 00000000..1ab105d9
--- /dev/null
+++ b/tools/asinfo/tests/init.sh
@@ -0,0 +1,97 @@
+#!/bin/sh
+#
+# Copyright (c) 2011-2017 The strace developers.
+# Copyright (c) 2017 Edgar Kaziakhmedov <edgar.kaziakhmedov at virtuozzo.com>
+# 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.
+
+ME_="${0##*/}"
+LOG="log"
+OUT="out"
+EXP="exp"
+ASINFO="../../asinfo"
+
+fail_() { warn_ "$ME_: failed test: $*"; exit 1; }
+warn_() { printf >&2 '%s\n' "$*"; }
+
+run_prog()
+{
+	if [ $# -eq 0 ]; then
+		set -- "../$NAME"
+	fi
+	args="$*"
+	"$@" || {
+		rc=$?
+		if [ $rc != 0 ]; then
+			fail_ "$args failed with code $rc"
+		fi
+	}
+}
+
+
+dump_log_and_fail_with()
+{
+	cat < "$LOG" >&2
+	fail_ "$*"
+}
+
+run_asinfo()
+{
+	args="$*"
+	$ASINFO "$@" 2>&1
+}
+
+match_diff()
+{
+	local output expected error
+	if [ $# -eq 0 ]; then
+		output="$LOG"
+	else
+		output="$1"; shift
+	fi
+	if [ $# -eq 0 ]; then
+		expected="$srcdir/$NAME.expected"
+	else
+		expected="$1"; shift
+	fi
+	if [ $# -eq 0 ]; then
+		error="$STRACE $args output mismatch"
+	else
+		error="$1"; shift
+	fi
+
+	diff -u -- "$expected" "$output" ||
+		fail_ "$error"
+}
+
+NAME="${ME_%.test}"
+TESTDIR="$NAME.dir"
+rm -rf -- "$TESTDIR"
+mkdir -- "$TESTDIR"
+cd "$TESTDIR"
+case "$srcdir" in
+	/*) ;;
+	*) srcdir="../$srcdir" ;;
+esac
+
diff --git a/tools/asinfo/tests/list_arch.c b/tools/asinfo/tests/list_arch.c
new file mode 100644
index 00000000..a8b91553
--- /dev/null
+++ b/tools/asinfo/tests/list_arch.c
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include "ref_asinfo_output.h"
+
+int
+main(int argc, char *argv[])
+{
+	puts("1"  BFIN_32bit_STR"\n"
+	     "2"  IA64_64bit_STR"\n"
+	     "3"  M68K_32bit_STR"\n"
+	     "4"  SPARC64_64bit_STR"\n"
+	     "5"  SPARC64_32bit_STR"\n"
+	     "6"  SPARC_32bit_STR"\n"
+	     "7"  METAG_32bit_STR"\n"
+	     "8"  MIPS64_N64_STR"\n"
+	     "9"  MIPS64_N32_STR"\n"
+	     "10" MIPS64_O32_STR"\n"
+	     "11" MIPS_O32_STR"\n"
+	     "12" ALPHA_64bit_STR"\n"
+	     "13" PPC64_64bit_STR"\n"
+	     "14" PPC64_32bit_STR"\n"
+	     "15" PPC_32bit_STR"\n"
+	     "16" AARCH64_64bit_STR"\n"
+	     "17" AARCH64_eabi_STR"\n"
+	     "18" ARM_oabi_STR"\n"
+	     "19" ARM_eabi_STR"\n"
+	     "20" AVR32_32bit_STR"\n"
+	     "21" ARC_32bit_STR"\n"
+	     "22" S390X_64bit_STR"\n"
+	     "23" S390_32bit_STR"\n"
+	     "24" PARISC_32bit_STR"\n"
+	     "25" SH64_64bit_STR"\n"
+	     "26" SH_32bit_STR"\n"
+	     "27" X86_64_64bit_STR"\n"
+	     "28" X86_64_X32_STR"\n"
+	     "29" X86_64_32bit_STR"\n"
+	     "30" X86_32bit_STR"\n"
+	     "31" CRISV10_32bit_STR"\n"
+	     "32" CRISV32_32bit_STR"\n"
+	     "33" TILE_64bit_STR"\n"
+	     "34" TILE_32bit_STR"\n"
+	     "35" TILEPRO_32bit_STR"\n"
+	     "36" MICROBLAZE_32bit_STR"\n"
+	     "37" NIOS2_32bit_STR"\n"
+	     "38" OR1K_32bit_STR"\n"
+	     "39" XTENSA_32bit_STR"\n"
+	     "40" RISCV_64bit_STR"\n"
+	     "41" RISCV_32bit_STR);
+	return 0;
+}
diff --git a/tools/asinfo/tests/list_arch.test b/tools/asinfo/tests/list_arch.test
new file mode 100755
index 00000000..263d69df
--- /dev/null
+++ b/tools/asinfo/tests/list_arch.test
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"
+
+run_prog > $EXP
+run_asinfo --list-arch --raw > $LOG
+match_diff "$LOG" "$EXP"
diff --git a/tools/asinfo/tests/multiarch_get_sname.c b/tools/asinfo/tests/multiarch_get_sname.c
new file mode 100644
index 00000000..53d219a9
--- /dev/null
+++ b/tools/asinfo/tests/multiarch_get_sname.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include "ref_asinfo_output.h"
+
+int
+main(int argc, char *argv[])
+{
+	//--get-sname write
+	puts("1;write;1;1;4;4;\n"
+	//--get-sname /write
+	     "1;process_vm_writev;311;540;348;348;\n"
+	     "2;pwrite64;18;18;181;181;\n"
+	     "3;pwritev;296;535;334;334;\n"
+	     "4;pwritev2;328;547;379;379;\n"
+	     "5;write;1;1;4;4;\n"
+	     "6;writev;20;516;146;146;\n"
+	//--get-sname write,read
+	     "1;read;0;0;3;3;\n"
+	     "2;write;1;1;4;4;\n"
+	//--get-sname 1
+	     "1;exit;-;-;1;1;\n"
+	     "2;write;1;1;-;-;\n"
+	//--get-sname 1000
+	     "../../asinfo: invalid system call(x86_64/64bit) \'1000\'\n"
+	//--get-sname helloworld
+	     "../../asinfo: invalid system call(x86_64/64bit) \'helloworld\'");
+	return 0;
+}
diff --git a/tools/asinfo/tests/multiarch_get_sname.test b/tools/asinfo/tests/multiarch_get_sname.test
new file mode 100755
index 00000000..0ff7bb92
--- /dev/null
+++ b/tools/asinfo/tests/multiarch_get_sname.test
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"
+
+run_prog > $EXP
+run_asinfo --set-arch x86_64,x86 --list-abi --get-sname write --raw > $LOG
+run_asinfo --set-arch x86_64,x86 --list-abi --get-sname /write --raw >> $LOG
+run_asinfo --set-arch x86_64,x86 --list-abi --get-sname write,read --raw >> $LOG
+run_asinfo --set-arch x86_64,x86 --list-abi --get-sname 1 --raw >> $LOG
+run_asinfo --set-arch x86_64,x86 --list-abi --get-sname 1000 --raw >> $LOG
+run_asinfo --set-arch x86_64,x86 --list-abi --get-sname helloworld --raw >> $LOG
+match_diff "$LOG" "$EXP"
diff --git a/tools/asinfo/tests/multiarch_get_snum.c b/tools/asinfo/tests/multiarch_get_snum.c
new file mode 100644
index 00000000..27658d20
--- /dev/null
+++ b/tools/asinfo/tests/multiarch_get_snum.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include "ref_asinfo_output.h"
+
+int
+main(int argc, char *argv[])
+{
+	//--get-snum write
+	puts("1;1;write;write;-;-;\n"
+	     "2;4;-;-;write;write;\n"
+	//--get-snum /write
+	     "1;1;write;write;-;-;\n"
+	     "2;4;-;-;write;write;\n"
+	     "3;18;pwrite64;pwrite64;-;-;\n"
+	     "4;20;writev;-;-;-;\n"
+	     "5;146;-;-;writev;writev;\n"
+	     "6;181;-;-;pwrite64;pwrite64;\n"
+	     "7;296;pwritev;-;-;-;\n"
+	     "8;311;process_vm_writev;-;-;-;\n"
+	     "9;328;pwritev2;-;-;-;\n"
+	     "10;334;-;-;pwritev;pwritev;\n"
+	     "11;348;-;-;process_vm_writev;process_vm_writev;\n"
+	     "12;379;-;-;pwritev2;pwritev2;\n"
+	     "13;516;-;writev;-;-;\n"
+	     "14;535;-;pwritev;-;-;\n"
+	     "15;540;-;process_vm_writev;-;-;\n"
+	     "16;547;-;pwritev2;-;-;\n"
+	//--get-snum write,read
+	     "1;0;read;read;-;-;\n"
+	     "2;1;write;write;-;-;\n"
+	     "3;3;-;-;read;read;\n"
+	     "4;4;-;-;write;write;\n"
+	//--get-snum 1
+	     "1;1;write;write;exit;exit;\n"
+	//--get-snum 1000
+	     "../../asinfo: invalid system call(x86_64/64bit) \'1000\'\n"
+	//--get-snum helloworld
+	     "../../asinfo: invalid system call(x86_64/64bit) \'helloworld\'");
+	return 0;
+}
diff --git a/tools/asinfo/tests/multiarch_get_snum.test b/tools/asinfo/tests/multiarch_get_snum.test
new file mode 100755
index 00000000..364903a6
--- /dev/null
+++ b/tools/asinfo/tests/multiarch_get_snum.test
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"
+
+run_prog > $EXP
+run_asinfo --set-arch x86_64,x86 --list-abi --get-snum write --raw > $LOG
+run_asinfo --set-arch x86_64,x86 --list-abi --get-snum /write --raw >> $LOG
+run_asinfo --set-arch x86_64,x86 --list-abi --get-snum write,read --raw >> $LOG
+run_asinfo --set-arch x86_64,x86 --list-abi --get-snum 1 --raw >> $LOG
+run_asinfo --set-arch x86_64,x86 --list-abi --get-snum 1000 --raw >> $LOG
+run_asinfo --set-arch x86_64,x86 --list-abi --get-snum helloworld --raw >> $LOG
+match_diff "$LOG" "$EXP"
diff --git a/tools/asinfo/tests/ref_asinfo_output.h b/tools/asinfo/tests/ref_asinfo_output.h
new file mode 100644
index 00000000..bc5fce4c
--- /dev/null
+++ b/tools/asinfo/tests/ref_asinfo_output.h
@@ -0,0 +1,42 @@
+/* Reference output strings for asinfo tool which are necessary for tests */
+#define BFIN_32bit_STR		";blackfin/bfin;32bit;391;external;external;"
+#define IA64_64bit_STR		";ia64;64bit;707;external;external;"
+#define M68K_32bit_STR		";m68k;32bit;378;internal;internal;"
+#define SPARC64_64bit_STR	";sparc64;64bit;340;internal;internal;"
+#define SPARC64_32bit_STR	";sparc64;32bit;358;internal;internal;"
+#define SPARC_32bit_STR		";sparc;32bit;358;internal;internal;"
+#define METAG_32bit_STR		";metag;32bit;280;external;external;"
+#define MIPS64_N64_STR		";mips64/mips64le;n64;1000;int/ext;int/ext;"
+#define MIPS64_N32_STR		";mips64/mips64le;n32;1004;int/ext;int/ext;"
+#define MIPS64_O32_STR		";mips64/mips64le;o32;1039;internal;internal;"
+#define MIPS_O32_STR		";mips/mipsle;o32;1039;internal;internal;"
+#define ALPHA_64bit_STR		";alpha;64bit;442;external;external;"
+#define PPC64_64bit_STR		";ppc64/ppc64le/powerpc64;64bit;374;int/ext;int/ext;"
+#define PPC64_32bit_STR		";ppc64/ppc64le/powerpc64;32bit;383;int/ext;int/ext;"
+#define PPC_32bit_STR		";ppc/ppcle/powerpc;32bit;383;int/ext;int/ext;"
+#define AARCH64_64bit_STR	";aarch64/arm64;64bit;332;external;external;"
+#define AARCH64_eabi_STR	";aarch64/arm64;eabi;400;external;external;"
+#define ARM_oabi_STR		";arm;oabi;400;int/ext;int/ext;"
+#define ARM_eabi_STR		";arm;eabi;400;external;external;"
+#define AVR32_32bit_STR		";avr32;32bit;329;external;external;"
+#define ARC_32bit_STR		";arc;32bit;281;external;external;"
+#define S390X_64bit_STR		";s390x;64bit;326;internal;internal;"
+#define S390_32bit_STR		";s390;32bit;359;internal;internal;"
+#define PARISC_32bit_STR	";parisc/hppa;32bit;349;external;external;"
+#define SH64_64bit_STR		";sh64;64bit;382;int/ext;int/ext;"
+#define SH_32bit_STR		";sh;32bit;374;internal;internal;"
+#define X86_64_64bit_STR	";x86_64/amd64/EM64T;64bit;333;external;external;"
+#define X86_64_X32_STR		";x86_64/amd64/EM64T;x32;369;external;external;"
+#define X86_64_32bit_STR	";x86_64/amd64/EM64T;32bit;381;internal;internal;"
+#define X86_32bit_STR		";x86/i386/i486/i586/i686;32bit;381;internal;internal;"
+#define CRISV10_32bit_STR	";cris/crisv10;32bit;355;internal;internal;"
+#define CRISV32_32bit_STR	";crisv32;32bit;355;internal;internal;"
+#define TILE_64bit_STR		";tile/tilegx;64bit;278;external;external;"
+#define TILE_32bit_STR		";tile/tilegx;32bit;278;external;external;"
+#define TILEPRO_32bit_STR	";tilepro;32bit;278;external;external;"
+#define MICROBLAZE_32bit_STR	";microblaze;32bit;395;external;external;"
+#define NIOS2_32bit_STR		";nios2;32bit;277;external;external;"
+#define OR1K_32bit_STR		";openrisc/or1k;32bit;277;external;external;"
+#define XTENSA_32bit_STR	";xtensa;32bit;325;external;external;"
+#define RISCV_64bit_STR		";riscv;64bit;276;external;external;"
+#define RISCV_32bit_STR		";riscv;32bit;276;external;external;"
diff --git a/tools/asinfo/tests/set_abi.c b/tools/asinfo/tests/set_abi.c
new file mode 100644
index 00000000..b74e0ccb
--- /dev/null
+++ b/tools/asinfo/tests/set_abi.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+#include "ref_asinfo_output.h"
+
+int
+main(int argc, char *argv[])
+{
+	puts("1" X86_64_64bit_STR);
+	return 0;
+}
diff --git a/tools/asinfo/tests/set_abi.test b/tools/asinfo/tests/set_abi.test
new file mode 100755
index 00000000..70b1f429
--- /dev/null
+++ b/tools/asinfo/tests/set_abi.test
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"
+
+run_prog > $EXP
+run_asinfo --set-arch x86_64 --set-abi 64bit --raw > $LOG
+match_diff "$LOG" "$EXP"
diff --git a/tools/asinfo/tests/set_arch.c b/tools/asinfo/tests/set_arch.c
new file mode 100644
index 00000000..05f44b79
--- /dev/null
+++ b/tools/asinfo/tests/set_arch.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include "ref_asinfo_output.h"
+
+int
+main(int argc, char *argv[])
+{
+	puts("1" X86_64_64bit_STR "\n"
+	     "2" X86_64_X32_STR "\n"
+	     "3" X86_64_32bit_STR);
+	return 0;
+}
diff --git a/tools/asinfo/tests/set_arch.test b/tools/asinfo/tests/set_arch.test
new file mode 100755
index 00000000..e9a102c6
--- /dev/null
+++ b/tools/asinfo/tests/set_arch.test
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"
+
+run_prog > $EXP
+run_asinfo --set-arch x86_64 --list-abi --raw > $LOG
+match_diff "$LOG" "$EXP"
diff --git a/tools/asinfo/tests/set_mult_abi.c b/tools/asinfo/tests/set_mult_abi.c
new file mode 100644
index 00000000..4107fabb
--- /dev/null
+++ b/tools/asinfo/tests/set_mult_abi.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include "ref_asinfo_output.h"
+
+int
+main(int argc, char *argv[])
+{
+	puts("1" X86_64_64bit_STR "\n"
+	     "2" AARCH64_64bit_STR "\n"
+	     "3" AARCH64_eabi_STR );
+	return 0;
+}
diff --git a/tools/asinfo/tests/set_mult_abi.test b/tools/asinfo/tests/set_mult_abi.test
new file mode 100755
index 00000000..555c27ca
--- /dev/null
+++ b/tools/asinfo/tests/set_mult_abi.test
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"
+
+run_prog > $EXP
+run_asinfo --set-arch x86_64,aarch64 --set-abi 64bit,all --raw >> $LOG
+match_diff "$LOG" "$EXP"
diff --git a/tools/asinfo/tests/set_mult_arch.c b/tools/asinfo/tests/set_mult_arch.c
new file mode 100644
index 00000000..ed8d66df
--- /dev/null
+++ b/tools/asinfo/tests/set_mult_arch.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include "ref_asinfo_output.h"
+
+int
+main(int argc, char *argv[])
+{
+	puts("1" AARCH64_64bit_STR "\n"
+	     "2" AARCH64_eabi_STR "\n"
+	     "3" ARM_oabi_STR "\n"
+	     "4" ARM_eabi_STR );
+	return 0;
+}
diff --git a/tools/asinfo/tests/set_mult_arch.test b/tools/asinfo/tests/set_mult_arch.test
new file mode 100755
index 00000000..d0152d60
--- /dev/null
+++ b/tools/asinfo/tests/set_mult_arch.test
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"
+
+run_prog > $EXP
+run_asinfo --set-arch aarch64,arm --list-abi --raw >> $LOG
+match_diff "$LOG" "$EXP"
-- 
2.11.0





More information about the Strace-devel mailing list