1345 Commits

Author SHA1 Message Date
JingPiao Chen
5626a08061 netlink: print unrecognized netlink messages in hex
* netlink.c (fetch_nlmsghdr): Replace printstrn
with printstr_ex and set QUOTE_FORCE_HEX flag.
* tests/netlink_protocol.c (send_query): Update expected output.
2017-07-07 16:43:41 +00:00
JingPiao Chen
b61dfe9a37 netlink: print unrecognized netlink payload in hex
* netlink.c (decode_payload): Replace printstrn
with printstr_ex and set QUOTE_FORCE_HEX flag.
* tests/netlink_protocol.c (send_query, test_nlmsgerr,
test_nlmsg_done): Update expected output.
* tests/netlink_generic.c (test_nlmsg_type): Likewise.
2017-07-07 16:43:41 +00:00
JingPiao Chen
dbb622c061 netlink: print unrecognized nlmsgerr in hex
* netlink.c (decode_nlmsgerr): Replace printstrn
with printstr_ex and set QUOTE_FORCE_HEX flag.
* tests/netlink_protocol.c (test_nlmsgerr): Update expected output.
2017-07-07 16:43:41 +00:00
JingPiao Chen
73698eb8f1 netlink: print unrecognized attribute data in hex
* nlattr.c (decode_nlattr_with_data): Replace printstrn
with printstr_ex and set QUOTE_FORCE_HEX flag.
* tests/tests.h (print_quoted_hex): New prototype.
* tests/print_quoted_string.c (print_quoted_hex): New function.
* tests/test_nlattr.h (TEST_NLATTR_OBJECT, TEST_NLATTR_ARRAY): Use it
for updated expected output.  Change the type of "plen" variable
to unsigned int.
* tests/nlattr.c (test_nlattr): Update expected output.
2017-07-07 16:43:41 +00:00
JingPiao Chen
8d71474ea1 tests: print quotation marks in print_quoted_memory
* tests/print_quoted_string.c (print_quoted_memory): Print opening
and closing quotation marks.
* tests/getcwd.c (main): Do not print quotation marks around
print_quoted_string.
* tests/uname.c (main): Likewise.
* tests/keyctl.c (print_quoted_string_limit): Do not print quotation
marks around print_quoted_memory.
* tests/netlink_protocol.c (send_query): Likewise.
* tests/xattr.c (main): Likewise.
2017-07-07 16:43:41 +00:00
bcc7daac6c tests: robustify create_nl_socket based tests against the race condition
There is a race condition between the moment a netlink socket is created
and the moment it is reported via SOCK_DIAG_BY_FAMILY interface.
Add one more operation on the socket created by create_nl_socket
to increase chances of winning the race.

* tests/create_nl_socket.c (create_nl_socket_ext): Add a getsockopt call
with the created socket.
2017-07-04 22:31:08 +00:00
Eugene Syromyatnikov
da160ae8ed tests: add multi-process check to qual_fault.test
Check that syscall counters used for tampering are per-tcb.

* tests/qual_fault.c: Include <fcntl.h> for open(),
<sys/param.h> for PATH_MAX, and <sys/wait.h> for wait().
(expfd): Rename to exp_fd, remove const qualifier and initialization.
(gotfd): Rename to got_fd, remove const qualifier and initialization.
(out_fd): New variable, for the expected strace output.
(open_file): New helper function.
(main): Remove st, add num_procs, proc, exp_prefix, got_prefix,
out_prefix, pid_prefix.  Remove stat asserts, update argc assert.
Add num_procs, exp_prefix, got_prefix, out_prefix, pid_prefix
initialization.  Add per-process loop, open expfd, gotfd, out_fd, pidfd
in each one, print process's pid to pidfd, print exit message to out_fd.
Add wait() call for each forked process.
* tests/qual_fault.test (N): increase to 100 in order to check
concurrent process execution.
(check_fault_injection): Take additional argument for the process
count, pass it to qual_fault, add filename variables for expected strace
output and pid file, pass them to qual_fault.
Specify -ff parameter to strace invocation.
Compare write and strace output for the each process.
Update all check_fault_injection invocation with process count argument,
add an invocation with 4 concurrent processes.
* tests/init.sh (TIMEOUT_DURATION): Raise from 120 to 300.

Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2017-07-03 19:31:04 +00:00
dbd060526c tests: adjust TEST_NLATTR_OBJECT and TEST_NLATTR_ARRAY for large objects
* tests/test_nlattr.h (TEST_NLATTR_OBJECT, TEST_NLATTR_ARRAY): Add
support for objects larger than DEFAULT_STRLEN.
* tests/nlattr_inet_diag_msg.c (main): Change pattern size
from DEFAULT_STRLEN to 4096.
* tests/nlattr_netlink_diag_msg.c: Likewise.
* tests/nlattr_unix_diag_msg.c: Likewise.

