1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light user test program
6 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #include <sys/types.h>
34 #include <sys/queue.h>
40 #include "test_common.h"
46 sprintf(buf, "===== START: %s ", (str)); \
49 memset(buf+len, '=', 100-len); \
58 printf("----- END TEST successfully ---"); \
59 printf("-----------------------------"); \
60 printf("-------------------\n"); \
65 char *path="/mnt/lustre/test_t1";
66 ENTRY("create/delete");
75 char *path="/mnt/lustre/test_t2";
85 char *path="/mnt/lustre/test_t3";
86 ENTRY("regular stat");
89 t_check_stat(path, NULL);
96 char *path="/mnt/lustre/test_t4";
100 t_check_stat(path, NULL);
105 #define PAGE_SIZE (4096)
106 #define _npages (2048)
108 static int _buffer[_npages][PAGE_SIZE/sizeof(int)];
110 /* pos: i/o start from
111 * xfer: npages per transfer
113 static void pages_io(int xfer, loff_t pos)
115 char *path="/mnt/lustre/test_t5";
116 int check_sum[_npages] = {0,};
119 memset(_buffer, 0, sizeof(_buffer));
121 /* create sample data */
122 for (i = 0; i < _npages; i++) {
123 for (j = 0; j < PAGE_SIZE/sizeof(int); j++) {
124 _buffer[i][j] = rand();
128 /* compute checksum */
129 for (i = 0; i < _npages; i++) {
130 for (j = 0; j < PAGE_SIZE/sizeof(int); j++) {
131 check_sum[i] += _buffer[i][j];
140 lseek(fd, pos, SEEK_SET);
141 for (i = 0; i < _npages; i += xfer) {
142 rc = write(fd, _buffer[i], PAGE_SIZE * xfer);
143 if (rc != PAGE_SIZE * xfer) {
144 printf("write error %d (i = %d)\n", rc, i);
148 printf("succefully write %d pages(%d per xfer)\n", _npages, xfer);
149 memset(_buffer, 0, sizeof(_buffer));
152 lseek(fd, pos, SEEK_SET);
153 for (i = 0; i < _npages; i += xfer) {
154 rc = read(fd, _buffer[i], PAGE_SIZE * xfer);
155 if (rc != PAGE_SIZE * xfer) {
156 printf("read error %d (i = %d)\n", rc, i);
160 printf("succefully read %d pages(%d per xfer)\n", _npages, xfer);
162 /* compute checksum */
163 for (i = 0; i < _npages; i++) {
165 for (j = 0; j < PAGE_SIZE/sizeof(int); j++) {
166 sum += _buffer[i][j];
168 if (sum != check_sum[i]) {
169 printf("chunk %d checksum error: expected 0x%x, get 0x%x\n",
170 i, check_sum[i], sum);
173 printf("checksum verified OK!\n");
182 loff_t off_array[] = {1, 4, 17, 255, 258, 4095, 4097, 8191, 1024*1024*1024};
186 while (np <= _npages) {
187 sprintf(text, "pages_io: %d per transfer, offset %lld",
190 pages_io(np, offset);
195 for (i = 0; i < sizeof(off_array)/sizeof(loff_t); i++) {
196 offset = off_array[i];
197 sprintf(text, "pages_io: 16 per transfer, offset %lld",
200 pages_io(16, offset);
207 char *path="/mnt/lustre/test_t6";
208 char *path2="/mnt/lustre/test_t6_link";
212 t_symlink(path, path2);
213 t_check_stat(path2, NULL);
221 char *path="/mnt/lustre/test_t7";
224 t_mknod(path, S_IFCHR | 0644, 5, 4);
225 t_check_stat(path, NULL);
232 char *path="/mnt/lustre/test_t8";
236 t_chmod_raw(path, 0700);
237 t_check_stat(path, NULL);
244 char *path="/mnt/lustre/test_t9";
245 char *path2="/mnt/lustre/test_t9_link";
250 t_check_stat(path, NULL);
251 t_check_stat(path2, NULL);
259 char *dir1="/mnt/lustre/test_t10_dir1";
260 char *dir2="/mnt/lustre/test_t10_dir2";
261 char *path1="/mnt/lustre/test_t10_reg1";
262 char *path2="/mnt/lustre/test_t10_reg2";
263 char *rename1="/mnt/lustre/test_t10_dir1/rename1";
264 char *rename2="/mnt/lustre/test_t10_dir2/rename2";
265 char *rename3="/mnt/lustre/test_t10_dir2/rename3";
272 t_rename(path1, rename1);
273 t_rename(path2, rename2);
274 t_rename(rename1, rename2);
275 t_rename(dir1, rename3);
284 char *base="/mnt/lustre";
285 char path[4096], path2[4096];
286 int i, j, level = 5, nreg = 5;
291 for (i = 0; i < level; i++) {
292 for (j = 0; j < nreg; j++) {
293 sprintf(path2, "%s/file%d", path, j);
297 strcat(path, "/dir");
301 for (i = level; i > 0; i--) {
303 for (j = 1; j < i; j++)
304 strcat(path, "/dir");
306 for (j = 0; j < nreg; j++) {
307 sprintf(path2, "%s/file%d", path, j);
311 strcat(path, "/dir");
320 char *dir="/mnt/lustre/test_t12_dir";
323 ENTRY("empty directory readdir");
327 t_ls(fd, buf, sizeof(buf));
335 char *dir="/mnt/lustre/test_t13_dir/";
338 const int nfiles = 20;
339 char *prefix = "test13_filename_prefix_";
341 ENTRY("multiple entries directory readdir");
344 printf("Creating %d files...\n", nfiles);
345 for (i = 0; i < nfiles; i++) {
346 sprintf(name, "%s%s%05d", dir, prefix, i);
350 t_ls(fd, buf, sizeof(buf));
352 printf("Cleanup...\n");
353 for (i = 0; i < nfiles; i++) {
354 sprintf(name, "%s%s%05d", dir, prefix, i);
363 char *dir="/mnt/lustre/test_t14_dir/";
366 const int nfiles = 256;
367 char *prefix = "test14_filename_long_prefix_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA___";
369 ENTRY(">1 block(4k) directory readdir");
372 printf("Creating %d files...\n", nfiles);
373 for (i = 0; i < nfiles; i++) {
374 sprintf(name, "%s%s%05d", dir, prefix, i);
378 t_ls(fd, buf, sizeof(buf));
380 printf("Cleanup...\n");
381 for (i = 0; i < nfiles; i++) {
382 sprintf(name, "%s%s%05d", dir, prefix, i);
391 char *file = "/mnt/lustre/test_t15_file";
393 ENTRY("open-stat-close");
397 t_check_stat(file, NULL);
403 extern void __liblustre_setup_(void);
404 extern void __liblustre_cleanup_(void);
406 void usage(char *cmd)
408 printf("Usage: \t%s --target mdsnid:/mdsname/profile\n", cmd);
409 printf(" \t%s --dumpfile dumpfile\n", cmd);
413 int main(int argc, char * const argv[])
416 static struct option long_opts[] = {
418 {"dumpfile", 1, 0, 0},
425 while ((c = getopt_long(argc, argv, "", long_opts, &opt_index)) != -1) {
431 if (!strcmp(long_opts[opt_index].name, "target")) {
432 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
433 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
434 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
447 __liblustre_setup_();
467 printf("liblustre is about shutdown\n");
468 __liblustre_cleanup_();
470 printf("complete successfully\n");