On Wed, 2021-08-25 at 17:09 +0200, Jan Kiszka wrote:
> On 25.08.21 12:32, Florian Bezdeka wrote:
> > Make sure that named semaphores as well as mqueues are exported to the
> > procfs.
> > 
> > Signed-off-by: Florian Bezdeka <[email protected]>
> > ---
> >  testsuite/smokey/leaks/leaks.c | 27 +++++++++++++++++++++++++++
> >  1 file changed, 27 insertions(+)
> > 
> > diff --git a/testsuite/smokey/leaks/leaks.c b/testsuite/smokey/leaks/leaks.c
> > index bbe5fc3ad..b867bc727 100644
> > --- a/testsuite/smokey/leaks/leaks.c
> > +++ b/testsuite/smokey/leaks/leaks.c
> > @@ -28,6 +28,7 @@
> >  #include <pthread.h>
> >  #include <fcntl.h>
> >  #include <sys/mman.h>
> > +#include <sys/stat.h>
> >  #include <semaphore.h>
> >  #include <mqueue.h>
> >  #include <signal.h>
> > @@ -71,6 +72,24 @@ const char *memdev[] = {
> >  
> >  static int memdevfd[3];
> >  
> > +static int procfs_exists(const char *type, const char *name)
> > +{
> > +   struct stat s;
> > +   char path[128];
> > +   int ret;
> > +
> > +   /* Ignore if the kernel seems to be compiled without procfs support */
> > +   if (stat("/proc/xenomai", &s) || !S_ISDIR(s.st_mode))
> > +           return 0;
> > +
> > +   ret = snprintf(path, 128, "%s/%s/%s", "/proc/xenomai/registry/posix",
> > +                  type, &name[1]);
> > +   if (ret < 0)
> > +           return -EINVAL;
> > +
> > +   return smokey_check_errno(stat(path, &s));
> > +}
> > +
> >  static unsigned long long get_used(void)
> >  {
> >     struct cobalt_memdev_stat statbuf;
> > @@ -121,6 +140,10 @@ static inline int subprocess_leak(void)
> >     if (ret)
> >             return ret;
> >  
> > +   ret = procfs_exists("sem", SEM_NAME);
> > +   if (ret)
> > +           return ret;
> > +
> 
> This comes too fast for the registry, see failing tests in CI, e.g.
> https://source.denx.de/Xenomai/xenomai-images/-/jobs/313503. The
> registration with /proc seems to happen asynchronously. If I add a
> usleep(100000) to procfs_exists(), the tests seem to pass.

ACK that's a race. The export itself is delegated to Linux, that's the
root cause. Let's try the usleep(). I don't have a better idea right
now.

> 
> Jan
> 
> >     sevt.sigev_notify = SIGEV_THREAD_ID;
> >     sevt.sigev_signo = SIGALRM;
> >     sevt.sigev_notify_thread_id = syscall(__NR_gettid);
> > @@ -132,6 +155,10 @@ static inline int subprocess_leak(void)
> >     if (ret < 0)
> >             return ret;
> >  
> > +   ret = procfs_exists("mqueue", MQ_NAME);
> > +   if (ret)
> > +           return ret;
> > +
> >     return 0;
> >  }
> >  
> > 
> 

Reply via email to