On Fri, Mar 18, 2016 at 10:14:26AM +0530, Jay Joshi wrote: > >From 6785e2dc6f15104537d2e27387279a04c9bcfb25 Mon Sep 17 00:00:00 2001 > From: JayRJoshi <jay.r.joshi...@gmail.com> > Date: Tue, 15 Mar 2016 16:41:39 +0530 > Subject: [PATCH] tests: add getcwd.test
getcwd.test seems to be popular nowadays. :) See also my comments on another getcwd.test submission. > --- /dev/null > +++ b/tests/getcwd.c > @@ -0,0 +1,50 @@ > +#include "tests.h" > + > +#include <sys/stat.h> > +#include <sys/syscall.h> > + <nitpick> You can include <sys/stat.h> after the check. </nitpick> > +#ifdef __NR_getcwd > + > +#include <stdio.h> > +#include <unistd.h> > +#include <errno.h> <nitpick> ifdef'ed includes look better when indented. </nitpick> > + > +#define sample_dir "getcwd.sample_dir" > + > +int > +main(void) > +{ > + long res; > + char cur_dir[2048]; 2048 is definitely less than current PATH_MAX value. > + if (mkdir(sample_dir, S_IRWXU)) > + perror_msg_and_fail("mkdir"); > + > + if (chdir(sample_dir)) > + perror_msg_and_skip("chdir"); Why mkdir error is fatal but chdir is not? > + res = syscall(__NR_getcwd, cur_dir, sizeof(cur_dir)); > + > + if (res != 0) { > + printf("getcwd(\"%s\", %zu) = %ld\n", cur_dir, sizeof(cur_dir), res); If cur_dir contains special characters, then this output won't match the output produced by strace. > + } else { > + perror_msg_and_fail("getcwd"); > + } > + > + if (rmdir(cur_dir)) > + perror_msg_and_fail("rmdir"); > + > + syscall(__NR_getcwd, cur_dir, sizeof(cur_dir)); > + > + printf("getcwd(%p, %zu) = -1 ENOENT (%m)\n", cur_dir, sizeof(cur_dir)); > + > + puts("+++ exited with 0 +++"); > + > + return 0; > +} > + > +#else > + > +SKIP_MAIN_UNDEFINED("__NR_getcwd"); > + > +#endif > diff --git a/tests/getcwd.test b/tests/getcwd.test > new file mode 100755 > index 0000000..c744c0e > --- /dev/null > +++ b/tests/getcwd.test > @@ -0,0 +1,11 @@ > +#!/bin/sh It would be a good idea to add a comment what's being tested here. This is much better than the first edition, but still looks a bit overcomplicated. For example, wouldn't a check for ERANGE instead of ENOENT make the whole test simpler? You won't need all these mkdir/chdir/rmdir calls. -- ldv
pgpUAT3XT3YlV.pgp
Description: PGP signature
------------------------------------------------------------------------------ Transform Data into Opportunity. Accelerate data analysis in your applications with Intel Data Analytics Acceleration Library. Click to learn more. http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
_______________________________________________ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel