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

Moyano, Gabriel gabriel.moyano at dlr.de
Tue Mar 31 08:57:56 UTC 2020


---
 testsuite/dhcpcd01/test_main.c | 24 +++++++++++++++++++++---
 testsuite/dhcpcd02/test_main.c | 19 +++++++++++++++++--
 2 files changed, 38 insertions(+), 5 deletions(-)

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);
 		++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);
 
-	rtems_task_delete(RTEMS_SELF);
-	assert(0);
+	// Verify whether an output file is created by the hook
+	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));
+	}
 }
 
 #define DEFAULT_NETWORK_DHCPCD_ENABLE
diff --git a/testsuite/dhcpcd02/test_main.c b/testsuite/dhcpcd02/test_main.c
index 611c12b1..d5a6900f 100644
--- a/testsuite/dhcpcd02/test_main.c
+++ b/testsuite/dhcpcd02/test_main.c
@@ -32,14 +32,29 @@
 #include <assert.h>
 
 #include <rtems.h>
+#include <fcntl.h>
+#include <glob.h>
 
 #define TEST_NAME "LIBBSD DHCPCD 2"
 
 static void
 test_main(void)
 {
-	rtems_task_delete(RTEMS_SELF);
-	assert(0);
+	int fd;
+	glob_t globbuf;
+
+	// Verify whether the dhcpcd creates a file with the lease
+	while(true)
+	{
+		glob("/var/db/dhcpcd-*.lease", 0, NULL, &globbuf);
+		fd = open(globbuf.gl_pathv[0], O_RDONLY);
+		if (fd >= 0)
+		{
+			close(fd);
+			exit(0);
+		}
+		rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(1000));
+	}
 }
 
 #define DEFAULT_NETWORK_DHCPCD_ENABLE
-- 
2.12.3



More information about the devel mailing list