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 #define MAX_PATH_LENGTH 4096
110 static int _buffer[_npages][PAGE_SIZE/sizeof(int)];
112 /* pos: i/o start from
113 * xfer: npages per transfer
115 static void pages_io(int xfer, loff_t pos)
117 char *path="/mnt/lustre/test_t5";
118 int check_sum[_npages] = {0,};
121 memset(_buffer, 0, sizeof(_buffer));
123 /* create sample data */
124 for (i = 0; i < _npages; i++) {
125 for (j = 0; j < PAGE_SIZE/sizeof(int); j++) {
126 _buffer[i][j] = rand();
130 /* compute checksum */
131 for (i = 0; i < _npages; i++) {
132 for (j = 0; j < PAGE_SIZE/sizeof(int); j++) {
133 check_sum[i] += _buffer[i][j];
142 lseek(fd, pos, SEEK_SET);
143 for (i = 0; i < _npages; i += xfer) {
144 rc = write(fd, _buffer[i], PAGE_SIZE * xfer);
145 if (rc != PAGE_SIZE * xfer) {
146 printf("write error %d (i = %d)\n", rc, i);
150 printf("succefully write %d pages(%d per xfer)\n", _npages, xfer);
151 memset(_buffer, 0, sizeof(_buffer));
154 lseek(fd, pos, SEEK_SET);
155 for (i = 0; i < _npages; i += xfer) {
156 rc = read(fd, _buffer[i], PAGE_SIZE * xfer);
157 if (rc != PAGE_SIZE * xfer) {
158 printf("read error %d (i = %d)\n", rc, i);
162 printf("succefully read %d pages(%d per xfer)\n", _npages, xfer);
164 /* compute checksum */
165 for (i = 0; i < _npages; i++) {
167 for (j = 0; j < PAGE_SIZE/sizeof(int); j++) {
168 sum += _buffer[i][j];
170 if (sum != check_sum[i]) {
171 printf("chunk %d checksum error: expected 0x%x, get 0x%x\n",
172 i, check_sum[i], sum);
175 printf("checksum verified OK!\n");
184 loff_t off_array[] = {1, 4, 17, 255, 258, 4095, 4097, 8191, 1024*1024*1024};
188 while (np <= _npages) {
189 sprintf(text, "pages_io: %d per transfer, offset %lld",
192 pages_io(np, offset);
197 for (i = 0; i < sizeof(off_array)/sizeof(loff_t); i++) {
198 offset = off_array[i];
199 sprintf(text, "pages_io: 16 per transfer, offset %lld",
202 pages_io(16, offset);
209 char *path="/mnt/lustre/test_t6";
210 char *path2="/mnt/lustre/test_t6_link";
214 t_symlink(path, path2);
215 t_check_stat(path2, NULL);
223 char *path="/mnt/lustre/test_t7";
226 t_mknod(path, S_IFCHR | 0644, 5, 4);
227 t_check_stat(path, NULL);
234 char *path="/mnt/lustre/test_t8";
238 t_chmod_raw(path, 0700);
239 t_check_stat(path, NULL);
246 char *path="/mnt/lustre/test_t9";
247 char *path2="/mnt/lustre/test_t9_link";
252 t_check_stat(path, NULL);
253 t_check_stat(path2, NULL);
261 char *dir1="/mnt/lustre/test_t10_dir1";
262 char *dir2="/mnt/lustre/test_t10_dir2";
263 char *path1="/mnt/lustre/test_t10_reg1";
264 char *path2="/mnt/lustre/test_t10_reg2";
265 char *rename1="/mnt/lustre/test_t10_dir1/rename1";
266 char *rename2="/mnt/lustre/test_t10_dir2/rename2";
267 char *rename3="/mnt/lustre/test_t10_dir2/rename3";
274 t_rename(path1, rename1);
275 t_rename(path2, rename2);
276 t_rename(rename1, rename2);
277 t_rename(dir1, rename3);
286 char *base="/mnt/lustre";
287 char path[MAX_PATH_LENGTH], path2[MAX_PATH_LENGTH];
288 int i, j, level = 5, nreg = 5;
291 safe_strncpy(path, base, MAX_PATH_LENGTH);
293 for (i = 0; i < level; i++) {
294 for (j = 0; j < nreg; j++) {
295 sprintf(path2, "%s/file%d", path, j);
299 strcat(path, "/dir");
303 for (i = level; i > 0; i--) {
304 safe_strncpy(path, base, MAX_PATH_LENGTH);
305 for (j = 1; j < i; j++)
306 strcat(path, "/dir");
308 for (j = 0; j < nreg; j++) {
309 sprintf(path2, "%s/file%d", path, j);
313 strcat(path, "/dir");
322 char *dir="/mnt/lustre/test_t12_dir";
325 ENTRY("empty directory readdir");
329 t_ls(fd, buf, sizeof(buf));
337 char *dir="/mnt/lustre/test_t13_dir/";
340 const int nfiles = 20;
341 char *prefix = "test13_filename_prefix_";
343 ENTRY("multiple entries directory readdir");
346 printf("Creating %d files...\n", nfiles);
347 for (i = 0; i < nfiles; i++) {
348 sprintf(name, "%s%s%05d", dir, prefix, i);
352 t_ls(fd, buf, sizeof(buf));
354 printf("Cleanup...\n");
355 for (i = 0; i < nfiles; i++) {
356 sprintf(name, "%s%s%05d", dir, prefix, i);
365 char *dir="/mnt/lustre/test_t14_dir/";
368 const int nfiles = 256;
369 char *prefix = "test14_filename_long_prefix_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA___";
371 ENTRY(">1 block(4k) directory readdir");
374 printf("Creating %d files...\n", nfiles);
375 for (i = 0; i < nfiles; i++) {
376 sprintf(name, "%s%s%05d", dir, prefix, i);
380 t_ls(fd, buf, sizeof(buf));
382 printf("Cleanup...\n");
383 for (i = 0; i < nfiles; i++) {
384 sprintf(name, "%s%s%05d", dir, prefix, i);
393 char *file = "/mnt/lustre/test_t15_file";
395 ENTRY("open-stat-close");
399 t_check_stat(file, NULL);
405 extern void __liblustre_setup_(void);
406 extern void __liblustre_cleanup_(void);
408 void usage(char *cmd)
410 printf("Usage: \t%s --target mdsnid:/mdsname/profile\n", cmd);
411 printf(" \t%s --dumpfile dumpfile\n", cmd);
415 int main(int argc, char * const argv[])
418 static struct option long_opts[] = {
420 {"dumpfile", 1, 0, 0},
427 while ((c = getopt_long(argc, argv, "", long_opts, &opt_index)) != -1) {
433 if (!strcmp(long_opts[opt_index].name, "target")) {
434 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
435 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
436 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
449 __liblustre_setup_();
469 printf("liblustre is about shutdown\n");
470 __liblustre_cleanup_();
472 printf("complete successfully\n");