Skip to contentSkip to conversation

recvmmsg(2) system call tests

LTP Ramon Pantin 3 participants 11 messages Oct 31, 2018 – Nov 6, 2018

lore
Share & tools
lore
#1 lore raw

Hi Ramon,

thank you for moving from github pull request to mailing list.

Quoted 2 lines

Per Rafael's earlier email about how to proceed, find attached the path with the test cases.

You sent your patch as an attachment.
Please, next time, send is at plain text,
as although patchwork can work with that [1], mailman can't handle it [2]. Here are some instructions [3].
Please add your Signed-off-by: tag.

I've added some comments in github pull request [4], you didn't change them, so I repeat some of it here. But please, read the doc to provide usable patch [5] [6]. 2165 lines for one file suggest to split file into several.

Please have look into the to see code style (short code, easy to read, using SAFE_*() helpers to prevent reinventing a wheal, avoiding macros, remove comments which has nothing to say, ...).

LTP code varies, some is really old and ugly. But we try to include reasonably clean code. You can have look at this as a good example of code style:
testcases/kernel/syscalls/inotify/inotify09.c
59e0a81c5 inotify07: Add test for kernel crash during event notification It has also TST_TEST_TCONF

Quoted 4 lines

From dea04e5946e8a30787943f347cf3861a8dca6008 Mon Sep 17 00:00:00 2001
From: Ramon Pantin <[email protected]>
Date: Wed, 31 Oct 2018 16:26:50 -0700
Subject: [PATCH] recvmmsg(2) test cases

This should be removed.

Quoted 13 lines
---
 testcases/kernel/syscalls/recvmmsg/Makefile   |   27 +
 .../kernel/syscalls/recvmmsg/recvmmsg01.c     | 2165 +++++++++++++++++
 2 files changed, 2192 insertions(+)
 create mode 100644 testcases/kernel/syscalls/recvmmsg/Makefile
 create mode 100644 testcases/kernel/syscalls/recvmmsg/recvmmsg01.c
testcases/kernel/syscalls/recvmmsg/Makefile new file +0 -0
new file mode 100644
index 000000000..61b3a55e6

testcases/kernel/syscalls/recvmmsg/Makefile line 2

Quoted 2 lines
testcases/kernel/syscalls/recvmmsg/Makefile new file +2 -0
@@ -0,0 +1,27 @@
+#  Copyright (c) Google LLC, 2018
+#  Copyright (c) International Business Machines  Corp., 2001

^ Please delete this IBM copyright.

testcases/kernel/syscalls/recvmmsg/Makefile line 15

Quoted 13 lines
testcases/kernel/syscalls/recvmmsg/Makefile new file +13 -0
+#  This program is free software;  you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+#  the GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program;  if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

Please use just SPDX identifier instead of address:
# SPDX-License-Identifier: GPL-2.0-or-later

testcases/kernel/syscalls/recvmmsg/Makefile line 22

Quoted 7 lines
testcases/kernel/syscalls/recvmmsg/Makefile new file +7 -0
+#
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+CPPFLAGS		+= -I$(abs_srcdir)/../utils

Why this include?

testcases/kernel/syscalls/recvmmsg/Makefile line 23

Quoted 1 line
testcases/kernel/syscalls/recvmmsg/Makefile new file +1 -0
+CFLAGS			= -g -std=c99

Please can you remove CFLAGS and produce code without warnings? I'm also not sure about -std=c99. While you can grep for some -std=gnu99 in the code, these are just some outdated comments in the source, not passed to make.

Quoted 9 lines
testcases/kernel/syscalls/recvmmsg/Makefile new file +3 -0
+LDLIBS			+= -lpthread
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +0 -0
new file mode 100644
index 000000000..131bcfd66

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c

Quoted 5 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +4 -0
@@ -0,0 +1,2165 @@
+ //  Copyright (c) Google LLC, 2018
+ //  SPDX-License-Identifier: GPL-2.0-or-later
 
