PERFORCE change 165469 for review

Zhao Shuai zhaoshuai at FreeBSD.org
Tue Jun 30 14:24:24 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=165469

Change 165469 by zhaoshuai at zhaoshuai on 2009/06/30 14:23:35

	add new test in the regression tests
	bugs found in fifo_poll, not fixed

Affected files ...

.. //depot/projects/soc2009/fifo/fifo_test/regression/fifo_io/fifo_io.c#2 edit

Differences ...

==== //depot/projects/soc2009/fifo/fifo_test/regression/fifo_io/fifo_io.c#2 (text+ko) ====

@@ -1,6 +1,8 @@
 /*-
  * Copyright (c) 2005 Robert N. M. Watson
  * All rights reserved.
+ * Copyright (c) 2009 Zhao Shuai <zhaoshuai at FreeBSD.org>
+ * Google Summer of Code Project
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -1069,8 +1071,8 @@
  * based on earlier semantic tests: specifically, whether or not poll/select/
  * kevent will correctly inform on readable/writable state following I/O.
  *
- * It would be nice to also test status changes as a result of closing of one
- * or another fifo endpoint.
+ * test_events() also tests status changes as a result of closing of one or 
+ * another fifo endpoint.
  */
 static void
 test_events_outofbox(void)
@@ -1380,6 +1382,120 @@
 	cleanfifo2("testfifo", fd, kqueue_fd);
 }
 
+/*
+ * Test fifo status change after we close the reader side.
+ */
+static void
+test_events_close_reader(void)
+{
+	int kqueue_fd, reader_fd, writer_fd;
+
+	makefifo("testfifo", __func__);
+	if (openfifo("testfifo", __func__, &reader_fd, &writer_fd)
+	    < 0) {
+		warn("test_events_write_read_byte: openfifo: testfifo");
+		cleanfifo2("testfifo", -1, -1);
+		exit(-1);
+	}
+
+	kqueue_fd = kqueue();
+	if (kqueue_fd < 0) {
+		warn("%s: kqueue", __func__);
+		cleanfifo2("testfifo", reader_fd, writer_fd);
+		exit(-1);
+	}
+
+	if (kqueue_setup(kqueue_fd, reader_fd, __func__) < 0) {
+		cleanfifo3("testfifo", reader_fd, writer_fd, kqueue_fd);
+		exit(-1);
+	}
+
+	if (kqueue_setup(kqueue_fd, writer_fd, __func__) < 0) {
+		cleanfifo3("testfifo", reader_fd, writer_fd, kqueue_fd);
+		exit(-1);
+	}
+
+	/* 
+	 * close the reader, which should cause 
+	 * - reader_fd unreadable, unwritable, not exceptional
+	 * - writer_fd unreadable, unwritable, not exceptional
+	 */
+	close(reader_fd);
+
+	/*
+	if (assert_status(reader_fd, kqueue_fd, NOT_READABLE, NOT_WRITABLE,
+	    NOT_EXCEPTION, __func__, "close_reader", "reader_fd") < 0) {
+		cleanfifo2("testfifo", writer_fd, kqueue_fd);
+		exit(-1);
+	}
+	*/
+
+	if (assert_status(writer_fd, kqueue_fd, READABLE, WRITABLE,
+	    EXCEPTION, __func__, "close_reader", "writer_fd") < 0) {
+		cleanfifo2("testfifo", writer_fd, kqueue_fd);
+		exit(-1);
+	}
+
+	cleanfifo2("testfifo", writer_fd, kqueue_fd);
+}
+
+/*
+ * Test fifo status change after we close the writer side.
+ */
+static void
+test_events_close_writer(void)
+{
+	int kqueue_fd, reader_fd, writer_fd;
+
+	makefifo("testfifo", __func__);
+	if (openfifo("testfifo", __func__, &reader_fd, &writer_fd)
+	    < 0) {
+		warn("test_events_write_read_byte: openfifo: testfifo");
+		cleanfifo2("testfifo", -1, -1);
+		exit(-1);
+	}
+
+	kqueue_fd = kqueue();
+	if (kqueue_fd < 0) {
+		warn("%s: kqueue", __func__);
+		cleanfifo2("testfifo", reader_fd, writer_fd);
+		exit(-1);
+	}
+
+	if (kqueue_setup(kqueue_fd, reader_fd, __func__) < 0) {
+		cleanfifo3("testfifo", reader_fd, writer_fd, kqueue_fd);
+		exit(-1);
+	}
+
+	if (kqueue_setup(kqueue_fd, writer_fd, __func__) < 0) {
+		cleanfifo3("testfifo", reader_fd, writer_fd, kqueue_fd);
+		exit(-1);
+	}
+
+	/* 
+	 * close the writer, which should cause 
+	 * - reader_fd readable, unwritable, exceptional
+	 * - writer_fd unreadable, unwritable, not exceptional
+	 */
+	close(writer_fd);
+
+	if (assert_status(reader_fd, kqueue_fd, NOT_READABLE, NOT_WRITABLE,
+	    NOT_EXCEPTION, __func__, "close_writer", "reader_fd") < 0) {
+		cleanfifo2("testfifo", reader_fd, kqueue_fd);
+		exit(-1);
+	}
+
+	/*
+	if (assert_status(writer_fd, kqueue_fd, NOT_READABLE, NOT_WRITABLE,
+	    NOT_EXCEPTION, __func__, "close_writer", "writer_fd") < 0) {
+		cleanfifo2("testfifo", reader_fd, kqueue_fd);
+		exit(-1);
+	}
+	*/
+
+	cleanfifo2("testfifo", reader_fd, kqueue_fd);
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -1392,6 +1508,7 @@
 	if (chdir(temp_dir) < 0)
 		err(-1, "chdir %s", temp_dir);
 
+	/*
 	test_simpleio();
 	test_blocking_read_empty();
 	test_blocking_one_byte();
@@ -1404,6 +1521,9 @@
 	test_events_write_read_byte();
 	test_events_partial_write();
 	test_events_rdwr();
+	*/
+	test_events_close_reader();
+	test_events_close_writer();
 
 	return (0);
 }


More information about the p4-projects mailing list