Re: [Qemu-devel] [PATCH v1 10/24] tests/tcg/multiarch: Build fix for linux-test

2018-05-25 Thread Alex Bennée

Philippe Mathieu-Daudé  writes:

> On 04/15/2018 09:07 PM, Philippe Mathieu-Daudé wrote:
>> Hi Fam, Alex,
>>
>> On 04/10/2018 04:39 PM, Alex Bennée wrote:
>>> From: Fam Zheng 
>>>
>>> To keep the compiler happy, and to fit in our buildsys flags:
>>>
>>> - Make local functions "static"
>>> - #ifdef out unused functions
>>> - drop cutils/osdep dependencies
>>>
>>> Signed-off-by: Fam Zheng 
>>> [AJB: drop cutils/osdep dependencies]
>>> Signed-off-by: Alex Bennée 
>>> ---
>>>  tests/tcg/multiarch/linux-test.c | 68 
>>> +---
>>>  1 file changed, 21 insertions(+), 47 deletions(-)
>>>
>>> diff --git a/tests/tcg/multiarch/linux-test.c 
>>> b/tests/tcg/multiarch/linux-test.c
>>> index 5070d31446..4457bd04ba 100644
>>> --- a/tests/tcg/multiarch/linux-test.c
>>> +++ b/tests/tcg/multiarch/linux-test.c
>>> @@ -16,7 +16,6 @@
>>>   *  You should have received a copy of the GNU General Public License
>>>   *  along with this program; if not, see .
>>>   */
>>> -#define _GNU_SOURCE
>>>  #include 
>>>  #include 
>>>  #include 
>>> @@ -31,6 +30,7 @@
>>>  #include 
>>>  #include 
>>>  #include 
>>> +#include 
>>>  #include 
>>>  #include 
>>>  #include 
>>> @@ -39,13 +39,12 @@
>>>  #include 
>>>  #include 
>>>  #include 
>>> -#include "qemu/cutils.h"
>>>
>>>  #define TESTPATH "/tmp/linux-test.tmp"
>>>  #define TESTPORT 7654
>>>  #define STACK_SIZE 16384
>>>
>>> -void error1(const char *filename, int line, const char *fmt, ...)
>>> +static void error1(const char *filename, int line, const char *fmt, ...)
>>>  {
>>>  va_list ap;
>>>  va_start(ap, fmt);
>>> @@ -56,7 +55,7 @@ void error1(const char *filename, int line, const char 
>>> *fmt, ...)
>>>  exit(1);
>>>  }
>>>
>>> -int __chk_error(const char *filename, int line, int ret)
>>> +static int __chk_error(const char *filename, int line, int ret)
>>>  {
>>>  if (ret < 0) {
>>>  error1(filename, line, "%m (ret=%d, errno=%d)",
>>> @@ -73,7 +72,7 @@ int __chk_error(const char *filename, int line, int ret)
>>>
>>>  #define FILE_BUF_SIZE 300
>>>
>>> -void test_file(void)
>>> +static void test_file(void)
>>>  {
>>>  int fd, i, len, ret;
>>>  uint8_t buf[FILE_BUF_SIZE];
>>> @@ -210,7 +209,7 @@ void test_file(void)
>>>  chk_error(rmdir(TESTPATH));
>>>  }
>>>
>>> -void test_fork(void)
>>> +static void test_fork(void)
>>>  {
>>>  int pid, status;
>>>
>>> @@ -224,7 +223,7 @@ void test_fork(void)
>>>  error("waitpid status=0x%x", status);
>>>  }
>>>
>>> -void test_time(void)
>>> +static void test_time(void)
>>>  {
>>>  struct timeval tv, tv2;
>>>  struct timespec ts, rem;
>>> @@ -251,34 +250,7 @@ void test_time(void)
>>>  error("getrusage");
>>>  }
>>>
>>> -void pstrcpy(char *buf, int buf_size, const char *str)
>>> -{
>>> -int c;
>>> -char *q = buf;
>>> -
>>> -if (buf_size <= 0)
>>> -return;
>>> -
>>> -for(;;) {
>>> -c = *str++;
>>> -if (c == 0 || q >= buf + buf_size - 1)
>>> -break;
>>> -*q++ = c;
>>> -}
>>> -*q = '\0';
>>> -}
>>> -
>>> -/* strcat and truncate. */
>>> -char *pstrcat(char *buf, int buf_size, const char *s)
>>> -{
>>> -int len;
>>> -len = strlen(buf);
>>> -if (len < buf_size)
>>> -pstrcpy(buf + len, buf_size - len, s);
>>> -return buf;
>>> -}
>>> -
>>> -int server_socket(void)
>>> +static int server_socket(void)
>>>  {
>>>  int val, fd;
>>>  struct sockaddr_in sockaddr;
>>> @@ -298,7 +270,7 @@ int server_socket(void)
>>>
>>>  }
>>>
>>> -int client_socket(void)
>>> +static int client_socket(void)
>>>  {
>>>  int fd;
>>>  struct sockaddr_in sockaddr;
>>> @@ -312,9 +284,9 @@ int client_socket(void)
>>>  return fd;
>>>  }
>>>
>>> -const char socket_msg[] = "hello socket\n";
>>> +static const char socket_msg[] = "hello socket\n";
>>>
>>> -void test_socket(void)
>>> +static void test_socket(void)
>>>  {
>>>  int server_fd, client_fd, fd, pid, ret, val;
>>>  struct sockaddr_in sockaddr;
>>> @@ -348,9 +320,10 @@ void test_socket(void)
>>>  chk_error(close(server_fd));
>>>  }
>>>
>>> +#if 0
>>
>> Why keep this now dead code?
>
> You can use: #ifdef LINUX_TEST_CLONE
>
> But this my be even better to move this chunk as a stand-alone test in a
> new file, linux-clone-test.c and add a make rule to only include it in
> the TEST_SRCS var when the host is able to run it.

More of it gets un-#if 0'd in the follow-up patch. There is certainly
more clean-up to be done but for now I've just left it disabled. I think
splitting out a specific test-clone patch is a good follow-up candidate
though.

>
>>
>>>  #define WCOUNT_MAX 512
>>>
>>> -void test_pipe(void)
>>> +static void test_pipe(void)
>>>  {
>>>  fd_set rfds, wfds;
>>>  int fds[2], fd_max, ret;
>>> @@ -391,10 +364,10 @@ void test_pipe(void)
>>>  chk_error(close(fds[1]));
>>>  }
>>>
>>> -int 

Re: [Qemu-devel] [PATCH v1 10/24] tests/tcg/multiarch: Build fix for linux-test

2018-04-16 Thread Alex Bennée

Philippe Mathieu-Daudé  writes:

> On 04/15/2018 09:07 PM, Philippe Mathieu-Daudé wrote:
>> Hi Fam, Alex,
>> 
>> On 04/10/2018 04:39 PM, Alex Bennée wrote:
>>> From: Fam Zheng 
>>>
>>> To keep the compiler happy, and to fit in our buildsys flags:
>>>
>>> - Make local functions "static"
>>> - #ifdef out unused functions
>>> - drop cutils/osdep dependencies
>>>
>>> Signed-off-by: Fam Zheng 
>>> [AJB: drop cutils/osdep dependencies]
>>> Signed-off-by: Alex Bennée 
>>> ---
>>>  tests/tcg/multiarch/linux-test.c | 68 
>>> +---
>>>  1 file changed, 21 insertions(+), 47 deletions(-)
>>>
>>> diff --git a/tests/tcg/multiarch/linux-test.c 
>>> b/tests/tcg/multiarch/linux-test.c
>>> index 5070d31446..4457bd04ba 100644
>>> --- a/tests/tcg/multiarch/linux-test.c
>>> +++ b/tests/tcg/multiarch/linux-test.c
>>> @@ -16,7 +16,6 @@
>>>   *  You should have received a copy of the GNU General Public License
>>>   *  along with this program; if not, see .
>>>   */
>>> -#define _GNU_SOURCE
>>>  #include 
>>>  #include 
>>>  #include 
>>> @@ -31,6 +30,7 @@
>>>  #include 
>>>  #include 
>>>  #include 
>>> +#include 
>>>  #include 
>>>  #include 
>>>  #include 
>>> @@ -39,13 +39,12 @@
>>>  #include 
>>>  #include 
>>>  #include 
>>> -#include "qemu/cutils.h"
>>>  
>>>  #define TESTPATH "/tmp/linux-test.tmp"
>>>  #define TESTPORT 7654
>>>  #define STACK_SIZE 16384
>>>  
>>> -void error1(const char *filename, int line, const char *fmt, ...)
>>> +static void error1(const char *filename, int line, const char *fmt, ...)
>>>  {
>>>  va_list ap;
>>>  va_start(ap, fmt);
>>> @@ -56,7 +55,7 @@ void error1(const char *filename, int line, const char 
>>> *fmt, ...)
>>>  exit(1);
>>>  }
>>>  
>>> -int __chk_error(const char *filename, int line, int ret)
>>> +static int __chk_error(const char *filename, int line, int ret)
>>>  {
>>>  if (ret < 0) {
>>>  error1(filename, line, "%m (ret=%d, errno=%d)",
>>> @@ -73,7 +72,7 @@ int __chk_error(const char *filename, int line, int ret)
>>>  
>>>  #define FILE_BUF_SIZE 300
>>>  
>>> -void test_file(void)
>>> +static void test_file(void)
>>>  {
>>>  int fd, i, len, ret;
>>>  uint8_t buf[FILE_BUF_SIZE];
>>> @@ -210,7 +209,7 @@ void test_file(void)
>>>  chk_error(rmdir(TESTPATH));
>>>  }
>>>  
>>> -void test_fork(void)
>>> +static void test_fork(void)
>>>  {
>>>  int pid, status;
>>>  
>>> @@ -224,7 +223,7 @@ void test_fork(void)
>>>  error("waitpid status=0x%x", status);
>>>  }
>>>  
>>> -void test_time(void)
>>> +static void test_time(void)
>>>  {
>>>  struct timeval tv, tv2;
>>>  struct timespec ts, rem;
>>> @@ -251,34 +250,7 @@ void test_time(void)
>>>  error("getrusage");
>>>  }
>>>  
>>> -void pstrcpy(char *buf, int buf_size, const char *str)
>>> -{
>>> -int c;
>>> -char *q = buf;
>>> -
>>> -if (buf_size <= 0)
>>> -return;
>>> -
>>> -for(;;) {
>>> -c = *str++;
>>> -if (c == 0 || q >= buf + buf_size - 1)
>>> -break;
>>> -*q++ = c;
>>> -}
>>> -*q = '\0';
>>> -}
>>> -
>>> -/* strcat and truncate. */
>>> -char *pstrcat(char *buf, int buf_size, const char *s)
>>> -{
>>> -int len;
>>> -len = strlen(buf);
>>> -if (len < buf_size)
>>> -pstrcpy(buf + len, buf_size - len, s);
>>> -return buf;
>>> -}
>>> -
>>> -int server_socket(void)
>>> +static int server_socket(void)
>>>  {
>>>  int val, fd;
>>>  struct sockaddr_in sockaddr;
>>> @@ -298,7 +270,7 @@ int server_socket(void)
>>>  
>>>  }
>>>  
>>> -int client_socket(void)
>>> +static int client_socket(void)
>>>  {
>>>  int fd;
>>>  struct sockaddr_in sockaddr;
>>> @@ -312,9 +284,9 @@ int client_socket(void)
>>>  return fd;
>>>  }
>>>  
>>> -const char socket_msg[] = "hello socket\n";
>>> +static const char socket_msg[] = "hello socket\n";
>>>  
>>> -void test_socket(void)
>>> +static void test_socket(void)
>>>  {
>>>  int server_fd, client_fd, fd, pid, ret, val;
>>>  struct sockaddr_in sockaddr;
>>> @@ -348,9 +320,10 @@ void test_socket(void)
>>>  chk_error(close(server_fd));
>>>  }
>>>  
>>> +#if 0
>> 
>> Why keep this now dead code?
>
> You can use: #ifdef LINUX_TEST_CLONE
>
> But this my be even better to move this chunk as a stand-alone test in a
> new file, linux-clone-test.c and add a make rule to only include it in
> the TEST_SRCS var when the host is able to run it.

There is certainly some cleaning up to the tests to do. I'll put it in a
separate patch though.

>
>> 
>>>  #define WCOUNT_MAX 512
>>>  
>>> -void test_pipe(void)
>>> +static void test_pipe(void)
>>>  {
>>>  fd_set rfds, wfds;
>>>  int fds[2], fd_max, ret;
>>> @@ -391,10 +364,10 @@ void test_pipe(void)
>>>  chk_error(close(fds[1]));
>>>  }
>>>  
>>> -int thread1_res;
>>> -int thread2_res;
>>> +static int thread1_res;
>>> +static int thread2_res;
>>>  
>>> 

Re: [Qemu-devel] [PATCH v1 10/24] tests/tcg/multiarch: Build fix for linux-test

2018-04-11 Thread Thomas Huth
On 10.04.2018 21:39, Alex Bennée wrote:
> From: Fam Zheng 
> 
> To keep the compiler happy, and to fit in our buildsys flags:
> 
> - Make local functions "static"
> - #ifdef out unused functions
> - drop cutils/osdep dependencies
> 
> Signed-off-by: Fam Zheng 
> [AJB: drop cutils/osdep dependencies]
> Signed-off-by: Alex Bennée 
> ---
>  tests/tcg/multiarch/linux-test.c | 68 
> +---
>  1 file changed, 21 insertions(+), 47 deletions(-)

Reviewed-by: Thomas Huth