LIBS =
-noinst_HEADERS = test.h
-noinst_PROGRAMS = testapp testplus
+noinst_HEADERS = test.h server.h
+noinst_PROGRAMS = testapp testplus udptest
-testapp_SOURCES = test.c function.c ../src/generator.c ../src/execute.c
+testapp_SOURCES = test.c function.c ../src/generator.c ../src/execute.c server.c
testapp_LDADD = $(LDADDS)
-testplus_SOURCES = test.c plus.cpp
+testplus_SOURCES = test.c plus.cpp server.c
testplus_LDADD = $(LDADDS) ../lib/libmemcached.la
+udptest_SOURCES = test.c udp.c server.c
+udptest_LDADD = $(LDADDS) ../lib/libmemcached.la
+
record:
./testapp > output.res
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
+#include "server.h"
#include "../lib/common.h"
#include "../src/generator.h"
#include "../src/execute.h"
{0, 0, 0, 0}
};
-collection_st *gets_collections(void)
+#define SERVERS_TO_CREATE 5
+
+void *world_create(void)
+{
+ server_startup_st *construct;
+
+ construct= (server_startup_st *)malloc(sizeof(server_startup_st));
+ memset(construct, 0, sizeof(server_startup_st));
+ construct->count= SERVERS_TO_CREATE;
+ construct->udp= 0;
+ server_startup(construct);
+
+ return construct;
+}
+
+void world_destroy(void *p)
+{
+ server_startup_st *construct= (server_startup_st *)p;
+ memcached_server_st *servers= (memcached_server_st *)construct->servers;
+ memcached_server_list_free(servers);
+
+ server_shutdown(construct);
+ free(construct);
+}
+
+void get_world(world_st *world)
{
- return collection;
+ world->collections= collection;
+ world->create= world_create;
+ world->destroy= world_destroy;
}
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
+#include "server.h"
#include "test.h"
{0, 0, 0, 0}
};
-collection_st *gets_collections(void)
+#define SERVERS_TO_CREATE 1
+
+void *world_create(void)
+{
+ unsigned int x;
+ memcached_server_st *servers;
+ server_startup_st *construct;
+
+ construct= (server_startup_st *)malloc(sizeof(server_startup_st));
+ memset(construct, 0, sizeof(server_startup_st));
+
+ construct->count= SERVERS_TO_CREATE;
+ server_startup(construct);
+
+ return construct;
+}
+
+void world_destroy(void *p)
+{
+ server_startup_st *construct= (server_startup_st *)p;
+ memcached_server_st *servers= (memcached_server_st *)construct->servers;
+ memcached_server_list_free(servers);
+
+ server_shutdown(construct);
+ free(construct);
+}
+
+void get_world(world_st *world)
{
- return collection;
+ world->collections= collection;
+ world->create= world_create;
+ world->destroy= world_destroy;
}
--- /dev/null
+/*
+ Startup, and shutdown the memcached servers.
+*/
+
+#define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT+10
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <assert.h>
+#include <memcached.h>
+#include <unistd.h>
+#include "server.h"
+
+void server_startup(server_startup_st *construct)
+{
+ unsigned int x;
+
+ if ((construct->server_list= getenv("MEMCACHED_SERVERS")))
+ {
+ printf("servers %s\n", construct->server_list);
+ construct->servers= memcached_servers_parse(construct->server_list);
+ construct->server_list= NULL;
+ construct->count= 0;
+ }
+ else
+ {
+ WATCHPOINT;
+ {
+ char server_string_buffer[8096];
+ char *end_ptr;
+ end_ptr= server_string_buffer;
+
+ for (x= 0; x < construct->count; x++)
+ {
+ char buffer[1024]; /* Nothing special for number */
+ int count;
+
+ if (construct->udp)
+ sprintf(buffer, "memcached -d -P /tmp/%umemc.pid -U %u", x, x+ TEST_PORT_BASE);
+ else
+ sprintf(buffer, "memcached -d -P /tmp/%umemc.pid -p %u", x, x+ TEST_PORT_BASE);
+ system(buffer);
+ count= sprintf(end_ptr, "localhost:%u,", x + TEST_PORT_BASE);
+ end_ptr+= count;
+ }
+ *end_ptr= 0;
+
+ construct->server_list= strdup(server_string_buffer);
+ }
+ printf("servers %s\n", construct->server_list);
+ construct->servers= memcached_servers_parse(construct->server_list);
+ }
+
+ assert(construct->servers);
+
+ srandom(time(NULL));
+
+ for (x= 0; x < memcached_server_list_count(construct->servers); x++)
+ {
+ printf("\t%s : %u\n", construct->servers[x].hostname, construct->servers[x].port);
+ assert(construct->servers[x].fd == -1);
+ assert(construct->servers[x].cursor_active == 0);
+ }
+
+ printf("\n");
+}
+
+void server_shutdown(server_startup_st *construct)
+{
+ unsigned int x;
+
+ if (construct->server_list)
+ {
+ for (x= 0; x < construct->count; x++)
+ {
+ char buffer[1024]; /* Nothing special for number */
+ sprintf(buffer, "cat /tmp/%umemc.pid | xargs kill", x);
+ system(buffer);
+
+ sprintf(buffer, "/tmp/%umemc.pid", x);
+ unlink(buffer);
+ }
+
+ free(construct->server_list);
+ }
+}
--- /dev/null
+/*
+ Server startup and shutdown functions.
+*/
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <memcached.h>
+
+typedef struct server_startup_st server_startup_st;
+
+struct server_startup_st
+{
+ uint8_t count;
+ uint8_t udp;
+ memcached_server_st *servers;
+ char *server_list;
+};
+
+void server_startup(server_startup_st *construct);
+void server_shutdown(server_startup_st *construct);
+
+#ifdef __cplusplus
+}
+#endif
#include <unistd.h>
#include <time.h>
#include <fnmatch.h>
+#include "server.h"
#include "test.h"
-#define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT+10
-#define TEST_SERVERS 5
-
long int timedif(struct timeval a, struct timeval b)
{
register int us, s;
return s + us;
}
-char *server_startup()
-{
- unsigned int x;
- char server_string_buffer[8096];
- char *end_ptr;
-
- end_ptr= server_string_buffer;
-
- for (x= 0; x < TEST_SERVERS; x++)
- {
- char buffer[1024]; /* Nothing special for number */
- int count;
-
- sprintf(buffer, "memcached -d -P /tmp/%umemc.pid -p %u", x, x+ TEST_PORT_BASE);
- system(buffer);
- count= sprintf(end_ptr, "localhost:%u,", x + TEST_PORT_BASE);
- end_ptr+= count;
- }
- *end_ptr= 0;
-
- return strdup(server_string_buffer);
-}
-
-void server_shutdown(char *server_string)
-{
- unsigned int x;
-
- if (server_string)
- {
- for (x= 0; x < TEST_SERVERS; x++)
- {
- char buffer[1024]; /* Nothing special for number */
- sprintf(buffer, "cat /tmp/%umemc.pid | xargs kill", x);
- system(buffer);
- }
-
- free(server_string);
- }
-}
-
int main(int argc, char *argv[])
{
unsigned int x;
- char *server_list;
char *collection_to_run= NULL;
char *wildcard= NULL;
+ server_startup_st *startup_ptr;
memcached_server_st *servers;
+ world_st world;
collection_st *collection;
collection_st *next;
uint8_t failed;
+ void *world_ptr;
+
+ memset(&world, 0, sizeof(world_st));
+ get_world(&world);
+ collection= world.collections;
- collection= gets_collections();
+ if (world.create)
+ world_ptr= world.create();
+ startup_ptr= (server_startup_st *)world_ptr;
+ servers= (memcached_server_st *)startup_ptr->servers;
if (argc > 1)
collection_to_run= argv[1];
if (argc == 3)
wildcard= argv[2];
- if ((server_list= getenv("MEMCACHED_SERVERS")))
- {
- printf("servers %s\n", server_list);
- servers= memcached_servers_parse(server_list);
- server_list= NULL;
- }
- else
- {
- server_list= server_startup();
- printf("servers %s\n", server_list);
- servers= memcached_servers_parse(server_list);
- }
- assert(servers);
-
- srandom(time(NULL));
-
-
- for (x= 0; x < memcached_server_list_count(servers); x++)
- {
- printf("\t%s : %u\n", servers[x].hostname, servers[x].port);
- assert(servers[x].fd == -1);
- assert(servers[x].cursor_active == 0);
- }
-
- printf("\n");
-
for (next= collection; next->name; next++)
{
test_st *run;
fprintf(stderr, "All tests completed successfully\n\n");
- memcached_server_list_free(servers);
-
- server_shutdown(server_list);
+ if (world.destroy)
+ world.destroy(world_ptr);
return 0;
}
#include <memcached.h>
#include "../lib/common.h"
+typedef struct world_st world_st;
typedef struct collection_st collection_st;
typedef struct test_st test_st;
test_st *tests;
};
+struct world_st {
+ collection_st *collections;
+ void *(*create)(void);
+ void (*destroy)(void *collection_object);
+};
+
/* How we make all of this work :) */
-collection_st *gets_collections(void);
+void get_world(world_st *world);
#ifdef __cplusplus
}
--- /dev/null
+/*
+ Sample test application.
+*/
+#include <assert.h>
+#include <memcached.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <time.h>
+#include "test.h"
+#include "server.h"
+
+uint8_t set_test(memcached_st *memc)
+{
+ memcached_return rc;
+ char *key= "foo";
+ char *value= "when we sanitize";
+
+ rc= memcached_set(memc, key, strlen(key),
+ value, strlen(value),
+ (time_t)0, (uint32_t)0);
+ assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+
+ return 0;
+}
+
+test_st tests[] ={
+ {"set", 1, set_test },
+ {0, 0, 0}
+};
+
+collection_st collection[] ={
+ {"udp", 0, 0, tests},
+ {0, 0, 0, 0}
+};
+
+#define SERVERS_TO_CREATE 1
+
+void *world_create(void)
+{
+ server_startup_st *construct;
+
+ construct= (server_startup_st *)malloc(sizeof(server_startup_st));
+ memset(construct, 0, sizeof(server_startup_st));
+ construct->count= SERVERS_TO_CREATE;
+ construct->udp= 1;
+ server_startup(construct);
+
+ return construct;
+}
+
+void world_destroy(void *p)
+{
+ server_startup_st *construct= (server_startup_st *)p;
+ memcached_server_st *servers= (memcached_server_st *)construct->servers;
+ memcached_server_list_free(servers);
+
+ server_shutdown(construct);
+ free(construct);
+}
+
+void get_world(world_st *world)
+{
+ world->collections= collection;
+ world->create= world_create;
+ world->destroy= world_destroy;
+}