Browse files

start of the incr fix, rearranges a bunch, adds util, tests, etc

  • Loading branch information...
1 parent 9791d32 commit 420aa2d992093b78c1bba6cbb3577d5b53a19ec8 @bradfitz bradfitz committed with dustin Oct 14, 2008
Showing with 78 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +6 −2 Makefile.am
  3. +23 −0 globals.c
  4. +22 −0 internal_tests.c
  5. +2 −2 memcached.h
  6. +16 −0 util.c
  7. +8 −0 util.h
View
1 .gitignore
@@ -33,3 +33,4 @@ memcached-*.tar.gz
doc/protocol-binary-range.txt
doc/protocol-binary.txt
/sizes
+/internal_tests
View
8 Makefile.am
@@ -1,4 +1,4 @@
-bin_PROGRAMS = memcached memcached-debug sizes
+bin_PROGRAMS = memcached memcached-debug sizes internal_tests
pkginclude_HEADERS = protocol_binary.h
BUILT_SOURCES=
@@ -10,6 +10,7 @@ memcached_SOURCES = memcached.c memcached.h \
assoc.c assoc.h \
thread.c daemon.c \
stats.c stats.h \
+ util.c util.h \
trace.h
if BUILD_SOLARIS_PRIVS
@@ -26,6 +27,8 @@ memcached_DEPENDENCIES =
memcached_debug_DEPENDENCIES =
CLEANFILES=
+internal_tests_SOURCES = internal_tests.c util.c
+
if BUILD_DTRACE
BUILT_SOURCES += memcached_dtrace.h
CLEANFILES += memcached_dtrace.h
@@ -58,8 +61,9 @@ EXTRA_DIST = doc scripts TODO t memcached.spec memcached_dtrace.d
MOSTLYCLEANFILES = *.gcov *.gcno *.gcda *.tcov
-test: memcached-debug sizes
+test: memcached-debug internal_tests sizes
$(srcdir)/sizes
+ $(srcdir)/internal_tests
prove $(srcdir)/t
@if test `basename $(PROFILER)` = "gcov"; then \
for file in memcached_debug-*.gc??; do \
View
23 globals.c
@@ -0,0 +1,23 @@
+#include "memcached.h"
+
+/*
+ * This file contains global variables shared across the rest of the
+ * memcached codebase. These were originally in memcached.c but had
+ * to be removed to make the rest of the object files linkable into
+ * the test infrastructure.
+ *
+ */
+
+/*
+ * We keep the current time of day in a global variable that's updated by a
+ * timer event. This saves us a bunch of time() system calls (we really only
+ * need to get the time once a second, whereas there can be tens of thousands
+ * of requests a second) and allows us to use server-start-relative timestamps
+ * rather than absolute UNIX timestamps, a space savings on systems where
+ * sizeof(time_t) > sizeof(unsigned int).
+ */
+volatile rel_time_t current_time;
+
+/** exported globals **/
+struct stats stats;
+struct settings settings;
View
22 internal_tests.c
@@ -0,0 +1,22 @@
+/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "memcached.h"
+
+int main(int argc, char **argv) {
+ unsigned long long ull;
+ assert(safe_strtoull("123", &ull));
+ assert(ull == 123);
+
+ // Empty:
+ assert(!safe_strtoull("", &ull));
+
+ // Bogus:
+ assert(!safe_strtoull("123BOGUS", &ull));
+
+ printf("OK.\n");
+ return 0;
+}
View
4 memcached.h
@@ -24,7 +24,7 @@
#define UDP_MAX_PAYLOAD_SIZE 1400
#define UDP_HEADER_SIZE 8
#define MAX_SENDBUF_SIZE (256 * 1024 * 1024)
-/* I'm told the max legnth of a 64-bit num converted to string is 20 bytes.
+/* I'm told the max length of a 64-bit num converted to string is 20 bytes.
* Plus a few for spaces, \r\n, \0 */
#define SUFFIX_SIZE 24
@@ -337,7 +337,7 @@ extern int daemonize(int nochdir, int noclose);
#include "items.h"
#include "trace.h"
#include "hash.h"
-
+#include "util.h"
/*
* Functions such as the libevent-related calls that need to do cross-thread
View
16 util.c
@@ -0,0 +1,16 @@
+#include <stdlib.h>
+#include <assert.h>
+
+#include "memcached.h"
+
+bool safe_strtoull(const char *str, unsigned long long *out) {
+ assert(out != NULL);
+ *out = 0;
+ char *endptr;
+ unsigned long long ull = strtoull(str, &endptr, 10);
+ if (*endptr == '\0' && endptr != str) {
+ *out = ull;
+ return true;
+ }
+ return false;
+}
View
8 util.h
@@ -0,0 +1,8 @@
+/*
+ * str a NULL-terminated base decimal 10 unsigned integer
+ * out out parameter, if conversion succeeded
+ *
+ * returns true if conversion succeeded.
+ */
+bool safe_strtoull(const char *str, unsigned long long *out);
+

0 comments on commit 420aa2d

Please sign in to comment.