Commit 8b402fc8 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Create {{{toku_assert}}} (Fixes #354). Make the primes test actually work...

Create {{{toku_assert}}} (Fixes #354).  Make the primes test actually work (Fixes #355).  Addresses #277. 


git-svn-id: file:///svn/tokudb@2153 c7de825b-a66e-492c-adef-691d508d4ae1
parent cb44b35d
...@@ -54,6 +54,7 @@ REGRESSION_TESTS = \ ...@@ -54,6 +54,7 @@ REGRESSION_TESTS = \
fifo-test \ fifo-test \
brt-test \ brt-test \
test_oexcl \ test_oexcl \
test-assert \
test-primes \ test-primes \
list-test \ list-test \
# This line intentially kept commented so I can have a \ on the end of the previous line # This line intentially kept commented so I can have a \ on the end of the previous line
...@@ -69,11 +70,11 @@ BINS = $(REGRESSION_TESTS) \ ...@@ -69,11 +70,11 @@ BINS = $(REGRESSION_TESTS) \
tdb_logprint: LDFLAGS+=-lz tdb_logprint: LDFLAGS+=-lz
tdb_logprint.o: log-internal.h brttypes.h yerror.h log.h kv-pair.h tdb_logprint.o: log-internal.h brttypes.h yerror.h log.h kv-pair.h
tdb_logprint: log_code.o memory.o log.o brt-serialize.o fifo.o pma.o ybt.o fingerprint.o mempool.o primes.o roll.o brt.o cachetable.o brt-verify.o key.o tdb_logprint: log_code.o memory.o log.o brt-serialize.o fifo.o pma.o ybt.o fingerprint.o mempool.o primes.o toku_assert.o roll.o brt.o cachetable.o brt-verify.o key.o
recover: LDFLAGS+=-lz recover: LDFLAGS+=-lz
recover.o: log_header.h log-internal.h log.h yerror.h brttypes.h kv-pair.h memory.h key.h recover.o: log_header.h log-internal.h log.h yerror.h brttypes.h kv-pair.h memory.h key.h
recover: recover.o log_code.o memory.o log.o brt-serialize.o fifo.o pma.o ybt.o fingerprint.o mempool.o primes.o cachetable.o brt.o brt-verify.o key.o roll.o recover: recover.o log_code.o memory.o log.o brt-serialize.o fifo.o pma.o ybt.o fingerprint.o mempool.o primes.o toku_assert.o cachetable.o brt.o brt-verify.o key.o roll.o
roll.o: log_header.h log-internal.h log.h yerror.h brttypes.h kv-pair.h memory.h key.h cachetable.h pma.h roll.o: log_header.h log-internal.h log.h yerror.h brttypes.h kv-pair.h memory.h key.h cachetable.h pma.h
...@@ -90,14 +91,27 @@ CHECKS = \ ...@@ -90,14 +91,27 @@ CHECKS = \
cachetable-test \ cachetable-test \
cachetable-test2 \ cachetable-test2 \
brt-serialize-test \ brt-serialize-test \
brt-test fifo-test \ brt-test \
fifo-test \
test_toku_malloc_plain_free \ test_toku_malloc_plain_free \
test-primes \ test-primes \
list-test list-test \
# This line intentially kept commented so I can have a \ on the previous line
check: bins $(patsubst %,check_%,$(CHECKS)) check_benchmarktest_256 check: bins $(patsubst %,check_%,$(CHECKS)) check_benchmarktest_256
check_benchmarktest_256: benchmark-test check_benchmarktest_256: benchmark-test
$(DTOOL) ./benchmark-test $(VERBVERBOSE) --valsize 256 --verify 1 $(DTOOL) ./benchmark-test $(VERBVERBOSE) --valsize 256 --verify 1
check_test-assert: test-assert
@# no arguments, should err
$(DTOOL) ./test-assert > /dev/null 2>&1 ; test \($$?\)
@# one argument, not "ok" should err
@echo Expect an abort message:
($(DTOOL) ./test-assert notok) > test-assert.out 2>&1 ; test \($$?\)
@fgrep failed test-assert.out > /dev/null
@rm test-assert.out
@# one argument, "ok" should not error
$(DTOOL) ./test-assert ok
check_%: % check_%: %
$(DTOOL) ./$< $(VERBVERBOSE) $(DTOOL) ./$< $(VERBVERBOSE)
...@@ -114,20 +128,20 @@ pma-test benchmark-test brt-test brt-serialize-test brtdump: LDFLAGS+=-lz ...@@ -114,20 +128,20 @@ pma-test benchmark-test brt-test brt-serialize-test brtdump: LDFLAGS+=-lz
BRT_INTERNAL_H_INCLUDES = brt-internal.h cachetable.h fifo.h pma.h brt.h brttypes.h yerror.h ybt.h log.h ../include/db.h kv-pair.h memory.h crc.h BRT_INTERNAL_H_INCLUDES = brt-internal.h cachetable.h fifo.h pma.h brt.h brttypes.h yerror.h ybt.h log.h ../include/db.h kv-pair.h memory.h crc.h
key.o: brttypes.h key.h key.o: brttypes.h key.h
pma-test.o: $(BRT_INTERNAL_H_INCLUDES) pma-internal.h pma.h list.h mempool.h pma-test.o: $(BRT_INTERNAL_H_INCLUDES) pma-internal.h pma.h list.h mempool.h
pma-test: pma.o memory.o key.o ybt.o log.o mempool.o fingerprint.o brt-serialize.o fifo.o primes.o log_code.o roll.o brt.o cachetable.o brt-verify.o pma-test: pma.o memory.o key.o ybt.o log.o mempool.o fingerprint.o brt-serialize.o fifo.o primes.o toku_assert.o log_code.o roll.o brt.o cachetable.o brt-verify.o
pma.o: pma.h yerror.h pma-internal.h memory.h key.h ybt.h brttypes.h log.h ../include/db.h log_header.h pma.o: pma.h yerror.h pma-internal.h memory.h key.h ybt.h brttypes.h log.h ../include/db.h log_header.h
ybt.o: ybt.h brttypes.h ../include/db.h ybt.o: ybt.h brttypes.h ../include/db.h
ybt-test: ybt-test.o ybt.o memory.o ybt-test: ybt-test.o ybt.o memory.o
ybt-test.o: ybt.h ../include/db.h ybt-test.o: ybt.h ../include/db.h
cachetable.o: cachetable.h hashfun.h memory.h cachetable.o: cachetable.h hashfun.h memory.h
brt-test: ybt.o brt.o fifo.o pma.o memory.o brt-serialize.o cachetable.o ybt.o key.o primes.o log.o mempool.o brt-verify.o fingerprint.o log_code.o roll.o brt-test: ybt.o brt.o fifo.o pma.o memory.o brt-serialize.o cachetable.o ybt.o key.o primes.o toku_assert.o log.o mempool.o brt-verify.o fingerprint.o log_code.o roll.o
log.o: log_header.h log-internal.h log.h wbuf.h crc.h brttypes.h $(BRT_INTERNAL_H_INCLUDES) log.o: log_header.h log-internal.h log.h wbuf.h crc.h brttypes.h $(BRT_INTERNAL_H_INCLUDES)
brt-test.o brt.o: brt.h ../include/db.h fifo.h pma.h brttypes.h cachetable.h memory.h brt-test.o brt.o: brt.h ../include/db.h fifo.h pma.h brttypes.h cachetable.h memory.h
brt-serialize-test.o: $(BRT_INTERNAL_H_INCLUDES) brt-serialize-test.o: $(BRT_INTERNAL_H_INCLUDES)
brt.o: $(BRT_INTERNAL_H_INCLUDES) key.h log_header.h brt.o: $(BRT_INTERNAL_H_INCLUDES) key.h log_header.h
fifo.o: fifo.h brttypes.h fifo.o: fifo.h brttypes.h
memory.o: memory.h memory.o: memory.h
primes.o: primes.h primes.o: primes.h toku_assert.h
fifo-test: fifo.o memory.o fifo-test: fifo.o memory.o
brt-serialize.o: $(BRT_INTERNAL_H_INCLUDES) key.h wbuf.h rbuf.h brt-serialize.o: $(BRT_INTERNAL_H_INCLUDES) key.h wbuf.h rbuf.h
brt-bigtest: memory.o ybt.o brt.o pma.o cachetable.o key.o fifo.o brt-serialize.o brt-bigtest: memory.o ybt.o brt.o pma.o cachetable.o key.o fifo.o brt-serialize.o
...@@ -135,23 +149,26 @@ brt-bigtest.o: brt.h ../include/db.h ...@@ -135,23 +149,26 @@ brt-bigtest.o: brt.h ../include/db.h
log-test: log.o memory.o log-test: log.o memory.o
brt-verify.o: $(BRT_INTERNAL_H_INCLUDES) brt-verify.o: $(BRT_INTERNAL_H_INCLUDES)
fingerprint.o: $(BRT_INTERNAL_H_INCLUDES) fingerprint.o: $(BRT_INTERNAL_H_INCLUDES)
toku_assert.o: toku_assert.h
brt-serialize-test: brt-serialize-test.o brt-serialize.o memory.o fifo.o pma.o key.o ybt.o brt.o cachetable.o primes.o log.o mempool.o brt-verify.o fingerprint.o log_code.o roll.o brt-serialize-test: brt-serialize-test.o brt-serialize.o memory.o fifo.o pma.o key.o ybt.o brt.o cachetable.o primes.o toku_assert.o log.o mempool.o brt-verify.o fingerprint.o log_code.o roll.o
test_toku_malloc_plain_free: memory.o test_toku_malloc_plain_free: memory.o
cachetable-test.o: cachetable.h memory.h cachetable-test.o: cachetable.h memory.h
cachetable-test: cachetable.o memory.o cachetable-test.o primes.o cachetable-test: cachetable.o memory.o cachetable-test.o primes.o toku_assert.o
cachetable-test2.o: cachetable.h memory.h cachetable-test2.o: cachetable.h memory.h
cachetable-test2: cachetable.o memory.o cachetable-test2.o primes.o cachetable-test2: cachetable.o memory.o cachetable-test2.o primes.o toku_assert.o
benchmark-test: benchmark-test.o ybt.o memory.o brt.o pma.o cachetable.o key.o fifo.o brt-serialize.o primes.o log.o mempool.o brt-verify.o fingerprint.o log_code.o roll.o benchmark-test: benchmark-test.o ybt.o memory.o brt.o pma.o cachetable.o key.o fifo.o brt-serialize.o primes.o toku_assert.o log.o mempool.o brt-verify.o fingerprint.o log_code.o roll.o
benchmark-test.o: brt.h ../include/db.h benchmark-test.o: brt.h ../include/db.h
test-primes: test-primes.o primes.o test-primes: test-primes.o toku_assert.o primes.o toku_assert.o toku_assert.o
test-assert: test-assert.o toku_assert.o
brtdump: brtdump.o brt-serialize.o memory.o pma.o key.o fingerprint.o log.o log_code.o roll.o cachetable.o primes.o brt.o ybt.o fifo.o mempool.o brt-verify.o brtdump: brtdump.o brt-serialize.o memory.o pma.o key.o fingerprint.o log.o log_code.o roll.o cachetable.o primes.o toku_assert.o brt.o ybt.o fifo.o mempool.o brt-verify.o
checko2: checko2:
ifeq ($(OPTFLAGS),-O2) ifeq ($(OPTFLAGS),-O2)
......
/* -*- mode: C; c-basic-offset: 4 -*- */ /* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
#include <assert.h> #include "toku_assert.h"
static int is_prime (int n) { static int is_prime (int n) {
int i; int i;
...@@ -26,16 +26,16 @@ int toku_get_prime (unsigned int idx) { ...@@ -26,16 +26,16 @@ int toku_get_prime (unsigned int idx) {
primes[i]=j; primes[i]=j;
} }
} }
assert(idx<N_PRIMES); toku_assert(idx<N_PRIMES);
return primes[idx]; return primes[idx];
} }
void toku_test_primes (void) { void toku_test_primes (void) {
assert(toku_get_prime(0)==2); toku_assert(toku_get_prime(0)==2);
assert(toku_get_prime(1)==5); toku_assert(toku_get_prime(1)==5);
assert(toku_get_prime(2)==11); toku_assert(toku_get_prime(2)==11);
assert(toku_get_prime(3)==17); toku_assert(toku_get_prime(3)==17);
assert(toku_get_prime(4)==37); toku_assert(toku_get_prime(4)==37);
assert(toku_get_prime(5)==67); toku_assert(toku_get_prime(5)==67);
assert(toku_get_prime(6)==131); toku_assert(toku_get_prime(6)==131);
} }
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
/* Return the smallest prime >= 2^(idx+1) /* Return the smallest prime >= 2^(idx+1)
* Only works for idx<30 */ * Only works for idx<30 */
int toku_get_prime (unsigned int idx) __attribute__((const)); int toku_get_prime (unsigned int idx) __attribute__((const));
void toku_test_primes(void) __attribute__((const)); void toku_test_primes(void);
#include "toku_assert.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main (int argc, const char *argv[]) {
if (argc!=2) { printf("argcount should be 2.\n"); exit(1); }
const char *str=argv[1];
toku_assert(strcmp(str,"ok")==0);
return 0;
}
#include "toku_assert.h"
#include <stdio.h>
#include <stdlib.h>
void toku_do_assert(int expr,const char* expr_as_string,const char *function,const char*file,int line) {
if (expr==0) {
fprintf(stderr, "%s:%d %s: Assertion `%s' failed\n", file,line,function,expr_as_string);
abort();
}
}
/* The problem with assert.h: If NDEBUG is set then it doesn't execute the function, if NDEBUG isn't set then we get a branch that isn't taken. */
/* This version will complain if NDEBUG is set. */
/* It evaluates the argument and then calls a function toku_do_assert() which takes all the hits for the branches not taken. */
#ifdef NDEBUG
#error NDEBUG should not be set
#endif
void toku_do_assert(int,const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/);
#ifndef FAST_ASSERT
#define toku_assert(expr) toku_do_assert(expr, #expr, __FUNCTION__, __FILE__, __LINE__)
#else
#define toku_assert(expr) ({ int __assert_expr = expr; if (__assert_expr==0) toku_do_assert(0, #expr, __FUNCTION__, __FILE__, __LINE__); })
#endif
void dontuseassert (int) __attribute__((deprecated));
#define assert(barf) dontuseassert(barf)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment