[SCM] Samba Shared Repository - branch master updated

Christof Schmitt cs at samba.org
Wed Apr 10 00:18:03 UTC 2019


The branch, master has been updated
       via  9ee32f3a965 ctdb-test: Adding test case to verify queue resizeing
       via  1f193174f21 ctdb-test: Adding test case verifying data in buffer move
       via  5c1009b3191 ctdb-test: Modify ctdb_io_test test_setup to provide queue reference
      from  bfbe24d8274 leases_db: Make leases_db_del use leases_db_do_locked

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 9ee32f3a9654452e855bfa99801d977fa7168dec
Author: Swen Schillig <swen at linux.ibm.com>
Date:   Mon Mar 18 15:25:54 2019 +0100

    ctdb-test: Adding test case to verify queue resizeing
    
    If a data packet arrives which exceeds the queue's current buffer size,
    the buffer needs to be increased to hold the full packet. Once the packet
    is processed the buffer size should be decreased to its standard size again.
    This test case verifies this process.
    
    Signed-off-by: Swen Schillig <swen at linux.ibm.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Christof Schmitt <cs at samba.org>
    
    Autobuild-User(master): Christof Schmitt <cs at samba.org>
    Autobuild-Date(master): Wed Apr 10 00:17:37 UTC 2019 on sn-devel-144

commit 1f193174f21860b586eae1485e6d378441608e8d
Author: Swen Schillig <swen at linux.ibm.com>
Date:   Mon Mar 18 15:22:19 2019 +0100

    ctdb-test: Adding test case verifying data in buffer move
    
    Signed-off-by: Swen Schillig <swen at linux.ibm.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Christof Schmitt <cs at samba.org>

commit 5c1009b3191cb9ecfd879d824e7ffee4283d9105
Author: Swen Schillig <swen at linux.ibm.com>
Date:   Mon Mar 18 15:15:25 2019 +0100

    ctdb-test: Modify ctdb_io_test test_setup to provide queue reference
    
    Some test scenarios require access to the created queue.
    Prepare the test_setup function to provide it as additional parameter.
    
    Signed-off-by: Swen Schillig <swen at linux.ibm.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Christof Schmitt <cs at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 ctdb/tests/cunit/ctdb_io_test_001.sh |   2 +
 ctdb/tests/src/ctdb_io_test.c        | 160 ++++++++++++++++++++++++++++++++++-
 2 files changed, 159 insertions(+), 3 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ctdb/tests/cunit/ctdb_io_test_001.sh b/ctdb/tests/cunit/ctdb_io_test_001.sh
index 15842ea8e17..b6d3bce4782 100755
--- a/ctdb/tests/cunit/ctdb_io_test_001.sh
+++ b/ctdb/tests/cunit/ctdb_io_test_001.sh
@@ -6,3 +6,5 @@ ok_null
 
 unit_test ctdb_io_test 1
 unit_test ctdb_io_test 2
+unit_test ctdb_io_test 3
+unit_test ctdb_io_test 4
diff --git a/ctdb/tests/src/ctdb_io_test.c b/ctdb/tests/src/ctdb_io_test.c
index 5a2f81538a1..9cd02aa0eaa 100644
--- a/ctdb/tests/src/ctdb_io_test.c
+++ b/ctdb/tests/src/ctdb_io_test.c
@@ -34,7 +34,8 @@ void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...)
 
 static void test_setup(ctdb_queue_cb_fn_t cb,
 		       int *pfd,
-		       struct ctdb_context **pctdb)
+		       struct ctdb_context **pctdb,
+		       struct ctdb_queue **pqueue)
 {
 	int pipefd[2], ret;
 	struct ctdb_context *ctdb;
@@ -54,6 +55,9 @@ static void test_setup(ctdb_queue_cb_fn_t cb,
 
 	*pctdb = ctdb;
 	*pfd = pipefd[1];
+	if (pqueue != NULL) {
+		*pqueue = queue;
+	}
 }
 
 static const size_t test1_req_len = 8;
@@ -76,7 +80,7 @@ static void test1(void)
 	int fd, ret;
 	uint32_t pkt_size;
 
-	test_setup(test1_callback, &fd, &ctdb);
+	test_setup(test1_callback, &fd, &ctdb, NULL);
 
 	pkt_size = sizeof(uint32_t) + test1_req_len;
 	ret = write(fd, &pkt_size, sizeof(pkt_size));
@@ -116,7 +120,7 @@ static void test2(void)
 		req[i] = i % CHAR_MAX;
 	}
 
