Patch: Allow the socket-wrapper stuff to work with net ads dns register etc
Richard Sharpe
realrichardsharpe at gmail.com
Wed May 11 04:06:14 UTC 2016
On Tue, May 10, 2016 at 1:39 AM, Andreas Schneider <asn at samba.org> wrote:
> On Monday, May 09, 2016 08:17:43 AM Richard Sharpe wrote:
>> Hi folks,
>
> Hi Richard,
>
>> Attached is a preliminary patch to the socket wrapper code to help
>> with self tests of things like net ads dns ...
>>
>> I will write a test for this, but wanted to let people know what I was
>> thinking of.
>
> could you please create a patch against the socket_wrapper repository?
>
> You can find it here:
>
> https://git.samba.org/?p=socket_wrapper.git;a=summary
>
> Please also provide a testcase! You could add a test to:
>
> https://git.samba.org/?p=socket_wrapper.git;a=blob;f=tests/test_echo_udp_sendto_recvfrom.c;h=79948ced4718668cec037a0d2efb3a72704f08ac;hb=refs/heads/master
>
> For developing the test you can run it without socket_wrapper first. How you
> do that is described here:
>
> https://git.samba.org/?p=socket_wrapper.git;a=blob;f=tests/README;h=26bf1fbb5b53cfaec2ff2dabe1487b440245f9e8;hb=refs/heads/master
>
> After that it should work with socket_wrapper after applying your patch.
OK, I seem to have some code that tests OK when run as you suggest above:
[==========] Running 3 test(s).
[ RUN ] test_sendto_recvfrom_ipv4
WARNING the echo server is still running!
[ OK ] test_sendto_recvfrom_ipv4
[ RUN ] test_connect_sendto_recvfrom_ipv4
[ OK ] test_connect_sendto_recvfrom_ipv4
[ RUN ] test_sendto_recvfrom_ipv6
[ OK ] test_sendto_recvfrom_ipv6
[==========] 3 test(s) run.
[ PASSED ] 3 test(s).
Here is a patch for the test ... If it looks OK, I will send it as a
git format-patch patch
--- a/tests/test_echo_udp_sendto_recvfrom.c
+++ b/tests/test_echo_udp_sendto_recvfrom.c
@@ -38,7 +38,7 @@ static int teardown(void **state)
return 0;
}
-static void test_sendto_recvfrom_ipv4(void **state)
+static void test_connect_sendto_recvfrom_ipv4(void **state)
{
struct torture_address addr = {
.sa_socklen = sizeof(struct sockaddr_in),
@@ -114,6 +114,62 @@ static void test_sendto_recvfrom_ipv4(void **state)
close(s);
}
+static void test_sendto_recvfrom_ipv4(void **state)
+{
+ struct torture_address addr = {
+ .sa_socklen = sizeof(struct sockaddr_in),
+ };
+ char send_buf[64] = {0};
+ char recv_buf[64] = {0};
+ ssize_t ret;
+ int rc;
+ int i;
+ int s;
+
+ (void) state; /* unused */
+
+ addr.sa.in.sin_family = AF_INET;
+ addr.sa.in.sin_port = htons(torture_server_port());
+
+ rc = inet_pton(AF_INET,
+ torture_server_address(AF_INET),
+ &addr.sa.in.sin_addr);
+ assert_int_equal(rc, 1);
+
+ for (i = 0; i < 10; i++) {
+ int cret = 0;
+
+ s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ assert_int_not_equal(s, -1);
+
+ /* Now, connect */
+ cret = connect(s, &addr.sa.s, addr.sa_socklen);
+ assert_int_not_equal(cret, -1);
+
+ snprintf(send_buf, sizeof(send_buf), "packet.%d", i);
+
+ ret = sendto(s,
+ send_buf,
+ sizeof(send_buf),
+ 0,
+ NULL,
+ 0);
+ assert_int_not_equal(ret, -1);
+
+ ret = recvfrom(s,
+ recv_buf,
+ sizeof(recv_buf),
+ 0,
+ NULL,
+ 0);
+ assert_int_not_equal(ret, -1);
+
+ assert_memory_equal(send_buf, recv_buf, sizeof(send_buf));
+
+ close(s);
+ }
+}
+
#ifdef HAVE_IPV6
static void test_sendto_recvfrom_ipv6(void **state)
{
@@ -199,6 +255,9 @@ int main(void) {
cmocka_unit_test_setup_teardown(test_sendto_recvfrom_ipv4,
setup_echo_srv_udp_ipv4,
teardown),
+
cmocka_unit_test_setup_teardown(test_connect_sendto_recvfrom_ipv4,
+ setup_echo_srv_udp_ipv4,
+ teardown),
#ifdef HAVE_IPV6
cmocka_unit_test_setup_teardown(test_sendto_recvfrom_ipv6,
setup_echo_srv_udp_ipv6,
--
Regards,
Richard Sharpe
(何以解憂?唯有杜康。--曹操)
More information about the samba-technical
mailing list