Reported-by: JingPiao Chen <chenjingpiao@gmail.com>
2017-07-03 15:14:54 +00:00
005c67a900 tests: move DEFAULT_STRLEN macro to tests.h
* tests/tests.h [!DEFAULT_STRLEN] (DEFAULT_STRLEN): New macro.
* tests/mincore.c (DEFAULT_STRLEN): Remove.
* tests/mmsg_name.c: Likewise.
* tests/msg_control.c: Likewise.
* tests/netlink_protocol.c: Likewise.
* tests/nlattr.c: Likewise.
* tests/nlattr_inet_diag_msg.c: Likewise.
* tests/nlattr_netlink_diag_msg.c: Likewise.
* tests/nlattr_unix_diag_msg.c: Likewise.
* tests/printstr.c: Likewise.
* tests/xattr.c: Likewise.
* tests/execve.c: Likewise.
(main): Initialize str_a and str_b arrays at run time.
* tests/execveat.c: Likewise.

Suggested-by: JingPiao Chen <chenjingpiao@gmail.com>
2017-07-03 15:14:54 +00:00
Eugene Syromyatnikov
7d465949e4 tests: use unified diff in order to improve test log readability
* tests/init.sh (match_diff): Add -u option to the diff invocation.
2017-07-03 15:14:54 +00:00
373265e699 Fix error diagnostics in case of zero argc
* strace.c (init): Adjust argc along with argv,
check that adjusted argc is sane.
* tests/zeroargc.c: New file.
* tests/.gitignore: Add zeroargc.
* tests/Makefile.am (check_PROGRAMS): Likewise.
* tests/options-syntax.test: Check strace error diagnostics
in case of zero argc.
2017-07-02 10:01:22 +00:00
eaa2f6e06d Introduce generic STRINGIFY and STRINGIFY_VAL macros
* macros.h (STRINGIFY, STRINGIFY_VAL): New macros.
* mpers_type.h: Include "macros.h".
[IN_MPERS] (STRINGIFY): Remove.
* tests/sockname.c (TEST_SYSCALL_STR__, TEST_SYSCALL_STR_): Remove.
(TEST_SYSCALL_STR): Use STRINGIFY_VAL.

Co-authored-by: Victor Krapivensky <krapivenskiy.va@phystech.edu>
2017-07-02 00:11:31 +00:00
38198609df Introduce macros.h
Introduce a separate header file for generic macros shared between
strace and its tests.  Start this unification with ARRAY_SIZE macro.

* defs.h: Include "macros.h".
(ARRAY_SIZE): Move ...
* macros.h: ... to new file.
* Makefile.am (strace_SOURCES): Add it.
* tests/tests.h: Include "macros.h".
(ARRAY_SIZE): Remove.  All callers updated.
2017-07-02 00:11:31 +00:00
26954f7753 Unify different generic PRINT_FIELD_* implementations
Create a new header print_fields.h and move generic PRINT_FIELD_*
macros there.

