On 15.06.2018 21:46, Alex Bennée wrote:
> The fixed path and ports get in the way of running our tests and
> builds in parallel. Instead of using TESTPATH we use mkdtemp() and
> instead of a fixed port we allow the kernel to assign one and query it
> afterwards.
> 
> Signed-off-by: Alex Bennée <alex.ben...@linaro.org>
> ---
>  tests/tcg/multiarch/linux-test.c | 37 ++++++++++++++++----------------
>  1 file changed, 19 insertions(+), 18 deletions(-)
> 
> diff --git a/tests/tcg/multiarch/linux-test.c 
> b/tests/tcg/multiarch/linux-test.c
> index 6f2c531474..3f73b96420 100644
> --- a/tests/tcg/multiarch/linux-test.c
> +++ b/tests/tcg/multiarch/linux-test.c
> @@ -41,8 +41,6 @@
>  #include <setjmp.h>
>  #include <sys/shm.h>
>  
> -#define TESTPATH "/tmp/linux-test.tmp"
> -#define TESTPORT 7654
>  #define STACK_SIZE 16384
>  
>  static void error1(const char *filename, int line, const char *fmt, ...)
> @@ -85,19 +83,15 @@ static void test_file(void)
>      struct iovec vecs[2];
>      DIR *dir;
>      struct dirent *de;
> +    char template[] = "/tmp/linux-test-XXXXXX";
> +    char *tmpdir = mkdtemp(template);
>  
> -    /* clean up, just in case */
> -    unlink(TESTPATH "/file1");
> -    unlink(TESTPATH "/file2");
> -    unlink(TESTPATH "/file3");
> -    rmdir(TESTPATH);
> +    chk_error(strlen(tmpdir));

That line looks wrong to me. According to my man-page of mkdtemp(), it
returns either NULL or a pointer to the modified string.
In case of NULL, strlen(tmpdir) will simply crash. And even if it would
not crash, strlen() only returns values >= 0, so there is no way the
chk_error could ever report an error here.

 Thomas

Reply via email to