[CRIU] [PATCH]v2 zdtm: test semi-closed unix stream connection for data loss

Ruslan Kuprieiev kupruser at gmail.com
Mon Aug 26 17:38:42 EDT 2013


On 08/27/2013 01:07 AM, Andrew Vagin wrote:
> On Mon, Aug 26, 2013 at 09:27:27PM +0400, Ruslan Kuprieiev wrote:
>> Hi!
>>
>> Added test for data loss in semi-closed stream unix connection.
> Why do you decide to add a new test? In a previous attempt you tryed to
> expand the socket02 test and I think it was the right way.
> You replaced one check on another and I suggested to add one more check
> and do nothing with the previous one.
>
It was impulsive decision=).
Here is one more try.
If this patch is ok, please, tell me if i should send it again with 
[PATCH]v3 tag.
-------------- next part --------------
Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>

diff --git a/test/zdtm/live/static/sockets02.c b/test/zdtm/live/static/sockets02.c
index 8ff38f8..3e6829d 100644
--- a/test/zdtm/live/static/sockets02.c
+++ b/test/zdtm/live/static/sockets02.c
@@ -12,6 +12,7 @@
 #include <sys/stat.h>
 #include <limits.h>
 #include <fcntl.h>
+#include <time.h>
 
 #include "zdtmtst.h"
 
@@ -21,7 +22,10 @@ const char *test_author	= "Pavel Emelyanov <xemul at parallels.com>\n";
 int main(int argc, char *argv[])
 {
 	int ssk_pair[2], ret;
-	char aux;
+	char aux, data;
+
+	srandom(time(NULL));
+	data = (char)random();
 
 	test_init(argc, argv);
 
@@ -30,6 +34,12 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
+	ret = write(ssk_pair[1], &data, sizeof(data));
+	if (ret != sizeof(data)) {
+		fail("write\n");
+		exit(1);
+	}
+
 	close(ssk_pair[1]);
 
 	test_daemon();
@@ -37,9 +47,12 @@ int main(int argc, char *argv[])
 
 	errno = 0;
 	ret = read(ssk_pair[0], &aux, sizeof(aux));
-	if (ret != 0 || errno != 0) {
+	if (ret != sizeof(data)) {
 		fail("Opened end in wrong state (%d/%d)", ret, errno);
 		return 0;
+	} else if (aux != data) {
+		fail("Data loss (write %d/read %d)", data, aux);
+		return 0;
 	}
 
 	errno = 0;


More information about the CRIU mailing list