All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Stancek <jstancek@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/2] SAFE_MACROS: Redirect to tst_brk_() early
Date: Mon, 13 Feb 2017 08:30:02 -0500 (EST)	[thread overview]
Message-ID: <1698464367.3738204.1486992602576.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <20170213080929.GB16567@rei.suse.cz>



----- Original Message -----
> From: "Cyril Hrubis" <chrubis@suse.cz>
> To: "Jan Stancek" <jstancek@redhat.com>
> Cc: ltp@lists.linux.it
> Sent: Monday, 13 February, 2017 9:09:29 AM
> Subject: Re: [LTP] [PATCH 1/2] SAFE_MACROS: Redirect to tst_brk_() early
> 
> Hi!
> > How about we provide different version of tst_brkm for library and
> > different
> > for tests? For library we obviously want to allow calls from both oldlib
> > and
> > newlib code, and redirect as needed. But for tests (users of library) we
> > would allow only oldlib tests to call tst_brkm.
> > 
> > So for tests tst_brkm_ stays the same - NORETURN, for library code, we
> > use either tst_brk_ or tst_brkm_, which means we'll need to fix any
> > potential warnings only in library.
> > 
> > This also forbids usage of tst_brkm from newlib tests, previously
> > it was OK if you didn't provide cleanup, now it would reject all
> > calls from newlib tests.
> 
> This sounds good. The only problem we could hit is some common code
> outside the lib/ directory used in both newlib and oldlib tests. Which
> was the original reason I put the redirection directly into the
> tst_brkm_() code...

Good point, I guess we'd have to do the same as for ltp/lib, that
is add -DLTPLIB and deal with warnings.

---

Or we don't make tst_brkm_ so strict, we keep it as it is,
but we find way to prevent newlib users only direct usage
of tst_brkm() macro:

diff --git a/include/old/safe_macros.h b/include/old/safe_macros.h
index 25001e806c12..96fb0c21876e 100644
--- a/include/old/safe_macros.h
+++ b/include/old/safe_macros.h
@@ -331,10 +331,10 @@ static inline int safe_setrlimit(const char *file, const int lineno,
 
 #define SAFE_IOCTL(cleanup_fn, fd, request, ...)             \
        ({int ret = ioctl(fd, request, __VA_ARGS__);         \
-         ret < 0 ?                                          \
-          tst_brkm(TBROK | TERRNO, cleanup_fn,              \
-                   "ioctl(%i,%s,...) failed", fd, #request) \
-        : ret;})
+         if (ret < 0)                                       \
+             tst_brkm(TBROK | TERRNO, cleanup_fn,           \
+                   "ioctl(%i,%s,...) failed", fd, #request); \
+         ret;})
 
 #endif /* __SAFE_MACROS_H__ */
 #endif /* __TEST_H__ */
diff --git a/include/old/test.h b/include/old/test.h
index d49256073741..93d0c360dfca 100644
--- a/include/old/test.h
+++ b/include/old/test.h
@@ -34,6 +34,10 @@
 #ifndef __TEST_H__
 #define __TEST_H__
 
+#ifdef TST_TEST_H__
+#error newlib already included
+#endif
+
 #include <stdio.h>
 #include <signal.h>
 #include <unistd.h>
@@ -153,9 +157,19 @@ void tst_resm_hexd_(const char *file, const int lineno, int ttype,
 void tst_brkm_(const char *file, const int lineno, int ttype,
        void (*func)(void), const char *arg_fmt, ...)
        __attribute__ ((format (printf, 5, 6))) LTP_ATTRIBUTE_NORETURN;
-#define tst_brkm(ttype, func, arg_fmt, ...) \
-       tst_brkm_(__FILE__, __LINE__, (ttype), (func), \
-                 (arg_fmt), ##__VA_ARGS__)
+
+#ifdef LTPLIB
+#include "ltp_priv.h"
+# define tst_brkm(flags, cleanup, fmt, ...) do { \
+               if (tst_test) \
+                       tst_brk_(__FILE__, __LINE__, flags, fmt, ##__VA_ARGS__); \
+               else \
+                       tst_brkm_(__FILE__, __LINE__, flags, cleanup, fmt, ##__VA_ARGS__); \
+               } while (0)
+#else
+# define tst_brkm(flags, cleanup, fmt, ...) \
+                       tst_brkm_(__FILE__, __LINE__, flags, cleanup, fmt, ##__VA_ARGS__)
+#endif
 
 void tst_require_root(void);
 void tst_exit(void) LTP_ATTRIBUTE_NORETURN;
diff --git a/include/tst_test.h b/include/tst_test.h
index 7dc371ccf095..463418ab2de2 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -18,6 +18,10 @@
 #ifndef TST_TEST_H__
 #define TST_TEST_H__
 
+#ifdef __TEST_H__
+#error oldlib already included
+#endif
+
 #include <unistd.h>
 
 #include "tst_common.h"
diff --git a/lib/Makefile b/lib/Makefile
index 663455ee31ad..6b3f6e1917fb 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -24,7 +24,7 @@ top_srcdir            ?= ..
 
 include $(top_srcdir)/include/mk/env_pre.mk
 
-CFLAGS                 += -I.
+CFLAGS                 += -I. -DLTPLIB
 
 ifneq ($(ANDROID),1)
 FILTER_OUT_DIRS                += android_libpthread android_librt


> We would also need to sprinkle the library code with returns as a part
> of the patch if I'm not mistaken.

Agreed, after removing NORETURN there's no way around that.

--

I keep thinking if we shouldn't do those ~30 trivial changes,
and have one simple tst_brkm() macro for both library and tests.

Regards,
Jan

  reply	other threads:[~2017-02-13 13:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-09 14:44 [LTP] [PATCH 1/2] SAFE_MACROS: Redirect to tst_brk_() early Cyril Hrubis
2017-02-09 14:44 ` [LTP] [PATCH 2/2] newlib: Allow SAFE_MACROS to be called from cleanup Cyril Hrubis
2017-02-09 15:56 ` [LTP] [PATCH 1/2] SAFE_MACROS: Redirect to tst_brk_() early Jan Stancek
2017-02-09 16:11   ` Cyril Hrubis
2017-02-10  8:27     ` Jan Stancek
2017-02-10  8:35       ` Jan Stancek
2017-02-10  9:38         ` Jan Stancek
2017-02-13  8:09           ` Cyril Hrubis
2017-02-13 13:30             ` Jan Stancek [this message]
2017-02-13 15:14               ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1698464367.3738204.1486992602576.JavaMail.zimbra@redhat.com \
    --to=jstancek@redhat.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.