* print_fields.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* netlink_sock_diag.c: Include "print_fields.h".
(PRINT_FIELD_U, PRINT_FIELD_X, PRINT_FIELD_COOKIE, PRINT_FIELD_FLAGS,
PRINT_FIELD_XVAL): Move to print_fields.h file.
* quota.c: Include "print_fields.h".
(PRINT_FIELD_D): Move to print_fields.h file.
(PRINT_FIELD_U, PRINT_FIELD_X): Remove.
* statx.c: Include "print_fields.h".
(PRINT_FIELD_U): Remove.
(SYS_FUNC(statx)): Update PRINT_FIELD_U callers.
* tests/quotactl.h: Include "print_fields.h".
* tests/quotactl-xfs.c: Update callers of PRINT_FIELD_* macros.
* tests/quotactl.c: Likewise.
(PRINT_FIELD_D, PRINT_FIELD_U, PRINT_FIELD_X): Remove.
* tests/test_nlattr.h: Include "print_fields.h".
(PRINT_FIELD_U, PRINT_FIELD_X): Remove.
* tests/xstatx.c: Include "print_fields.h".
(PRINT_FIELD_U): Remove.
(print_stat): Update PRINT_FIELD_U callers.
* tests/tests.h [!STRACE_PRINTF] (STRACE_PRINTF): Define to printf.
2017-07-01 13:14:49 +00:00
1b7a74f3e0 tests: enhance nlattr_unix_diag_msg test
* tests/nlattr_unix_diag_msg.c: Include "test_nlattr.h".
(test_unix_diag_vfs, test_unix_diag_icons, test_unix_diag_rqlen):
Remove.
(init_unix_diag_msg): Add const qualifier to arguments and variables.
(print_unix_diag_msg, print_uint): New functions.
(main): Use them and macros from test_nlattr.h file.
2017-07-01 00:05:39 +00:00
JingPiao Chen
d4b9472d5f tests: check decoding of netlink unix_diag_msg attributes
* tests/nlattr_unix_diag_msg.c: New file.
* tests/gen_tests.in (nlattr_unix_diag_msg): New entry.
* tests/pure_executables.list: Add nlattr_unix_diag_msg.
* tests/.gitignore: Likewise.
2017-07-01 00:05:39 +00:00
e4cfb43cd3 tests: enhance nlattr_netlink_diag_msg test
* tests/nlattr_netlink_diag_msg.c: Include "test_nlattr.h".
(test_netlink_diag_groups, test_netlink_diag_rx_ring,
test_netlink_diag_flags): Remove.
(init_netlink_diag_msg): Add const qualifier to arguments and variables.
(print_netlink_diag_msg, print_xlong): New functions.
(main): Use them and macros from test_nlattr.h file.
2017-07-01 00:05:39 +00:00
JingPiao Chen
5f81d2df70 tests: check decoding of netlink_diag_msg attributes
* tests/nlattr_netlink_diag_msg.c: New file.
* tests/gen_tests.in (nlattr_netlink_diag_msg): New entry.
* tests/pure_executables.list: Add nlattr_netlink_diag_msg.
* tests/.gitignore: Likewise.
2017-07-01 00:05:39 +00:00
0c3ef7dffd netlink_sock_diag: print inet_diag_sockid.idiag_if as an interface index
* netlink_sock_diag.c (print_inet_diag_sockid): Print idiag_if field
using print_ifindex.
* tests/nlattr_inet_diag_msg.c: Include <net/if.h>.
(IFINDEX_LO): New macro.
(init_inet_diag_msg): Set inet_diag_sockid.idiag_if field.
(print_inet_diag_msg): Update expected output.
2017-07-01 00:05:39 +00:00
6c7c4e50b1 tests: check decoding of several standard netlink attributes
* tests/nlattr_inet_diag_msg.c (main): Check decoding of uint32_t,
uint8_t, and zero-terminated string attributes.

