|
Samba 国際化プロジェクト > smbtorture の詳細
smbtorture の詳細目次smbtorture について
smbtortureはSambaサーバが想定されたように動作しているかを確かめる、テスト用クライアントツールです。
$ cd source $ make smbtortureビルドファームでのSambaサーバ動作確認には主にこのプログラムが使用されています。しかし、テストするパラメータがハードコーディングされているため、国際化対応のテストに関しては十分ではありません。 そこで、このプロジェクトでは smbtorture の機能を拡張し、さまざまな文字列を渡してSambaサーバの国際化対応を確認するテストを追加しました。 このドキュメントは smbtorture に新しいテストを追加する方法をまとめたものです。 smbtorture に新しいテストを追加するには
smbtorture に新しいテストを追加するには、torture/torture.c に次の修正を
加えます。
name ・・・ コマンドラインで指定するテスト名 fn ・・・ テスト内で実行される関数 flags ・・・ マルチプロセスを使用するかどうかのフラグここでは実例として、DUMMY というテストを追加してみます。
static struct {
const char *name;
BOOL (*fn)(int);
unsigned flags;
} torture_ops[] = {
{"FDPASS", run_fdpasstest, 0},
{"LOCK1", run_locktest1, 0},
:
:
{"DUMMY", run_dummy, 0}, <=== 追加
{NULL,NULL,0}
};
上の例では、テスト名は "DUMMY"、DUMMY テストの実装は "run_dummy(int)" 関数で行われます。まず run_test 関数を実装する前に下準備をする必要があります。
もし run_dummy 関数を torture/torture.c 以外の新しいファイルの中で定義したい場合は、いくつかの必要なパラメータをインクルードする必要があります。テストパッチを当てたSamba 3.0では source/torture/torture.h というファイルがありますので、このファイルをインクルードしてください。
#include "../torture/torture.h"
また、たとえば source/torture/dummytest.c を新しく作成した場合、source/Makefile.in も以下のように編集して smbtorture のビルド時にリンクされるようにします。
SMBTORTURE_OBJ1 = torture/torture.o torture/nbio.o torture/scanner.o torture/utable.o \
torture/denytest.o torture/mangle_test.o \
torture/dummytest.o <=== 追加
なお、この作業は関数を直接 torture.c に追加する場合は必要ありません。
以上の作業を行ったら、run_test 関数の実装を行います。 この関数は引数で int を受け取りますが、この値はマルチプロセス用テストに使用されるので、今回のテスト関数内では使用しません。 smbtorture のテストは、テストに成功したら True、失敗したら False を返します。 ここでは一番簡単な例として、つねに成功するテストを作成してみましょう。
static BOOL run_dummy(int dummy)
{
printf("This is dummy\n");
return True;
}
以上で新しいテストの追加作業は終了しました。source ディレクトリで $ make torture を実行し、smbtorture をビルドします。 Makefile.in などを編集した場合は、header などを削除してから再度コンパイルしてください。
$ cd samba/source
$ make delheaders headers
$ make proto
$ make smbtorture
ビルドが終わったら smbtorture の usage を参照して、使用可能なテストの
リストに DUMMY が入ってるのを確認します。
$ smbtorture -h
Usage: smbtorture //server/share
DUMMY テストを実行するには、次のようにテストを指定します。
$ smbtorture //server/share -U user%passwd DUMMY
テストが終了すると、その結果が画面に表示されます。
smbtorture のサンプルコード
以下は、smbtorture に新たなテストを加える、簡単なコードサンプルです。
--- samba-3.0.0.org/source/torture/torture.c Wed Oct 1 16:44:00 2003
+++ samba-3.0.0/source/torture/torture.c Thu Oct 2 16:01:14 2003
@@ -34,6 +34,7 @@
static BOOL use_oplocks;
static BOOL use_level_II_oplocks;
static const char *client_txt = "client_oplocks.txt";
+static const char *i18n_txt = "i18n_chars.txt";
static BOOL use_kerberos;
BOOL torture_showall = False;
@@ -4417,6 +4418,119 @@
return True;
}
+
+static BOOL test_i18n_file(struct cli_state *cli, pstring *filename) {
+
+ fstring fname;
+ pstring pname;
+ int fnum;
+ BOOL correct = True;
+
+ slprintf(fname, sizeof(fname), "\\%s", filename);
+
+ cli_unlink(cli, fname);
+
+ fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
+ if (fnum == -1) {
+ printf("ERROR: Failed to open %s\n", fname);
+ correct = False;
+ }
+
+ if (!cli_qfilename(cli, fnum, pname)) {
+ printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
+ correct = False;
+ }
+
+ if (strcmp(pname, fname)) {
+ printf("ERROR: qfilename returned different names? [%s] [%s]\n",
+ fname, pname);
+ correct = False;
+ } else {
+ printf("RESULT: same value provided by qfilename [%s]\n", fname);
+ }
+
+ cli_close(cli, fnum);
+
+ if (!cli_unlink(cli, fname)) {
+ printf("ERROR: deleting file (%s) failed\n", fname);
+ correct = False;
+ }
+
+ return correct;
+}
+
+
+static BOOL run_i18n_test(int dummy) {
+
+ struct cli_state *cli;
+ pstring line;
+ int i, j;
+ const char *params[20];
+ int line_count = 0;
+ int test_count = 0;
+ int success_count = 0;
+ BOOL correct = True;
+ FILE *f;
+
+ printf("starting i18n file test\n");
+
+ if (!torture_open_connection(&cli)) {
+ printf("ERROR: connection to the server failed!\n");
+ return False;
+ }
+
+ cli_sockopt(cli, sockops);
+
+ f = fopen(i18n_txt, "r");
+ if (!f) {
+ perror(i18n_txt);
+ torture_close_connection(cli);
+ return False;
+ }
+
+ while (fgets(line, sizeof(line)-1, f)) {
+ line_count++;
+
+ line[strlen(line)-1] = 0;
+
+ printf("[%d] %s\n", line_count, line);
+
+ /* parse the command parameters */
+ params[0] = strtok(line," ");
+ i = 0;
+ while (params[i]) params[++i] = strtok(NULL," ");
+ params[i] = '\0';
+
+ j = 0;
+ while (params[j]) {
+ printf("Test filename is (%s)\n",params[j]);
+ test_count++;
+ if (test_i18n_file(cli,params[j++])) {
+ success_count++;
+ } else {
+ correct = False;
+ }
+ }
+
+ }
+ fclose(f);
+
+ if (!torture_close_connection(cli)) {
+ printf("ERROR: disconnection to the server failed!\n");
+ correct = False;
+ }
+
+ if (test_count==success_count) {
+ printf("All tests have succeeded. (%d/%d)\n", success_count,
+ test_count);
+ } else {
+ printf("Some tests have failed. (%d/%d)\n", success_count,
+ test_count);
+ }
+
+ return correct;
+}
+
static double create_procs(BOOL (*fn)(int), BOOL *result)
{
int i, status;
@@ -4566,6 +4680,7 @@
{"IOCTL", torture_ioctl_test, 0},
{"CHKPATH", torture_chkpath_test, 0},
{"FDSESS", run_fdsesstest, 0},
+ {"I18N", run_i18n_test, 0},
{NULL, NULL, 0}};
@@ -4621,7 +4736,7 @@
printf("\t-d debuglevel\n");
printf("\t-U user%%pass\n");
- printf("\t-k use kerberos\n");
+ printf("\t-k use kerberos\n");
printf("\t-N numprocs\n");
printf("\t-n my_netbios_name\n");
printf("\t-W workgroup\n");
@@ -4630,6 +4745,7 @@
printf("\t-m maximum protocol\n");
printf("\t-L use oplocks\n");
printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
+ printf("\t-i I18N.TXT specify i18n load file for I18N\n");
printf("\t-A showall\n");
printf("\t-p port\n");
printf("\t-s seed\n");
@@ -4701,7 +4817,7 @@
fstrcpy(workgroup, lp_workgroup());
- while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Ac:ks:")) != EOF) {
+ while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Aci:ks:")) != EOF) {
switch (opt) {
case 'p':
port_to_use = atoi(optarg);
@@ -4738,6 +4854,9 @@
break;
case 'c':
client_txt = optarg;
+ break;
+ case 'i':
+ i18n_txt = optarg;
break;
case 'k':
#ifdef HAVE_KRB5
|
|