-	test_setup(test2_callback, &fd, &ctdb);
+	test_setup(test2_callback, &fd, &ctdb, NULL);
 
 	/*
 	 * request 0
@@ -168,6 +172,148 @@ static void test2(void)
 	TALLOC_FREE(ctdb);
 }
 
+static void test_cb(uint8_t *data, size_t length, void *private_data)
+{
+	/* dummy handler, not verifying anything */
+	TALLOC_FREE(data);
+}
+
+static void test3(void)
+{
+	struct ctdb_context *ctdb;
+	struct ctdb_queue *queue;
+	uint32_t pkt_size;
+	char *request;
+	size_t req_len;
+	int fd;
+	int ret;
+
+	test_setup(test_cb, &fd, &ctdb, &queue);
+	request = talloc_zero_size(queue, queue->buffer_size);
+
+	/*
+	 * calculate a request length which will fit into the buffer
+	 * but not twice. Because we need to write the size integer
+	 * as well (4-bytes) we're guaranteed that no 2 packets will fit.
+	 */
+	req_len = queue->buffer_size >> 1;
+
+	/* writing first packet */
+	pkt_size = sizeof(uint32_t) + req_len;
+
+	ret = write(fd, &pkt_size, sizeof(pkt_size));
+	assert(ret == sizeof(pkt_size));
+
+	ret = write(fd, request, req_len);
+	assert(ret == req_len);
+
+	/* writing second, incomplete packet */
+	pkt_size = sizeof(uint32_t) + req_len;
+
+	ret = write(fd, &pkt_size, sizeof(pkt_size));
+	assert(ret == sizeof(pkt_size));
+
+	ret = write(fd, request, req_len >> 1);
+	assert(ret == req_len >> 1);
+
+	/* process...only 1st packet can be processed */
+	tevent_loop_once(ctdb->ev);
+
+	/* we should see a progressed offset of req_len + sizeof(pkt_size) */
+	assert(queue->buffer.offset == req_len + sizeof(pkt_size));
+
+	/* writing another few bytes of the still incomplete packet */
+	ret = write(fd, request, (req_len >> 1) - 1);
+	assert(ret == (req_len >> 1) - 1);
+
+	/*
+	 * the packet is still incomplete and connot be processed
+	 * but the packet data had to be moved in the buffer in order
+	 * to fetch the new 199 bytes -> offset must be 0 now.
+	 */
+	tevent_loop_once(ctdb->ev);
+	/*
+	 * needs to be called twice as an incomplete packet
+	 * does not trigger a schedule_immediate
+	 */
+	tevent_loop_once(ctdb->ev);
+
+	assert(queue->buffer.offset == 0);
+
+	TALLOC_FREE(ctdb);
+}
+
+static void test4(void)
+{
+	struct ctdb_context *ctdb;
+	struct ctdb_queue *queue;
+	uint32_t pkt_size;
+	char *request;
+	size_t req_len;
+	int fd;
+	int ret;
+
+	test_setup(test_cb, &fd, &ctdb, &queue);
+
+	req_len = queue->buffer_size << 1; /* double the buffer size */
+	request = talloc_zero_size(queue, req_len);
+
+	/* writing first part of packet exceeding standard buffer size */
+	pkt_size = sizeof(uint32_t) + req_len;
+
+	ret = write(fd, &pkt_size, sizeof(pkt_size));
+	assert(ret == sizeof(pkt_size));
+
+	ret = write(fd, request, req_len - (queue->buffer_size >> 1));
+	assert(ret == req_len - (queue->buffer_size >> 1));
+
+	/*
+	 * process...
+	 * this needs to be done to have things changed
+	 */
+	tevent_loop_once(ctdb->ev);
+	/*
+	 * needs to be called twice as an initial incomplete packet
+	 * does not trigger a schedule_immediate
+	 */
+	tevent_loop_once(ctdb->ev);
+
+	/* the buffer should be resized to packet size now */
+	assert(queue->buffer.size == pkt_size);
+
+	/* writing remaining data */
+	ret = write(fd, request, queue->buffer_size >> 1);
+	assert(ret == (queue->buffer_size >> 1));
+
+	/* process... */
+	tevent_loop_once(ctdb->ev);
+
+	/*
+	 * the buffer was increased beyond its standard size.
+	 * once packet got processed, the buffer has to be free'd
+	 * and will be re-allocated with standard size on new request arrival.
+	 */
+
+	assert(queue->buffer.size == 0);
+
+	/* writing new packet to verify standard buffer size */
+	pkt_size = sizeof(uint32_t) + (queue->buffer_size >> 1);
+
+	ret = write(fd, &pkt_size, sizeof(pkt_size));
+	assert(ret == sizeof(pkt_size));
+
+	ret = write(fd, request, (queue->buffer_size >> 1));
+	assert(ret == (queue->buffer_size >> 1));
+
+	/* process... */
+	tevent_loop_once(ctdb->ev);
+
+	/* back to standard buffer size */
+	assert(queue->buffer.size == queue->buffer_size);
+
+	TALLOC_FREE(ctdb);
+}
+
 int main(int argc, const char **argv)
 {
 	int num;
@@ -188,6 +334,14 @@ int main(int argc, const char **argv)
 		test2();
 		break;
 
+	case 3:
+		test3();
+		break;
+
+	case 4:
+		test4();
+		break;
+
 	default:
 		fprintf(stderr, "Unknown test number %s\n", argv[1]);
 	}


-- 
Samba Shared Repository



More information about the samba-cvs mailing list