Co-authored-by: JingPiao Chen <chenjingpiao@gmail.com>
2017-07-01 00:05:39 +00:00
aecff115c0 tests: enhance nlattr_inet_diag_msg test
* tests/test_nlattr.h: New file.
* tests/Makefile.am (libtests_a_SOURCES): Add it.
* tests/nlattr_inet_diag_msg.c: Include "test_nlattr.h".
(test_inet_diag_meminfo, test_inet_diag_vegasinfo,
test_inet_diag_dctcpinfo, test_inet_diag_bbrinfo): Remove.
(address): New variable.
(init_inet_diag_msg): Remove "address" argument, add const qualifier
to all remaining arguments.
(print_inet_diag_msg, print_uint): New functions.
(main): Use macros from test_nlattr.h file.
2017-06-30 21:38:49 +00:00
JingPiao Chen
16ebda581e tests: check decoding of netlink inet_diag_msg attributes
* tests/nlattr_inet_diag_msg.c: New file.
* tests/gen_tests.in (nlattr_inet_diag_msg): New entry.
* tests/pure_executables.list: Add nlattr_inet_diag_msg.
* tests/.gitignore: Likewise.
2017-06-30 21:38:49 +00:00
JingPiao Chen
663b4f8273 tests: introduce NLMSG_ATTR macro
* tests/tests.h (NLMSG_ATTR): New macro.
* tests/nlattr.c (test_nlattr, test_nla_type): Use it.
2017-06-27 09:43:18 +00:00
11621507fb Check -s argument early
* util.c (printstr_ex): Move the check that -s argument
does not exceed -1U / 4 ...
* strace.c (init): ... here.
* tests/options-syntax.test: Check it.
2017-06-26 22:30:19 +00:00
4a2a9a7cb1 Include "netlink.h" instead of <linux/netlink.h>
* net.c: Include "netlink.h" instead of <linux/netlink.h>.
* sockaddr.c: Likewise.
* tests/create_nl_socket.c: Likewise.
* tests/net-sockaddr.c: Likewise.
* tests/netlink_audit.c: Likewise.
* tests/netlink_generic.c: Likewise.
* tests/netlink_inet_diag.c: Likewise.
* tests/netlink_netfilter.c: Likewise.
* tests/netlink_route.c: Likewise.
* tests/netlink_selinux.c: Likewise.
* tests/netlink_xfrm.c: Likewise.
* tests/net-yy-netlink.c: Include "netlink.h" instead
of <linux/netlink.h>, remove fallback definition of NETLINK_SOCK_DIAG.
* tests/netlink_netlink_diag.c: Likewise.
* tests/netlink_protocol.c: Likewise.
* tests/netlink_sock_diag.c: Likewise.
* tests/netlink_unix_diag.c: Likewise.
* tests/nlattr.c: Likewise.
2017-06-25 00:40:29 +00:00
012e650b08 tests: check more corner cases of nlattr decoding
* tests/nlattr.c (test_nlattr): Check decoding in case of invalid
struct nlattr.nla_len.
2017-06-21 16:36:33 +00:00
JingPiao Chen
1794dea92e tests: check decoding of netlink attribute
* tests/nlattr.c: New file.
* tests/gen_tests.in (nlattr): New entry.
* tests/pure_executables.list: Add nlattr.
* tests/.gitignore: Likewise.
2017-06-21 16:36:33 +00:00
JingPiao Chen
72ecbdb9f3 netlink: introduce netlink.h
* netlink.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* netlink_sock_diag.c: Include "netlink.h",
remove <sys/socket.h> and <linux/netlink.h>.
* netlink.c: Likewise.
(NLMSG_HDRLEN): Move to netlink.h.
* tests/netlink_protocol.c: Replace <linux/netlink.h> with "netlink.h".
* tests/netlink_sock_diag.c: Likewise.
2017-06-21 16:31:04 +00:00
a726fa5c35 tests: add SET_STRUCT macro to tests.h
* tests/netlink_sock_diag.c (INIT_STRUCT): Rename to SET_STRUCT,
all callers updated.  Move ...
* tests/tests.h: ... here.
2017-06-20 17:41:59 +00:00
0fb4b6e0cb tests: fix potential unaligned access in netlink_sock_diag.test
Despite our efforts made to avoid unaligned access, gcc appears to be
generating instructions that might cause unaligned access when copying
structures to unaligned addresses.

