[LTP] [PATCH v3 1/1] Extend ioctl02 to test termio and termios

Petr Vorel pvorel@suse.cz
Fri Dec 1 19:48:16 CET 2023


I posted it to the cover letter, but better to add it also to the patch:

BTW this v3 is exactly the same as v2. What am I missing?

Cyril asked you [1] to pass flag parameter to the macro, because you modify it
and it's not a good code to modify variable in macro without passing it.
Obviously you should return it as well (not that compact code, but it's really
better).

I understood it like:

#define CMP_ATTR(term_exp, term, attr, flag) \
	({                                                      \
	flag += cmp_attr((term_exp).attr, (term).attr, #attr);	\
	flag;                                                   \
	})

To speedup this, I merged with following diff below.
Thanks!

Kind regards,
Petr

[1] https://lore.kernel.org/ltp/ZUUV9MiVadNA75WY@yuki/

+++ testcases/kernel/syscalls/ioctl/ioctl02.c
@@ -8,8 +8,7 @@
 /*\
  * [Description]
  *
- * Testcase to test the TCGETA/TCGETS, and TCSETA/TCSETS ioctl
- * implementations for the tty driver
+ * Test TCGETA/TCGETS and TCSETA/TCSETS ioctl implementations for tty driver.
  *
  * In this test, the parent and child open the parentty and the childtty
  * respectively.  After opening the childtty the child flushes the stream
@@ -27,19 +26,10 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <termios.h>
 
 #include "lapi/ioctl.h"
-
-#include "tst_checkpoint.h"
 #include "tst_test.h"
-#include "tst_safe_macros.h"
 
 static struct termio termio, termio_exp;
 static struct termios termios, termios_exp, termios_bak;
@@ -176,21 +166,28 @@ static int cmp_c_cc(unsigned char *exp_c_cc, unsigned char *act_c_cc, int ncc)
 	return fails;
 }
 
-#define CMP_ATTR(term_exp, term, attr) \
-	(flag += cmp_attr((term_exp).attr, (term).attr, #attr))
+#define CMP_ATTR(term_exp, term, attr, flag)				\
+({															\
+	flag += cmp_attr((term_exp).attr, (term).attr, #attr);	\
+	flag;                                                   \
+})
 
-#define CMP_C_CC(term_exp, term) \
-	(flag += cmp_c_cc(term_exp.c_cc, term.c_cc, sizeof(term.c_cc)))
+#define CMP_C_CC(term_exp, term, flag)								\
+({																	\
+	flag += cmp_c_cc(term_exp.c_cc, term.c_cc, sizeof(term.c_cc));	\
+	flag;															\
+})
 
 static void chk_tty_parms_termio(void)
 {
 	int flag = 0;
 
-	CMP_ATTR(termio_exp, termio, c_line);
-	CMP_C_CC(termio_exp, termio);
-	CMP_ATTR(termio_exp, termio, c_lflag);
-	CMP_ATTR(termio_exp, termio, c_iflag);
-	CMP_ATTR(termio_exp, termio, c_oflag);
+	flag = CMP_ATTR(termio_exp, termio, c_line, flag);
+	flag = CMP_C_CC(termio_exp, termio, flag);
+	flag = CMP_ATTR(termio_exp, termio, c_lflag, flag);
+	flag = CMP_ATTR(termio_exp, termio, c_iflag, flag);
+	flag = CMP_ATTR(termio_exp, termio, c_oflag, flag);
+
 	if (!flag)
 		tst_res(TPASS, "TCGETA/TCSETA tests");
 }
@@ -199,11 +196,12 @@ static void chk_tty_parms_termios(void)
 {
 	int flag = 0;
 
-	CMP_ATTR(termios_exp, termios, c_line);
-	CMP_C_CC(termios_exp, termios);
-	CMP_ATTR(termios_exp, termios, c_lflag);
-	CMP_ATTR(termios_exp, termios, c_iflag);
-	CMP_ATTR(termios_exp, termios, c_oflag);
+	flag = CMP_ATTR(termios_exp, termios, c_line, flag);
+	flag = CMP_C_CC(termios_exp, termios, flag);
+	flag = CMP_ATTR(termios_exp, termios, c_lflag, flag);
+	flag = CMP_ATTR(termios_exp, termios, c_iflag, flag);
+	flag = CMP_ATTR(termios_exp, termios, c_oflag, flag);
+
 	if (!flag)
 		tst_res(TPASS, "TCGETS/TCSETS tests");
 }
@@ -255,4 +253,4 @@ static struct tst_test test = {
 		{"D:", &device, "Tty device. For example, /dev/tty[0-9]"},
 		{}
 	}
-};
\ No newline at end of file
+};


More information about the ltp mailing list