summaryrefslogtreecommitdiff
path: root/ndb/test
diff options
context:
space:
mode:
Diffstat (limited to 'ndb/test')
-rw-r--r--ndb/test/include/getarg.h115
-rw-r--r--ndb/test/ndbapi/testBlobs.cpp224
-rw-r--r--ndb/test/odbc/tpcb/Makefile30
-rw-r--r--ndb/test/odbc/tpcb/Makefile_mysql33
-rw-r--r--ndb/test/odbc/tpcb/Makefile_ndb30
-rw-r--r--ndb/test/odbc/tpcb/readme.txt15
-rw-r--r--ndb/test/odbc/tpcb/timesten.h188
-rw-r--r--ndb/test/odbc/tpcb/tpcb.cpp1415
-rw-r--r--ndb/test/odbc/tpcb/ttTime.c366
-rw-r--r--ndb/test/odbc/tpcb/ttTime.h125
-rw-r--r--ndb/test/run-test/Makefile.am3
-rw-r--r--ndb/test/run-test/main.cpp2
-rw-r--r--ndb/test/src/Makefile.am2
-rw-r--r--ndb/test/src/getarg.c607
14 files changed, 898 insertions, 2257 deletions
diff --git a/ndb/test/include/getarg.h b/ndb/test/include/getarg.h
new file mode 100644
index 00000000000..03ed25f6828
--- /dev/null
+++ b/ndb/test/include/getarg.h
@@ -0,0 +1,115 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/*
+ * Copyright (c) 1997, 1999 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* $KTH: getarg.h,v 1.9 2000/09/01 21:25:55 lha Exp $ */
+
+#ifndef __GETARG_H__
+#define __GETARG_H__
+
+#include <ndb_global.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ arg_integer,
+ arg_string,
+ arg_flag,
+ arg_negative_flag,
+ arg_strings,
+ arg_double,
+ arg_collect,
+ arg_counter
+} arg_type;
+
+struct getargs{
+ const char *long_name;
+ char short_name;
+ arg_type type;
+ void *value;
+ const char *help;
+ const char *arg_help;
+};
+
+enum {
+ ARG_ERR_NO_MATCH = 1,
+ ARG_ERR_BAD_ARG,
+ ARG_ERR_NO_ARG
+};
+
+typedef struct getarg_strings {
+ int num_strings;
+ char **strings;
+} getarg_strings;
+
+typedef int (*getarg_collect_func)(int short_opt,
+ int argc,
+ const char **argv,
+ int *optind,
+ int *optarg,
+ void *data);
+
+typedef struct getarg_collect_info {
+ getarg_collect_func func;
+ void *data;
+} getarg_collect_info;
+
+int getarg(struct getargs *args, size_t num_args,
+ int argc, const char **argv, int *optind);
+
+void arg_printusage (struct getargs *args,
+ size_t num_args,
+ const char *progname,
+ const char *extra_string);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __GETARG_H__ */
diff --git a/ndb/test/ndbapi/testBlobs.cpp b/ndb/test/ndbapi/testBlobs.cpp
index 41bb82f3e06..efa0811aa39 100644
--- a/ndb/test/ndbapi/testBlobs.cpp
+++ b/ndb/test/ndbapi/testBlobs.cpp
@@ -42,13 +42,14 @@ struct Opt {
bool m_core;
bool m_dbg;
bool m_dbgall;
+ const char* m_dbug;
bool m_full;
unsigned m_loop;
unsigned m_parts;
unsigned m_rows;
unsigned m_seed;
const char* m_skip;
- const char* m_style;
+ const char* m_test;
// metadata
const char* m_tname;
const char* m_x1name; // hash index
@@ -66,13 +67,14 @@ struct Opt {
m_core(false),
m_dbg(false),
m_dbgall(false),
+ m_dbug(0),
m_full(false),
m_loop(1),
m_parts(10),
m_rows(100),
m_seed(0),
- m_skip(""),
- m_style("012"),
+ m_skip(0),
+ m_test(0),
// metadata
m_tname("TBLOB1"),
m_x1name("TBLOB1X1"),
@@ -100,46 +102,46 @@ printusage()
<< " -core dump core on error" << endl
<< " -dbg print debug" << endl
<< " -dbgall print also NDB API debug (if compiled in)" << endl
+ << " -dbug opt dbug options" << endl
<< " -full read/write only full blob values" << endl
- << " -inline read/write only blobs which fit inline" << endl
<< " -loop N loop N times 0=forever [" << d.m_loop << "]" << endl
<< " -parts N max parts in blob value [" << d.m_parts << "]" << endl
<< " -rows N number of rows [" << d.m_rows << "]" << endl
<< " -seed N random seed 0=loop number [" << d.m_seed << "]" << endl
- << " -skip xxx skip these tests (see list) [" << d.m_skip << endl
- << " -style xxx access styles to test (see list) [" << d.m_style << "]" << endl
+ << " -skip xxx skip given tests (see list) [no tests]" << endl
+ << " -test xxx only given tests (see list) [all tests]" << endl
<< "metadata" << endl
<< " -pk2len N length of PK2 [" << d.m_pk2len << "/" << g_max_pk2len <<"]" << endl
<< " -oneblob only 1 blob attribute [default 2]" << endl
- << "testcases for -skip" << endl
+ << "testcases for test/skip" << endl
<< " k primary key ops" << endl
<< " i hash index ops" << endl
<< " s table scans" << endl
<< " r ordered index scans" << endl
- << " u update blob value" << endl
- << "access styles for -style" << endl
+ << "additional flags for test/skip" << endl
+ << " u update existing blob value" << endl
+ << " n normal insert and update" << endl
+ << " w insert and update using writeTuple" << endl
<< " 0 getValue / setValue" << endl
<< " 1 setActiveHook" << endl
<< " 2 readData / writeData" << endl
<< "bug tests (no blob test)" << endl
<< " -bug 4088 ndb api hang with mixed ops on index table" << endl
- << " -bug 2222 delete + write gives 626" << endl
- << " -bug 3333 acc crash on delete and long key" << endl
+ << " -bug nnnn delete + write gives 626" << endl
+ << " -bug nnnn acc crash on delete and long key" << endl
;
}
static Opt g_opt;
static bool
-skipcase(int x)
+testcase(char x)
{
- return strchr(g_opt.m_skip, x) != 0;
-}
-
-static bool
-skipstyle(int x)
-{
- return strchr(g_opt.m_style, '0' + x) == 0;
+ if (x < 10)
+ x += '0';
+ return
+ (g_opt.m_test == 0 || strchr(g_opt.m_test, x) != 0) &&
+ (g_opt.m_skip == 0 || strchr(g_opt.m_skip, x) == 0);
}
static Ndb* g_ndb = 0;
@@ -435,7 +437,9 @@ getBlobLength(NdbBlob* h, unsigned& len)
CHK(h->getLength(len2) == 0);
len = (unsigned)len2;
assert(len == len2);
- DBG("getBlobLength " << h->getColumn()->getName() << " len=" << len);
+ bool isNull;
+ CHK(h->getNull(isNull) == 0);
+ DBG("getBlobLength " << h->getColumn()->getName() << " len=" << len << " null=" << isNull);
return 0;
}
@@ -912,6 +916,41 @@ updatePk(int style)
}
static int
+writePk(int style)
+{
+ DBG("--- writePk " << stylename[style] << " ---");
+ for (unsigned k = 0; k < g_opt.m_rows; k++) {
+ Tup& tup = g_tups[k];
+ DBG("writePk pk1=" << hex << tup.m_pk1);
+ CHK((g_con = g_ndb->startTransaction()) != 0);
+ CHK((g_opr = g_con->getNdbOperation(g_opt.m_tname)) != 0);
+ CHK(g_opr->writeTuple() == 0);
+ CHK(g_opr->equal("PK1", tup.m_pk1) == 0);
+ if (g_opt.m_pk2len != 0)
+ CHK(g_opr->equal("PK2", tup.m_pk2) == 0);
+ CHK(getBlobHandles(g_opr) == 0);
+ if (style == 0) {
+ CHK(setBlobValue(tup) == 0);
+ } else if (style == 1) {
+ // non-nullable must be set
+ CHK(g_bh1->setValue("", 0) == 0);
+ CHK(setBlobWriteHook(tup) == 0);
+ } else {
+ // non-nullable must be set
+ CHK(g_bh1->setValue("", 0) == 0);
+ CHK(g_con->execute(NoCommit) == 0);
+ CHK(writeBlobData(tup) == 0);
+ }
+ CHK(g_con->execute(Commit) == 0);
+ g_ndb->closeTransaction(g_con);
+ g_opr = 0;
+ g_con = 0;
+ tup.m_exists = true;
+ }
+ return 0;
+}
+
+static int
deletePk()
{
DBG("--- deletePk ---");
@@ -996,6 +1035,39 @@ updateIdx(int style)
}
static int
+writeIdx(int style)
+{
+ DBG("--- writeIdx " << stylename[style] << " ---");
+ for (unsigned k = 0; k < g_opt.m_rows; k++) {
+ Tup& tup = g_tups[k];
+ DBG("writeIdx pk1=" << hex << tup.m_pk1);
+ CHK((g_con = g_ndb->startTransaction()) != 0);
+ CHK((g_opx = g_con->getNdbIndexOperation(g_opt.m_x1name, g_opt.m_tname)) != 0);
+ CHK(g_opx->writeTuple() == 0);
+ CHK(g_opx->equal("PK2", tup.m_pk2) == 0);
+ CHK(getBlobHandles(g_opx) == 0);
+ if (style == 0) {
+ CHK(setBlobValue(tup) == 0);
+ } else if (style == 1) {
+ // non-nullable must be set
+ CHK(g_bh1->setValue("", 0) == 0);
+ CHK(setBlobWriteHook(tup) == 0);
+ } else {
+ // non-nullable must be set
+ CHK(g_bh1->setValue("", 0) == 0);
+ CHK(g_con->execute(NoCommit) == 0);
+ CHK(writeBlobData(tup) == 0);
+ }
+ CHK(g_con->execute(Commit) == 0);
+ g_ndb->closeTransaction(g_con);
+ g_opx = 0;
+ g_con = 0;
+ tup.m_exists = true;
+ }
+ return 0;
+}
+
+static int
deleteIdx()
{
DBG("--- deleteIdx ---");
@@ -1167,10 +1239,16 @@ deleteScan(bool idx)
// main
+// from here on print always
+#undef DBG
+#define DBG(x) \
+ do { \
+ ndbout << "line " << __LINE__ << " " << x << endl; \
+ } while (0)
+
static int
testmain()
{
- int style;
g_ndb = new Ndb("TEST_DB");
CHK(g_ndb->init() == 0);
CHK(g_ndb->waitUntilReady() == 0);
@@ -1194,55 +1272,88 @@ testmain()
if (g_opt.m_seed != 0)
srandom(g_opt.m_seed);
for (g_loop = 0; g_opt.m_loop == 0 || g_loop < g_opt.m_loop; g_loop++) {
+ int style;
DBG("=== loop " << g_loop << " ===");
if (g_opt.m_seed == 0)
srandom(g_loop);
// pk
for (style = 0; style <= 2; style++) {
- if (skipcase('k') || skipstyle(style))
+ if (! testcase('k') || ! testcase(style))
continue;
DBG("--- pk ops " << stylename[style] << " ---");
- calcTups(false);
- CHK(insertPk(style) == 0);
- CHK(verifyBlob() == 0);
- CHK(readPk(style) == 0);
- if (! skipcase('u')) {
- calcTups(style);
- CHK(updatePk(style) == 0);
+ if (testcase('n')) {
+ calcTups(false);
+ CHK(insertPk(style) == 0);
+ CHK(verifyBlob() == 0);
+ CHK(readPk(style) == 0);
+ if (testcase('u')) {
+ calcTups(style);
+ CHK(updatePk(style) == 0);
+ CHK(verifyBlob() == 0);
+ CHK(readPk(style) == 0);
+ }
+ CHK(deletePk() == 0);
+ CHK(verifyBlob() == 0);
+ }
+ if (testcase('w')) {
+ calcTups(false);
+ CHK(writePk(style) == 0);
+ CHK(verifyBlob() == 0);
+ CHK(readPk(style) == 0);
+ if (testcase('u')) {
+ calcTups(style);
+ CHK(writePk(style) == 0);
+ CHK(verifyBlob() == 0);
+ CHK(readPk(style) == 0);
+ }
+ CHK(deletePk() == 0);
CHK(verifyBlob() == 0);
}
- CHK(readPk(style) == 0);
- CHK(deletePk() == 0);
- CHK(verifyBlob() == 0);
}
// hash index
for (style = 0; style <= 2; style++) {
- if (skipcase('i') || skipstyle(style))
+ if (! testcase('i') || ! testcase(style))
continue;
DBG("--- idx ops " << stylename[style] << " ---");
- calcTups(false);
- CHK(insertPk(style) == 0);
- CHK(verifyBlob() == 0);
- CHK(readIdx(style) == 0);
- calcTups(style);
- if (! skipcase('u')) {
- CHK(updateIdx(style) == 0);
+ if (testcase('n')) {
+ calcTups(false);
+ CHK(insertPk(style) == 0);
+ CHK(verifyBlob() == 0);
+ CHK(readIdx(style) == 0);
+ if (testcase('u')) {
+ calcTups(style);
+ CHK(updateIdx(style) == 0);
+ CHK(verifyBlob() == 0);
+ CHK(readIdx(style) == 0);
+ }
+ CHK(deleteIdx() == 0);
+ CHK(verifyBlob() == 0);
+ }
+ if (testcase('w')) {
+ calcTups(false);
+ CHK(writePk(style) == 0);
CHK(verifyBlob() == 0);
CHK(readIdx(style) == 0);
+ if (testcase('u')) {
+ calcTups(style);
+ CHK(writeIdx(style) == 0);
+ CHK(verifyBlob() == 0);
+ CHK(readIdx(style) == 0);
+ }
+ CHK(deleteIdx() == 0);
+ CHK(verifyBlob() == 0);
}
- CHK(deleteIdx() == 0);
- CHK(verifyBlob() == 0);
}
// scan table
for (style = 0; style <= 2; style++) {
- if (skipcase('s') || skipstyle(style))
+ if (! testcase('s') || ! testcase(style))
continue;
DBG("--- table scan " << stylename[style] << " ---");
calcTups(false);
CHK(insertPk(style) == 0);
CHK(verifyBlob() == 0);
CHK(readScan(style, false) == 0);
- if (! skipcase('u')) {
+ if (testcase('u')) {
CHK(updateScan(style, false) == 0);
CHK(verifyBlob() == 0);
}
@@ -1251,14 +1362,14 @@ testmain()
}
// scan index
for (style = 0; style <= 2; style++) {
- if (skipcase('r') || skipstyle(style))
+ if (! testcase('r') || ! testcase(style))
continue;
DBG("--- index scan " << stylename[style] << " ---");
calcTups(false);
CHK(insertPk(style) == 0);
CHK(verifyBlob() == 0);
CHK(readScan(style, true) == 0);
- if (! skipcase('u')) {
+ if (testcase('u')) {
CHK(updateScan(style, true) == 0);
CHK(verifyBlob() == 0);
}
@@ -1331,9 +1442,7 @@ static struct {
int m_bug;
int (*m_test)();
} g_bugtest[] = {
- { 4088, bugtest_4088 },
- { 2222, bugtest_2222 },
- { 3333, bugtest_3333 }
+ { 4088, bugtest_4088 }
};
NDB_COMMAND(testOdbcDriver, "testBlobs", "testBlobs", "testBlobs", 65535)
@@ -1361,6 +1470,12 @@ NDB_COMMAND(testOdbcDriver, "testBlobs", "testBlobs", "testBlobs", 65535)
putenv(strdup("NDB_BLOB_DEBUG=1"));
continue;
}
+ if (strcmp(arg, "-dbug") == 0) {
+ if (++argv, --argc > 0) {
+ g_opt.m_dbug = strdup(argv[0]);
+ continue;
+ }
+ }
if (strcmp(arg, "-full") == 0) {
g_opt.m_full = true;
continue;
@@ -1395,9 +1510,9 @@ NDB_COMMAND(testOdbcDriver, "testBlobs", "testBlobs", "testBlobs", 65535)
continue;
}
}
- if (strcmp(arg, "-style") == 0) {
+ if (strcmp(arg, "-test") == 0) {
if (++argv, --argc > 0) {
- g_opt.m_style = strdup(argv[0]);
+ g_opt.m_test = strdup(argv[0]);
continue;
}
}
@@ -1431,9 +1546,14 @@ NDB_COMMAND(testOdbcDriver, "testBlobs", "testBlobs", "testBlobs", 65535)
printusage();
return NDBT_ProgramExit(NDBT_WRONGARGS);
}
+ if (g_opt.m_dbug != 0) {
+ DBUG_PUSH(g_opt.m_dbug);
+ }
if (g_opt.m_pk2len == 0) {
char b[100];
- strcpy(b, g_opt.m_skip);
+ b[0] = 0;
+ if (g_opt.m_skip != 0)
+ strcpy(b, g_opt.m_skip);
strcat(b, "i");
strcat(b, "r");
g_opt.m_skip = strdup(b);
diff --git a/ndb/test/odbc/tpcb/Makefile b/ndb/test/odbc/tpcb/Makefile
deleted file mode 100644
index 8ab429c8ea1..00000000000
--- a/ndb/test/odbc/tpcb/Makefile
+++ /dev/null
@@ -1,30 +0,0 @@
-include .defs.mk
-
-TYPE = *
-
-BIN_TARGET = tpcb
-
-SOURCES = ttTime.c tpcb.cpp
-
-CCFLAGS_LOC += \
- -I$(NDB_TOP)/include \
- -I$(NDB_TOP)/include/ndbapi \
- -I$(NDB_TOP)/include/portlib \
- -I$(NDB_TOP)/include/util \
- -I$(NDB_TOP)/test/include \
- -I/usr/local/include
-
-CCFLAGS_WARNINGS += -Wno-unused -Wno-sign-compare -Wformat
-
-CCFLAGS_TOP += -DndbODBC
-
-BIN_TARGET_LIBS = NDB_API_pic NDB_ODBC_pic NDBT
-
-ifeq ($(NDB_OS),SOLARIS)
-BIN_TARGET_LIBS += dmallocthcxx
-CCFLAGS_TOP += -DDMALLOC
-endif
-
-include $(NDB_TOP)/Epilogue.mk
-
-$(BIN_DIR)$(BIN_TARGET): Makefile
diff --git a/ndb/test/odbc/tpcb/Makefile_mysql b/ndb/test/odbc/tpcb/Makefile_mysql
deleted file mode 100644
index 4e1b9a25fe2..00000000000
--- a/ndb/test/odbc/tpcb/Makefile_mysql
+++ /dev/null
@@ -1,33 +0,0 @@
-include $(NDB_TOP)/Defs.mk
-
-TYPE = odbcclient
-
-BIN_TARGET = tpcb
-
-SOURCES = ttTime.c tpcb.cpp
-
-CCFLAGS_LOC += -I/usr/local/include \
- -I$(NDB_TOP)/test/include \
- -I$(NDB_TOP)/include \
- -I$(NDB_TOP)/include/util \
- -I$(NDB_TOP)/src/client/odbc/common
-
-
-
-
-#CCFLAGS_WARNINGS += -Wno-unused
-
-LIBS_LOC += -L/usr/local/lib
-BIN_TARGET_LIBS_DIRS += /usr/local/lib
-BIN_TARGET_LIBS += odbc odbcinst
-
-#LIBS_SPEC += -pg
-# -lNDBT \
-# -lodbc \
-# -lodbcinst \
-# -lportlib
-
-
-
-include $(NDB_TOP)/Epilogue.mk
-
diff --git a/ndb/test/odbc/tpcb/Makefile_ndb b/ndb/test/odbc/tpcb/Makefile_ndb
deleted file mode 100644
index 85960413ef0..00000000000
--- a/ndb/test/odbc/tpcb/Makefile_ndb
+++ /dev/null
@@ -1,30 +0,0 @@
-include $(NDB_TOP)/Defs.mk
-
-TYPE = *
-
-BIN_TARGET = tpcb
-
-SOURCES = ttTime.c tpcb.cpp
-
-CCFLAGS_LOC += \
- -I$(NDB_TOP)/include \
- -I$(NDB_TOP)/include/ndbapi \
- -I$(NDB_TOP)/include/portlib \
- -I$(NDB_TOP)/include/util \
- -I$(NDB_TOP)/test/include \
- -I/usr/local/include
-
-CCFLAGS_WARNINGS += -Wno-unused -Wno-sign-compare -Wformat
-
-CCFLAGS_TOP += -DndbODBC
-
-BIN_TARGET_LIBS = NDB_API_pic NDB_ODBC_pic NDBT
-
-ifeq ($(NDB_OS),SOLARIS)
-BIN_TARGET_LIBS += dmallocthcxx
-CCFLAGS_TOP += -DDMALLOC
-endif
-
-include $(NDB_TOP)/Epilogue.mk
-
-$(BIN_DIR)$(BIN_TARGET): Makefile
diff --git a/ndb/test/odbc/tpcb/readme.txt b/ndb/test/odbc/tpcb/readme.txt
deleted file mode 100644
index 008cafb9d2f..00000000000
--- a/ndb/test/odbc/tpcb/readme.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-'tpcb' requires an .odbc.ini file in
-/etc/
-or in
-/home/user/
-
-The .odbc.ini file must contain a DSN entry called ndb:
-
-#--------- .odbc.ini example --------------------
-
-[ndb]
-Driver = /path_to_installation/lib/libNDB_ODBC.so
-
-#--------- End of example -----------------------
-
-
diff --git a/ndb/test/odbc/tpcb/timesten.h b/ndb/test/odbc/tpcb/timesten.h
deleted file mode 100644
index 45579f9d277..00000000000
--- a/ndb/test/odbc/tpcb/timesten.h
+++ /dev/null
@@ -1,188 +0,0 @@
-/* Copyright (C) 2003 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-/*
- * $Revision: 1.1 $
- * (c) Copyright 1997-2003, TimesTen, Inc.
- * All rights reserved.
- */
-
-#ifndef TIMESTEN_H_INCLUDED
-#define TIMESTEN_H_INCLUDED
-
-#ifdef _WIN32
-#include <windows.h>
-#endif
-
-#include <sql.h>
-#include <sqltypes.h>
-#include <sqlext.h>
-/*
- * TimesTen extension to application data types; only usable
- * when application directly linked to the TimesTen driver.
- */
-#define SQL_C_ADDR 100
-
-#ifndef SQL_C_SBIGINT
-#if (ODBCVER < 0x0300)
-#define SQL_C_SBIGINT (SQL_BIGINT+SQL_SIGNED_OFFSET)
-#define SQL_C_UBIGINT (SQL_BIGINT+SQL_UNSIGNED_OFFSET)
-#endif
-#endif
-
-#define SQL_C_BIGINT SQL_C_SBIGINT
-
-#if (ODBCVER < 0x0300)
-#ifdef _WIN32
-typedef __int64 SQLBIGINT;
-/* On Unix platforms SQLBIGINT is defined in odbcinclude directory*/
-#endif
-#endif
-
-#define BIGINT SQLBIGINT
-
-#ifdef _WIN32
-#define UBIGINT unsigned __int64
-#else
-#define UBIGINT unsigned long long
-#endif
-
-
-#define SQL_WCHAR (-8)
-#define SQL_WVARCHAR (-9)
-#define SQL_WLONGVARCHAR (-10)
-#define SQL_C_WCHAR SQL_WCHAR
-
-/* SQLGetInfo() InfoTypes */
-#define SQL_CONVERT_WCHAR 122
-#define SQL_CONVERT_WLONGVARCHAR 125
-#define SQL_CONVERT_WVARCHAR 126
-
-/* TimesTen specific SQLGetInfo types */
-#define TT_REPLICATION_INVALID (SQL_INFO_DRIVER_START + 2000)
-
-/* SQLGetInfo() return value bitmasks */
-#ifndef SQL_CVT_WCHAR
-/*
-** These definitions differ from Microsoft in that they are not
-** specified as long (e.g. 0x00200000L), hence they are protected
-** by the ifndef above.
-*/
-#define SQL_CVT_WCHAR 0x00200000
-#define SQL_CVT_WLONGVARCHAR 0x00400000
-#define SQL_CVT_WVARCHAR 0x00800000
-#endif
-
-/*
-** The Microsoft Driver Manager SQLBindParameter() will not pass SQL_WCHAR
-** through. Use this hack to get around it.
-*/
-#define SQL_WCHAR_DM_SQLBINDPARAMETER_BYPASS -888
-
-/* This is an extension to ODBC's isolation levels. It reflects an
- * earlier implementation of read-committed that released locks on
- * next fetch, rather than releasing locks before returning value to
- * application. */
-#define SQL_TXN_CURSOR_STABILITY 0x00001000
-#define SQL_TXN_NOBLOCK_DELETE 0x00002000
-
-/* TimesTen-specific connection option */
-#define TT_PREFETCH_CLOSE 10001
-#define TT_PREFETCH_CLOSE_OFF 0
-#define TT_PREFETCH_CLOSE_ON 1
-
-/* Adding a new sql connection option */
-#define TT_PREFETCH_COUNT 10003
-#define TT_PREFETCH_COUNT_MAX 128
-
-/*
- * Platform specific data types for integers that scale
- * with pointer size
- */
-
-#ifdef _IA64_
-typedef signed __int64 tt_ptrint;
-typedef unsigned __int64 tt_uptrint;
-#else
-#ifdef _WIN32
-typedef signed long tt_ptrint;
-typedef unsigned long tt_uptrint;
-#else
-typedef signed long tt_ptrint;
-typedef unsigned long tt_uptrint;
-#endif
-#endif
-
-#ifdef _WIN32
-typedef signed __int64 tt_int8;
-typedef unsigned __int64 tt_uint8;
-#else
-typedef signed long long tt_int8;
-typedef unsigned long long tt_uint8;
-#endif
-
-/* printf formats for pointer-sized integers */
-#ifdef _IA64_ /* 64-bit NT */
-#define PTRINT_FMT "I64d"
-#define UPTRINT_FMT "I64u"
-#define xPTRINT_FMT "I64x"
-#define XPTRINT_FMT "I64X"
-#else
-#ifdef _WIN32 /* 32-bit NT */
-#define PTRINT_FMT "ld"
-#define UPTRINT_FMT "lu"
-#define xPTRINT_FMT "lx"
-#define XPTRINT_FMT "lX"
-#else /* 32 and 64-bit UNIX */
-#define PTRINT_FMT "ld"
-#define UPTRINT_FMT "lu"
-#define xPTRINT_FMT "lx"
-#define XPTRINT_FMT "lX"
-#endif
-#endif
-
-/* printf formats for 8-byte integers */
-#ifndef INT8_FMT_DEFINED
-#ifdef _WIN32 /* 32 and 64-bit NT */
-#define INT8_FMT "I64d"
-#define UINT8_FMT "I64u"
-#define xINT8_FMT "I64x"
-#define XINT8_FMT "I64X"
-#else /* 32 and 64-bit UNIX */
-#define INT8_FMT "lld"
-#define UINT8_FMT "llu"
-#define xINT8_FMT "llx"
-#define XINT8_FMT "llX"
-#endif
-#define INT8_FMT_DEFINED 1
-#endif
-
-/* The following types are defined in the newer odbc include files
- from Microsoft
-*/
-#if defined (_WIN32) && !defined (_IA64_)
-#ifndef SQLROWSETSIZE
-#define SQLROWSETSIZE SQLUINTEGER
-#define SQLLEN SQLINTEGER
-#define SQLROWOFFSET SQLINTEGER
-#define SQLROWCOUNT SQLUINTEGER
-#define SQLULEN SQLUINTEGER
-#define SQLSETPOSIROW SQLUSMALLINT
-#endif
-#endif
-
-
-#endif
diff --git a/ndb/test/odbc/tpcb/tpcb.cpp b/ndb/test/odbc/tpcb/tpcb.cpp
deleted file mode 100644
index 60d746e7844..00000000000
--- a/ndb/test/odbc/tpcb/tpcb.cpp
+++ /dev/null
@@ -1,1415 +0,0 @@
-/* Copyright (C) 2003 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-static const volatile char cvsid[] = "$Id: tpcb.cpp,v 1.4 2003/09/26 09:04:34 johan Exp $";
-/*
- * $Revision: 1.4 $
- * (c) Copyright 1996-2003, TimesTen, Inc.
- * All rights reserved.
- */
-
-/* This source is best displayed with a tabstop of 4 */
-
-#define NDB
-
-//#define MYSQL
-
-#ifdef WIN32
-#include <windows.h>
-#include "ttRand.h"
-#else
-#if !defined NDB && !defined MYSQL
-#include <sqlunix.h>
-#endif
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#ifdef SB_P_OS_CHORUS
-#include "ttRand.h"
-#endif
-#endif
-
-#include <math.h>
-#include <time.h>
-#include <sql.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-
-#if !defined NDB && !defined MYSQL
-#include "ttTime.h"
-#include "utils.h"
-#include "tt_version.h"
-#include "timesten.h"
-#endif
-
-#if defined NDB || defined MYSQL
-#include <NdbOut.hpp>
-#include <string.h>
-
-#include <sqlext.h>
-#include <sql.h>
-extern "C" {
-#include "ttTime.h"
-#include "timesten.h"
- void ttGetWallClockTime(ttWallClockTime* timeP);
- void ttCalcElapsedWallClockTime(ttWallClockTime* beforeP,
- ttWallClockTime* afterP,
- double* nmillisecondsP);
- void ttGetThreadTimes(ttThreadTimes * endRes);
- void ttCalcElapsedThreadTimes(ttThreadTimes* startRes,
- ttThreadTimes * endRes,
- double * kernel,
- double * user);
-}
-
-#define app_exit exit
-#define status_msg0 ndbout_c
-#define status_msg1 ndbout_c
-#define status_msg2 ndbout_c
-#define err_msg0 ndbout_c
-#define err_msg1 ndbout_c
-#define err_msg3 ndbout_c
-#define out_msg0 ndbout_c
-#define out_msg1 ndbout_c
-#define out_msg3 ndbout_c
-#define CONN_STR_LEN 255
-#define DBMS_TIMESTEN 1
-#define DBMS_MSSQL 2
-#define DBMS_UNKNOWN 3
-#define ABORT_DISCONNECT_EXIT 1
-#define NO_EXIT 0
-#define ERROR_EXIT 1
-#define DISCONNECT_EXIT 2
-#endif
-
-#define VERBOSE_NOMSGS 0
-/* this value is used for results (and err msgs) only */
-#define VERBOSE_RESULTS 1
-/* this value is the default for the cmdline demo */
-#define VERBOSE_DFLT 2
-#define VERBOSE_ALL 3
-
-#ifdef MYSQL
-#define DSNNAME "DSN=myodbc3"
-#elif defined NDB
-#define DSNNAME "DSN=ndb"
-#else
-#define DSNNAME "DSN="
-#endif
-
-/* number of branches, tellers, and accounts */
-
-#define NumBranches 1
-#define TellersPerBranch 10
-#define AccountsPerBranch 10000
-
-/* number of transactions to execute */
-
-#define NumXacts 25000
-
-/* starting seed value for the random number generator */
-
-#define SeedVal 84773
-
-/* for MS SQL, the drop, create and use database statements */
-
-#define DatabaseDropStmt "drop database tpcbDB;"
-#ifdef MYSQL
-#define DatabaseCreateStmt "create database tpcbDB;"
-#else
-#define DatabaseCreateStmt "create database tpcbDB ON DEFAULT = %d;"
-#endif
-#define DatabaseUseStmt "use tpcbDB;"
-
-/*
- * Specifications of table columns.
- * Fillers of 80, 80, 84, and 24 bytes, respectively, are used
- * to ensure that rows are the width required by the benchmark.
- *
- * Note: The TimesTen and MS SQL CREATE TABLE statements for the
- * accounts, tellers and branches tables are different.
- *
- */
-
-#define TuplesPerPage 256
-
-
-#ifdef MYSQL
-
-#define AccountCrTblStmt "create table accounts \
-(number integer not null primary key, \
-branchnum integer not null, \
-balance float not null, \
-filler char(80));"
-
-#define TellerCrTblStmt "create table tellers \
-(number integer not null primary key, \
-branchnum integer not null, \
-balance float not null, \
-filler char(80));"
-
-#define BranchCrTblStmt "create table branches \
-(number integer not null primary key, \
-balance float not null, \
-filler char(84));"
-
-#endif
-
-
-#ifdef NDB
-#define AccountCrTblStmt "create table accounts \
-(number integer not null primary key, \
-branchnum integer not null, \
-balance float not null, \
-filler char(80)) nologging"
-
-#define TellerCrTblStmt "create table tellers \
-(number integer not null primary key, \
-branchnum integer not null, \
-balance float not null, \
-filler char(80)) nologging"
-
-#define BranchCrTblStmt "create table branches \
-(number integer not null primary key, \
-balance float not null, \
-filler char(84)) nologging"
-#endif
-
-#ifdef NDB
-
-#define HistoryCrTblStmt "create table History \
-(tellernum integer not null, \
-branchnum integer not null, \
-accountnum integer not null, \
-delta float not null, \
-createtime integer not null, \
-filler char(24), \
-primary key (tellernum, branchnum, accountnum, delta, createtime)) nologging"
-
-#else
-
-#ifdef MYSQL
-
-#define HistoryCrTblStmt "create table History \
-(tellernum integer not null, \
-branchnum integer not null, \
-accountnum integer not null, \
-delta float(53) not null, \
-createtime integer not null, \
-filler char(24))"
-#endif
-
-#define HistoryCrTblStmt "create table History \
-(tellernum integer not null, \
-branchnum integer not null, \
-accountnum integer not null, \
-delta float(53) not null, \
-createtime integer not null, \
-filler char(24));"
-#endif
-
-#define TTAccountCrTblStmt "create table accounts \
-(number integer not null primary key, \
-branchnum integer not null, \
-balance float(53) not null, \
-filler char(80)) unique hash on (number) pages = %" PTRINT_FMT ";"
-
-#define TTTellerCrTblStmt "create table tellers \
-(number integer not null primary key, \
-branchnum integer not null, \
-balance float(53) not null, \
-filler char(80)) unique hash on (number) pages = %" PTRINT_FMT ";"
-
-#define TTBranchCrTblStmt "create table branches \
-(number integer not null primary key, \
-balance float(53) not null, \
-filler char(84)) unique hash on (number) pages = %" PTRINT_FMT ";"
-
-
-/* Insertion statements used to populate the tables */
-
-#define NumInsStmts 3
-char* insStmt[NumInsStmts] = {
- "insert into branches values (?, 0.0, NULL)",
- "insert into tellers values (?, ?, 0.0, NULL)",
- "insert into accounts values (?, ?, 0.0, NULL)"
-};
-
-/* Transaction statements used to update the tables */
-
-#define NumXactStmts 5
-
-#ifdef NDB
-char* tpcbXactStmt[NumXactStmts] = {
- "update accounts \
-set balance = balance + ? \
-where number = ?",
-
- "select balance \
-from accounts \
-where number = ?",
-
- "update tellers \
-set balance = balance + ? \
-where number = ?",
-
- "update branches \
-set balance = balance + ? \
-where number = ?",
-
- "insert into History(tellernum, branchnum, \
-accountnum, delta, createtime, filler) \
-values (?, ?, ?, ?, ?, NULL)"
-};
-
-#else
-char* tpcbXactStmt[NumXactStmts] = {
- "update accounts \
-set balance = balance + ? \
-where number = ?;",
-
- "select balance \
-from accounts \
-where number = ?;",
-
- "update tellers \
-set balance = balance + ? \
-where number = ?;",
-
- "update branches \
-set balance = balance + ? \
-where number = ?;",
-
- "insert into History \
-values (?, ?, ?, ?, ?, NULL);"
-};
-
-
-#endif
-
-/* Global parameters and flags (typically set by parse_args()) */
-
-int tabFlag = 0; /* Default is NOT tab output mode */
-char szConnStrIn[CONN_STR_LEN]; /* ODBC Connection String */
-int printXactTimes = 0; /* Transaction statistics
- * gathering flag */
-char statFile[FILENAME_MAX]; /* Transaction statistics filename */
-int scaleFactor = 2; /* Default TPS scale factor */
-int numBranchTups; /* Number of branches */
-int numTellerTups; /* Number of tellers */
-int numAccountTups; /* Number of accounts */
-int numNonLocalAccountTups; /* Number of local accounts */
-int numXacts = NumXacts; /* Default number of transactions */
-int verbose = VERBOSE_DFLT; /* Verbose level */
-FILE *statusfp; /* File for status messages */
-
-
-
-int DBMSType; /* DBMS type (DBMS_TIMESTEN, DBMS_MSSQL...) */
-
-
-SQLHENV henv; /* Environment handle */
-
-
-
-
-
-
-
-void handle_errors( SQLHDBC hdbc, SQLHSTMT hstmt, int errcode, int action, char * msg,
- char * file, int line) {
-
- if (errcode == SQL_SUCCESS)
- return;
-
- if(errcode == SQL_ERROR) {
- int ret;
- long diagCount=0;
- short length=0;
- SQLCHAR state[10] = "";
- SQLCHAR message[200] = "";
- long native = 0;
- if(hstmt != 0) {
- ret = SQLGetDiagField(SQL_HANDLE_STMT, hstmt, 0, SQL_DIAG_NUMBER, &diagCount, SQL_IS_INTEGER, 0);
-
- for(long i = 0; i < diagCount; i++) {
- ret = SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, i, (SQLCHAR*)state, &native, (SQLCHAR*)message, 200, &length);
- ndbout_c("GetDiagRec: Message : %s ", message);
- }
- }
- }
-
- if(errcode != SQL_SUCCESS) {
- ndbout_c("Message: %s", msg);
- switch(errcode) {
- case SQL_SUCCESS_WITH_INFO:
- ndbout_c("SQL_SUCCESS_WITH_INFO");
- break;
- case SQL_STILL_EXECUTING:
- ndbout_c("SQL_STILL_EXECUTING");
- break;
- case SQL_ERROR:
- ndbout_c("SQL_ERROR");
- break;
- case SQL_INVALID_HANDLE:
- ndbout_c("SQL_INVALID_HANDLE");
- break;
- default:
- ndbout_c("Some other error");
- }
- exit(1);
- }
-
-
-}
-
-
-
-
-
-/*********************************************************************
- * FUNCTION: usage
- *
- * DESCRIPTION: This function prints a usage message describing
- * the command line options of the program.
- *
- * PARAMETERS: char* prog full program path name
- *
- * RETURNS: void
- *
- * NOTES: NONE
- *
- *********************************************************************/
-
-static void usage(char *prog)
-{
- char *progname;
-
- /* Get the name of the program (sans path). */
-
-#ifdef WIN32
- progname = strrchr(prog, '\\');
-#else
- progname = strrchr(prog, '/');
-#endif
- if (progname == 0)
- progname = prog;
- else
- ++progname;
-
- /* Print the usage message */
-
- fprintf(stderr,
- "Usage:\t%s [-h] [-help] [-V] [-connStr <string>] [-v <level>]\n"
- "\t\t[-xact <xacts>] [-scale <scale>] [-tabs] [-s <statfile>]\n\n"
- " -h Prints this message and exits.\n"
- " -help Same as -h.\n"
- " -V Prints version number and exits.\n"
- " -connStr <string> Specifies an ODBC connection string to replace the\n"
- " default DSN for the program. The default is\n"
- " \"DSN=TpcbData<version>;OverWrite=1\".\n"
- " -v <level> Verbose level\n"
- " 0 = errors only\n"
- " 1 = results only\n"
- " 2 = results and some status messages (default)\n"
- " 3 = all messages\n"
- " -xact <xacts> Specifies the number of transactions to be run\n"
- " The default is 25000 transactions.\n"
- " -scale <scale> Specifies a scale factor which determines the\n"
- " number of branches (scale), tellers (scale x 10),\n"
- " accounts (scale x 10000) and non-local accounts\n"
- " ((scale-1) x 10000. The default scale factor is 2.\n"
- " -tabs Specifies that the output be a tab-separated\n"
- " format suitable for import into a spreadsheet.\n"
- " Results only go to stdout; status and other\n"
- " messages go to stderr.\n"
- " -s <statfile> Prints individual transaction times to <statfile>.\n",
- progname);
-}
-
-/*********************************************************************
- *
- * FUNCTION: parse_args
- *
- * DESCRIPTION: This function parses the command line arguments
- * passed to main(), setting the appropriate global
- * variables and issuing a usage message for
- * invalid arguments.
- *
- * PARAMETERS: int argc # of arguments from main()
- * char *argv[] arguments from main()
- *
- * RETURNS: void
- *
- * NOTES: NONE
- *
- *********************************************************************/
-
-void
-parse_args(int argc, char *argv[])
-{
- int i = 1;
-
- *szConnStrIn = 0;
-
- while (i < argc) {
-
- if ( !strcmp(argv[i], "-h") || !strcmp(argv[i], "-help") ) {
- usage(argv[0]);
- app_exit(0);
- }
- /*
- if (!strcmp(argv[i], "-V")) {
- printf("%s\n", TTVERSION_STRING);
- app_exit(0);
- }
- */
- if (strcmp(argv[i], "-s") == 0) {
- if (argc < i+2 ) {
- usage(argv[0]);
- app_exit(1);
- }
- if (sscanf(argv[i+1], "%s", statFile) == 0) {
- usage(argv[0]);
- app_exit(1);
- }
- printXactTimes = 1;
- i += 2;
- }
- else if (!strcmp(argv[i], "-connStr")) {
- if (argc < i+2 ) {
- usage(argv[0]);
- app_exit(1);
- }
- strcpy(szConnStrIn, argv[i+1]);
- i += 2;
- continue;
- }
- else if (strcmp("-v", argv[i]) == 0) {
- if (argc < i+2 ) {
- usage(argv[0]);
- app_exit(1);
- }
- if (sscanf(argv[i+1], "%d", &verbose) == -1 ||
- verbose < 0 || verbose > 3) {
- fprintf(stderr, "-v flag requires an integer parameter (0-3)\n");
- usage(argv[0]);
- app_exit(1);
- }
- i += 2;
- }
- else if (strcmp("-xact",argv[i]) == 0) {
- if (argc < i+2 ) {
- usage(argv[0]);
- app_exit(1);
- }
-
- if (sscanf(argv[i+1], "%" PTRINT_FMT, &numXacts) == -1 || numXacts < 0) {
- fprintf(stderr, "-xact flag requires a non-negative integer argument\n");
- usage(argv[0]);
- app_exit(1);
- }
-
- i += 2;
- }
- else if (strcmp("-scale",argv[i]) == 0) {
- if (argc < i+2 ) {
- usage(argv[0]);
- app_exit(1);
- }
- if (sscanf(argv[i+1], "%d", &scaleFactor) == -1 || scaleFactor < 1) {
- fprintf(stderr, "-scale flag requires an integer argument >= 1\n");
- usage(argv[0]);
- app_exit(1);
- }
- /* Calculate tuple sizes */
- numBranchTups = NumBranches * scaleFactor;
- numTellerTups = TellersPerBranch * scaleFactor;
- numAccountTups = AccountsPerBranch * scaleFactor;
- numNonLocalAccountTups = AccountsPerBranch * (scaleFactor-1);
- i += 2;
- }
- else if (strcmp("-tabs",argv[i]) == 0) {
- tabFlag = 1;
- statusfp = stderr;
- i += 1;
- }
- else {
- usage(argv[0]);
- app_exit(1);
- }
- }
-}
-
-/*********************************************************************
- *
- * FUNCTION: doImmed
- *
- * DESCRIPTION: This function executes and frees the specified
- * statement. It is used as a direct means to
- * create the tables used by this benchmark,
- *
- * PARAMETERS: SQLHDBC hdbc SQL Connection handle
- * SQLHSTMT hs SQL Statement handle
- * char* cmd SQL Statement text
- *
- * RETURNS: void
- *
- * NOTES: NONE
- *
- *********************************************************************/
-
-void
-doImmed(SQLHDBC hdbc, SQLHSTMT hs, char* cmd)
-{
- SQLRETURN rc;
-
- /* Execute the command */
-
- rc = SQLExecDirect(hs, (SQLCHAR *) cmd, SQL_NTS);
- handle_errors(hdbc, hs, rc, ABORT_DISCONNECT_EXIT,
- "Error executing statement", __FILE__, __LINE__);
-
- /* Close associated cursor and drop pending results */
-
- rc = SQLFreeStmt(hs, SQL_CLOSE);
- handle_errors(hdbc, hs, rc, ABORT_DISCONNECT_EXIT,
- "closing statement handle",
- __FILE__, __LINE__);
-
-}
-
-
-/*********************************************************************
- *
- * FUNCTION: main
- *
- * DESCRIPTION: This is the main function of the tpcb benchmark.
- * It connects to an ODBC data source, creates and
- * populates tables, updates the tables in a user-
- * specified number of transactions and reports on
- * on the transaction times.
- *
- * PARAMETERS: int argc # of command line arguments
- * char *argv[] command line arguments
- *
- * RETURNS: void
- *
- * NOTES: NONE
- *
- *********************************************************************/
-
-int
-main(int argc, char *argv[])
-{
-
- /* variables used for setting up the tables */
-
- char cmdStr[1024];
- char errstr[4096];
-
- /* variables used during transactions */
-
- int accountNum;
- int tellerNum;
- int branchNum;
- int timeStamp;
- double delta;
- unsigned int lrand;
- unsigned short *srands, localLimit;
- int lp64;
-
- /* variables used for timing and statistics */
-
- int warmup;
- double kernel, user, real;
- ttThreadTimes startRes, endRes;
- ttWallClockTime startT, endT;
- ttWallClockTime** rtStart;
- ttWallClockTime** rtEnd;
- double** resTime;
- double maxTime, totTime;
- int i;
- int j;
- int numLocalXacts=0, numRemoteXacts=0;
-
- /* variables for ODBC */
-
- SQLHDBC hdbc;
- SQLHSTMT hstmt;
- SQLHSTMT txstmt[NumXactStmts];
- SQLRETURN rc;
- char DBMSName[32];
- char DBMSVersion[32];
- int databaseSize;
-
- int fThreadTime = 1;
-
-#ifdef WIN32
- OSVERSIONINFO sysInfo;
-
- sysInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionEx (&sysInfo);
-
- /* GetThreadTimes is not supported on 95/98. Hence,
- we do not support Resource/User/System times */
- if (sysInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
- fThreadTime = 0;
-#endif
-#if defined(TTCLIENTSERVER) && defined(__hpux) && !defined(__LP64__)
- /* HP requires this for C main programs that call aC++ shared libs */
- _main();
-#endif /* hpux32 */
-
- /* Set up default signal handlers */
-
-#ifndef NDB
- /* StopRequestClear();
- if (HandleSignals() != 0) {
- err_msg0("Unable to set signal handlers\n");
- return 1;
- }
- */
-#endif
- /* set IO mode for demo */
- /* set_io_mode(); */
-
- /* initialize the file for status messages */
- statusfp = stdout;
-
- /* set variable for 8-byte longs */
- lp64 = (sizeof(lrand) == 8);
-
- /* set the default tuple sizes */
-
- numBranchTups = NumBranches * scaleFactor;
- numTellerTups = TellersPerBranch * scaleFactor;
- numAccountTups = AccountsPerBranch * scaleFactor;
- numNonLocalAccountTups = AccountsPerBranch * (scaleFactor-1);
-
- /* parse the command arguments */
- parse_args(argc, argv);
-
- /* allocate the transaction-based variables */
-
- rtStart = (ttWallClockTime**) malloc(numXacts * sizeof(ttWallClockTime*));
- if (!rtStart) {
- err_msg0("Cannot allocate the transaction timing structures");
- app_exit(1);
- }
- for (i = 0; i < numXacts; i++) {
- rtStart[i] = (ttWallClockTime*) malloc(sizeof(ttWallClockTime));
- if (!rtStart[i]) {
- err_msg0("Cannot allocate the transaction timing structures");
- app_exit(1);
- }
- }
-
- rtEnd = (ttWallClockTime**) malloc(numXacts * sizeof(ttWallClockTime*));
- if (!rtEnd) {
- err_msg0("Cannot allocate the transaction timing structures");
- app_exit(1);
- }
- for (i = 0; i < numXacts; i++) {
- rtEnd[i] = (ttWallClockTime*) malloc(sizeof(ttWallClockTime));
- if (!rtEnd[i]) {
- err_msg0("Cannot allocate the transaction timing structures");
- app_exit(1);
- }
- }
-
- resTime = (double**) malloc(numXacts * sizeof(double*));
- if (!resTime) {
- err_msg0("Cannot allocate the transaction timing structures");
- app_exit(1);
- }
- for (i = 0; i < numXacts; i++) {
- resTime[i] = (double*) malloc(sizeof(double));
- if (!resTime[i]) {
- err_msg0("Cannot allocate the transaction timing structures");
- app_exit(1);
- }
- }
-
- /* ODBC initialization */
-
- rc = SQLAllocEnv(&henv);
- if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
- /* error occurred -- don't bother calling handle_errors, since handle
- * is not valid so SQLError won't work */
- err_msg3("ERROR in %s, line %d: %s\n",
- __FILE__, __LINE__, "allocating an environment handle");
- app_exit(1);
- }
- SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);
-
- /* call this in case of warning */
- handle_errors(NULL, NULL, rc, NO_EXIT,
- "allocating execution environment",
- __FILE__, __LINE__);
-
- rc = SQLAllocConnect(henv, &hdbc);
- handle_errors(NULL, NULL, rc, ERROR_EXIT,
- "allocating connection handle",
- __FILE__, __LINE__);
-
- /* Connect to data store */
-
- status_msg0("Connecting to the data source...\n");
-
- /* Set up the connection options if not specified on the command line
- * (default to TimesTen settings).
- */
-
- if ( !*szConnStrIn ) {
- /* Running the benchmark with a scale factor creates (scale) branches,
- * (scale x 10) tellers, (scale x 10000) accounts and ((scale-1) x 10000)
- * non-local accounts. The size of the table rows are branches (141)
- * tellers (141) and accounts (141). Therefore the data size requirements
- * of this benchmark is:
- * size ~= 141 * ((scale * 20011) - 10000) (bytes)
- *
- * Multiply data size by 20% to account for additional DB overhead (e.g.
- * indexes), and round up the nearest 10Mb for safety.
- */
-
- int est_size = (int) (3.6 * scaleFactor + 10.0);
- est_size = est_size - (est_size % 10);
-
- sprintf(szConnStrIn,"OverWrite=1;PermSize=%d;%s",
- est_size, DSNNAME);
- status_msg0("Connecting to the data source... %s \n", szConnStrIn);
- }
-
- rc = SQLDriverConnect(hdbc, NULL, (SQLCHAR *) szConnStrIn, SQL_NTS,
- NULL, 0, NULL,
- SQL_DRIVER_NOPROMPT);
-
- status_msg0("Connected to the data source...\n");
- sprintf(errstr, "connecting to driver (connect string %s)\n",
- szConnStrIn);
- handle_errors(hdbc, NULL, rc, ERROR_EXIT,
- errstr, __FILE__, __LINE__);
-
- /* Turn auto-commit off */
-
- rc = SQLSetConnectOption(hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
- handle_errors(hdbc, NULL, rc, DISCONNECT_EXIT,
- "switching off the AUTO_COMMIT option",
- __FILE__, __LINE__);
-
- /* Allocate a statement handle */
-
- rc = SQLAllocStmt(hdbc, &hstmt);
- handle_errors(hdbc, NULL, rc, DISCONNECT_EXIT,
- "allocating a statement handle",
- __FILE__, __LINE__);
-
- /* (Implicit) Transaction begin */
-
- /* Determine the DBMS Type*/
-
- DBMSName[0] = '\0';
- rc = SQLGetInfo(hdbc, SQL_DBMS_NAME, (PTR) &DBMSName,
- sizeof(DBMSName), NULL);
- rc = SQLGetInfo(hdbc, SQL_DRIVER_VER, (PTR) &DBMSVersion,
- sizeof(DBMSVersion), NULL);
-
- if (strcmp(DBMSName, "TimesTen") == 0)
- DBMSType = DBMS_TIMESTEN;
- else if (strcmp(DBMSName, "Microsoft SQL Server") == 0)
- DBMSType = DBMS_MSSQL;
- else DBMSType = DBMS_UNKNOWN;
-
- /* if not TimesTen: delete (if it exists), create & use the new database */
-
- if (DBMSType != DBMS_TIMESTEN) {
- status_msg0("Deleting the database...\n");
- rc = SQLExecDirect(hstmt, (SQLCHAR *) DatabaseDropStmt, SQL_NTS);
-
- /* estimate database size, size = data space + log space
- * data space = (#tuples)/(tuples per page) * 2K bytes/page
- * tuples per page = useable page size / row size (no index) = 2016/(96+2)
- * log space = #transactions * average log size for the program transaction mix
- * database size is in MB
- */
-
- databaseSize = (int) ceil((((numBranchTups + numTellerTups + numAccountTups)/
- (2016/98)) * 2048 + (numXacts * 600)) / 1000000.0);
-
- status_msg1("Creating the database (%dMB)...\n", databaseSize);
-#ifndef NDB
- sprintf(cmdStr, DatabaseCreateStmt, databaseSize);
- doImmed(hdbc, hstmt, cmdStr);
- strcpy(cmdStr, DatabaseUseStmt);
- doImmed(hdbc, hstmt, cmdStr);
-#endif
- }
-
- status_msg2("Connected to '%s' version '%s'...\n", DBMSName, DBMSVersion);
-
- /* create branches table */
- status_msg0("Creating tasddbles...\n");
-#ifndef NDB
- if (DBMSType == DBMS_TIMESTEN)
- sprintf(cmdStr, TTBranchCrTblStmt, numBranchTups/TuplesPerPage + 1);
- else
-#endif
- sprintf(cmdStr, BranchCrTblStmt);
- doImmed(hdbc, hstmt, cmdStr);
-
- /* create tellers table */
-#ifndef NDB
- if (DBMSType == DBMS_TIMESTEN)
- sprintf(cmdStr, TTTellerCrTblStmt, numTellerTups/TuplesPerPage + 1);
-
- else
-#endif
- sprintf(cmdStr, TellerCrTblStmt);
- doImmed(hdbc, hstmt, cmdStr);
-
- /* create accounts table */
-#ifndef NDB
- if (DBMSType == DBMS_TIMESTEN)
- sprintf(cmdStr, TTAccountCrTblStmt, numAccountTups/TuplesPerPage + 1);
- else
-#endif
- sprintf(cmdStr, AccountCrTblStmt);
- doImmed(hdbc, hstmt, cmdStr);
-
- /* create History table */
-
- doImmed(hdbc, hstmt, HistoryCrTblStmt);
-
- /* lock the database during population */
-#ifndef NDB
- if ( DBMSType == DBMS_TIMESTEN ) {
- rc = SQLExecDirect(hstmt, (SQLCHAR *)"call ttlocklevel('DS')", SQL_NTS);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "specifying dbs lock usage",
- __FILE__, __LINE__);
- /* make sure dbs lock take effect in next transaction */
- rc = SQLTransact(henv,hdbc,SQL_COMMIT);
- if ( rc != SQL_SUCCESS) {
- handle_errors(hdbc, SQL_NULL_HSTMT, rc, ERROR_EXIT,
- "committing transaction",
- __FILE__, __LINE__);
- }
- }
-#endif
- /* populate branches table */
-
-
- rc = SQLPrepare(hstmt, (SQLCHAR *) insStmt[0], SQL_NTS);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "preparing statement",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 10, 0, &branchNum, sizeof branchNum, NULL);
-
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
-
- status_msg1("Populating branches table (%" PTRINT_FMT " rows)...\n",
- numBranchTups);
-
-
- for (i=0; i<numBranchTups; i++) {
- branchNum = i;
- rc = SQLExecute(hstmt);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "Error executing statement",
- __FILE__, __LINE__);
- }
-
- /* Reset all bind-parameters for the statement handle. */
- rc = SQLFreeStmt(hstmt, SQL_RESET_PARAMS);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "resetting parms on statement handle",
- __FILE__, __LINE__);
-
- /* populate tellers table */
-
- status_msg1("Populating tellers table (%" PTRINT_FMT " rows)...\n",
- numTellerTups);
-
-
- rc = SQLPrepare(hstmt, (SQLCHAR *) insStmt[1], SQL_NTS);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "preparing statement",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER,
- 10, 0, &tellerNum, sizeof tellerNum, NULL);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER,
- 10, 0, &branchNum, sizeof branchNum, NULL);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- for (i=0; i<numTellerTups; i++) {
- tellerNum = i;
- branchNum = i/TellersPerBranch;
- rc = SQLExecute(hstmt);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "Error executing statement",
- __FILE__, __LINE__);
- }
-
- /* Reset all bind-parameters for the statement handle. */
-
- rc = SQLFreeStmt(hstmt, SQL_RESET_PARAMS);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "resetting parms on statement handle",
- __FILE__, __LINE__);
-
- /* populate accounts table */
-
- status_msg1("Populating accounts table (%" PTRINT_FMT " rows)...\n",
- numAccountTups);
-
- rc = SQLPrepare(hstmt, (SQLCHAR *) insStmt[2], SQL_NTS);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "preparing statement",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER,
- 10, 0, &accountNum, sizeof accountNum, NULL);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER,
- 10, 0, &branchNum, sizeof branchNum, NULL);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- for (i=0; i<numAccountTups; i++) {
- accountNum = i;
- branchNum = i/AccountsPerBranch;
- rc = SQLExecute(hstmt);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "Error executing statement",
- __FILE__, __LINE__);
- }
- status_msg0("Commit...\n");
- rc = SQLTransact(henv, hdbc, SQL_COMMIT);
- status_msg0("Commit done...\n");
- handle_errors(hdbc, NULL, rc, ERROR_EXIT,
- "committing transaction",
- __FILE__, __LINE__);
-
- /* compile SQL statements of transaction */
-
- status_msg0("Compiling statements of transaction...\n");
- for (i=0; i<NumXactStmts; i++) {
-#ifndef NDB
- rc = SQLAllocStmt(hdbc, &txstmt[i]);
- handle_errors(hdbc, NULL, rc, ABORT_DISCONNECT_EXIT,
- "allocating a statement handle",
- __FILE__, __LINE__);
-#else
- rc = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &txstmt[i]);
- handle_errors(hdbc, NULL, rc, ABORT_DISCONNECT_EXIT,
- "allocating a statement handle",
- __FILE__, __LINE__);
-
-#endif
-
- rc = SQLPrepare(txstmt[i], (SQLCHAR *) tpcbXactStmt[i], SQL_NTS);
- handle_errors(hdbc, txstmt[i], rc, ABORT_DISCONNECT_EXIT,
- "preparing statement",
- __FILE__, __LINE__);
- }
-
- /* unuse dbs lock */
-#ifndef NDB
- if ( DBMSType == DBMS_TIMESTEN ) {
- rc = SQLExecDirect(hstmt, (SQLCHAR *)"call ttlocklevel('Row')", SQL_NTS);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "specifying row lock usage",
- __FILE__, __LINE__);
- }
-#endif
-
- /* commit transaction */
-
- rc = SQLTransact(henv, hdbc, SQL_COMMIT);
- handle_errors(hdbc, NULL, rc, ERROR_EXIT,
- "committing transaction",
- __FILE__, __LINE__);
-
-
- /* Initialize random seed and timers */
-
- srand48(SeedVal);
- localLimit = (unsigned short)((1<<16) * 0.85);
-
- /* Initialize parameter lists for each of the transactions */
-
- rc = SQLBindParameter(txstmt[0], 1, SQL_PARAM_INPUT, SQL_C_DOUBLE,
- SQL_DOUBLE, 15, 0, &delta, sizeof delta, NULL);
- handle_errors(hdbc, txstmt[0], rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(txstmt[0], 2, SQL_PARAM_INPUT, SQL_C_SLONG,
- SQL_INTEGER, 10, 0, &accountNum, sizeof accountNum,
- NULL);
- handle_errors(hdbc, txstmt[0], rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(txstmt[1], 1, SQL_PARAM_INPUT, SQL_C_SLONG,
- SQL_INTEGER, 10, 0, &accountNum, sizeof accountNum,
- NULL);
- handle_errors(hdbc, txstmt[1], rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(txstmt[2], 1, SQL_PARAM_INPUT, SQL_C_DOUBLE,
- SQL_DOUBLE, 15, 0, &delta, sizeof delta, NULL);
- handle_errors(hdbc, txstmt[2], rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(txstmt[2], 2, SQL_PARAM_INPUT, SQL_C_SLONG,
- SQL_INTEGER, 10, 0, &tellerNum, sizeof tellerNum,
- NULL);
- handle_errors(hdbc, txstmt[2], rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(txstmt[3], 1, SQL_PARAM_INPUT, SQL_C_DOUBLE,
- SQL_DOUBLE, 15, 0, &delta, sizeof delta, NULL);
- handle_errors(hdbc, txstmt[3], rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(txstmt[3], 2, SQL_PARAM_INPUT, SQL_C_SLONG,
- SQL_INTEGER, 10, 0, &branchNum, sizeof branchNum,
- NULL);
- handle_errors(hdbc, txstmt[3], rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(txstmt[4], 1, SQL_PARAM_INPUT, SQL_C_SLONG,
- SQL_INTEGER, 10, 0, &tellerNum, sizeof tellerNum,
- NULL);
- handle_errors(hdbc, txstmt[4], rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(txstmt[4], 2, SQL_PARAM_INPUT, SQL_C_SLONG,
- SQL_INTEGER, 10, 0, &branchNum, sizeof branchNum,
- NULL);
- handle_errors(hdbc, txstmt[4], rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(txstmt[4], 3, SQL_PARAM_INPUT, SQL_C_SLONG,
- SQL_INTEGER, 10, 0, &accountNum, sizeof accountNum,
- NULL);
- handle_errors(hdbc, txstmt[4], rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(txstmt[4], 4, SQL_PARAM_INPUT, SQL_C_DOUBLE,
- SQL_DOUBLE, 15, 0, &delta, sizeof delta, NULL);
- handle_errors(hdbc, txstmt[4], rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- rc = SQLBindParameter(txstmt[4], 5, SQL_PARAM_INPUT, SQL_C_SLONG,
- SQL_INTEGER, 10, 0, &timeStamp, sizeof timeStamp,
- NULL);
- handle_errors(hdbc, txstmt[4], rc, ABORT_DISCONNECT_EXIT,
- "binding parameter",
- __FILE__, __LINE__);
-
- /* Execute transaction loop.
- * Do it twice, once briefly as a warm-up. */
-
-
-
- for (warmup = 1; warmup >= 0; warmup--) {
-
- int max_i = (warmup ? numXacts/10 : numXacts);
-
- /* Execute tpcb transaction max_i times.*/
-
- if (warmup) {
- status_msg1("\nWarming up with %d tpcb transactions...\n", max_i);
- }
- else {
- status_msg1("Executing and timing %d tpcb transactions...\n", max_i);
- }
-
- ttGetWallClockTime(&startT);
- ttGetThreadTimes(&startRes);
-
- for (i = 0; i < max_i; i++) {
-
- lrand = lrand48();
- srands = (unsigned short *)(&lrand);
- if (lp64) srands += 2; /* skip high half -- all zero */
-
- /* randomly choose a teller */
-
- tellerNum = srands[0] % numTellerTups;
-
- /* compute branch */
-
- branchNum = (tellerNum / TellersPerBranch);
-
- /* randomly choose an account */
-
- if (srands[1] < localLimit || numBranchTups == 1) {
-
- /* choose account local to selected branch */
-
- accountNum = branchNum * AccountsPerBranch +
- (lrand48() % AccountsPerBranch);
-
- ++numLocalXacts;
-
- }
- else {
- /* choose account not local to selected branch */
-
- /* first select account in range [0,numNonLocalAccountTups) */
-
- accountNum = lrand48() % numNonLocalAccountTups;
-
- /* if branch number of selected account is at least as big
- * as local branch number, then increment account number
- * by AccountsPerBranch to skip over local accounts
- */
-
- if ((accountNum/AccountsPerBranch) >= branchNum)
- accountNum += AccountsPerBranch;
-
- ++numRemoteXacts;
- }
-
- /* select delta amount, -999,999 to +999,999 */
-
- delta = ((lrand48() % 1999999) - 999999);
-
-
- /* begin timing the "residence time" */
-
- ttGetWallClockTime(rtStart[i]);
-
- for ( j = 0; j < NumXactStmts - 2; j++) {
- rc = SQLExecute(txstmt[j]);
- handle_errors(hdbc, txstmt[j], rc, ABORT_DISCONNECT_EXIT,
- "Error executing statement1",
- __FILE__, __LINE__);
-
- /* Close the handle after the SELECT statement
- * (txstmt[1]) for non TimesTen DBMS' */
-
- if ((DBMSType != DBMS_TIMESTEN) && (j == 1)) {
- SQLFreeStmt(txstmt[1], SQL_CLOSE);
- }
-
-
- }
-
- /* note that time must be taken within the */
- timeStamp = time(NULL);
-
- rc = SQLExecute(txstmt[NumXactStmts - 1]);
- handle_errors(hdbc, txstmt[NumXactStmts - 1], rc,
- ABORT_DISCONNECT_EXIT, "Error executing statement2",
- __FILE__, __LINE__);
-
- rc = SQLTransact(henv, hdbc, SQL_COMMIT);
- handle_errors(hdbc, NULL, rc, ERROR_EXIT,
- "Error committing transaction",
- __FILE__, __LINE__);
-
- ttGetWallClockTime(rtEnd[i]);
-
- } /* end fortransaction loop */
-
-
-
-
- ttGetThreadTimes(&endRes);
- ttGetWallClockTime(&endT);
- ttCalcElapsedThreadTimes(&startRes, &endRes, &kernel, &user);
- ttCalcElapsedWallClockTime(&startT, &endT, &real);
-
- if (warmup) {
- if (!tabFlag) {
- if (verbose) {
- if (fThreadTime) {
- out_msg0(" time user system\n");
-
- out_msg3("Warmup time (sec): %12.3f %12.3f %12.3f\n\n",
- real/1000.0, user, kernel);
- } else {
- out_msg1("Warmup time (sec): %12.3f\n\n", real/1000.0);
- }
- }
- } else {
- if (verbose) {
- if (fThreadTime) {
- out_msg0("\ttime\tuser\tsystem\n");
-
- out_msg3("Warmup time (sec):\t%12.3f\t%12.3f\t%12.3f\n",
- real/1000.0, user, kernel);
- } else {
- out_msg1("Warmup time (sec):\t%12.3f\n", real/1000.0);
- }
- }
- }
- }
- }
-
- status_msg0("\nExecution completed...\n");
-
- /* Compute and report timing statistics */
-
- maxTime = 0.0;
- totTime = 0.0;
-
- for (i = 0; i < numXacts; i++) {
- ttCalcElapsedWallClockTime(rtStart[i], rtEnd[i], resTime[i]);
- totTime += *(resTime[i]);
-
- if (*(resTime[i]) > maxTime) maxTime = *(resTime[i]);
- }
-
- if (!tabFlag) {
- if (verbose) {
- if (fThreadTime) {
- out_msg0(" time user system\n");
- out_msg3("Total time (sec): %12.3f %12.3f %12.3f\n",
- real/1000.0, user, kernel);
- } else {
- out_msg1("Total time (sec): %12.3f\n", real/1000.0);
- }
- }
-
- if (verbose)
- out_msg1("\nAverage transaction time (msec):%12.3f\n",
- totTime/numXacts);
- if (verbose)
- out_msg1("Maximum transaction time (msec):%12.3f\n", maxTime);
- if (verbose)
- out_msg1("\nLocal transactions: %7" PTRINT_FMT "\n", numLocalXacts);
- if (verbose)
- out_msg1("Remote transactions: %7" PTRINT_FMT "\n", numRemoteXacts);
-
- } else {
- if (verbose) {
- if (fThreadTime) {
- out_msg0("\ttime\tuser\tsystem\n");
- out_msg3("Total time (sec):\t%12.3f\t%12.3f\t%12.3f\n",
- real/1000.0, user, kernel);
- } else {
- out_msg1("Total time (sec):\t%12.3f\n", real/1000.0);
- }
- }
-
- if (verbose)
- out_msg1("\nAverage transaction time (msec):\t%12.3f\n",
- totTime/numXacts);
- if (verbose)
- out_msg1("Maximum transaction time (msec):\t%12.3f\n", maxTime);
- if (verbose)
- out_msg1("Local transactions:\t%7" PTRINT_FMT "\n", numLocalXacts);
-
- if (verbose)
- out_msg1("Remote transactions:\t%7" PTRINT_FMT "\n", numRemoteXacts);
-
-
-
- }
-
- /* If the statfile option is selected, print each transaction's time */
-
- if (printXactTimes) {
- FILE * fp;
- if ( (fp = fopen (statFile, "w")) == NULL ) {
- err_msg1("Unable to open stat file %s for writing\n\n", statFile);
- } else {
- for (int i = 0; i < numXacts; i++)
- fprintf(fp,"%6d: %12.3f\n", i, *(resTime[i]));
- fclose(fp);
- }
- }
-
- /* Disconnect and return */
-
- rc = SQLFreeStmt(hstmt, SQL_DROP);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "dropping the statement handle",
- __FILE__, __LINE__);
-
- for (int i=0; i<NumXactStmts; i++) {
- rc = SQLFreeStmt(txstmt[i], SQL_DROP);
- handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
- "dropping the statement handle",
- __FILE__, __LINE__);
- }
-
- if (verbose >= VERBOSE_DFLT)
- status_msg0("Disconnecting from the data source...\n");
-
- rc = SQLDisconnect(hdbc);
- handle_errors(hdbc, NULL, rc, ERROR_EXIT,
- "disconnecting",
- __FILE__, __LINE__);
-
- rc = SQLFreeConnect(hdbc);
- handle_errors(hdbc, NULL, rc, ERROR_EXIT,
- "freeing connection handle",
- __FILE__, __LINE__);
-
- rc = SQLFreeEnv(henv);
- handle_errors(NULL, NULL, rc, ERROR_EXIT,
- "freeing environment handle",
- __FILE__, __LINE__);
-
- app_exit(0);
- return 0;
-}
-
-
-
-
-
-/* Emacs variable settings */
-/* Local Variables: */
-/* tab-width:8 */
-/* indent-tabs-mode:nil */
-/* c-basic-offset:2 */
-/* End: */
-
-
-
diff --git a/ndb/test/odbc/tpcb/ttTime.c b/ndb/test/odbc/tpcb/ttTime.c
deleted file mode 100644
index 8f10b0c6b91..00000000000
--- a/ndb/test/odbc/tpcb/ttTime.c
+++ /dev/null
@@ -1,366 +0,0 @@
-/* Copyright (C) 2003 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-static const volatile char cvsid[] = "$Id: ttTime.c,v 1.1 2003/09/23 12:43:46 johan Exp $";
-/*
- * $Revision: 1.1 $
- * (c) Copyright 1996-2003, TimesTen, Inc.
- * All rights reserved.
- *
- */
-
-
-/* Contains functions for performing elapsed-time calculations
- in a portable manner */
-
-#include "ttTime.h"
-
-#ifdef WIN32
-
-#include <stdio.h>
-#include <mapiutil.h>
-
-/*------------*/
-/* NT VERSION */
-/*------------*/
-
-/*********************************************************************
- *
- * FUNCTION: ttGetThreadTimes
- *
- * DESCRIPTION: This function sets the supplied parameter's
- * user and kernel time for the current thread.
- *
- * PARAMETERS: ttThreadTimes* timesP thread time structure
- *
- * RETURNS: void
- *
- * NOTES: NONE
- *
- *********************************************************************/
-
-void
-ttGetThreadTimes(ttThreadTimes* timesP)
-{
- BOOL rc;
- HANDLE curThread;
- FILETIME creationTime;
- FILETIME exitTime;
- FILETIME kTime;
- FILETIME uTime;
-
- memset (&kTime, 0, sizeof (FILETIME));
- memset (&uTime, 0, sizeof (FILETIME));
-
- curThread = GetCurrentThread();
- rc = GetThreadTimes(curThread,
- &creationTime,
- &exitTime,
- &kTime,
- &uTime);
-
- timesP->kernelTime = kTime;
- timesP->userTime = uTime;
-
-}
-
-/*********************************************************************
- *
- * FUNCTION: ttCalcElapsedThreadTimes
- *
- * DESCRIPTION: This function calculates the user and kernel
- * time deltas.
- *
- * PARAMETERS: ttThreadTimes* beforeP beginning timestamp (IN)
- * ttThreadTimes* afterP ending timestamp (IN)
- * double* kernelDeltaP kernel time delta (OUT)
- * double* userDeltaP user time delta (OUT)
- *
- * RETURNS: void
- *
- * NOTES: NONE
- *
- *********************************************************************/
-
-void
-ttCalcElapsedThreadTimes(ttThreadTimes* beforeP,
- ttThreadTimes* afterP,
- double* kernelDeltaP,
- double* userDeltaP)
-{
- static const double secPerHi = (double) 4.294967296; /* 2**32 * 10**-9 */
- FILETIME *before, *after;
-
- before = &beforeP->kernelTime;
- after = &afterP->kernelTime;
- *kernelDeltaP = (double) ((after->dwHighDateTime - before->dwHighDateTime) * secPerHi
- + (after->dwLowDateTime - before->dwLowDateTime) * 100e-9);
- before = &beforeP->userTime;
- after = &afterP->userTime;
- *userDeltaP = (double) ((after->dwHighDateTime - before->dwHighDateTime) * secPerHi
- + (after->dwLowDateTime - before->dwLowDateTime) * 100e-9);
-}
-
-/*********************************************************************
- *
- * FUNCTION: ttGetWallClockTime
- *
- * DESCRIPTION: This function gets the current wall-clock time.
- *
- * PARAMETERS: ttWallClockTime* timeP tms time structure (OUT)
- *
- * RETURNS: void
- *
- * NOTES: NONE
- *
- *********************************************************************/
-
-void
-ttGetWallClockTime(ttWallClockTime* timeP)
-{
- LARGE_INTEGER frequency;
- if ( QueryPerformanceFrequency(&frequency) ) {
- QueryPerformanceCounter(&(timeP->time64));
- }
- else {
- _ftime(&(timeP->notSoLargeTime));
- }
-}
-
-/*********************************************************************
- *
- * FUNCTION: ttCalcElapsedWallClockTime
- *
- * DESCRIPTION: This function calculates the elapsed wall-clock
- * time in msec.
- *
- * PARAMETERS: ttWallClockTime* beforeP starting timestamp
- * ttWallClockTime* afterP ending timestamp
- * double* nmillisecondsP elapsed time (OUT)
- *
- * RETURNS: void
- *
- * NOTES: NONE
- *
- *********************************************************************/
-
-void
-ttCalcElapsedWallClockTime(ttWallClockTime* beforeP,
- ttWallClockTime* afterP,
- double* nmillisecondsP)
-{
- LARGE_INTEGER frequency;
-
- if ( QueryPerformanceFrequency(&frequency) ) {
- *nmillisecondsP = 1000 * ((double) (afterP->time64.QuadPart
- - beforeP->time64.QuadPart))
- / frequency.QuadPart;
-
- }
- else {
- double start;
- double end;
-
- start = (double) beforeP->notSoLargeTime.time * 1000. +
- (double) beforeP->notSoLargeTime.millitm;
- end = (double) afterP->notSoLargeTime.time * 1000. +
- (double) afterP->notSoLargeTime.millitm;
-
- *nmillisecondsP = (double) (end - start);
- }
-}
-
-#elif defined (RTSYS_VXWORKS)
-
-/*-----------------*/
-/* VxWorks VERSION */
-/*-----------------*/
-
-/*
- * The TimeBase registers have a period of 60ns, i.e.
- * 0.00000006 or (6e-8) seconds.
- */
-#define TIMER_MSEC_PER_CYC (6e-5)
-
-void
-ttGetWallClockTime(ttWallClockTime* timeP)
-{
- vxTimeBaseGet(&timeP->sep.upper32, &timeP->sep.lower32);
-}
-
-
-void
-ttCalcElapsedWallClockTime(ttWallClockTime* beforeP,
- ttWallClockTime* afterP,
- double* nmillisecondsP)
-{
- *nmillisecondsP = (double)(afterP->val - beforeP->val) * TIMER_MSEC_PER_CYC;
-}
-
-
-#else
-
-/*--------------*/
-/* UNIX VERSION */
-/*--------------*/
-
-#include <unistd.h>
-
-/*********************************************************************
- *
- * FUNCTION: ttGetThreadTimes
- *
- * DESCRIPTION: This function sets the supplied parameter's
- * tms structure.
- *
- * PARAMETERS: ttThreadTimes* timesP tms time structure
- *
- * RETURNS: void
- *
- * NOTES: NONE
- *
- *********************************************************************/
-
-#ifdef SB_P_OS_CHORUS
-void ttGetThreadTimes(ttThreadTimes* timesP)
-{
- KnCap actorCap;
-
- if (acap (agetId(), &actorCap) == -1) {
- timesP->ins.tmSec = 0;
- timesP->ins.tmNSec = 0;
- timesP->ext.tmSec = 0;
- timesP->ext.tmNSec = 0;
- }
- else {
- (void) threadTimes (&actorCap, K_ALLACTORTHREADS,
- &timesP->ins, &timesP->ext);
- }
-}
-#else
-void ttGetThreadTimes(ttThreadTimes* timesP)
-{
- (void) times(timesP);
-}
-#endif
-
-/*********************************************************************
- *
- * FUNCTION: ttCalcElapsedThreadTimes
- *
- * DESCRIPTION: This function calculates the user and kernel
- * time deltas.
- *
- * PARAMETERS: ttThreadTimes* beforeP beginning timestamp (IN)
- * ttThreadTimes* afterP ending timestamp (IN)
- * double* kernelDeltaP kernel time delta (OUT)
- * double* userDeltaP user time delta (OUT)
- *
- * RETURNS: void
- *
- * NOTES: NONE
- *
- *********************************************************************/
-
-#ifdef SB_P_OS_CHORUS
-void
-ttCalcElapsedThreadTimes(ttThreadTimes* beforeP,
- ttThreadTimes* afterP,
- double* kernelDeltaP,
- double* userDeltaP)
-{
- double kernelBefore;
- double kernelAfter;
- double userBefore;
- double userAfter;
-
- kernelBefore = (beforeP->ext.tmSec) + (beforeP->ext.tmNSec / 1e9);
- kernelAfter = (afterP->ext.tmSec) + (afterP->ext.tmNSec / 1e9);
- *kernelDeltaP = kernelAfter - kernelBefore;
-
- userBefore = (beforeP->ins.tmSec) + (beforeP->ins.tmNSec / 1e9);
- userAfter = (afterP->ins.tmSec) + (afterP->ins.tmNSec / 1e9);
- *userDeltaP = userAfter - userBefore;
-
-}
-#else
-void
-ttCalcElapsedThreadTimes(ttThreadTimes* beforeP,
- ttThreadTimes* afterP,
- double* kernelDeltaP,
- double* userDeltaP)
-{
- double ticks = (double)sysconf(_SC_CLK_TCK);
-
- *kernelDeltaP = (afterP->tms_stime - beforeP->tms_stime) / ticks;
- *userDeltaP = (afterP->tms_utime - beforeP->tms_utime) / ticks;
-}
-#endif
-
-/*********************************************************************
- *
- * FUNCTION: ttGetWallClockTime
- *
- * DESCRIPTION: This function gets the current wall-clock time.
- *
- * PARAMETERS: ttWallClockTime* timeP tms time structure (OUT)
- *
- * RETURNS: void
- *
- * NOTES: NONE
- *
- *********************************************************************/
-
-void
-ttGetWallClockTime(ttWallClockTime* timeP)
-{
- gettimeofday(timeP, NULL);
-}
-
-/*********************************************************************
- *
- * FUNCTION: ttCalcElapsedWallClockTime
- *
- * DESCRIPTION: This function calculates the elapsed wall-clock
- * time is msec.
- *
- * PARAMETERS: ttWallClockTime* beforeP starting timestamp
- * ttWallClockTime* afterP ending timestamp
- * double* nmillisecondsP elapsed time (OUT)
- *
- * RETURNS: void
- *
- * NOTES: NONE
- *
- *********************************************************************/
-
-void
-ttCalcElapsedWallClockTime(ttWallClockTime* beforeP,
- ttWallClockTime* afterP,
- double* nmillisP)
-{
- *nmillisP = (afterP->tv_sec - beforeP->tv_sec)*1000.0 +
- (afterP->tv_usec - beforeP->tv_usec)/1000.0;
-}
-
-#endif
-
-/* Emacs variable settings */
-/* Local Variables: */
-/* tab-width:8 */
-/* indent-tabs-mode:nil */
-/* c-basic-offset:2 */
-/* End: */
diff --git a/ndb/test/odbc/tpcb/ttTime.h b/ndb/test/odbc/tpcb/ttTime.h
deleted file mode 100644
index f78b71667fe..00000000000
--- a/ndb/test/odbc/tpcb/ttTime.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/* Copyright (C) 2003 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-/*
- * $Revision: 1.1 $
- * (c) Copyright 1996-2003, TimesTen, Inc.
- * All rights reserved.
- *
- */
-
-#ifndef __TT_TIME
-#define __TT_TIME
-
-
-#ifdef WIN32
-
-#include <windows.h>
-#include <sys/types.h>
-#include <sys/timeb.h>
-
-typedef struct {
- FILETIME kernelTime;
- FILETIME userTime;
-} ttThreadTimes;
-
-
-typedef union {
- LARGE_INTEGER time64;
- struct _timeb notSoLargeTime;
-} ttWallClockTime;
-
-#elif defined(RTSYS_VXWORKS)
-
-#define srand48(x) sb_srand48((x))
-#define drand48() sb_drand48()
-
-#ifdef SB_P_OS_VXPPC
-/* For little-endian switch the lower, upper fields */
-typedef union {
- struct {
- unsigned int upper32;
- unsigned int lower32;
- } sep;
- long long val;
-} ttWallClockTime;
-
-/*
- * This is a VxWorks private function to read the PPC's 64 bit Time Base
- * Register. This is the assembler dump of this function.
- 001126e4 7cad42e6 mftb r5, TBU
- 001126e8 7ccc42e6 mftb r6, TBL
- 001126ec 7ced42e6 mftb r7, TBU
- 001126f0 7c053800 cmp crf0, 0, r5, r7
- 001126f4 4082fff0 bc 0x4, 0x2, vxTimeBaseGet
- 001126f8 90a30000 stw r5, 0x0(r3)
- 001126fc 90c40000 stw r6, 0x0(r4)
- 00112700 4e800020 blr
- * This is a fine grained timer with a period of 60ns.
- */
-void vxTimeBaseGet(unsigned int* pUpper32, unsigned int* pLower32);
-#endif /* SB_P_OS_VXPPC */
-
-#elif defined(SB_P_OS_CHORUS)
-#include <sys/types.h>
-#include <sys/times.h>
-#include <sys/time.h>
-
-#include <vtimer/chVtimer.h>
-
-struct chrTimes {
- KnTimeVal ins;
- KnTimeVal ext;
-};
-typedef struct chrTimes ttThreadTimes;
-
-typedef struct timeval ttWallClockTime;
-
-#else
-/* UNIX version */
-
-#include <sys/times.h>
-#include <sys/time.h>
-
-typedef struct tms ttThreadTimes;
-
-typedef struct timeval ttWallClockTime;
-
-#endif /* NT, VxWorks, Chorus, Unix */
-
-
-#ifndef RTSYS_VXWORKS
-void ttGetThreadTimes(ttThreadTimes* timesP);
-void ttCalcElapsedThreadTimes(ttThreadTimes* beforeP, ttThreadTimes* afterP,
- double* kernelDeltaP, double* userDeltaP);
-#endif /* ! VXWORKS */
-void ttGetWallClockTime(ttWallClockTime* timeP);
-void ttCalcElapsedWallClockTime(ttWallClockTime* beforeP,
- ttWallClockTime* afterP,
- double* nmillisecondsP);
-
-
-
-
-
-#endif /* __TT_TIME */
-
-/* Emacs variable settings */
-/* Local Variables: */
-/* tab-width:8 */
-/* indent-tabs-mode:nil */
-/* c-basic-offset:2 */
-/* End: */
diff --git a/ndb/test/run-test/Makefile.am b/ndb/test/run-test/Makefile.am
index 3bf2edde47a..1eac96e7ac7 100644
--- a/ndb/test/run-test/Makefile.am
+++ b/ndb/test/run-test/Makefile.am
@@ -11,8 +11,9 @@ test_SCRIPTS=atrt-analyze-result.sh atrt-gather-result.sh atrt-setup.sh \
atrt-clear-result.sh make-config.sh make-index.sh make-html-reports.sh
atrt_SOURCES = main.cpp
-INCLUDES_LOC = -I$(top_srcdir)/ndb/src/mgmclient
+INCLUDES_LOC = -I$(top_srcdir)/ndb/test/include -I$(top_srcdir)/ndb/src/mgmclient
LDADD_LOC = $(top_builddir)/ndb/src/mgmclient/CpcClient.o \
+ $(top_builddir)/ndb/test/src/libNDBT.a \
$(top_builddir)/ndb/src/libndbclient.la \
$(top_builddir)/dbug/libdbug.a \
$(top_builddir)/mysys/libmysys.a \
diff --git a/ndb/test/run-test/main.cpp b/ndb/test/run-test/main.cpp
index 22799a9a1b2..e5f73bc6a5c 100644
--- a/ndb/test/run-test/main.cpp
+++ b/ndb/test/run-test/main.cpp
@@ -459,7 +459,7 @@ setup_config(atrt_config& config){
proc.m_type = atrt_process::NDB_MGM;
proc.m_proc.m_name.assfmt("%d-%s", index, "ndb_mgmd");
proc.m_proc.m_path.assign(dir).append("/libexec/ndb_mgmd");
- proc.m_proc.m_args = "--nodaemon -c initconfig.txt";
+ proc.m_proc.m_args = "--nodaemon -f config.ini";
proc.m_proc.m_cwd.appfmt("%d.ndb_mgmd", index);
connect_string.appfmt("host=%s:%d;",
proc.m_hostname.c_str(), proc.m_ndb_mgm_port);
diff --git a/ndb/test/src/Makefile.am b/ndb/test/src/Makefile.am
index a513086dc33..a8f34a0ea22 100644
--- a/ndb/test/src/Makefile.am
+++ b/ndb/test/src/Makefile.am
@@ -9,7 +9,7 @@ libNDBT_a_SOURCES = \
HugoAsynchTransactions.cpp UtilTransactions.cpp \
NdbRestarter.cpp NdbRestarts.cpp NDBT_Output.cpp \
NdbBackup.cpp NdbConfig.cpp NdbGrep.cpp NDBT_Table.cpp \
- NdbSchemaCon.cpp NdbSchemaOp.cpp
+ NdbSchemaCon.cpp NdbSchemaOp.cpp getarg.c
INCLUDES_LOC = -I$(top_srcdir)/ndb/src/common/mgmcommon -I$(top_srcdir)/ndb/include/mgmcommon -I$(top_srcdir)/ndb/include/kernel -I$(top_srcdir)/ndb/src/mgmapi
diff --git a/ndb/test/src/getarg.c b/ndb/test/src/getarg.c
new file mode 100644
index 00000000000..9f03af69824
--- /dev/null
+++ b/ndb/test/src/getarg.c
@@ -0,0 +1,607 @@
+/* -*- c-basic-offset: 4; -*- */
+/*
+ * Copyright (c) 1997 - 2000 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ndb_global.h>
+
+#include "getarg.h"
+
+#ifndef HAVE_STRLCPY
+static size_t
+strlcpy (char *dst, const char *src, size_t dst_sz)
+{
+ size_t n;
+ char *p;
+ for (p = dst, n = 0;
+ n + 1 < dst_sz && *src != '\0';
+ ++p, ++src, ++n)
+ *p = *src;
+ *p = '\0';
+ if (*src == '\0')
+ return n;
+ else
+ return n + strlen (src);
+}
+#endif
+#ifndef HAVE_STRLCAT
+static size_t
+strlcat (char *dst, const char *src, size_t dst_sz)
+{
+ size_t len = strlen(dst);
+ return len + strlcpy (dst + len, src, dst_sz - len);
+}
+#endif
+
+#define ISFLAG(X) ((X).type == arg_flag || (X).type == arg_negative_flag)
+
+#ifndef max
+#define max(a, b) (a) > (b) ? (a) : (b)
+#endif
+
+#ifdef HAVE___PROGNAME
+extern char *__progname;
+#endif
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+char *
+strupr(char *str)
+{
+ char *s;
+
+ for(s = str; *s; s++)
+ *s = toupper(*s);
+ return str;
+}
+
+static size_t
+print_arg (char *string, size_t len, int mdoc, int longp, struct getargs *arg)
+{
+ const char *s;
+
+ *string = '\0';
+
+ if (ISFLAG(*arg) || (!longp && arg->type == arg_counter))
+ return 0;
+
+ if(mdoc){
+ if(longp)
+ strlcat(string, "= Ns", len);
+ strlcat(string, " Ar ", len);
+ }else
+ if (longp)
+ strlcat (string, "=", len);
+ else
+ strlcat (string, " ", len);
+
+ if (arg->arg_help)
+ s = arg->arg_help;
+ else if (arg->type == arg_integer || arg->type == arg_counter)
+ s = "integer";
+ else if (arg->type == arg_string)
+ s = "string";
+ else if (arg->type == arg_double)
+ s = "float";
+ else
+ s = "<undefined>";
+
+ strlcat(string, s, len);
+ return 1 + strlen(s);
+}
+
+#ifdef GETARGMANDOC
+static void
+mandoc_template(struct getargs *args,
+ size_t num_args,
+ const char *progname,
+ const char *extra_string)
+{
+ size_t i;
+ char timestr[64], cmd[64];
+ char buf[128];
+ const char *p;
+ time_t t;
+
+ printf(".\\\" Things to fix:\n");
+ printf(".\\\" * correct section, and operating system\n");
+ printf(".\\\" * remove Op from mandatory flags\n");
+ printf(".\\\" * use better macros for arguments (like .Pa for files)\n");
+ printf(".\\\"\n");
+ t = time(NULL);
+ strftime(timestr, sizeof(timestr), "%B %e, %Y", localtime(&t));
+ printf(".Dd %s\n", timestr);
+ p = strrchr(progname, '/');
+ if(p) p++; else p = progname;
+ strlcpy(cmd, p, sizeof(cmd));
+ strupr(cmd);
+
+ printf(".Dt %s SECTION\n", cmd);
+ printf(".Os OPERATING_SYSTEM\n");
+ printf(".Sh NAME\n");
+ printf(".Nm %s\n", p);
+ printf(".Nd\n");
+ printf("in search of a description\n");
+ printf(".Sh SYNOPSIS\n");
+ printf(".Nm\n");
+ for(i = 0; i < num_args; i++){
+ /* we seem to hit a limit on number of arguments if doing
+ short and long flags with arguments -- split on two lines */
+ if(ISFLAG(args[i]) ||
+ args[i].short_name == 0 || args[i].long_name == NULL) {
+ printf(".Op ");
+
+ if(args[i].short_name) {
+ print_arg(buf, sizeof(buf), 1, 0, args + i);
+ printf("Fl %c%s", args[i].short_name, buf);
+ if(args[i].long_name)
+ printf(" | ");
+ }
+ if(args[i].long_name) {
+ print_arg(buf, sizeof(buf), 1, 1, args + i);
+ printf("Fl -%s%s%s",
+ args[i].type == arg_negative_flag ? "no-" : "",
+ args[i].long_name, buf);
+ }
+ printf("\n");
+ } else {
+ print_arg(buf, sizeof(buf), 1, 0, args + i);
+ printf(".Oo Fl %c%s \\*(Ba Xo\n", args[i].short_name, buf);
+ print_arg(buf, sizeof(buf), 1, 1, args + i);
+ printf(".Fl -%s%s Oc\n.Xc\n", args[i].long_name, buf);
+ }
+ /*
+ if(args[i].type == arg_strings)
+ fprintf (stderr, "...");
+ */
+ }
+ if (extra_string && *extra_string)
+ printf (".Ar %s\n", extra_string);
+ printf(".Sh DESCRIPTION\n");
+ printf("Supported options:\n");
+ printf(".Bl -tag -width Ds\n");
+ for(i = 0; i < num_args; i++){
+ printf(".It Xo\n");
+ if(args[i].short_name){
+ printf(".Fl %c", args[i].short_name);
+ print_arg(buf, sizeof(buf), 1, 0, args + i);
+ printf("%s", buf);
+ if(args[i].long_name)
+ printf(" Ns ,");
+ printf("\n");
+ }
+ if(args[i].long_name){
+ printf(".Fl -%s%s",
+ args[i].type == arg_negative_flag ? "no-" : "",
+ args[i].long_name);
+ print_arg(buf, sizeof(buf), 1, 1, args + i);
+ printf("%s\n", buf);
+ }
+ printf(".Xc\n");
+ if(args[i].help)
+ printf("%s\n", args[i].help);
+ /*
+ if(args[i].type == arg_strings)
+ fprintf (stderr, "...");
+ */
+ }
+ printf(".El\n");
+ printf(".\\\".Sh ENVIRONMENT\n");
+ printf(".\\\".Sh FILES\n");
+ printf(".\\\".Sh EXAMPLES\n");
+ printf(".\\\".Sh DIAGNOSTICS\n");
+ printf(".\\\".Sh SEE ALSO\n");
+ printf(".\\\".Sh STANDARDS\n");
+ printf(".\\\".Sh HISTORY\n");
+ printf(".\\\".Sh AUTHORS\n");
+ printf(".\\\".Sh BUGS\n");
+}
+#endif /* GETARGMANDOC */
+
+static int
+check_column(FILE *f, int col, int len, int columns)
+{
+ if(col + len > columns) {
+ fprintf(f, "\n");
+ col = fprintf(f, " ");
+ }
+ return col;
+}
+
+void
+arg_printusage (struct getargs *args,
+ size_t num_args,
+ const char *progname,
+ const char *extra_string)
+{
+ unsigned int i;
+ size_t max_len = 0;
+ char buf[128];
+ int col = 0, columns;
+
+#ifdef HAVE___PROGNAME
+ if (progname == NULL)
+ progname = __progname;
+#endif
+ if (progname == NULL)
+ progname = "";
+
+#ifdef GETARGMANDOC
+ if(getenv("GETARGMANDOC")){
+ mandoc_template(args, num_args, progname, extra_string);
+ return;
+ }
+#endif
+
+ columns = 80; /* Always assume that the window is 80 chars wide */
+ col = 0;
+ col += fprintf (stderr, "Usage: %s", progname);
+ for (i = 0; i < num_args; ++i) {
+ size_t len = 0;
+
+ if (args[i].long_name) {
+ buf[0] = '\0';
+ strlcat(buf, "[--", sizeof(buf));
+ len += 2;
+ if(args[i].type == arg_negative_flag) {
+ strlcat(buf, "no-", sizeof(buf));
+ len += 3;
+ }
+ strlcat(buf, args[i].long_name, sizeof(buf));
+ len += strlen(args[i].long_name);
+ len += print_arg(buf + strlen(buf), sizeof(buf) - strlen(buf),
+ 0, 1, &args[i]);
+ strlcat(buf, "]", sizeof(buf));
+ if(args[i].type == arg_strings)
+ strlcat(buf, "...", sizeof(buf));
+ col = check_column(stderr, col, strlen(buf) + 1, columns);
+ col += fprintf(stderr, " %s", buf);
+ }
+ if (args[i].short_name) {
+ snprintf(buf, sizeof(buf), "[-%c", args[i].short_name);
+ len += 2;
+ len += print_arg(buf + strlen(buf), sizeof(buf) - strlen(buf),
+ 0, 0, &args[i]);
+ strlcat(buf, "]", sizeof(buf));
+ if(args[i].type == arg_strings)
+ strlcat(buf, "...", sizeof(buf));
+ col = check_column(stderr, col, strlen(buf) + 1, columns);
+ col += fprintf(stderr, " %s", buf);
+ }
+ if (args[i].long_name && args[i].short_name)
+ len += 2; /* ", " */
+ max_len = max(max_len, len);
+ }
+ if (extra_string) {
+ col = check_column(stderr, col, strlen(extra_string) + 1, columns);
+ fprintf (stderr, " %s\n", extra_string);
+ } else
+ fprintf (stderr, "\n");
+ for (i = 0; i < num_args; ++i) {
+ if (args[i].help) {
+ size_t count = 0;
+
+ if (args[i].short_name) {
+ count += fprintf (stderr, "-%c", args[i].short_name);
+ print_arg (buf, sizeof(buf), 0, 0, &args[i]);
+ count += fprintf(stderr, "%s", buf);
+ }
+ if (args[i].short_name && args[i].long_name)
+ count += fprintf (stderr, ", ");
+ if (args[i].long_name) {
+ count += fprintf (stderr, "--");
+ if (args[i].type == arg_negative_flag)
+ count += fprintf (stderr, "no-");
+ count += fprintf (stderr, "%s", args[i].long_name);
+ print_arg (buf, sizeof(buf), 0, 1, &args[i]);
+ count += fprintf(stderr, "%s", buf);
+ }
+ while(count++ <= max_len)
+ putc (' ', stderr);
+ fprintf (stderr, "%s\n", args[i].help);
+ }
+ }
+}
+
+static void
+add_string(getarg_strings *s, char *value)
+{
+ s->strings = realloc(s->strings, (s->num_strings + 1) * sizeof(*s->strings));
+ s->strings[s->num_strings] = value;
+ s->num_strings++;
+}
+
+static int
+arg_match_long(struct getargs *args, size_t num_args,
+ char *argv, int argc, const char **rargv, int *optind)
+{
+ unsigned int i;
+ const char *optarg = NULL;
+ int negate = 0;
+ int partial_match = 0;
+ struct getargs *partial = NULL;
+ struct getargs *current = NULL;
+ int argv_len;
+ char *p;
+
+ argv_len = strlen(argv);
+ p = strchr (argv, '=');
+ if (p != NULL)
+ argv_len = p - argv;
+
+ for (i = 0; i < num_args; ++i) {
+ if(args[i].long_name) {
+ int len = strlen(args[i].long_name);
+ char *p = argv;
+ int p_len = argv_len;
+ negate = 0;
+
+ for (;;) {
+ if (strncmp (args[i].long_name, p, p_len) == 0) {
+ if(p_len == len)
+ current = &args[i];
+ else {
+ ++partial_match;
+ partial = &args[i];
+ }
+ optarg = p + p_len;
+ } else if (ISFLAG(args[i]) && strncmp (p, "no-", 3) == 0) {
+ negate = !negate;
+ p += 3;
+ p_len -= 3;
+ continue;
+ }
+ break;
+ }
+ if (current)
+ break;
+ }
+ }
+ if (current == NULL) {
+ if (partial_match == 1)
+ current = partial;
+ else
+ return ARG_ERR_NO_MATCH;
+ }
+
+ if(*optarg == '\0'
+ && !ISFLAG(*current)
+ && current->type != arg_collect
+ && current->type != arg_counter)
+ return ARG_ERR_NO_MATCH;
+ switch(current->type){
+ case arg_integer:
+ {
+ int tmp;
+ if(sscanf(optarg + 1, "%d", &tmp) != 1)
+ return ARG_ERR_BAD_ARG;
+ *(int*)current->value = tmp;
+ return 0;
+ }
+ case arg_string:
+ {
+ *(char**)current->value = (char*)optarg + 1;
+ return 0;
+ }
+ case arg_strings:
+ {
+ add_string((getarg_strings*)current->value, (char*)optarg + 1);
+ return 0;
+ }
+ case arg_flag:
+ case arg_negative_flag:
+ {
+ int *flag = current->value;
+ if(*optarg == '\0' ||
+ strcmp(optarg + 1, "yes") == 0 ||
+ strcmp(optarg + 1, "true") == 0){
+ *flag = !negate;
+ return 0;
+ } else if (*optarg && strcmp(optarg + 1, "maybe") == 0) {
+ *flag = rand() & 1;
+ } else {
+ *flag = negate;
+ return 0;
+ }
+ return ARG_ERR_BAD_ARG;
+ }
+ case arg_counter :
+ {
+ int val;
+
+ if (*optarg == '\0')
+ val = 1;
+ else {
+ char *endstr;
+
+ val = strtol (optarg, &endstr, 0);
+ if (endstr == optarg)
+ return ARG_ERR_BAD_ARG;
+ }
+ *(int *)current->value += val;
+ return 0;
+ }
+ case arg_double:
+ {
+ double tmp;
+ if(sscanf(optarg + 1, "%lf", &tmp) != 1)
+ return ARG_ERR_BAD_ARG;
+ *(double*)current->value = tmp;
+ return 0;
+ }
+ case arg_collect:{
+ struct getarg_collect_info *c = current->value;
+ int o = argv - rargv[*optind];
+ return (*c->func)(FALSE, argc, rargv, optind, &o, c->data);
+ }
+
+ default:
+ abort ();
+ }
+}
+
+static int
+arg_match_short (struct getargs *args, size_t num_args,
+ char *argv, int argc, const char **rargv, int *optind)
+{
+ int j, k;
+
+ for(j = 1; j > 0 && j < (int)strlen(rargv[*optind]); j++) {
+ for(k = 0; k < (int)num_args; k++) {
+ char *optarg;
+
+ if(args[k].short_name == 0)
+ continue;
+ if(argv[j] == args[k].short_name) {
+ if(args[k].type == arg_flag) {
+ *(int*)args[k].value = 1;
+ break;
+ }
+ if(args[k].type == arg_negative_flag) {
+ *(int*)args[k].value = 0;
+ break;
+ }
+ if(args[k].type == arg_counter) {
+ ++*(int *)args[k].value;
+ break;
+ }
+ if(args[k].type == arg_collect) {
+ struct getarg_collect_info *c = args[k].value;
+
+ if((*c->func)(TRUE, argc, rargv, optind, &j, c->data))
+ return ARG_ERR_BAD_ARG;
+ break;
+ }
+
+ if(argv[j + 1])
+ optarg = &argv[j + 1];
+ else {
+ ++*optind;
+ optarg = (char *) rargv[*optind];
+ }
+ if(optarg == NULL) {
+ --*optind;
+ return ARG_ERR_NO_ARG;
+ }
+ if(args[k].type == arg_integer) {
+ int tmp;
+ if(sscanf(optarg, "%d", &tmp) != 1)
+ return ARG_ERR_BAD_ARG;
+ *(int*)args[k].value = tmp;
+ return 0;
+ } else if(args[k].type == arg_string) {
+ *(char**)args[k].value = optarg;
+ return 0;
+ } else if(args[k].type == arg_strings) {
+ add_string((getarg_strings*)args[k].value, optarg);
+ return 0;
+ } else if(args[k].type == arg_double) {
+ double tmp;
+ if(sscanf(optarg, "%lf", &tmp) != 1)
+ return ARG_ERR_BAD_ARG;
+ *(double*)args[k].value = tmp;
+ return 0;
+ }
+ return ARG_ERR_BAD_ARG;
+ }
+ }
+ if (k == (int)num_args)
+ return ARG_ERR_NO_MATCH;
+ }
+ return 0;
+}
+
+int
+getarg(struct getargs *args, size_t num_args,
+ int argc, const char **argv, int *optind)
+{
+ int i;
+ int ret = 0;
+
+ srand (time(NULL));
+ (*optind)++;
+ for(i = *optind; i < argc; i++) {
+ if(argv[i][0] != '-')
+ break;
+ if(argv[i][1] == '-'){
+ if(argv[i][2] == 0){
+ i++;
+ break;
+ }
+ ret = arg_match_long (args, num_args, (char *) argv[i] + 2,
+ argc, argv, &i);
+ } else {
+ ret = arg_match_short (args, num_args, (char *) argv[i],
+ argc, argv, &i);
+ }
+ if(ret)
+ break;
+ }
+ *optind = i;
+ return ret;
+}
+
+
+#if TEST
+int foo_flag = 2;
+int flag1 = 0;
+int flag2 = 0;
+int bar_int;
+char *baz_string;
+
+struct getargs args[] = {
+ { NULL, '1', arg_flag, &flag1, "one", NULL },
+ { NULL, '2', arg_flag, &flag2, "two", NULL },
+ { "foo", 'f', arg_negative_flag, &foo_flag, "foo", NULL },
+ { "bar", 'b', arg_integer, &bar_int, "bar", "seconds"},
+ { "baz", 'x', arg_string, &baz_string, "baz", "name" },
+};
+
+int main(int argc, char **argv)
+{
+ int optind = 0;
+ while(getarg(args, 5, argc, argv, &optind))
+ printf("Bad arg: %s\n", argv[optind]);
+ printf("flag1 = %d\n", flag1);
+ printf("flag2 = %d\n", flag2);
+ printf("foo_flag = %d\n", foo_flag);
+ printf("bar_int = %d\n", bar_int);
+ printf("baz_flag = %s\n", baz_string);
+ arg_printusage (args, 5, argv[0], "nothing here");
+}
+#endif