Fix this issue by replacing copying of structures to unaligned addresses
with memcpy calls.

* tests/netlink_sock_diag.c (INIT_STRUCT): New macro.
(test_odd_family_req, test_odd_family_msg, test_unix_diag_req,
test_unix_diag_msg, test_netlink_diag_req, test_netlink_diag_msg,
test_packet_diag_req, test_packet_diag_msg, test_inet_diag_sockid,
test_inet_diag_req, test_inet_diag_req_v2, test_inet_diag_msg,
test_smc_diag_req, test_smc_diag_msg): Use it to initialize potentially
unaligned struct nlmsghdr.  Do not access nlh->nlmsg_len.
2017-06-19 21:45:58 +00:00
Masatake YAMATO
c7f371df30 tests: check decoding of NETLINK_GENERIC message types
* tests/netlink_generic.c: New file.
* tests/gen_tests.in (netlink_generic): New entry.
* tests/pure_executables.list: Add netlink_generic.
* tests/.gitignore: Likewise.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2017-06-19 21:45:58 +00:00
f639f90241 netlink: do not print extra braces around payloadless nlmsghdr
* netlink.c (decode_nlmsghdr_with_payload): Print braces before
print_nlmsghdr and after decode_payload iff decode_payload is invoked.
* tests/netlink_audit.c (test_nlmsg_type): Update expected output.
* tests/netlink_netfilter.c: Likewise.
* tests/netlink_selinux.c: Likewise.
* tests/netlink_protocol.c (send_query): Likewise.
* tests/netlink_route.c (test_nlmsg_type, test_nlmsg_flags): Likewise.
* tests/netlink_sock_diag.c: Likewise.
* tests/netlink_xfrm.c: Likewise.
2017-06-18 21:43:39 +00:00
184e94ba05 Fix a few spacing style issues
Reported by kernel's checkpatch.pl script.
2017-06-17 22:54:08 +00:00
e0433c5509 Strip redundant trailing semicolons
Strip trailing semicolons from macro definitions.
Strip extra semicolons from statements terminations.

Reported by kernel's checkpatch.pl script.
2017-06-17 22:50:41 +00:00
6c08f7d65c Fix macros encosure in a do/while loop
Enclose macros with multiple statements and macros starting
with "if" statement in a do/while loop.
Do not enclose single statement macros in a do/while loop.

Reported by kernel's checkpatch.pl script.
2017-06-17 21:51:48 +00:00
3baf7ef953 Fix a few initialization style issues
Do not initialise statics and globals to 0, NULL, or false.

Reported by kernel's checkpatch.pl script.
2017-06-17 20:49:09 +00:00
a74c084611 Fix a few sizeof style issues
Reported by kernel's checkpatch.pl script.
2017-06-17 18:49:58 +00:00
7f2b636a22 Fix a few misspellings in comments
Reported by kernel's checkpatch.pl script.
2017-06-17 10:40:05 +00:00
8384bf8067 tests: check decoding of incomplete SCM_TIMESTAMP* control messages
* tests/msg_control.c (test_scm_timestamp, test_scm_timestampns,
test_scm_timestamping): Check decoding of incomplete control messages.
2017-06-15 23:52:48 +00:00
Miroslav Lichvar
c0a127d163 msghdr: print SCM_TIMESTAMP* control messages
Add support for printing control messages containing software and/or
hardware timestamps, which are typically enabled by NTP and PTP
implementations.

