[CRIU] [PATCH] zdtm: Update sockets00 test -- add dgrams
Andrew Vagin
avagin at parallels.com
Thu Feb 9 03:48:27 EST 2012
On Tue, Feb 07, 2012 at 04:54:22PM +0400, Cyrill Gorcunov wrote:
> It looks ugly but test all cases at once.
Why do you not create a separate test for each case?
This cases don't share code. zdtm is a set of unit tests, so a test may be small.
Now this test is hard for reading and investigating.
>
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
> test/zdtm/live/static/sockets00.c | 135 ++++++++++++++++++++++++++++++++++++-
> 1 files changed, 134 insertions(+), 1 deletions(-)
>
> diff --git a/test/zdtm/live/static/sockets00.c b/test/zdtm/live/static/sockets00.c
> index 376347b..929e867 100644
> --- a/test/zdtm/live/static/sockets00.c
> +++ b/test/zdtm/live/static/sockets00.c
> @@ -23,14 +23,26 @@ const char *test_author = "Cyrill Gorcunov <gorcunov at openvz.org";
>
> #define SK_DATA "packet"
>
> +#define SK_DATA_BOUND "data-packet-bound"
> +#define SK_DATA_CONN "data-packet-conn"
> +#define SK_DATA_BOUND_CONN "data-packet-bound-conn"
> +
> int main(int argc, char *argv[])
> {
> int ssk_icon[2];
> int ssk_pair[2];
> struct sockaddr_un addr;
> + struct sockaddr_un name_bound;
> + struct sockaddr_un name_conn;
> + struct sockaddr_un name_bound_conn;
> + int sk_dgram_bound_client;
> + int sk_dgram_bound_server;
> + int sk_dgram_conn_client;
> + int sk_dgram_conn_server;
> + int sk_dgram_bound_conn;
> unsigned int addrlen;
>
> - char path[PATH_MAX] = { };
> + char path[PATH_MAX];
> char buf[64];
> char *cwd;
>
> @@ -44,9 +56,11 @@ int main(int argc, char *argv[])
> exit(1);
> }
>
> + memset(path, 0, sizeof(path));
> strncat(path, cwd, sizeof(path));
> strncat(path, "/test-socket", sizeof(path));
> unlink(path);
> +
> addr.sun_family = AF_UNIX;
> strncpy(addr.sun_path, path, sizeof(addr.sun_path));
> addrlen = sizeof(addr.sun_family) + strlen(path);
> @@ -81,6 +95,75 @@ int main(int argc, char *argv[])
> exit(1);
> }
>
> + sk_dgram_bound_client = socket(AF_UNIX, SOCK_DGRAM, 0);
> + sk_dgram_bound_server = socket(AF_UNIX, SOCK_DGRAM, 0);
> + sk_dgram_conn_client = socket(AF_UNIX, SOCK_DGRAM, 0);
> + sk_dgram_conn_server = socket(AF_UNIX, SOCK_DGRAM, 0);
> + sk_dgram_bound_conn = socket(AF_UNIX, SOCK_DGRAM, 0);
> +
> + if (sk_dgram_conn_server < 0 ||
> + sk_dgram_bound_server < 0 ||
> + sk_dgram_conn_client < 0 ||
> + sk_dgram_conn_server < 0 ||
> + sk_dgram_bound_conn < 0) {
> + fail("socket");
> + exit(1);
> + }
> +
> + memset(path, 0, sizeof(path));
> + strncat(path, cwd, sizeof(path));
> + strncat(path, "/test-socket-bound", sizeof(path));
> + unlink(path);
> +
> + name_bound.sun_family = AF_UNIX;
> + strncpy(name_bound.sun_path, path, sizeof(name_bound.sun_path));
> +
> + memset(path, 0, sizeof(path));
> + strncat(path, cwd, sizeof(path));
> + strncat(path, "/test-socket-conn", sizeof(path));
> + unlink(path);
> +
> + name_conn.sun_family = AF_UNIX;
> + strncpy(name_conn.sun_path, path, sizeof(name_conn.sun_path));
> +
> + memset(path, 0, sizeof(path));
> + strncat(path, cwd, sizeof(path));
> + strncat(path, "/test-socket-bound-conn", sizeof(path));
> + unlink(path);
> +
> + name_bound_conn.sun_family = AF_UNIX;
> + strncpy(name_bound_conn.sun_path, path, sizeof(name_bound_conn.sun_path));
> +
> + ret = bind(sk_dgram_bound_server, &name_bound, sizeof(name_bound));
> + if (ret) {
> + fail("bind");
> + exit(1);
> + }
> +
> + ret = bind(sk_dgram_conn_server, &name_conn, sizeof(name_conn));
> + if (ret) {
> + fail("bind");
> + exit(1);
> + }
> +
> + ret = bind(sk_dgram_bound_conn, &name_bound_conn, sizeof(name_bound_conn));
> + if (ret) {
> + fail("bind");
> + exit(1);
> + }
> +
> + ret = connect(sk_dgram_conn_client, &name_conn, sizeof(name_conn));
> + if (ret) {
> + fail("connect");
> + exit(1);
> + }
> +
> + ret = connect(sk_dgram_bound_conn, &name_bound_conn, sizeof(name_bound_conn));
> + if (ret) {
> + fail("connect");
> + exit(1);
> + }
> +
> write(ssk_pair[0], SK_DATA, sizeof(SK_DATA));
> read(ssk_pair[1], &buf, sizeof(buf));
> if (strcmp(buf, SK_DATA)) {
> @@ -89,6 +172,31 @@ int main(int argc, char *argv[])
> }
> test_msg("stream : '%s'\n", buf);
>
> + sendto(sk_dgram_bound_client, SK_DATA_BOUND, sizeof(SK_DATA_BOUND), 0,
> + &name_bound, sizeof(name_bound));
> + read(sk_dgram_bound_server, &buf, sizeof(buf));
> + if (strcmp(buf, SK_DATA_BOUND)) {
> + fail("data corrupted\n");
> + exit(1);
> + }
> + test_msg("dgram-bound : '%s'\n", buf);
> +
> + write(sk_dgram_conn_client, SK_DATA_CONN, sizeof(SK_DATA_CONN));
> + read(sk_dgram_conn_server, &buf, sizeof(buf));
> + if (strcmp(buf, SK_DATA_CONN)) {
> + fail("data corrupted\n");
> + exit(1);
> + }
> + test_msg("dgram-conn : '%s'\n", buf);
> +
> + write(sk_dgram_bound_conn, SK_DATA_BOUND_CONN, sizeof(SK_DATA_BOUND_CONN));
> + read(sk_dgram_bound_conn, &buf, sizeof(buf));
> + if (strcmp(buf, SK_DATA_BOUND_CONN)) {
> + fail("data corrupted\n");
> + exit(1);
> + }
> + test_msg("dgram-bound-conn : '%s'\n", buf);
> +
> test_daemon();
> test_waitsig();
>
> @@ -115,6 +223,31 @@ int main(int argc, char *argv[])
> }
> test_msg("stream : '%s'\n", buf);
>
> + sendto(sk_dgram_bound_client, SK_DATA_BOUND, sizeof(SK_DATA_BOUND), 0,
> + &name_bound, sizeof(name_bound));
> + read(sk_dgram_bound_server, &buf, sizeof(buf));
> + if (strcmp(buf, SK_DATA_BOUND)) {
> + fail("data corrupted\n");
> + exit(1);
> + }
> + test_msg("dgram-bound : '%s'\n", buf);
> +
> + write(sk_dgram_conn_client, SK_DATA_CONN, sizeof(SK_DATA_CONN));
> + read(sk_dgram_conn_server, &buf, sizeof(buf));
> + if (strcmp(buf, SK_DATA_CONN)) {
> + fail("data corrupted\n");
> + exit(1);
> + }
> + test_msg("dgram-conn : '%s'\n", buf);
> +
> + write(sk_dgram_bound_conn, SK_DATA_BOUND_CONN, sizeof(SK_DATA_BOUND_CONN));
> + read(sk_dgram_bound_conn, &buf, sizeof(buf));
> + if (strcmp(buf, SK_DATA_BOUND_CONN)) {
> + fail("data corrupted\n");
> + exit(1);
> + }
> + test_msg("dgram-bound-conn : '%s'\n", buf);
> +
> pass();
> return 0;
> }
> --
> 1.7.7.6
>
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://openvz.org/mailman/listinfo/criu
More information about the CRIU
mailing list