Fix for bad location of include directory
[awesomized/libmemcached] / tests / server.c
1 /*
2 Startup, and shutdown the memcached servers.
3 */
4
5 #define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT+10
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <time.h>
10 #include <assert.h>
11 #include <memcached.h>
12 #include <unistd.h>
13 #include "server.h"
14
15 void server_startup(server_startup_st *construct)
16 {
17 unsigned int x;
18
19 if ((construct->server_list= getenv("MEMCACHED_SERVERS")))
20 {
21 printf("servers %s\n", construct->server_list);
22 construct->servers= memcached_servers_parse(construct->server_list);
23 construct->server_list= NULL;
24 construct->count= 0;
25 }
26 else
27 {
28 {
29 char server_string_buffer[8096];
30 char *end_ptr;
31 end_ptr= server_string_buffer;
32
33 for (x= 0; x < construct->count; x++)
34 {
35 char buffer[1024]; /* Nothing special for number */
36 int count;
37 int status;
38
39 if (construct->udp)
40 sprintf(buffer, "memcached -d -P /tmp/%umemc.pid -t 1 -U %u", x, x+ TEST_PORT_BASE);
41 else
42 sprintf(buffer, "memcached -d -P /tmp/%umemc.pid -t 1 -p %u", x, x+ TEST_PORT_BASE);
43 status= system(buffer);
44 WATCHPOINT_ASSERT(status == 0);
45 count= sprintf(end_ptr, "localhost:%u,", x + TEST_PORT_BASE);
46 end_ptr+= count;
47 }
48 *end_ptr= 0;
49
50 construct->server_list= strdup(server_string_buffer);
51 }
52 printf("servers %s\n", construct->server_list);
53 construct->servers= memcached_servers_parse(construct->server_list);
54 }
55
56 assert(construct->servers);
57
58 srandom(time(NULL));
59
60 for (x= 0; x < memcached_server_list_count(construct->servers); x++)
61 {
62 printf("\t%s : %u\n", construct->servers[x].hostname, construct->servers[x].port);
63 assert(construct->servers[x].fd == -1);
64 assert(construct->servers[x].cursor_active == 0);
65 }
66
67 printf("\n");
68 }
69
70 void server_shutdown(server_startup_st *construct)
71 {
72 unsigned int x;
73
74 if (construct->server_list)
75 {
76 for (x= 0; x < construct->count; x++)
77 {
78 char buffer[1024]; /* Nothing special for number */
79 sprintf(buffer, "cat /tmp/%umemc.pid | xargs kill", x);
80 system(buffer);
81
82 sprintf(buffer, "/tmp/%umemc.pid", x);
83 unlink(buffer);
84 }
85
86 free(construct->server_list);
87 }
88 }