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 (512)
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\n", _npages);
150 memset(_buffer, 0, sizeof(_buffer));
153 lseek(fd, pos, SEEK_SET);
154 for (i = 0; i < _npages; i += xfer) {
155 rc = read(fd, _buffer[i], PAGE_SIZE * xfer);
156 if (rc != PAGE_SIZE * xfer) {
157 printf("read error %d (i = %d)\n", rc, i);
161 printf("succefully read %d pages\n", _npages);
163 /* compute checksum */
164 for (i = 0; i < _npages; i++) {
166 for (j = 0; j < PAGE_SIZE/sizeof(int); j++) {
167 sum += _buffer[i][j];
169 if (sum != check_sum[i]) {
170 printf("chunk %d checksum error: expected 0x%x, get 0x%x\n",
171 i, check_sum[i], sum);
174 printf("checksum verified OK!\n");
183 loff_t off_array[] = {1, 17, 255, 257, 4095, 4097, 8191, 1024*1024*1024};
187 while (np <= _npages) {
188 sprintf(text, "pages_io: %d per transfer, offset %lld",
191 pages_io(np, offset);
196 for (i = 0; i < sizeof(off_array)/sizeof(loff_t); i++) {
197 offset = off_array[i];
198 sprintf(text, "pages_io: 16 per transfer, offset %lld",
201 pages_io(16, offset);
208 char *path="/mnt/lustre/test_t6";
209 char *path2="/mnt/lustre/test_t6_link";
213 t_symlink(path, path2);
214 t_check_stat(path2, NULL);
222 char *path="/mnt/lustre/test_t7";
225 t_mknod(path, S_IFCHR | 0644, 5, 4);
226 t_check_stat(path, NULL);
233 char *path="/mnt/lustre/test_t8";
237 t_chmod_raw(path, 0700);
238 t_check_stat(path, NULL);
245 char *path="/mnt/lustre/test_t9";
246 char *path2="/mnt/lustre/test_t9_link";
251 t_check_stat(path, NULL);
252 t_check_stat(path2, NULL);
260 char *dir1="/mnt/lustre/test_t10_dir1";
261 char *dir2="/mnt/lustre/test_t10_dir2";
262 char *path1="/mnt/lustre/test_t10_reg1";
263 char *path2="/mnt/lustre/test_t10_reg2";
264 char *rename1="/mnt/lustre/test_t10_dir1/rename1";
265 char *rename2="/mnt/lustre/test_t10_dir2/rename2";
266 char *rename3="/mnt/lustre/test_t10_dir2/rename3";
273 t_rename(path1, rename1);
274 t_rename(path2, rename2);
275 t_rename(rename1, rename2);
276 t_rename(dir1, rename3);
285 char *base="/mnt/lustre";
286 char path[4096], path2[4096];
287 int i, j, level = 5, nreg = 5;
292 for (i = 0; i < level; i++) {
293 for (j = 0; j < nreg; j++) {
294 sprintf(path2, "%s/file%d", path, j);
298 strcat(path, "/dir");
302 for (i = level; i > 0; i--) {
304 for (j = 1; j < i; j++)
305 strcat(path, "/dir");
307 for (j = 0; j < nreg; j++) {
308 sprintf(path2, "%s/file%d", path, j);
312 strcat(path, "/dir");
319 extern void __liblustre_setup_(void);
320 extern void __liblustre_cleanup_(void);
322 void usage(char *cmd)
324 printf("Usage: \t%s --target mdsnid:/mdsname/profile\n", cmd);
325 printf(" \t%s --dumpfile dumpfile\n", cmd);
329 int main(int argc, char * const argv[])
332 static struct option long_opts[] = {
334 {"dumpfile", 1, 0, 0},
341 while ((c = getopt_long(argc, argv, "", long_opts, &opt_index)) != -1) {
344 printf("optindex %d\n", opt_index);
348 if (!strcmp(long_opts[opt_index].name, "target")) {
349 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
350 } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
351 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
364 __liblustre_setup_();
381 printf("liblustre is about shutdown\n");
382 __liblustre_cleanup_();
384 printf("complete successfully\n");