+ //
+ //{

Why these lines?

Quoted 8 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +8 -0
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c

Quoted 10 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +10 -0
+#include <pthread.h>
+#include <assert.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/signal.h>
+#include <sys/uio.h>
+#include <sys/file.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>

Some of the includes will not be needed if you use API functions (SAFE_*, [5], [6]).

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c

Quoted 5 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +5 -0
+
+// #define RECVMMSG_USE_SCTP
+#ifdef RECVMMSG_USE_SCTP
+#include <netinet/sctp.h>
+#endif

Code related to RECVMMSG_USE_SCTP should be checked with autotools. There is our header include/lapi/sctp.h, you can include it and add (in separate commit) definitions, which are needed. If you really need netinet/sctp.h header, you can add exit clause with TST_TEST_TCONF

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c

Quoted 2 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +2 -0
+
+#define TST_NO_DEFAULT_MAIN

You're not supposed to use this

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c

Quoted 2 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +2 -0
+#include "tst_test.h"
+// #include "safe_macros.h"

Please remove all comments left

Quoted 5 lines

+
+ //}
+ // Declarations.
+ //
+ //{ <-- (curly-brace match to move through major sections of this file)

Please comments like this.
Please use C style comments /* */

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c

Quoted 10 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +10 -0
+int con_receive_iovec_boundary_checks(con_t *conp, int tn, size_t niov);
+int con_receive_iovec_boundary_checks_peeking(con_t *conp, int tn, size_t niov);
+int con_receive_file_descriptor(con_t *conp, int tn, int cloexec_flag,
+				bool some_data, ssize_t controllen_delta);
+int con_message_too_long_to_fit_might_discard_bytes(con_t *conp, int tn,
+						    int type);
+int con_receive_waits_for_message(con_t *conp, int tn);
+int con_receiver_doesnt_wait_for_messages(con_t *conp, int tn);
+int con_receive_returns_what_is_available(con_t *conp, int tn);
+int con_empty_datagram_received_as_empty_datagram(con_t *conp, int tn);

Function signatures aren't needed when used just in one file. Actually, in this case we declare functions as static.

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c

Quoted 10 lines

