[PATCH 3/3] testsuite/dhcpd0x: Tests automatized

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Mar 31 09:11:54 UTC 2020


On 31/03/2020 10:57, Moyano, Gabriel wrote:
> diff --git a/testsuite/dhcpcd01/test_main.c b/testsuite/dhcpcd01/test_main.c
> index 358b4ac8..f04c3270 100644
> --- a/testsuite/dhcpcd01/test_main.c
> +++ b/testsuite/dhcpcd01/test_main.c
> @@ -34,6 +34,7 @@
>   
>   #include <rtems.h>
>   #include <rtems/dhcpcd.h>
> +#include <fcntl.h>
>   
>   #define TEST_NAME "LIBBSD DHCPCD 1"
>   
> @@ -42,11 +43,17 @@ dhcpcd_hook_handler(rtems_dhcpcd_hook *hook, char *const *env)
>   {
>   
>   	(void)hook;
> +	int fd;
> +
> +	fd = open("/var/hook_out", O_CREAT | O_WRONLY,
> +		S_IRWXU | S_IRWXG | S_IRWXO);
>   
>   	while (*env != NULL) {
> -		printf("%s\n", *env);
> +		dprintf(fd, "%s\n", *env);
Do we see the environment in the test output after this change? What 
happens if "/var" doesn't exist? I would do the synchronization with the 
main thread with an event or semaphore instead of a file.
>   		++env;
>   	}
> +
> +	close(fd);
>   }
>   
>   static rtems_dhcpcd_hook dhcpcd_hook = {
> @@ -57,11 +64,22 @@ static rtems_dhcpcd_hook dhcpcd_hook = {
>   static void
>   test_main(void)
>   {
> +	int fd;
>   
> +	// Add hook
>   	rtems_dhcpcd_add_hook(&dhcpcd_hook);
What is the purpose of this comment? For a function with the name 
rtems_dhcpcd_add_hook() it should be obvious that it adds a hook.
>   
> -	rtems_task_delete(RTEMS_SELF);
> -	assert(0);
> +	// Verify whether an output file is created by the hook
Please use the FreeBSD coding style.
> +	while(true)
> +	{
> +		fd = open("/var/hook_out", O_RDONLY);
> +		if (fd >= 0)
> +		{
> +			close(fd);
> +			exit(0);
> +		}
> +		rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(1000));
> +	}
>   }


More information about the devel mailing list