* print_timeval.c (print_struct_timeval_data_size): New mpers printer.
* print_timespec.c (print_struct_timespec_data_size,
print_struct_timespec_array_data_size): Likewise.
* msghdr.c (print_scm_timestamp, print_scm_timestampns,
print_scm_timestamping): New functions.
(cmsg_socket_printers): Add them.
* NEWS: Mention this change.
* tests/msg_control.c: Include "xlat.h" and "xlat/scmvals.h".
(test_scm_timestamp, test_scm_timestampns, test_scm_timestamping):
New functions.
(test_sol_socket): Use them.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2017-06-15 23:52:48 +00:00
JingPiao Chen
97d771159b tests: check decoding of NETLINK_SOCK_DIAG AF_SMC messages
* tests/netlink_sock_diag.c: Include <linux/smc_diag.h>.
(SMC_ACTIVE): New macro.
(test_smc_diag_req, test_smc_diag_msg): New functions.
(main): Use them.
2017-06-15 23:52:48 +00:00
JingPiao Chen
c17150366c tests: check decoding of NETLINK_SOCK_DIAG AF_INET messages
* tests/netlink_sock_diag.c: Include <arpa/inet.h>
and <linux/inet_diag.h>.
(test_inet_diag_sockid, test_inet_diag_req, test_inet_diag_req_v2,
test_inet_diag_msg): New functions.
(mian): Use them.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-06-15 23:52:47 +00:00
bd70a9c411 Introduce print_inet_addr
* defs.h (print_inet_addr): New prototype.
* sockaddr.c (print_inet_addr): New function.
(print_sockaddr_data_in6): Use it.
* net.c (print_mreq6): Likewise.
* tests/ip_mreq.c (main): Update expected output.
2017-06-15 23:52:47 +00:00
JingPiao Chen
a9345e97e2 tests: check decoding of NETLINK_SOCK_DIAG AF_PACKET messages
* tests/netlink_sock_diag.c: Include <linux/if_ether.h>
and <linux/packet_diag.h>.
(test_packet_diag_req, test_packet_diag_msg): New functions.
(main): Use them.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-06-15 22:44:04 +00:00
JingPiao Chen
2e8cfe367b tests: check decoding of NETLINK_SOCK_DIAG AF_NETLINK messages
* tests/netlink_sock_diag.c: Include <linux/netlink_diag.h>.
(test_netlink_diag_req, test_netlink_diag_msg): New functions.
(main): Use them.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
2017-06-15 22:20:41 +00:00
4a5b3b30e6 tests: check decoding of NETLINK_SOCK_DIAG AF_UNIX messages
* tests/netlink_sock_diag.c: Include <netinet/tcp.h>
and <linux/unix_diag.h>.
(test_odd_family_req, test_odd_family_msg, test_unix_diag_req,
test_unix_diag_msg): New functions.
(main): Use them.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
Co-authored-by: JingPiao Chen <chenjingpiao@gmail.com>
2017-06-15 00:30:47 +00:00
JingPiao Chen
084d748015 tests: extend printstr test
* tests/printstr.c (main): Add a case for short read.
2017-06-14 04:38:13 +00:00
c2449486d6 v4l2: fix preprocessor checks
Fix checks for struct v4l2_window.global_alpha and struct
v4l2_sdr_format.buffersize.

* v4l2.c (print_v4l2_format_fmt): Do not assume that
HAVE_STRUCT_V4L2_WINDOW_GLOBAL_ALPHA and
HAVE_STRUCT_V4L2_SDR_FORMAT_BUFFERSIZE are defined.
* tests/ioctl_v4l2.c (init_v4l2_format, dprint_ioctl_v4l2): Likewise.
2017-06-13 21:00:04 +00:00
JingPiao Chen
1d2dddc73f tests: fix typo
* tests/dup3.c (SKIP_MAIN_UNDEFINED): Remove duplicated &&.
2017-06-12 15:47:39 +00:00
JingPiao Chen
427e30ef1c tests: add check for decoding netlink get and new flags
* tests/netlink_route.c (test_nlmsg_flags): New function, checks
decoding of NETLINK_ROUTE get and new flags.
(main): Use it.
* tests/netlink_sock_diag.c (test_nlmsg_flags): New function, checks
decoding of NETLINK_SOCK_DIAG get flags.
(main): Use it.
* tests/netlink_xfrm.c: (test_nlmsg_flags): New function, checks
decoding of NETLINK_XFRM get and new flags.
(main): Use it.
2017-06-08 22:26:46 +00:00