+ // ensure() tests something that shouldn't fail, doesn't abort like assert()

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +9 -0
+
+#define ensure(test_number, expr)					    \
+	((expr) ? (test_verbose < 2 ||			    		    \
+		   (print_prefix(test_number),				    \
+		    printf("%s(): true: " #expr " \n", __FUNCTION__)))	    \
+		: (++ensure_failures,					    \
+		   printf("test_number = %d: %s(): false: "		    \
+			  #expr " : failed\n",				    \
+			  test_number, __FUNCTION__)))

We use tst_res(TINFO, ...) instead of printf.
We try to avoid macros.

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c

Quoted 8 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +8 -0
+int con_receive_iovec_boundary_checks(con_t *conp, int tn, size_t niov)
+{
+	size_t iov_max = iovec_max();
+	int salt = tn + subtest_number();	// salt test data
+
+	int client_data[niov];
+	iovec_t client_iov[niov];
+	for (int i = 0; i < niov; ++i) {

int i should be defined before.

#2 lore raw

Please see below. Before I email another patch please advise about my response below to each one of your individual items of feedback.

Quoted 6 lines · Petr Vorel

Hi Ramon,

thank you for moving from github pull request to mailing list.

Quoted 7 lines
Quoted 2 lines

Per Rafael's earlier email about how to proceed, find attached the path with the test cases.

You sent your patch as an attachment.
Please, next time, send is at plain text,
as although patchwork can work with that [1], mailman can't handle it [2]. Here are some instructions [3].
Please add your Signed-off-by: tag.

I am still confused where it is that you want that to be added and what is it that it is supposed to contain?

Should I have as the first line of the patch a line that says?

Signed-off-by [email protected]

If not what should it be?

Quoted 4 lines

I've added some comments in github pull request [4], you didn't change them, so I repeat some of it here. But please, read the doc to provide usable patch [5] [6]. 2165 lines for one file suggest to split file into several.

That is unnecessary, it would then require a header file. Its needless complexity.

Quoted 11 lines

Please have look into the to see code style (short code, easy to read, using SAFE_*() helpers to prevent reinventing a wheal, avoiding macros, remove comments which has nothing to say, ...).

LTP code varies, some is really old and ugly. But we try to include reasonably clean code. You can have look at this as a good example of code style:
testcases/kernel/syscalls/inotify/inotify09.c
59e0a81c5 inotify07: Add test for kernel crash during event notification It has also TST_TEST_TCONF

Quoted 5 lines
Quoted 4 lines

From dea04e5946e8a30787943f347cf3861a8dca6008 Mon Sep 17 00:00:00 2001
From: Ramon Pantin <[email protected]>
Date: Wed, 31 Oct 2018 16:26:50 -0700
Subject: [PATCH] recvmmsg(2) test cases

This should be removed.

In an earlier email you asked me to use this tool:
git format-patch
Which I used, which put that in the patch file. Confused. What harm does that cause?

In any case I will delete those lines. You mean delete the 4 lines right?

Quoted 8 lines
Quoted 7 lines

---
testcases/kernel/syscalls/recvmmsg/Makefile | 27 +
.../kernel/syscalls/recvmmsg/recvmmsg01.c | 2165 +++++++++++++++++

2 files changed, 2192 insertions(+)

create mode 100644 testcases/kernel/syscalls/recvmmsg/Makefile create mode 100644 testcases/kernel/syscalls/recvmmsg/recvmmsg01.c

Quoted 9 lines

testcases/kernel/syscalls/recvmmsg/Makefile line 2

Quoted 8 lines
testcases/kernel/syscalls/recvmmsg/Makefile new file +2 -0
new file mode 100644
index 000000000..61b3a55e6
@@ -0,0 +1,27 @@
+#  Copyright (c) Google LLC, 2018
+#  Copyright (c) International Business Machines  Corp., 2001

^ Please delete this IBM copyright.

As I said I said in an earlier email I copied the Makefile from an IBM Makefile that had that copyright. I will find another one to copy from that uses the SPDX license identifier instead and copy from that.

Quoted 17 lines
Quoted 4 lines
testcases/kernel/syscalls/recvmmsg/Makefile new file +3 -0
+#  This program is free software;  you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or

testcases/kernel/syscalls/recvmmsg/Makefile line 15

Quoted 10 lines
testcases/kernel/syscalls/recvmmsg/Makefile new file +10 -0
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+#  the GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program;  if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

Please use just SPDX identifier instead of address:
# SPDX-License-Identifier: GPL-2.0-or-later

Quoted 8 lines

testcases/kernel/syscalls/recvmmsg/Makefile line 22

Quoted 7 lines
testcases/kernel/syscalls/recvmmsg/Makefile new file +7 -0
+#
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+CPPFLAGS		+= -I$(abs_srcdir)/../utils

Why this include?

That was there in the file from the test case that I copied. I guess that was needed when using the original “test.h” (which in your earlier email you said was obsolete) so that came from that. I’ll see if it builds removing that.

Quoted 3 lines

testcases/kernel/syscalls/recvmmsg/Makefile line 23

Quoted 2 lines
testcases/kernel/syscalls/recvmmsg/Makefile new file +1 -0
+CFLAGS			= -g -std=c99

Please can you remove CFLAGS and produce code without warnings?

To be able to use ANSI C99 features on the builds from the continuous integration I have to have at least C99 enabled. The ANSI C99 standard is 19 years old, its silly to ask that the code be C89. I won’t change that. I’ll remove the “-g”

The test code uses variable declarations intermixed with statements, a feature of C99, reorganizing the code to be compatible with a 29 year old C standard would be silly.

Quoted 15 lines

I'm also not sure about -std=c99. While you can grep for some -std=gnu99 in the code, these are just some outdated comments in the source, not passed to make.

Quoted 11 lines
testcases/kernel/syscalls/recvmmsg/Makefile new file +3 -0
+LDLIBS			+= -lpthread
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +2 -0
new file mode 100644
index 000000000..131bcfd66
@@ -0,0 +1,2165 @@
+ //  Copyright (c) Google LLC, 2018
+ //  SPDX-License-Identifier: GPL-2.0-or-later
Quoted 3 lines

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c line 4

Quoted 2 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +2 -0
+ //
+ //{

Why these lines?

To navigate better within the source code within various areas in it. You go to the line and press ‘%’ in vi or whatever you use to go to the matching curly-brace in your source code editor.

Quoted 12 lines
Quoted 12 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +11 -0
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <assert.h>
+#include <sys/types.h>
Quoted 8 lines

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c line 22

Quoted 7 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +7 -0
+#include <sys/time.h>
+#include <sys/signal.h>
+#include <sys/uio.h>
+#include <sys/file.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>

Some of the includes will not be needed if you use API functions (SAFE_*, [5], [6]).

I’d rather base the test cases on standard UNIX system calls (Linux is mostly UNIX compliant), there is no value in using non standard APIs which I don’t want to have to bother learning about.

Quoted 9 lines

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c line 27

Quoted 6 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +5 -0
+
+// #define RECVMMSG_USE_SCTP
+#ifdef RECVMMSG_USE_SCTP
+#include <netinet/sctp.h>
+#endif

Code related to RECVMMSG_USE_SCTP should be checked with autotools. There is our header include/lapi/sctp.h, you can include it and add (in separate commit) definitions, which are needed. If you really need netinet/sctp.h header, you can add exit clause with TST_TEST_TCONF

I’ll address this later with a later patch. For now it causes no harm. Right?

Quoted 5 lines

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c line 29

Quoted 3 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +2 -0
+
+#define TST_NO_DEFAULT_MAIN

You're not supposed to use this

Its there for a reason. I have my own main() program, main() is standard and part of C, don’t want to learn about some other stuff unrelated to what I am testing. In UNIX programs start in main() right?

Quoted 3 lines

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c line 31

Quoted 2 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +2 -0
+#include "tst_test.h"
+// #include "safe_macros.h"

Please remove all comments left

I will remove that.

Quoted 7 lines

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c line 36

Quoted 5 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +5 -0
+
+ //}
+ // 	Declarations.
+ //
+ //{	<-- (curly-brace match to move through major sections of this file)

Please comments like this.
Please use C style comments /* */

C99 allows for // as comments. I don’t want to make the code bigger needlessly.

Quoted 13 lines

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c line 46

Quoted 11 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +10 -0
+int con_receive_iovec_boundary_checks(con_t *conp, int tn, size_t niov);
+int con_receive_iovec_boundary_checks_peeking(con_t *conp, int tn, size_t niov);
+int con_receive_file_descriptor(con_t *conp, int tn, int cloexec_flag,
+				bool some_data, ssize_t controllen_delta);
+int con_message_too_long_to_fit_might_discard_bytes(con_t *conp, int tn,
+						    int type);
+int con_receive_waits_for_message(con_t *conp, int tn);
+int con_receiver_doesnt_wait_for_messages(con_t *conp, int tn);
+int con_receive_returns_what_is_available(con_t *conp, int tn);
+int con_empty_datagram_received_as_empty_datagram(con_t *conp, int tn);

Function signatures aren't needed when used just in one file. Actually, in this case we declare functions as static.

The ARE required unless you reorganize you code to be all in the order of called functions preceding called functions, which is silly. Furthermore if there were mutually recursive functions you couldn’t do that either.

Having “static” for internal functions only matters if the test program is more than one source file. This is just one file. Its easier to debug when the symbols are visible to the debugger, with some compilers “static” functions can not be debugged because the symbols end up not being in the symbol table.

Quoted 13 lines

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c line 56

Quoted 11 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +10 -0
+ //  ensure() tests something that shouldn't fail, doesn't abort like assert()
+
+#define ensure(test_number, expr)					    \
+	((expr) ? (test_verbose < 2 ||			    		    \
+		   (print_prefix(test_number),				    \
+		    printf("%s(): true: " #expr " \n", __FUNCTION__)))	    \
+		: (++ensure_failures,					    \
+		   printf("test_number = %d: %s(): false: "		    \
+			  #expr " : failed\n",				    \
+			  test_number, __FUNCTION__)))

We use tst_res(TINFO, ...) instead of printf.
We try to avoid macros.

Because printf() is documented. You use macros when there is no other choice. For example when you need to stringify something for example with the #expr above, when you want to use __FUNCTION__, __FILE__, and __LINE__, etc.

Quoted 10 lines

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c line 64

Quoted 9 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +8 -0
+int con_receive_iovec_boundary_checks(con_t *conp, int tn, size_t niov)
+{
+	size_t iov_max = iovec_max();
+	int salt = tn + subtest_number();	// salt test data
+
+	int client_data[niov];
+	iovec_t client_iov[niov];
+	for (int i = 0; i < niov; ++i) {

int i should be defined before.

No it is not needed outside the loop.

Quoted 7 lines
Quoted 4 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +3 -0
+		client_data[i] = i + salt;
+		iovec_init(&client_iov[i], &client_data[i],
+			   sizeof(client_data[0]));

…

regards,
Ramon

Quoted 10 lines

Kind regards,
Petr

[1] https://patchwork.ozlabs.org/patch/991864/
[2] http://lists.linux.it/pipermail/ltp/2018-November/009781.html
[3] https://www.kernel.org/doc/html/v4.17/process/submitting-patches.html#no-mime-no-links-no-compression-no-attachments-just-plain-text
[4] https://github.com/linux-test-project/ltp/pull/414
[5] https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#2-writing-a-testcase)
[6] https://github.com/linux-test-project/ltp/wiki/C-Test-Case-Tutorial

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20181101/98f6870a/attachment-0001.html>

#3 lore raw

Hi!

Quoted 11 lines
Quoted 5 lines

You sent your patch as an attachment.
Please, next time, send is at plain text,
as although patchwork can work with that [1], mailman can't handle it [2]. Here are some instructions [3].
Please add your Signed-off-by: tag.

I am still confused where it is that you want that to be added and what is it that it is supposed to contain?

Should I have as the first line of the patch a line that says?

Signed-off-by [email protected]

If not what should it be?

See:

https://www.kernel.org/doc/html/latest/process/submitting-patches.html#developer-s-certificate-of-origin-1-1

The process for LTP is more or less the same as for the linux kernel so most of it applies here as well.

Quoted 6 lines
Quoted 2 lines
Quoted 1 line

+CFLAGS = -g -std=c99

Please can you remove CFLAGS and produce code without warnings?

To be able to use ANSI C99 features on the builds from the continuous integration I have to have at least C99 enabled. The ANSI C99 standard is 19 years old, its silly to ask that the code be C89. I won???t change that. I???ll remove the ???-g???

The test code uses variable declarations intermixed with statements, a feature of C99, reorganizing the code to be compatible with a 29 year old C standard would be silly.

Actually the default for gcc is gnu90 which is close to c99 anyways, so we do not have to do anything about it.

Quoted 15 lines
Quoted 15 lines

I'm also not sure about -std=c99. While you can grep for some -std=gnu99 in the code, these are just some outdated comments in the source, not passed to make.

Quoted 11 lines
(quoted diff) +3 -0
+LDLIBS			+= -lpthread
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +2 -0
new file mode 100644
index 000000000..131bcfd66
@@ -0,0 +1,2165 @@
+ //  Copyright (c) Google LLC, 2018
+ //  SPDX-License-Identifier: GPL-2.0-or-later
Quoted 7 lines
Quoted 3 lines

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c line 4

Quoted 2 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +2 -0
+ //
+ //{

Why these lines?

To navigate better within the source code within various areas in it. You go to the line and press ???%??? in vi or whatever you use to go to the matching curly-brace in your source code editor.

Please don't do that.

Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +11 -0
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <assert.h>
+#include <sys/types.h>
Quoted 8 lines

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c line 22

Quoted 7 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +7 -0
+#include <sys/time.h>
+#include <sys/signal.h>
+#include <sys/uio.h>
+#include <sys/file.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>

Some of the includes will not be needed if you use API functions (SAFE_*, [5], [6]).

Quoted 1 line

I???d rather base the test cases on standard UNIX system calls (Linux is mostly UNIX compliant), there is no value in using non standard APIs which I don???t want to have to bother learning about.

These are not non-standard APIs, these are just tiny wrappers around standard UNIX apis that handle failures automatically, which greatly simplifies the test code.

Quoted 9 lines
Quoted 7 lines

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c line 26

Quoted 4 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +4 -0
+// #define RECVMMSG_USE_SCTP
+#ifdef RECVMMSG_USE_SCTP
+#include <netinet/sctp.h>
+#endif

Code related to RECVMMSG_USE_SCTP should be checked with autotools. There is our header include/lapi/sctp.h, you can include it and add (in separate commit) definitions, which are needed. If you really need netinet/sctp.h header, you can add exit clause with TST_TEST_TCONF

I???ll address this later with a later patch. For now it causes no harm. Right?

Sure.

Quoted 9 lines
Quoted 4 lines

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c line 28

Quoted 2 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +2 -0
+
+#define TST_NO_DEFAULT_MAIN

You're not supposed to use this

Its there for a reason. I have my own main() program, main() is standard and part of C, don???t want to learn about some other stuff unrelated to what I am testing. In UNIX programs start in main() right?

If you are writing LTP test you are not supposed to define main().

Seriously you just need to write the function that does the test and that's it. Plese do not fight the infrastructure that is there to help you and to make your life easier.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +4 -0
+int con_receive_iovec_boundary_checks(con_t *conp, int tn, size_t niov);
+int con_receive_iovec_boundary_checks_peeking(con_t *conp, int tn, size_t niov);
+int con_receive_file_descriptor(con_t *conp, int tn, int cloexec_flag,
+				bool some_data, ssize_t controllen_delta);
Quoted 8 lines

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c line 38

Quoted 6 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +6 -0
+int con_message_too_long_to_fit_might_discard_bytes(con_t *conp, int tn,
+						    int type);
+int con_receive_waits_for_message(con_t *conp, int tn);
+int con_receiver_doesnt_wait_for_messages(con_t *conp, int tn);
+int con_receive_returns_what_is_available(con_t *conp, int tn);
+int con_empty_datagram_received_as_empty_datagram(con_t *conp, int tn);

Function signatures aren't needed when used just in one file. Actually, in this case we declare functions as static.

Quoted 3 lines

The ARE required unless you reorganize you code to be all in the order of called functions preceding called functions, which is silly. Furthermore if there were mutually recursive functions you couldn???t do that either.

Having ???static??? for internal functions only matters if the test program is more than one source file. This is just one file. Its easier to debug when the symbols are visible to the debugger, with some compilers ???static??? functions can not be debugged because the symbols end up not being in the symbol table.

Actually neither of that is true.

Having static defined tells the compiler that the function is used only in the local file, which can for example tell you that some of the functions are unused.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +4 -0
+ //  ensure() tests something that shouldn't fail, doesn't abort like assert()
+
+#define ensure(test_number, expr)					    \
+	((expr) ? (test_verbose < 2 ||			    		    \
Quoted 8 lines

testcases/kernel/syscalls/recvmmsg/recvmmsg01.c line 48

Quoted 6 lines
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c new file +6 -0
+		   (print_prefix(test_number),				    \
+		    printf("%s(): true: " #expr " \n", __FUNCTION__)))	    \
+		: (++ensure_failures,					    \
+		   printf("test_number = %d: %s(): false: "		    \
+			  #expr " : failed\n",				    \
+			  test_number, __FUNCTION__)))

We use tst_res(TINFO, ...) instead of printf.
We try to avoid macros.

Quoted 1 line

Because printf() is documented. You use macros when there is no other choice. For example when you need to stringify something for example with the #expr above, when you want to use __FUNCTION__, __FILE__, and __LINE__, etc.

Plase do not use macros like that also the __FILE__ and __LINE__ is printed by the tst_res() itself. Please do not reinvent the wheel and use the standard LTP reporting API.

Signature · 2 lines
Cyril Hrubis
[email protected]
#4 lore raw

Cyril,

Can you help me understand why you don't want to allow this test case to make use of the C99 programming language?

It is only a 19 year old standard.

If there is a problem with C99 use, can you indicate that the problem is?

thank you,
Ramon

Quoted 2 lines · Cyril Hrubis

Actually the default for gcc is gnu90 which is close to c99 anyways, so we do not have to do anything about it.

#5 lore raw

Pardon the typo, can you indicate *what* the problem is with using C99.

Quoted 16 lines · Ramon Pantin

Cyril,

Can you help me understand why you don't want to allow this test case to make use of the C99 programming language?

It is only a 19 year old standard.

If there is a problem with C99 use, can you indicate that the problem is?

thank you,
Ramon

Quoted 2 lines · Cyril Hrubis

Actually the default for gcc is gnu90 which is close to c99 anyways, so we do not have to do anything about it.

#6 lore raw
In reply to Ramon Pantin

Hi!

Quoted 6 lines

Can you help me understand why you don't want to allow this test case to make use of the C99 programming language?

It is only a 19 year old standard.

If there is a problem with C99 use, can you indicate that the problem is?

What I'm trying to say is:

* Reasonable recent compilers support c99 features without -c99 explicitelly passed on command line

* It's a very bad idea to hardcode switches in random leaf Makefiles as from maintenance point of view this is real disaster

If we ever want to stick to some C standard it has to be a top level decision, but honestly I do prefer the compiler defaults.

Signature · 2 lines
Cyril Hrubis
[email protected]
#7 lore raw

Ok, so my test cases are using arrays on the stack dimensioned at run-time based on other values computed at run time. C99 is needed for that. I don't see any value in changing them to use alloca(), its a waste of time.

Is it really going to be an issue if I use a feature of a 19 year old language?

Quoted 18 lines · Cyril Hrubis

Hi!

Quoted 6 lines

Can you help me understand why you don't want to allow this test case to make use of the C99 programming language?

It is only a 19 year old standard.

If there is a problem with C99 use, can you indicate that the problem is?

What I'm trying to say is:

* Reasonable recent compilers support c99 features without -c99 explicitelly passed on command line

* It's a very bad idea to hardcode switches in random leaf Makefiles as from maintenance point of view this is real disaster

If we ever want to stick to some C standard it has to be a top level decision, but honestly I do prefer the compiler defaults.

#8 lore raw

Hi!

Quoted 4 lines

Ok, so my test cases are using arrays on the stack dimensioned at run-time based on other values computed at run time. C99 is needed for that. I don't see any value in changing them to use alloca(), its a waste of time.

That is not true, at least for gcc variable arrays have been supported as an extension in the default gnu89 mode for years now. I think that it even predates the c99 standard, which is what I'm trying to explain for quite some time now.

The only difference I'm aware of is how inline keyword behaves between c99 and gnu89 mode, there may be some other minor differencies though.

The C accepted by default by a modern (10 years old+) compilers is much closer than c99 than to the original c89.

Can we please stop this useless arguemnts and focus on the actual code now?

Signature · 2 lines
Cyril Hrubis
[email protected]
#9 lore raw
In reply to Cyril Hrubis

Hi Cyril,

About this statemement that you made:

"Function signatures aren't needed when used just in one file."

To whch I replied:

"ARE required unless you reorganize you code to be all in the order of called functions preceding called functions"

To which you replied:

"Actually neither of that is true"

If you don't use prototypes you do have to reorganize the functions in the order they are called.

Are you really questioning that? I don't want to have to explain that unless you don't understand why prototypes are required in some cases.

If you are not questioning that. Are you ok with me using prototypes?

I don't mind adding static, but do realize that that will indeed mean that in some compilation systems the sysmbols won't be in the symbol table and will make debugging harder. I don't care if you question this statment, don't have time to explain that.

regards,
Ramon Pantin

Quoted 12 lines · Cyril Hrubis
Quoted 12 lines
Quoted 12 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+int con_receive_iovec_boundary_checks(con_t *conp, int tn, size_t niov);
+int con_receive_iovec_boundary_checks_peeking(con_t *conp, int tn, size_t niov);
+int con_receive_file_descriptor(con_t *conp, int tn, int cloexec_flag,
+				bool some_data, ssize_t controllen_delta);
+int con_message_too_long_to_fit_might_discard_bytes(con_t *conp, int tn,
+						    int type);
+int con_receive_waits_for_message(con_t *conp, int tn);
+int con_receiver_doesnt_wait_for_messages(con_t *conp, int tn);
+int con_receive_returns_what_is_available(con_t *conp, int tn);
+int con_empty_datagram_received_as_empty_datagram(con_t *conp, int tn);

Function signatures aren't needed when used just in one file. Actually, in this case we declare functions as static.

Quoted 9 lines
Quoted 3 lines

The ARE required unless you reorganize you code to be all in the order of called functions preceding called functions, which is silly. Furthermore if there were mutually recursive functions you couldn???t do that either.

Having ???static??? for internal functions only matters if the test program is more than one source file. This is just one file. Its easier to debug when the symbols are visible to the debugger, with some compilers ???static??? functions can not be debugged because the symbols end up not being in the symbol table.

Actually neither of that is true.

Having static defined tells the compiler that the function is used only in the local file, which can for example tell you that some of the functions are unused.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20181103/52884ba9/attachment.html>

#10 lore raw

Hi!

Quoted 4 lines

About this statemement that you made:

"Function signatures aren't needed when used just in one file."

Quoted 8 lines

To whch I replied:

"ARE required unless you reorganize you code to be all in the order of called functions preceding called functions"

To which you replied:

"Actually neither of that is true"

I actually answered only the part about 'static' being useless. Sorry for not being clear on that.

Quoted 2 lines

If you don't use prototypes you do have to reorganize the functions in the order they are called.

That is indeed true.

Quoted 2 lines

Are you really questioning that? I don't want to have to explain that unless you don't understand why prototypes are required in some cases.

Not at all.

Quoted 1 line

If you are not questioning that. Are you ok with me using prototypes?

I do prefer to organize tests so that we don't have to use them, but I can live with code that does not follow that as well.

Quoted 4 lines

I don't mind adding static, but do realize that that will indeed mean that in some compilation systems the sysmbols won't be in the symbol table and will make debugging harder. I don't care if you question this statment, don't have time to explain that.

For modern enough compilers and debuggers this is not true. Ancient tooling may loose some debugging information when functions are inlined though.

Signature · 2 lines
Cyril Hrubis
[email protected]