File: timeout-t.c

package info (click to toggle)
remctl 3.18-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,612 kB
  • sloc: ansic: 19,504; sh: 5,386; perl: 1,778; java: 740; makefile: 715; xml: 502; python: 430
file content (71 lines) | stat: -rw-r--r-- 2,233 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Test suite for setting a timeout for the client.
 *
 * Written by Russ Allbery <eagle@eyrie.org>
 * Copyright 2012
 *     The Board of Trustees of the Leland Stanford Junior University
 *
 * SPDX-License-Identifier: MIT
 */

#include <config.h>
#include <portable/system.h>

#include <client/remctl.h>
#include <tests/tap/basic.h>
#include <tests/tap/kerberos.h>
#include <tests/tap/remctl.h>


int
main(void)
{
    struct kerberos_config *config;
    struct remctl *r;
    struct remctl_output *output;
    const char *command[] = {"test", "sleep", NULL, NULL};

    /* Set up Kerberos and remctld. */
    config = kerberos_setup(TAP_KRB_NEEDS_KEYTAB);
    remctld_start(config, "data/conf-simple", (char *) 0);

    plan(11);

    /*
     * Send the command with no arguments, which means we'll time out right
     * away without receiving a reply.
     */
    r = remctl_new();
    ok(remctl_set_timeout(r, 1), "set timeout");
    ok(remctl_open(r, "127.0.0.1", 14373, config->principal), "open");
    ok(remctl_command(r, command), "sent test sleep command");
    output = remctl_output(r);
    ok(output == NULL, "output is NULL");
    is_string("error receiving token: timed out", remctl_error(r),
              "correct error");

    /*
     * Send the command with an argument and ensure we can read one token and
     * then time out when waiting for the next token.  This also tests that we
     * close the socket and restart properly after a timeout error when
     * reusing the same remctl client struct.
     */
    command[2] = "hello";
    ok(remctl_command(r, command), "sent test sleep command with output");
    output = remctl_output(r);
    if (output == NULL)
        ok_block(3, 0, "output is NULL (%s)", remctl_error(r));
    else {
        is_int(REMCTL_OUT_OUTPUT, output->type, "got output token");
        ok(memcmp("hello\n", output->data, strlen("hello\n")) == 0,
           "  correct output");
        is_int(strlen("hello\n"), output->length, "  correct length");
    }
    output = remctl_output(r);
    ok(output == NULL, "second output token is NULL");
    is_string("error receiving token: timed out", remctl_error(r),
              "correct error");
    remctl_close(r);

    return 0;
}